equal
deleted
inserted
replaced
1 "{ Package: 'stx:goodies/petitparser/compiler' }" |
1 "{ Package: 'stx:goodies/petitparser/compiler' }" |
2 |
2 |
3 "{ NameSpace: Smalltalk }" |
3 "{ NameSpace: Smalltalk }" |
4 |
4 |
5 Object subclass:#PPCCodeGen |
5 Object subclass:#PPCCodeGen |
6 instanceVariableNames:'clazz arguments' |
6 instanceVariableNames:'clazz options' |
7 classVariableNames:'' |
7 classVariableNames:'' |
8 poolDictionaries:'' |
8 poolDictionaries:'' |
9 category:'PetitCompiler-Compiler-Codegen' |
9 category:'PetitCompiler-Compiler-Codegen' |
10 ! |
10 ! |
11 |
11 |
12 !PPCCodeGen class methodsFor:'instance creation'! |
12 !PPCCodeGen class methodsFor:'instance creation'! |
13 |
13 |
14 new |
14 new |
15 "return an initialized instance" |
15 "return an initialized instance" |
16 |
16 |
17 ^ self on: PPCArguments default |
17 ^ self on: PPCCompilationOptions default |
|
18 |
|
19 "Modified: / 24-08-2015 / 23:39:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
18 ! |
20 ! |
19 |
21 |
20 on: aPPCArguments |
22 on: aPPCArguments |
21 "return an initialized instance" |
23 "return an initialized instance" |
22 |
24 |
23 ^ self basicNew |
25 ^ self basicNew |
24 initialize; |
26 initialize; |
25 arguments: aPPCArguments |
27 options: aPPCArguments |
26 ! ! |
28 ! ! |
27 |
29 |
28 !PPCCodeGen methodsFor:'accessing'! |
30 !PPCCodeGen methodsFor:'accessing'! |
29 |
|
30 arguments: args |
|
31 arguments := args |
|
32 ! |
|
33 |
31 |
34 clazz |
32 clazz |
35 ^ clazz |
33 ^ clazz |
36 ! |
34 ! |
37 |
35 |
55 ^ clazz idGen ids |
53 ^ clazz idGen ids |
56 ! |
54 ! |
57 |
55 |
58 methodCategory |
56 methodCategory |
59 ^ 'generated' |
57 ^ 'generated' |
|
58 ! |
|
59 |
|
60 options: args |
|
61 options := args |
60 ! ! |
62 ! ! |
61 |
63 |
62 !PPCCodeGen methodsFor:'caching'! |
64 !PPCCodeGen methodsFor:'caching'! |
63 |
65 |
64 cacheMethod: method as: id |
66 cacheMethod: method as: id |
119 |
121 |
120 codeReturn |
122 codeReturn |
121 clazz currentMethod isInline ifTrue: [ |
123 clazz currentMethod isInline ifTrue: [ |
122 "If inlined, the return variable already holds the value" |
124 "If inlined, the return variable already holds the value" |
123 ] ifFalse: [ |
125 ] ifFalse: [ |
124 arguments profile ifTrue:[ |
126 options profile ifTrue:[ |
125 self codeProfileStop. |
127 self codeProfileStop. |
126 ]. |
128 ]. |
127 self code: '^ ', clazz currentMethod returnVariable |
129 self code: '^ ', clazz currentMethod returnVariable |
128 ]. |
130 ]. |
129 |
131 |
135 " - returns whatever is in code OR |
137 " - returns whatever is in code OR |
136 - assigns whatever is in code into the returnVariable" |
138 - assigns whatever is in code into the returnVariable" |
137 clazz currentMethod isInline ifTrue:[ |
139 clazz currentMethod isInline ifTrue:[ |
138 self codeEvaluateAndAssign: code to: clazz currentMethod returnVariable. |
140 self codeEvaluateAndAssign: code to: clazz currentMethod returnVariable. |
139 ] ifFalse: [ |
141 ] ifFalse: [ |
140 arguments profile ifTrue:[ |
142 options profile ifTrue:[ |
141 self codeProfileStop. |
143 self codeProfileStop. |
142 ]. |
144 ]. |
143 self code: '^ '. |
145 self code: '^ '. |
144 self codeOnLine: code |
146 self codeOnLine: code |
145 ] |
147 ] |
262 codeHalt |
264 codeHalt |
263 self code: 'self halt. ' |
265 self code: 'self halt. ' |
264 ! |
266 ! |
265 |
267 |
266 codeHaltIfShiftPressed |
268 codeHaltIfShiftPressed |
267 arguments debug ifTrue: [ |
269 options debug ifTrue: [ |
268 ((Smalltalk respondsTo: #isSmalltalkX) and:[Smalltalk isSmalltalkX]) ifFalse:[ |
270 ((Smalltalk respondsTo: #isSmalltalkX) and:[Smalltalk isSmalltalkX]) ifFalse:[ |
269 self code: 'Halt ifShiftPressed.' |
271 self code: 'Halt ifShiftPressed.' |
270 ] |
272 ] |
271 ] |
273 ] |
272 |
274 |
284 |
286 |
285 "Created: / 01-06-2015 / 21:19:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
287 "Created: / 01-06-2015 / 21:19:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
286 ! |
288 ! |
287 |
289 |
288 codeTranscriptShow: text |
290 codeTranscriptShow: text |
289 (arguments profile) ifTrue: [ |
291 (options profile) ifTrue: [ |
290 self code: 'Transcript show: ', text storeString, '; cr.'. |
292 self code: 'Transcript show: ', text storeString, '; cr.'. |
291 ] |
293 ] |
292 ! |
294 ! |
293 |
295 |
294 profileTokenRead: tokenName |
296 profileTokenRead: tokenName |
295 arguments profile ifTrue: [ |
297 options profile ifTrue: [ |
296 self code: 'context tokenRead: ', tokenName storeString, '.' |
298 self code: 'context tokenRead: ', tokenName storeString, '.' |
297 ] |
299 ] |
298 ! ! |
300 ! ! |
299 |
301 |
300 !PPCCodeGen methodsFor:'code error handling'! |
302 !PPCCodeGen methodsFor:'code error handling'! |
433 ! |
435 ! |
434 |
436 |
435 startMethod: id |
437 startMethod: id |
436 clazz startMethod: id category: self methodCategory. |
438 clazz startMethod: id category: self methodCategory. |
437 |
439 |
438 arguments profile ifTrue:[ |
440 options profile ifTrue:[ |
439 self codeProfileStart. |
441 self codeProfileStart. |
440 ]. |
442 ]. |
441 ! |
443 ! |
442 |
444 |
443 stopInline |
445 stopInline |