Skip to content

Composed image format: C translation #388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
95bca0b
Refactor: Preparing ComposedImageWriter for C translation
PalumboN Feb 1, 2022
4b6fbd6
Prepare ComposedImageWriter for C translation: open files and type de…
PalumboN Feb 4, 2022
ff5c0e3
C translation: header STON write
PalumboN Feb 4, 2022
d81baf0
C translation: Segments metadata STON write
PalumboN Feb 4, 2022
e6b9e74
Refactor: make files access C tranlation friendly for Composed images
PalumboN Feb 7, 2022
5a8ca84
Fix cCode in #createImageDirectory:
PalumboN Feb 7, 2022
9c2ac96
Translate to C image header reading code for ComposedImageReader
PalumboN Feb 10, 2022
3f0101c
Translate to C image segments reading code for ComposedImageReader
PalumboN Feb 10, 2022
f9b484e
Change loadPharoImage function + try memory map works
PalumboN Feb 10, 2022
7a0fded
Fix type declarations
PalumboN Feb 21, 2022
8a352ee
Fix ValueHolder contents translation
PalumboN Feb 21, 2022
206a639
Fix sizeOfIntegralCType:
PalumboN Feb 22, 2022
112f1b9
Refactor segments read loop
PalumboN Feb 22, 2022
d1ec8ac
Read STON fields separator from file
PalumboN Feb 22, 2022
73f96b8
Rollback StackInterpreter default image W/R
PalumboN Feb 23, 2022
d838029
Fix some image format related tests
PalumboN Feb 23, 2022
84868b0
Ups missing code, extension method added
PalumboN Feb 24, 2022
04c5051
Ups missing code, extension method added
PalumboN Feb 24, 2022
45fd8df
Composed image format by default in Interpreter
PalumboN Feb 24, 2022
42902b3
Merge branch 'feat/permSpace' of github.com:pharo-project/opensmallta…
PalumboN Feb 24, 2022
f58e728
Fix siglong:jmp: generation in StackVM
PalumboN Feb 24, 2022
79c374e
Fix Slang tests
PalumboN Feb 24, 2022
7a3ff14
Fix test timeout
PalumboN Feb 25, 2022
63c6ca5
Fix mkdir call in Windows
PalumboN Feb 25, 2022
2e1a7a0
Merge branch 'feat/permSpace' into composed-format-c-translation
tesonep Mar 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion extracted/vm/include/common/sq.h
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ sqInt ioDisableImageWrite(void);

#include "pharovm/imageAccess.h"

size_t readImageFromFileStartingAt(sqImageFile f, squeakFileOffsetType imageOffset);
sqInt readImageNamed(char* fileName);

/* Clipboard (cut/copy/paste). */
sqInt clipboardSize(void);
Expand Down
2 changes: 1 addition & 1 deletion include/pharovm/pharo.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ void *readAddress(sqInt anExternalAddress);
EXPORT(int) isVMRunOnWorkerThread();
void setMaxStacksToPrint(sqInt anInteger);

#define allocateMemoryBaseAddress(a, b) sqAllocateMemory(a, a, b)
#define allocateMemoryBaseAddress(desiredSize, baseAddress) sqAllocateMemory(0, desiredSize, baseAddress)
121 changes: 121 additions & 0 deletions smalltalksrc/Melchor/CCodeGeneratorGlobalStructure.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@ Class {
#category : #Melchor
}

{ #category : #'CAST translation' }
CCodeGeneratorGlobalStructure >> bindBlock: aTBlockNode withArgs: arguments [

| blockStatements argumentNames replacements |

blockStatements := aTBlockNode statements.
argumentNames := aTBlockNode args.

self assert: argumentNames size = arguments size.

replacements := argumentNames with: arguments collect: [ :name :value | name -> value ] .

^ blockStatements collect: [ :anStatement |
anStatement copy bindVariableUsesIn: replacements asDictionary ]
]

{ #category : #'C code generator' }
CCodeGeneratorGlobalStructure >> buildSortedVariablesCollection [
"Build sorted vars, end result will be sorted collection based on static usage,
Expand Down Expand Up @@ -166,13 +182,110 @@ CCodeGeneratorGlobalStructure >> emitGlobalStructFlagOn: aStream [
cr
]

{ #category : #'CAST translation' }
CCodeGeneratorGlobalStructure >> generateCASTSetFieldTo: aTSendNode [

| structType fieldName fieldVale setFieldStatements |

self assert: aTSendNode arguments size = 2.

fieldName := aTSendNode arguments first.
fieldVale := aTSendNode arguments second.

structType := self structTypeFor: aTSendNode receiver.


setFieldStatements := structType asClass allSlots collect: [ :slot |
| comparison |

comparison := TSendNode
receiver: (TConstantNode value: slot name asString)
selector: 'strcmp:'
arguments: { fieldName }.

TSendNode
receiver: comparison
selector: 'ifTrue:'
arguments: {
TStmtListNode
statements: {
TSendNode
receiver: aTSendNode receiver
selector: (slot name, ':')
arguments: { fieldVale }
}
}

].

^ CCompoundStatementNode statements: (setFieldStatements collect: [ :e | e asCASTIn: self]).

]

{ #category : #'CAST translation' }
CCodeGeneratorGlobalStructure >> generateCASTWithFieldsDoSeparatedBy: aTSendNode [

| structType allRewrittenStatements blockSeparatorStatements fieldBlock allFieldArguments |

self assert: aTSendNode arguments size = 2.
self assert: aTSendNode arguments first args size = 2.
self assert: aTSendNode arguments second args size = 0.

fieldBlock := aTSendNode arguments first.
blockSeparatorStatements := aTSendNode arguments second statements.

structType := self structTypeFor: aTSendNode receiver.

allFieldArguments := structType asClass allSlots collect: [ :slot |
{
TConstantNode value: slot name asString.
TSendNode receiver: aTSendNode receiver selector: slot name arguments: { }.
}
].

allRewrittenStatements := allFieldArguments collect: [ :fieldArgs |
(self bindBlock: fieldBlock withArgs: fieldArgs) , blockSeparatorStatements ].

^ CCompoundStatementNode statements: (allRewrittenStatements flattened collect: [ :e | e asCASTIn: self]).

]

{ #category : #'CAST translation' }
CCodeGeneratorGlobalStructure >> generateCASTWithStructNameDo: aTSendNode [

| argumentName structType rewrittenStatements aBlock |

self assert: aTSendNode arguments size = 1.
self assert: aTSendNode arguments first args size = 1.

structType := self structTypeFor: aTSendNode receiver.

aBlock := aTSendNode arguments first.
argumentName := aTSendNode arguments first args first.

rewrittenStatements := self bindBlock: aBlock withArgs: { TConstantNode value: structType asString }.

^ CCompoundStatementNode statements: (rewrittenStatements collect: [ :e | e asCASTIn: self]).

]

{ #category : #'C code generator' }
CCodeGeneratorGlobalStructure >> initialize [
super initialize.
localStructDef := nil. "ignored ivar - no longer used"
structDefDefine := '1'
]

{ #category : #initialization }
CCodeGeneratorGlobalStructure >> initializeCASTTranslationDictionary [

super initializeCASTTranslationDictionary.

castTranslationDict at: #withStructNameDo: put: #generateCASTWithStructNameDo:.
castTranslationDict at: #withFieldsDo:separatedBy: put: #generateCASTWithFieldsDoSeparatedBy:.
castTranslationDict at: #setField:to: put: #generateCASTSetFieldTo:.
]

{ #category : #public }
CCodeGeneratorGlobalStructure >> isGlobalStructureBuild [
^true
Expand Down Expand Up @@ -220,3 +333,11 @@ CCodeGeneratorGlobalStructure >> structDefDefine: aString [
'1' - which would mean always do it"
structDefDefine := aString
]

{ #category : #'CAST translation' }
CCodeGeneratorGlobalStructure >> structTypeFor: structNode [

| nodeType |
nodeType := self typeFor: structNode in: currentMethod.
^ nodeType trimRight: [ :c | { $* . $ } includes: c ]
]
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Class {
SlangMethodPrototypeTranslationTest class >> testParameters [

^ ParametrizedTestMatrix new
forSelector: #translationStrategy addOptions: { #slangTranslate . #astTranslate }
forSelector: #translationStrategy addOptions: { #astTranslate }
]

{ #category : #helpers }
Expand Down
7 changes: 5 additions & 2 deletions smalltalksrc/Slang/CCodeGenerator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -3434,7 +3434,8 @@ CCodeGenerator >> isNode: aNode constantValueWithinRangeOfType: aType [
{ #category : #'C code generator' }
CCodeGenerator >> isNonArgumentImplicitReceiverVariableName: aString [

^ (currentMethod definingClass implicitVariables includes: aString)
^ (currentMethod definingClass isNotNil and: [
currentMethod definingClass implicitVariables includes: aString ])
or: [ (self typeOfVariable: aString) == #implicit ]
]

Expand Down Expand Up @@ -4368,7 +4369,7 @@ CCodeGenerator >> returnTypeForSend: sendNode in: aTMethod boundTo: aCalledMetho
The integer promotions are performed on each of the operands. The type of the result is that of the promoted left operand..."
[#>>] -> [sendNode receiver typeFrom: self in: aTMethod].
[#<<] -> [sendNode receiver typeFrom: self in: aTMethod].
[#addressOf:] -> [(sendNode receiver typeFrom: self in: aTMethod)
[#addressOf:] -> [(sendNode arguments first typeFrom: self in: aTMethod)
ifNil: [#sqInt]
ifNotNil: [:type| type, (type last isLetter ifTrue: [' *'] ifFalse: ['*'])]].
[#at:] -> [self typeForDereference: sendNode in: aTMethod].
Expand Down Expand Up @@ -4587,6 +4588,8 @@ CCodeGenerator >> sizeOfIntegralCType: anIntegralCType [ "<String>"
"Standard C types"
['uint64_t'] -> [8].
['uint32_t'] -> [4].
['uint16_t'] -> [2].
['uint8_t'] -> [1].
}
otherwise:
[((anIntegralCType beginsWith: 'unsigned') "e.g. 'unsigned : 8'"
Expand Down
22 changes: 22 additions & 0 deletions smalltalksrc/Slang/SlangStructType.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,25 @@ SlangStructType class >> typeForSelf [
SlangStructType class >> voidStructTypeCache [
StructTypeNameCache := nil
]

{ #category : #macros }
SlangStructType >> setField: fieldName to: fieldValue [

| slot |
slot := self class slotNamed: fieldName.
slot write: fieldValue to: self
]

{ #category : #macros }
SlangStructType >> withFieldsDo: forEachBlock separatedBy: separatorBlock [

self class allSlots
do: [ :aSlot | forEachBlock value: aSlot name value: (aSlot read: self) ]
separatedBy: separatorBlock
]

{ #category : #macros }
SlangStructType >> withStructNameDo: aFullBlockClosure [

^ aFullBlockClosure value: self class structTypeName
]
8 changes: 4 additions & 4 deletions smalltalksrc/Slang/TMethod.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,7 @@ TMethod >> inlineSend: aSendNode directReturn: directReturn exitVar: exitVar in:
with: aSendNode args
do: [:formal :actual|
(meth declarationAt: formal ifAbsent: nil) ifNil:
[(self typeFor: actual in: aCodeGen) ifNotNil:
[(aCodeGen typeFor: actual in: self) ifNotNil:
[:type|
type ~= #sqInt ifTrue:
[meth declarationAt: formal put: (type last = $* ifTrue: [type, formal] ifFalse: [type, ' ', formal])]]]].
Expand Down Expand Up @@ -3017,9 +3017,9 @@ TMethod >> typeFor: aVariable in: aCodeGen [
ifTrue: [aCodeGen defaultType, ' ', varName]
ifFalse:
[(locals includes: varName) ifFalse: "don't provide type for locals"
[aCodeGen typeOfVariable: varName]]]) ifNotNil:
[:decl|
aCodeGen extractTypeFor: varName fromDeclaration: decl]
[aCodeGen typeOfVariable: varName ]]])
ifNotNil: [:decl|
aCodeGen extractTypeFor: varName fromDeclaration: decl]
]

{ #category : #utilities }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ SpurImageTestResource >> emptyVM [
{ #category : #accessing }
SpurImageTestResource >> initializedVM [
vmWithLoadedImage ifNil:
[vmWithLoadedImage := StackInterpreterSimulator newWithOptions: #(ObjectMemory Spur32BitMemoryManager).
[vmWithLoadedImage := StackInterpreterSimulator newWithOptions: #(ObjectMemory Spur32BitMemoryManager ImageReader SpurImageReader ImageWriter SpurImageWriter).
vmWithLoadedImage
openOn: self class imageNameForTests extraMemory: 0.
vmWithLoadedImage objectMemory
Expand Down
Loading