[Vm-dev] VM Maker: Cog-eem.47.mcz

commits at source.squeak.org commits at source.squeak.org
Thu Apr 5 17:00:36 UTC 2012


Eliot Miranda uploaded a new version of Cog to project VM Maker:
http://source.squeak.org/VMMaker/Cog-eem.47.mcz

==================== Summary ====================

Name: Cog-eem.47
Author: eem
Time: 5 April 2012, 10:00:28.116 am
UUID: 00cfe515-a00e-43b8-97b4-a117046d5ed0
Ancestors: Cog-eem.46

Moved TempScopeEditor to its own package
(http://source.squeak.org/trunk/TemporaryVariableScopeEditor)

=============== Diff against Cog-eem.46 ===============

Item was removed:
- ParseNodeVisitor subclass: #BlockNodeCollectingVisitor
- 	instanceVariableNames: 'blockNodes'
- 	classVariableNames: ''
- 	poolDictionaries: ''
- 	category: 'Cog-Scripts'!

Item was removed:
- ----- Method: BlockNodeCollectingVisitor>>blockNodes (in category 'accessing') -----
- blockNodes
- 	^blockNodes!

Item was removed:
- ----- Method: BlockNodeCollectingVisitor>>visitBlockNode: (in category 'visiting') -----
- visitBlockNode: aBlockNode
- 	(blockNodes ifNil: [blockNodes := OrderedCollection new]) addLast: aBlockNode.
- 	super visitBlockNode: aBlockNode!

Item was removed:
- ParseNodeVisitor subclass: #ReadBeforeWrittenVisitor
- 	instanceVariableNames: 'readBeforeWritten written'
- 	classVariableNames: ''
- 	poolDictionaries: ''
- 	category: 'Cog-Scripts'!
- 
- !ReadBeforeWrittenVisitor commentStamp: '<historical>' prior: 0!
- Answer the set of temporary variables that are read before they are written.!

Item was removed:
- ----- Method: ReadBeforeWrittenVisitor>>readBeforeWritten (in category 'accessing') -----
- readBeforeWritten
- 	^readBeforeWritten ifNil: [IdentitySet new]!

Item was removed:
- ----- Method: ReadBeforeWrittenVisitor>>visitAssignmentNode: (in category 'visiting') -----
- visitAssignmentNode: anAssignmentNode
- 	anAssignmentNode value accept: self.
- 	anAssignmentNode variable isTemp
- 		ifTrue:
- 			[written ifNil: [written := IdentitySet new].
- 			 written add: anAssignmentNode variable]
- 		ifFalse:
- 			[anAssignmentNode variable accept: self]!

Item was removed:
- ----- Method: ReadBeforeWrittenVisitor>>visitBlockNode: (in category 'visiting') -----
- visitBlockNode: aBlockNode
- 	| savedWritten |
- 	savedWritten := written copy.
- 	super visitBlockNode: aBlockNode.
- 	written := savedWritten!

Item was removed:
- ----- Method: ReadBeforeWrittenVisitor>>visitTempVariableNode: (in category 'visiting') -----
- visitTempVariableNode: aTempVariableNode
- 	(aTempVariableNode isArg
- 	 or: [written notNil
- 		and: [written includes: aTempVariableNode]]) ifTrue:
- 		[^self].
- 	readBeforeWritten ifNil:
- 		[readBeforeWritten := IdentitySet new].
- 	readBeforeWritten add: aTempVariableNode!

Item was removed:
- Object subclass: #TempScopeEditor
- 	instanceVariableNames: 'method methodNode out tempMap blockNodes sourceString soFar'
- 	classVariableNames: ''
- 	poolDictionaries: ''
- 	category: 'Cog-Scripts'!

Item was removed:
- ----- Method: TempScopeEditor class>>edit (in category 'as yet unclassified') -----
- edit
- 	"Trawl the system for methods containing misdeclared temps and correct these methods."
- 	SystemNavigation default allSelect:
- 		[:m| | scanner |
- 		(m isQuick not
- 		and: [(scanner := InstructionStream on: m) scanFor:
- 				[:b| b = 143 and: [scanner followingByte >= 16]]]) ifTrue:
- 			[(self new forMethod: m) edit].
- 		false]!

Item was removed:
- ----- Method: TempScopeEditor>>anyScopes:outsideExtent: (in category 'editing') -----
- anyScopes: referenceScopeDict outsideExtent: blockExtent
- 	^referenceScopeDict notNil
- 	   and: [referenceScopeDict notEmpty
- 	   and: [referenceScopeDict anySatisfy:
- 			[:set|
- 			set anySatisfy: [:location| (blockExtent rangeIncludes: location) not]]]]!

Item was removed:
- ----- Method: TempScopeEditor>>blockNode:isEnclosingScopeFor: (in category 'editing') -----
- blockNode: aBlockNode isEnclosingScopeFor: aTempVariableNode 
- 	^((self
- 		anyScopes: (aTempVariableNode instVarNamed: 'readingScopes')
- 		outsideExtent: aBlockNode blockExtent)
- 	or: [self
- 		anyScopes: (aTempVariableNode instVarNamed: 'writingScopes')
- 		outsideExtent: aBlockNode blockExtent]) not!

Item was removed:
- ----- Method: TempScopeEditor>>buildTempMap (in category 'editing') -----
- buildTempMap
- 	"Build the map for moving remote temps. Each remote temp
- 	 that should be moved is entered into the map referencing its
- 	 smallest enclosing scope.  This may seem backwards but it
- 	 means that the map is one-to-one, not one-to-many."
- 	| readBeforeWritten |
- 	readBeforeWritten := (methodNode accept: ReadBeforeWrittenVisitor new) readBeforeWritten.
- 	blockNodes do:
- 		[:blockNode|
- 		(blockNode temporaries notEmpty
- 		 and: [blockNode temporaries last isIndirectTempVector]) ifTrue:
- 			[blockNode temporaries last remoteTemps do:
- 				[:remoteTemp| | enclosingScopes smallestEnclosingBlockScope |
- 				 (readBeforeWritten includes: remoteTemp) ifFalse:
- 				 	[enclosingScopes := blockNodes select: [:blockScope|
- 															self blockNode: blockScope
- 																isEnclosingScopeFor: remoteTemp].
- 					 enclosingScopes notEmpty ifTrue:
- 						[smallestEnclosingBlockScope := enclosingScopes last.
- 						 smallestEnclosingBlockScope ~~ blockNode ifTrue:
- 							 [tempMap at: remoteTemp put: smallestEnclosingBlockScope]]]]]]!

Item was removed:
- ----- Method: TempScopeEditor>>copyMethodMovingTemps (in category 'editing') -----
- copyMethodMovingTemps
- 	| methodBodyStart tempsToKeep tempsStart tempsEnd |
- 	methodBodyStart := method methodClass parserClass new
- 							parseMethodComment: sourceString setPattern: [:ignored|];
- 							startOfNextToken.
- 	tempsStart := sourceString indexOf: $| startingAt: methodBodyStart.
- 	tempsEnd := sourceString indexOf: $| startingAt: tempsStart + 1.
- 	(tempsToKeep := self tempsToKeepAtMethodLevel) isEmpty
- 		ifTrue:
- 			[| startOfFirstBlock |
- 			 startOfFirstBlock := (methodNode encoder sourceRangeFor: blockNodes second closureCreationNode) first.
- 			 tempsStart < startOfFirstBlock
- 				ifTrue:
- 					 [out next: tempsStart - 1 putAll: sourceString.
- 					  soFar := tempsEnd + 1]
- 				ifFalse:
- 					[soFar := 1]]
- 		ifFalse:
- 			[out next: tempsStart putAll: sourceString.
- 			 tempsToKeep do: [:t| out space; nextPutAll: t name].
- 			 soFar := tempsEnd.
- 			 (sourceString at: soFar - 1) isSeparator ifTrue:
- 				[soFar := soFar - 1]].
- 	blockNodes allButFirst do:
- 		[:blockNode|
- 		self processBlockNode: blockNode].
- 	out next: sourceString size - soFar + 1 putAll: sourceString startingAt: soFar!

Item was removed:
- ----- Method: TempScopeEditor>>edit (in category 'editing') -----
- edit
- 	self buildTempMap.
- 	tempMap notEmpty ifTrue:
- 		[| mr |
- 		 mr := method methodReference.
- 		 self copyMethodMovingTemps.
- 		 Transcript cr; show: mr actualClass name, ' >> ', mr methodSymbol.
- 		 method methodClass compile: out contents classified: mr category]!

Item was removed:
- ----- Method: TempScopeEditor>>editNoCompile (in category 'editing') -----
- editNoCompile
- 	self buildTempMap.
- 	^tempMap isEmpty ifFalse:
- 		[self copyMethodMovingTemps.
- 		 out contents]!

Item was removed:
- ----- Method: TempScopeEditor>>forMethod: (in category 'initialize-release') -----
- forMethod: aCompiledMethod
- 	method := aCompiledMethod.
- 	sourceString := aCompiledMethod getSourceFromFile asString.
- 	methodNode := method methodClass parserClass new
- 						parse: sourceString
- 						class: method methodClass.
- 	methodNode ensureClosureAnalysisDone.
- 	blockNodes := (methodNode accept: BlockNodeCollectingVisitor new)
- 						blockNodes reject: [:bn| bn optimized].
- 	out := (String new: sourceString size) writeStream.
- 	tempMap := IdentityDictionary new
- 
- 
- 	"(TempScopeEditor new forMethod: SARInstaller class>>#ensurePackageWithId:) edit"!

Item was removed:
- ----- Method: TempScopeEditor>>processBlockNode: (in category 'editing') -----
- processBlockNode: blockNode
- 	| tempsToMoveHere startOfBlock endOfArgs maybeBlockTempsStart blockTempsInSource |
- 	tempsToMoveHere := (tempMap select: [:aBlockNode| aBlockNode == blockNode]) keys.
- 	tempsToMoveHere isEmpty ifTrue: [^self].
- 	startOfBlock := (methodNode encoder sourceRangeFor: blockNode closureCreationNode) first.
- 	endOfArgs := blockNode arguments isEmpty
- 					ifTrue: [startOfBlock]
- 					ifFalse: [sourceString indexOf: $| startingAt: startOfBlock].
- 	out next: endOfArgs - soFar + 1 putAll: sourceString startingAt: soFar.
- 	maybeBlockTempsStart := sourceString indexOf: $| startingAt: endOfArgs + 1 ifAbsent: sourceString size + 1.
- 	blockTempsInSource := (sourceString copyFrom: endOfArgs + 1 to: maybeBlockTempsStart - 1) allSatisfy:
- 								[:c| c isSeparator].
- 	blockTempsInSource
- 		ifTrue:
- 			[out next: maybeBlockTempsStart - endOfArgs putAll: sourceString startingAt: endOfArgs + 1.
- 			 (self tempsToKeepFor: blockNode) do:
- 				[:tempNode| out space; nextPutAll: tempNode name].
- 			 tempsToMoveHere do: [:t| out space; nextPutAll: t name].
- 			 soFar := sourceString indexOf: $| startingAt: maybeBlockTempsStart + 1.
- 			 (sourceString at: soFar - 1) isSeparator ifTrue:
- 				[soFar := soFar - 1]]
- 		ifFalse:
- 			[out space; nextPut: $|.
- 			 tempsToMoveHere do: [:t| out space; nextPutAll: t name].
- 			 out space; nextPut: $|.
- 			 soFar := endOfArgs + 1]!

Item was removed:
- ----- Method: TempScopeEditor>>tempsToKeepAtMethodLevel (in category 'editing') -----
- tempsToKeepAtMethodLevel
- 	^(self tempsToKeepFor: blockNodes first) select:
- 		[:t|t scope >= 0]!

Item was removed:
- ----- Method: TempScopeEditor>>tempsToKeepFor: (in category 'editing') -----
- tempsToKeepFor: blockNode
- 	| tempsToKeep |
- 	tempsToKeep := OrderedCollection new.
- 	blockNode temporaries do:
- 		[:t|
- 		t isIndirectTempVector
- 			ifTrue:
- 				[t remoteTemps do:
- 					[:rt|
- 					(tempMap includesKey: rt) ifFalse:
- 						[tempsToKeep addLast: rt]]]
- 			ifFalse:
- 				[tempsToKeep addLast: t]].
- 	^tempsToKeep!



More information about the Vm-dev mailing list