20 initialize; |
20 initialize; |
21 yourself |
21 yourself |
22 ! |
22 ! |
23 |
23 |
24 tokenizing |
24 tokenizing |
25 ^ PPCTokenizingConfiguration new |
25 | options | |
|
26 |
|
27 options := PPCCompilationOptions default. |
|
28 options tokenize: true. |
|
29 ^ PPCConfiguration new |
|
30 options: options; |
|
31 yourself |
|
32 |
|
33 "Modified: / 04-09-2015 / 16:21:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
26 ! |
34 ! |
27 |
35 |
28 universal |
36 universal |
29 ^ PPCUniversalConfiguration new |
37 | options | |
|
38 |
|
39 options := PPCCompilationOptions default. |
|
40 options tokenize: false. |
|
41 ^ PPCConfiguration new |
|
42 options: options; |
|
43 yourself |
|
44 |
|
45 "Modified: / 04-09-2015 / 16:21:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
30 ! ! |
46 ! ! |
31 |
47 |
32 !PPCConfiguration methodsFor:'accessing'! |
48 !PPCConfiguration methodsFor:'accessing'! |
33 |
49 |
34 context |
50 context |
52 ^ ir |
68 ^ ir |
53 ! |
69 ! |
54 |
70 |
55 ir: whatever |
71 ir: whatever |
56 ir := whatever |
72 ir := whatever |
|
73 ! |
|
74 |
|
75 options |
|
76 ^ context options |
|
77 |
|
78 "Modified: / 26-08-2015 / 19:48:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
79 ! |
|
80 |
|
81 options: aPPCCompilationOptions |
|
82 context options: aPPCCompilationOptions |
|
83 |
|
84 "Created: / 26-08-2015 / 19:56:46 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
85 ! |
|
86 |
|
87 passes |
|
88 ^ passes |
|
89 ! |
|
90 |
|
91 passes:aCollection |
|
92 passes := aCollection asOrderedCollection |
|
93 |
|
94 "Modified: / 04-09-2015 / 14:14:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
57 ! ! |
95 ! ! |
58 |
96 |
59 !PPCConfiguration methodsFor:'accessing - defaults'! |
97 !PPCConfiguration methodsFor:'accessing - defaults'! |
60 |
98 |
61 defaultParserSuperclass |
99 defaultPassesForTokenizingParser |
62 self subclassResponsibility |
100 ^ { |
63 |
101 PPCTokenDetector . |
64 "Created: / 01-09-2015 / 08:46:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
102 PPCCacheFirstFollowPass . |
|
103 PPCLL1Visitor . |
|
104 PPCTokenizingVisitor . |
|
105 PPCMergingVisitor . |
|
106 PPCSpecializingVisitor . |
|
107 PPCInliningVisitor . |
|
108 PPCMergingVisitor . |
|
109 PPCCheckingVisitor . |
|
110 PPCCacheFirstFollowPass . |
|
111 PPCTokenizingCodeGenerator . |
|
112 PPCFSAVisitor . |
|
113 PPCTokenCodeGenerator . |
|
114 PPCScannerCodeGenerator . |
|
115 } asOrderedCollection. |
|
116 |
|
117 "Created: / 04-09-2015 / 15:56:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
118 ! |
|
119 |
|
120 defaultPassesForUniversalParser |
|
121 ^ { |
|
122 PPCTokenDetector. |
|
123 PPCCacheFirstFollowPass. |
|
124 PPCSpecializingVisitor . |
|
125 PPCRecognizerComponentDetector . |
|
126 PPCSpecializingVisitor . |
|
127 PPCInliningVisitor . |
|
128 PPCMergingVisitor . |
|
129 PPCCheckingVisitor . |
|
130 PPCUniversalCodeGenerator |
|
131 } asOrderedCollection. |
|
132 |
|
133 "Created: / 04-09-2015 / 15:56:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
65 ! ! |
134 ! ! |
66 |
135 |
67 !PPCConfiguration methodsFor:'compiling'! |
136 !PPCConfiguration methodsFor:'compiling'! |
68 |
137 |
69 buildClass: clazz |
138 buildClass: clazz |
98 | parserClass parserSuper rootMethod | |
167 | parserClass parserSuper rootMethod | |
99 |
168 |
100 context options generate ifFalse:[ |
169 context options generate ifFalse:[ |
101 ^ self |
170 ^ self |
102 ]. |
171 ]. |
|
172 context parserClass methodDictionary isEmpty ifTrue:[ |
|
173 ^ self |
|
174 ]. |
|
175 |
103 parserSuper := context options parserSuperclass. |
176 parserSuper := context options parserSuperclass. |
104 parserSuper isNil ifTrue:[ |
177 parserSuper isNil ifTrue:[ |
105 parserSuper := self defaultParserSuperclass. |
178 parserSuper := context options tokenize |
|
179 ifTrue:[ PPTokenizingCompiledParser ] |
|
180 ifFalse:[ PPCompiledParser ] |
106 ]. |
181 ]. |
107 rootMethod := context parserClass propertyAt:#rootMethod. |
182 rootMethod := context parserClass propertyAt:#rootMethod. |
108 context parserClass name:context options parserName. |
183 context parserClass name:context options parserName. |
109 context parserClass superclass: parserSuper. |
184 context parserClass superclass: parserSuper. |
110 parserClass := self buildClass:context parserClass. |
185 parserClass := self buildClass:context parserClass. |
111 parserClass startSymbol:rootMethod methodName. |
186 parserClass startSymbol:rootMethod methodName. |
112 self remember:parserClass as:#parser. |
187 self remember:parserClass as:#parser. |
113 ir := parserClass new |
188 ir := parserClass new |
114 |
189 |
115 "Modified: / 25-08-2015 / 00:05:49 / Jan Vrany" |
190 "Modified: / 25-08-2015 / 00:05:49 / Jan Vrany" |
116 "Modified: / 01-09-2015 / 08:46:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
191 "Modified: / 04-09-2015 / 16:07:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
117 ! |
192 ! |
118 |
193 |
119 generateScanner |
194 generateScanner |
120 | scanner | |
195 | scanner | |
121 |
196 |
122 context options generate ifFalse:[ |
197 context options generate ifFalse:[ |
123 ^ self |
198 ^ self |
124 ]. |
199 ]. |
|
200 context scannerClass methodDictionary isEmpty ifTrue:[ |
|
201 ^ self |
|
202 ]. |
|
203 |
125 context scannerClass name:context options scannerName. |
204 context scannerClass name:context options scannerName. |
126 context scannerClass superclass:context options scannerSuperclass. |
205 context scannerClass superclass:context options scannerSuperclass. |
127 scanner := (self buildClass:context scannerClass). |
206 scanner := (self buildClass:context scannerClass). |
128 context parserClass addConstant:scanner as:#scannerClass. |
207 context parserClass addConstant:scanner as:#scannerClass. |
129 ir := scanner. |
208 ir := scanner. |
130 self remember:scanner as:#scanner |
209 self remember:scanner as:#scanner |
131 |
210 |
132 "Modified: / 25-08-2015 / 00:06:49 / Jan Vrany" |
211 "Modified: / 25-08-2015 / 00:06:49 / Jan Vrany" |
133 "Modified: / 26-08-2015 / 19:58:12 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
212 "Modified: / 04-09-2015 / 15:33:12 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
134 ! |
213 ! |
135 |
214 |
136 invokePhases |
215 invokePhases |
137 self subclassResponsibility |
216 self initializePassesIfNotAlready. |
|
217 |
|
218 self runPasses: passes. |
|
219 |
|
220 self generateScanner. |
|
221 self generateParser. |
|
222 |
|
223 "Modified: / 04-09-2015 / 16:22:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
138 ! ! |
224 ! ! |
139 |
225 |
140 !PPCConfiguration methodsFor:'debugging'! |
226 !PPCConfiguration methodsFor:'debugging'! |
141 |
227 |
142 copy: somethingTransformable |
228 copy: somethingTransformable |
162 ] |
248 ] |
163 |
249 |
164 "Modified: / 28-08-2015 / 14:14:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
250 "Modified: / 28-08-2015 / 14:14:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
165 ! ! |
251 ! ! |
166 |
252 |
167 !PPCConfiguration methodsFor:'error handling'! |
|
168 |
|
169 options |
|
170 ^ context options |
|
171 |
|
172 "Modified: / 26-08-2015 / 19:48:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
173 ! |
|
174 |
|
175 options: aPPCCompilationOptions |
|
176 context options: aPPCCompilationOptions |
|
177 |
|
178 "Created: / 26-08-2015 / 19:56:46 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
179 ! ! |
|
180 |
|
181 !PPCConfiguration methodsFor:'initialization'! |
253 !PPCConfiguration methodsFor:'initialization'! |
182 |
254 |
183 initialize |
255 initialize |
184 history := OrderedCollection new. |
256 history := OrderedCollection new. |
185 context := PPCCompilationContext new. |
257 context := PPCCompilationContext new. |
186 |
258 |
187 "Modified: / 26-08-2015 / 19:49:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
259 "Modified: / 04-09-2015 / 15:56:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
260 ! |
|
261 |
|
262 initializePassesIfNotAlready |
|
263 passes isNil ifTrue:[ |
|
264 context options tokenize ifTrue:[ |
|
265 passes := self defaultPassesForTokenizingParser |
|
266 ] ifFalse:[ |
|
267 passes := self defaultPassesForUniversalParser |
|
268 ]. |
|
269 ]. |
|
270 |
|
271 "Created: / 04-09-2015 / 16:02:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
188 ! ! |
272 ! ! |
189 |
273 |
190 !PPCConfiguration methodsFor:'reporting'! |
274 !PPCConfiguration methodsFor:'reporting'! |
191 |
275 |
192 reportTime: timeInMs |
276 reportTime: timeInMs |
197 "Modified: / 26-08-2015 / 16:35:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
281 "Modified: / 26-08-2015 / 16:35:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
198 ! ! |
282 ! ! |
199 |
283 |
200 !PPCConfiguration methodsFor:'running'! |
284 !PPCConfiguration methodsFor:'running'! |
201 |
285 |
|
286 removePass: pass |
|
287 | index | |
|
288 |
|
289 self initializePassesIfNotAlready. |
|
290 [ |
|
291 index := passes indexOf: pass. |
|
292 index ~~ 0 |
|
293 ] whileTrue:[ |
|
294 passes removeAtIndex: index |
|
295 ]. |
|
296 |
|
297 "Created: / 04-09-2015 / 11:24:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
298 "Modified: / 04-09-2015 / 16:02:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
299 ! |
|
300 |
202 runPass: pass |
301 runPass: pass |
203 | p | |
302 | p | |
204 |
303 |
205 p := pass asPPCPass. |
304 p := pass asPPCPass. |
206 ir := p run: ir in: context. |
305 ir := p run: ir in: context. |
207 self remember:(self copyTree:ir) as:p class name |
306 self remember:(self copyTree:ir) as:p class name |
208 |
307 |
209 "Created: / 26-08-2015 / 22:35:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
308 "Created: / 26-08-2015 / 22:35:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
210 "Modified: / 29-08-2015 / 07:16:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
309 "Modified: / 29-08-2015 / 07:16:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
211 ! ! |
310 ! |
212 |
311 |
|
312 runPasses: aCollection |
|
313 aCollection do:[:each | self runPass: each ] |
|
314 |
|
315 "Created: / 04-09-2015 / 11:23:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
316 ! ! |
|
317 |