[Vm-dev] VM Maker: VMMaker.oscog-eem.1557.mcz

commits at source.squeak.org commits at source.squeak.org
Sun Dec 6 00:13:04 UTC 2015


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

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

Name: VMMaker.oscog-eem.1557
Author: eem
Time: 5 December 2015, 4:11:06.632 pm
UUID: 62f0e86e-6d1b-4b56-889a-df2f75c352c0
Ancestors: VMMaker.oscog-eem.1556

More propitiation.  Refactor constant output so that macro output for the api header can collect any used constants so there can be emitted too.

=============== Diff against VMMaker.oscog-eem.1556 ===============

Item was changed:
  ----- Method: CCodeGenerator>>emitCAPIExportHeaderOn: (in category 'C code generator') -----
  emitCAPIExportHeaderOn: aStream 
  	"Store prototype declarations for all non-inlined methods on the given stream."
+ 	| api methodList usedConstants |
- 	| api methodList |
  	api := (vmClass translationClass exportAPISelectors: self options).
  	methodList := api
  					select:
  						[:s|
  						(methods includesKey: s)
  						or: [(vmClass whichClassIncludesSelector: s)
  								ifNil: [false]
  								ifNotNil: [:c|self shouldIncludeMethodFor: c selector: s]]]
  					thenCollect:
  						[:s|
  						methods
  							at: s
  							ifAbsent: [self compileToTMethodSelector: s
  										   in: (vmClass whichClassIncludesSelector: s)]].
  	methodList := self sortMethods: methodList.
  	methodList do:
  		[:m|
  		m static ifTrue:
  			[logger ensureCr; show: m selector, ' excluded from export API because it is static'; cr]].
  	self emitCFunctionPrototypes: methodList on: aStream.
  	self emitGlobalCVariablesOn: aStream.
+ 	usedConstants := self emitCMacros: methodList on: aStream.
+ 	self emitCConstants: usedConstants on: aStream!
- 	self emitCMacros: methodList on: aStream!

Item was added:
+ ----- Method: CCodeGenerator>>emitCConstants:on: (in category 'C code generator') -----
+ emitCConstants: constList on: aStream
+ 	"Store the global variable declarations on the given stream."
+ 	constList isEmpty ifTrue: [^self].
+ 	aStream cr; nextPutAll: '/*** Constants ***/'; cr.
+ 	(self sortStrings: constList) do:
+ 		[:varName| | node default value |
+ 		node := constants at: varName.
+ 		node name isEmpty ifFalse:
+ 			["If the definition includes a C comment, take it as is, otherwise convert the value from Smalltalk to C.
+ 			  Allow the class to provide an alternative definition, either of just the value or the whole shebang."
+ 			default := (node value isString and: [node value includesSubString: '/*'])
+ 							ifTrue: [node value]
+ 							ifFalse: [self cLiteralFor: node value name: varName].
+ 			value := vmClass
+ 						ifNotNil:
+ 							[(vmClass specialValueForConstant: node name default: default)
+ 								ifNotNil: [:specialDef| specialDef]
+ 								ifNil: [default]]
+ 						ifNil: [default].
+ 			value first ~= $# ifTrue:
+ 				[aStream nextPutAll: '#define '; nextPutAll: node name; space].
+ 			aStream nextPutAll: value; cr]].
+ 	aStream cr!

Item was changed:
  ----- Method: CCodeGenerator>>emitCConstantsOn: (in category 'C code generator') -----
  emitCConstantsOn: aStream 
  	"Store the global variable declarations on the given stream."
+ 	| unused |
- 	| unused constList |
  	unused := constants keys asSet.
  	"Don't generate any defines for the externally defined constants,
  	 STACKVM, COGVM, COGMTVM et al, unless they're actually used."
  	(VMClass class>>#initializeMiscConstants) literalsDo:
  		[:lit|
  		(lit isVariableBinding and: [lit key isString]) ifTrue:
  			[unused add: lit key]].
  	methods do:
  		[:meth|
  		meth declarations keysDo:
  			[:v|
  			(meth typeFor: v in: self) ifNotNil:
  				[:type| unused remove: type ifAbsent: []]].
  		unused remove: meth returnType ifAbsent: [].
  		meth parseTree nodesDo:
  			[:n| n isConstant ifTrue: [unused remove: n name ifAbsent: []]]].
  	unused copy do:
  		[:const|
  		(variableDeclarations anySatisfy: [:value| value includesSubString: const]) ifTrue:
  			[unused remove: const ifAbsent: []]].
  	"and VMBasicConstants mostBasicConstantNames *must* be taken from interp.h"
  	unused addAll: VMBasicConstants mostBasicConstantNames.
+ 	self emitCConstants: (constants keys reject: [:any| unused includes: any]) on: aStream!
- 	constList := constants keys reject: [:any| unused includes: any].
- 	aStream cr; nextPutAll: '/*** Constants ***/'; cr.
- 	(self sortStrings: constList) do:
- 		[:varName| | node default value |
- 		node := constants at: varName.
- 		node name isEmpty ifFalse:
- 			["If the definition includes a C comment, take it as is, otherwise convert the value from Smalltalk to C.
- 			  Allow the class to provide an alternative definition, either of just the value or the whole shebang."
- 			default := (node value isString and: [node value includesSubString: '/*'])
- 							ifTrue: [node value]
- 							ifFalse: [self cLiteralFor: node value name: varName].
- 			value := vmClass
- 						ifNotNil:
- 							[(vmClass specialValueForConstant: node name default: default)
- 								ifNotNil: [:specialDef| specialDef]
- 								ifNil: [default]]
- 						ifNil: [default].
- 			value first ~= $# ifTrue:
- 				[aStream nextPutAll: '#define '; nextPutAll: node name; space].
- 			aStream nextPutAll: value; cr]].
- 	aStream cr!

Item was changed:
  ----- Method: CCodeGenerator>>emitCMacros:on: (in category 'C code generator') -----
  emitCMacros: methodList on: aStream 
+ 	"Store the global variable declarations on the given stream.  Answer any constants used in the macros."
+ 	| usedConstants |
+ 	macros isEmpty ifTrue: [^#()].
- 	"Store the global variable declarations on the given stream."
- 	macros isEmpty ifTrue: [^self].
  	aStream cr; nextPutAll: '/*** Macros ***/'; cr.
+ 	usedConstants := Set new.
- 
  	(methodList reject: [:m| m isRealMethod]) do:
  		[:m |
  		m definedAsMacro ifTrue:
  			[aStream
  				nextPutAll: '#define ';
  				nextPutAll:(self cFunctionNameFor: m selector);
+ 				nextPutAll: (macros at: m selector); cr.
+ 			 m compiledMethod literalsDo:
+ 				[:lit|
+ 				(lit isVariableBinding and: [(macros at: m selector) includesSubString: lit key]) ifTrue:
+ 					[usedConstants add: lit key]]]].
+ 	aStream cr.
+ 	^usedConstants!
- 				nextPutAll: (macros at: m selector); cr]].
- 	aStream cr!



More information about the Vm-dev mailing list