29 ^ PPCUniversalConfiguration new |
29 ^ PPCUniversalConfiguration new |
30 ! ! |
30 ! ! |
31 |
31 |
32 !PPCConfiguration methodsFor:'accessing'! |
32 !PPCConfiguration methodsFor:'accessing'! |
33 |
33 |
|
34 context |
|
35 ^ context |
|
36 ! |
|
37 |
34 defaultArguments |
38 defaultArguments |
35 ^ PPCCompilationOptions default |
39 ^ PPCCompilationOptions default |
36 |
40 |
37 "Modified: / 24-08-2015 / 23:39:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
41 "Modified: / 24-08-2015 / 23:39:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
38 ! |
42 ! |
39 |
43 |
40 input: whatever |
44 input: aPPParser |
41 ir := whatever. |
45 ir := aPPParser asCompilerTree. |
42 |
|
43 self remember: (self copyTree: ir) as: #input |
46 self remember: (self copyTree: ir) as: #input |
|
47 |
|
48 "Modified (format): / 29-08-2015 / 07:18:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
44 ! |
49 ! |
45 |
50 |
46 ir |
51 ir |
47 ^ ir |
52 ^ ir |
48 ! |
53 ! |
49 |
54 |
50 ir: whatever |
55 ir: whatever |
51 ir := whatever |
56 ir := whatever |
52 ! ! |
57 ! ! |
53 |
58 |
54 !PPCConfiguration methodsFor:'caching'! |
59 !PPCConfiguration methodsFor:'accessing - defaults'! |
55 |
60 |
56 cacheFirstSet |
61 defaultParserSuperclass |
57 "Creates a PPCNodes from a PPParser" |
62 self subclassResponsibility |
58 | firstSets | |
63 |
59 firstSets := ir firstSets. |
64 "Created: / 01-09-2015 / 08:46:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
60 ir allNodesDo: [ :node | |
|
61 node firstSet: (firstSets at: node) |
|
62 ] |
|
63 ! |
|
64 |
|
65 cacheFirstSetWithProductions |
|
66 "Creates a PPCNodes from a PPParser" |
|
67 | firstSets | |
|
68 firstSets := ir firstSetsSuchThat: [:e | e name isNil not ]. |
|
69 ir allNodesDo: [ :node | |
|
70 node firstSetWithProductions: (firstSets at: node) |
|
71 ] |
|
72 ! |
|
73 |
|
74 cacheFirstSetWithTokens |
|
75 "Creates a PPCNodes from a PPParser" |
|
76 | firstSets | |
|
77 firstSets := ir firstSetsSuchThat: [:e | e isTerminal or: [ e isTokenNode ] ]. |
|
78 ir allNodesDo: [ :node | |
|
79 node firstSetWithTokens: (firstSets at: node) |
|
80 ] |
|
81 ! |
|
82 |
|
83 cacheFollowSet |
|
84 "Creates a PPCNodes from a PPParser" |
|
85 | followSets | |
|
86 followSets := ir followSets. |
|
87 ir allNodesDo: [ :node | |
|
88 node followSet: (followSets at: node) |
|
89 ] |
|
90 ! |
|
91 |
|
92 cacheFollowSetWithTokens |
|
93 "Creates a PPCNodes from a PPParser" |
|
94 | followSets | |
|
95 followSets := ir followSetsSuchThat: [:e | e isTerminal or: [ e isTokenNode ] ]. |
|
96 ir allNodesDo: [ :node | |
|
97 node followSetWithTokens: (followSets at: node) |
|
98 ] |
|
99 ! ! |
65 ! ! |
100 |
66 |
101 !PPCConfiguration methodsFor:'compiling'! |
67 !PPCConfiguration methodsFor:'compiling'! |
|
68 |
|
69 buildClass: clazz |
|
70 | builder | |
|
71 builder := PPCClassBuilder new. |
|
72 |
|
73 builder compiledClassName: clazz name. |
|
74 builder compiledSuperclass: clazz superclass. |
|
75 builder methodDictionary: clazz methodDictionary. |
|
76 builder constants: clazz constants. |
|
77 |
|
78 ^ builder compileClass. |
|
79 ! |
102 |
80 |
103 compile: whatever |
81 compile: whatever |
104 | time | |
82 | time | |
105 self input: whatever. |
83 self input: whatever. |
106 |
84 |
114 ^ ir |
92 ^ ir |
115 |
93 |
116 "Modified: / 17-08-2015 / 13:06:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
94 "Modified: / 17-08-2015 / 13:06:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
117 ! |
95 ! |
118 |
96 |
|
97 generateParser |
|
98 | parserClass parserSuper rootMethod | |
|
99 |
|
100 context options generate ifFalse:[ |
|
101 ^ self |
|
102 ]. |
|
103 parserSuper := context options parserSuperclass. |
|
104 parserSuper isNil ifTrue:[ |
|
105 parserSuper := self defaultParserSuperclass. |
|
106 ]. |
|
107 rootMethod := context parserClass propertyAt:#rootMethod. |
|
108 context parserClass name:context options parserName. |
|
109 context parserClass superclass: parserSuper. |
|
110 parserClass := self buildClass:context parserClass. |
|
111 parserClass startSymbol:rootMethod methodName. |
|
112 self remember:parserClass as:#parser. |
|
113 ir := parserClass new |
|
114 |
|
115 "Modified: / 25-08-2015 / 00:05:49 / Jan Vrany" |
|
116 "Modified: / 01-09-2015 / 08:46:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
117 ! |
|
118 |
|
119 generateScanner |
|
120 | scanner | |
|
121 |
|
122 context options generate ifFalse:[ |
|
123 ^ self |
|
124 ]. |
|
125 context scannerClass name:context options scannerName. |
|
126 context scannerClass superclass:context options scannerSuperclass. |
|
127 scanner := (self buildClass:context scannerClass). |
|
128 context parserClass addConstant:scanner as:#scannerClass. |
|
129 ir := scanner. |
|
130 self remember:scanner as:#scanner |
|
131 |
|
132 "Modified: / 25-08-2015 / 00:06:49 / Jan Vrany" |
|
133 "Modified: / 26-08-2015 / 19:58:12 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
134 ! |
|
135 |
119 invokePhases |
136 invokePhases |
120 self subclassResponsibility |
137 self subclassResponsibility |
121 ! ! |
138 ! ! |
122 |
139 |
123 !PPCConfiguration methodsFor:'debugging'! |
140 !PPCConfiguration methodsFor:'debugging'! |
138 history add: key -> (self copy: ir). |
155 history add: key -> (self copy: ir). |
139 ] |
156 ] |
140 ! |
157 ! |
141 |
158 |
142 remember: value as: key |
159 remember: value as: key |
143 self options debug ifTrue: [ |
160 context options debug ifTrue: [ |
144 history add: key -> value. |
161 history add: key -> value. |
145 ] |
162 ] |
|
163 |
|
164 "Modified: / 28-08-2015 / 14:14:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
146 ! ! |
165 ! ! |
147 |
166 |
148 !PPCConfiguration methodsFor:'error handling'! |
167 !PPCConfiguration methodsFor:'error handling'! |
149 |
168 |
150 options |
169 options |
164 initialize |
183 initialize |
165 history := OrderedCollection new. |
184 history := OrderedCollection new. |
166 context := PPCCompilationContext new. |
185 context := PPCCompilationContext new. |
167 |
186 |
168 "Modified: / 26-08-2015 / 19:49:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
187 "Modified: / 26-08-2015 / 19:49:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
169 ! ! |
|
170 |
|
171 !PPCConfiguration methodsFor:'phases'! |
|
172 |
|
173 cacheFirstFollow |
|
174 context options cacheFirstFollow ifFalse:[ |
|
175 ^ self |
|
176 ]. |
|
177 self cacheFirstSet. |
|
178 self cacheFollowSet. |
|
179 self cacheFirstSetWithTokens. |
|
180 self cacheFollowSetWithTokens. |
|
181 ! |
|
182 |
|
183 check |
|
184 ir checkTree |
|
185 ! |
|
186 |
|
187 createRecognizingComponents |
|
188 context options recognizingComponents ifFalse:[ |
|
189 ^ self |
|
190 ]. |
|
191 self runPass: PPCRecognizerComponentDetector |
|
192 |
|
193 "Modified: / 26-08-2015 / 22:36:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
194 ! |
|
195 |
|
196 createTokens |
|
197 context options detectTokens ifFalse:[ |
|
198 ^ self |
|
199 ]. |
|
200 self runPass: PPCTokenDetector |
|
201 |
|
202 "Modified: / 26-08-2015 / 22:36:19 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
203 ! |
|
204 |
|
205 inline |
|
206 context options inline ifFalse:[ |
|
207 ^ self |
|
208 ]. |
|
209 self runPass: PPCInliningVisitor |
|
210 |
|
211 "Modified: / 26-08-2015 / 22:36:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
212 ! |
|
213 |
|
214 merge |
|
215 "Merge equivalent nodes under one object with single identity" |
|
216 |
|
217 context options merge ifFalse:[ |
|
218 ^ self |
|
219 ]. |
|
220 self runPass: PPCMergingVisitor |
|
221 |
|
222 "Modified: / 26-08-2015 / 22:36:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
223 ! |
|
224 |
|
225 specialize |
|
226 context options specialize ifFalse:[ |
|
227 ^ self |
|
228 ]. |
|
229 " |
|
230 Invokes a visitor that creates specialized nodes |
|
231 for some patterns of PPCNodes, |
|
232 |
|
233 e.g. $a astar can be represented by PPCCharacterStarNode |
|
234 " |
|
235 self runPass: PPCSpecializingVisitor |
|
236 |
|
237 "Modified: / 26-08-2015 / 22:36:47 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
238 ! |
|
239 |
|
240 toPPCIr |
|
241 "Creates a PPCNodes from a PPParser" |
|
242 ir := ir asCompilerTree. |
|
243 |
|
244 self remember: (self copyTree: ir) as: #ppcNodes |
|
245 ! ! |
188 ! ! |
246 |
189 |
247 !PPCConfiguration methodsFor:'reporting'! |
190 !PPCConfiguration methodsFor:'reporting'! |
248 |
191 |
249 reportTime: timeInMs |
192 reportTime: timeInMs |
254 "Modified: / 26-08-2015 / 16:35:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
197 "Modified: / 26-08-2015 / 16:35:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
255 ! ! |
198 ! ! |
256 |
199 |
257 !PPCConfiguration methodsFor:'running'! |
200 !PPCConfiguration methodsFor:'running'! |
258 |
201 |
259 runPass: passClassOrAlike |
202 runPass: pass |
260 ir := passClassOrAlike run: ir in: context. |
203 | p | |
261 self remember:(self copyTree:ir) as:passClassOrAlike name |
204 |
|
205 p := pass asPPCPass. |
|
206 ir := p run: ir in: context. |
|
207 self remember:(self copyTree:ir) as:p class name |
262 |
208 |
263 "Created: / 26-08-2015 / 22:35:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
209 "Created: / 26-08-2015 / 22:35:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
264 ! ! |
210 "Modified: / 29-08-2015 / 07:16:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
265 |
211 ! ! |
|
212 |