Skip to content

Commit

Permalink
Exporting to C
Browse files Browse the repository at this point in the history
  • Loading branch information
tesonep committed Jan 26, 2022
1 parent 1132228 commit 1a89716
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 26 deletions.
1 change: 0 additions & 1 deletion smalltalksrc/VMMaker/AbstractImageAccess.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ AbstractImageAccess >> extractImageVersionFrom: fileVersion into: header [
"Read and verify the image file version number and return true if the the given image file needs to be byte-swapped. As a side effect, position the file stream just after the version number of the image header. This code prints a warning and does a hard-exit if it cannot find a valid version number."
"This code is based on C code by Ian Piumarta."

<inline: false>
| version firstVersion |
<var: #file type: #sqImageFile>
<var: #imageOffset type: #squeakFileOffsetType>
Expand Down
2 changes: 2 additions & 0 deletions smalltalksrc/VMMaker/Cogit.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,9 @@ Cogit class >> declareCVarsIn: aCCodeGenerator [
addHeaderFile:'"sqCogStackAlignment.h"';
addHeaderFile:'"dispdbg.h"'; "must precede cointerp.h & cogit.h otherwise NoDbgRegParms gets screwed up"
addHeaderFile:'"cogmethod.h"'.

aCCodeGenerator
addHeaderFile:'"vmMemoryMap.h"';
addHeaderFile:'"cointerp.h"';
addHeaderFile:'"cogit.h"';
addHeaderFile:'<stdint.h>'.
Expand Down
1 change: 0 additions & 1 deletion smalltalksrc/VMMaker/SpurImageReader.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ SpurImageReader >> readSegmentsFromImageFile: f header: aHeader [
segment that specify the distance to and the size of the subsequent segment."

<var: #f type: #sqImageFile>
<inline: false>
<var: 'segInfo' type: #'SpurSegmentInfo *'>
<var: 'aHeader' type: #SpurImageHeaderStruct>
| bytesRead totalBytesRead bridgehead bridge nextSegmentSize oldBase newBase bridgeSpan |
Expand Down
1 change: 0 additions & 1 deletion smalltalksrc/VMMaker/SpurImageWriter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ SpurImageWriter >> writeImageSegmentsToFile: aBinaryStream [

<var: 'aBinaryStream' type: #sqImageFile>
<var: 'aSegment' type:#'SpurSegmentInfo *'>
<inline: false>

| total |

Expand Down
3 changes: 3 additions & 0 deletions smalltalksrc/VMMaker/SpurMemoryManager.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5701,6 +5701,9 @@ SpurMemoryManager >> getMaxOldSpaceSize [
{ #category : #accessing }
SpurMemoryManager >> getMemoryMap [
<api>
<returnTypeC: #'VMMemoryMap *'>
^ memoryMap
]
Expand Down
6 changes: 5 additions & 1 deletion smalltalksrc/VMMaker/StackInterpreter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,9 @@ StackInterpreter class >> additionalHeadersDo: aBinaryBlock [
any additional header files that need to be generated."
aBinaryBlock
value: 'vmCallback.h'
value: self vmCallbackHeader
value: self vmCallbackHeader.

VMMemoryMap generateHeader: aBinaryBlock
]

{ #category : #translation }
Expand All @@ -498,6 +500,7 @@ StackInterpreter class >> ancilliaryClasses [
LibFFI.
CogStackPage.
SpurImageHeaderStruct.
AbstractImageAccess. "I am putting the abstract superclass... because I cannot make it work else"
self imageReaderClass.
self imageWriterClass}
]
Expand All @@ -521,6 +524,7 @@ StackInterpreter class >> declareCVarsIn: aCCodeGenerator [
addHeaderFile:'"vmCallback.h"';
addHeaderFile:'"sqMemoryFence.h"';
addHeaderFile:'"dispdbg.h"';
addHeaderFile:'"vmMemoryMap.h"';

"This cannot be properly expressed in slang.
If ffi is put as a separate header, slang will sort the header and put it outside the #ifdef"
Expand Down
2 changes: 1 addition & 1 deletion smalltalksrc/VMMaker/VMCallbackContext.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ VMCallbackContext class >> printTypedefOn: aStream [
newLine
]

{ #category : #asserting }
{ #category : #translation }
VMCallbackContext class >> shouldBeGenerated [

^ false
Expand Down
24 changes: 24 additions & 0 deletions smalltalksrc/VMMaker/VMMemoryMap.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,35 @@ VMMemoryMap class >> filteredInstVarNames [
^ super filteredInstVarNames copyWithout: #memoryManager
]

{ #category : #translation }
VMMemoryMap class >> generateHeader: aBinaryBlock [

aBinaryBlock
value: 'vmMemoryMap.h'
value: (String streamContents: [ :s |
self printTypedefOn: s.
s cr ])
]

{ #category : #translation }
VMMemoryMap class >> instVarNamesAndTypesForTranslationDo: aBinaryBlock [

self filteredInstVarNames do: [ :aName |
aBinaryBlock value: aName value: #'usqInt' ]
]

{ #category : #translation }
VMMemoryMap class >> needsTypeTag [

^true
]

{ #category : #translation }
VMMemoryMap class >> shouldBeGenerated [

^ false
]

{ #category : #accessing }
VMMemoryMap >> memoryManager [

Expand Down Expand Up @@ -86,6 +108,8 @@ VMMemoryMap >> oldSpaceStart: anObject [
{ #category : #accessing }
VMMemoryMap >> startOfObjectMemory [

<api>

"The first object space in the memory map is the newSpace."
^ self newSpaceStart
]
90 changes: 69 additions & 21 deletions smalltalksrc/VMMakerCompatibilityForPharo6/PharoVMMaker.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Class {
#superclass : #Object,
#instVars : [
'outputDirectory',
'stopOnErrors'
'stopOnErrors',
'generatePlugins',
'wordSizesToGenerate'
],
#category : #'VMMakerCompatibilityForPharo6-CommandLine'
}
Expand Down Expand Up @@ -49,7 +51,7 @@ PharoVMMaker >> generate: interpreterClass memoryManager: memoryManager compiler
{ #category : #generation }
PharoVMMaker >> generate: interpreterClass memoryManager: memoryManager compilerClass: compilerClass options: options [

| platformDirectory |
| platformDirectory vmmaker |

Author useAuthor: 'vmMaker' during: [

Expand All @@ -59,57 +61,91 @@ PharoVMMaker >> generate: interpreterClass memoryManager: memoryManager compiler

[

(VMMaker
vmmaker := VMMaker
makerFor: interpreterClass
and: compilerClass
with: {#ObjectMemory. memoryManager name.
#bytecodeTableInitializer. #initializeBytecodeTableForSistaV1} , options
to: platformDirectory
platformDir:platformDirectory
including: #()
configuration: VMMakerConfiguration)
configuration: VMMakerConfiguration.

vmmaker
stopOnErrors: stopOnErrors;
internal: #() external: #(FilePlugin SurfacePlugin FloatArrayPlugin);
generateInterpreterFile;
generateCogitFiles;
generateExternalPlugins] valueSupplyingAnswer:true.]
generateCogitFiles.
generatePlugins ifTrue: [ vmmaker generateExternalPlugins ]] valueSupplyingAnswer:true.]
]

{ #category : #generation }
PharoVMMaker >> generateCoInterpreter [

self generate: CoInterpreter memoryManager: Spur64BitCoMemoryManager.
self generate: CoInterpreter memoryManager: Spur32BitCoMemoryManager.
self generates64Bits ifTrue: [self generate: CoInterpreter memoryManager: Spur64BitCoMemoryManager].
self generates32Bits ifTrue: [ self generate: CoInterpreter memoryManager: Spur32BitCoMemoryManager ].

]

{ #category : #accessing }
PharoVMMaker >> generatePlugins [

^ generatePlugins
]

{ #category : #accessing }
PharoVMMaker >> generatePlugins: anObject [

generatePlugins := anObject
]

{ #category : #generation }
PharoVMMaker >> generateSistaVM [

self
generate: CoInterpreter
memoryManager: Spur64BitCoMemoryManager
compilerClass: SistaCogit
options: #( SistaVM true ).
self
generate: CoInterpreter
memoryManager: Spur32BitCoMemoryManager
compilerClass: SistaCogit
options: #( SistaVM true )
self generates64Bits ifTrue: [
self
generate: CoInterpreter
memoryManager: Spur64BitCoMemoryManager
compilerClass: SistaCogit
options: #( SistaVM true )].


self generates32Bits ifTrue: [
self
generate: CoInterpreter
memoryManager: Spur32BitCoMemoryManager
compilerClass: SistaCogit
options: #( SistaVM true )].


]

{ #category : #generation }
PharoVMMaker >> generateStackVM [

self generate: StackInterpreter memoryManager: Spur64BitMemoryManager.
self generate: StackInterpreter memoryManager: Spur32BitMemoryManager.
self generates64Bits ifTrue: [self generate: StackInterpreter memoryManager: Spur64BitMemoryManager].
self generates32Bits ifTrue: [ self generate: StackInterpreter memoryManager: Spur32BitMemoryManager ].

]

{ #category : #testing }
PharoVMMaker >> generates32Bits [

^ wordSizesToGenerate includes: 4
]

{ #category : #testing }
PharoVMMaker >> generates64Bits [

^ wordSizesToGenerate includes: 8
]

{ #category : #accessing }
PharoVMMaker >> initialize [
super initialize.
stopOnErrors := false
stopOnErrors := false.
generatePlugins := true.
wordSizesToGenerate := #(4 8).
]

{ #category : #accessing }
Expand Down Expand Up @@ -137,3 +173,15 @@ PharoVMMaker >> stopOnErrors [
PharoVMMaker >> stopOnErrors: anObject [
stopOnErrors := anObject
]

{ #category : #accessing }
PharoVMMaker >> wordSizesToGenerate [

^ wordSizesToGenerate
]

{ #category : #accessing }
PharoVMMaker >> wordSizesToGenerate: anObject [

wordSizesToGenerate := anObject
]

0 comments on commit 1a89716

Please sign in to comment.