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:#PPCConfiguration |
5 Object subclass:#PPCConfiguration |
6 instanceVariableNames:'context options ir history' |
6 instanceVariableNames:'context ir history' |
7 classVariableNames:'' |
7 classVariableNames:'' |
8 poolDictionaries:'' |
8 poolDictionaries:'' |
9 category:'PetitCompiler-Core' |
9 category:'PetitCompiler-Core' |
10 ! |
10 ! |
11 |
11 |
152 self options debug ifTrue: [ |
143 self options debug ifTrue: [ |
153 history add: key -> value. |
144 history add: key -> value. |
154 ] |
145 ] |
155 ! ! |
146 ! ! |
156 |
147 |
|
148 !PPCConfiguration methodsFor:'error handling'! |
|
149 |
|
150 options |
|
151 ^ context options |
|
152 |
|
153 "Modified: / 26-08-2015 / 19:48:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
154 ! |
|
155 |
|
156 options: aPPCCompilationOptions |
|
157 context options: aPPCCompilationOptions |
|
158 |
|
159 "Created: / 26-08-2015 / 19:56:46 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
160 ! ! |
|
161 |
157 !PPCConfiguration methodsFor:'initialization'! |
162 !PPCConfiguration methodsFor:'initialization'! |
158 |
163 |
159 initialize |
164 initialize |
160 history := OrderedCollection new. |
165 history := OrderedCollection new. |
161 context := PPCCompilationContext new. |
166 context := PPCCompilationContext new. |
162 options := PPCCompilationOptions default. |
167 |
163 |
168 "Modified: / 26-08-2015 / 19:49:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
164 "Modified: / 25-08-2015 / 00:02:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
165 ! ! |
169 ! ! |
166 |
170 |
167 !PPCConfiguration methodsFor:'phases'! |
171 !PPCConfiguration methodsFor:'phases'! |
168 |
172 |
169 cacheFirstFollow |
173 cacheFirstFollow |
170 options cacheFirstFollow ifFalse: [ ^ self ] . |
174 context options cacheFirstFollow ifFalse:[ |
171 |
175 ^ self |
|
176 ]. |
172 self cacheFirstSet. |
177 self cacheFirstSet. |
173 self cacheFollowSet. |
178 self cacheFollowSet. |
174 self cacheFirstSetWithTokens. |
179 self cacheFirstSetWithTokens. |
175 self cacheFollowSetWithTokens. |
180 self cacheFollowSetWithTokens. |
176 ! |
181 ! |
178 check |
183 check |
179 ir checkTree |
184 ir checkTree |
180 ! |
185 ! |
181 |
186 |
182 createRecognizingComponents |
187 createRecognizingComponents |
183 options recognizingComponents ifFalse: [ ^ self ] . |
188 context options recognizingComponents ifFalse:[ |
184 |
189 ^ self |
185 ir := PPCRecognizerComponentDetector new |
190 ]. |
186 options: options; |
191 ir := (PPCRecognizerComponentDetector new) |
187 visit: ir. |
192 options:context options; |
188 |
193 visit:ir. |
189 self remember: (self copyTree: ir) as: #recognizingComponents |
194 self remember:(self copyTree:ir) as:#recognizingComponents |
190 ! |
195 ! |
191 |
196 |
192 createTokens |
197 createTokens |
193 options detectTokens ifFalse: [ ^ self ] . |
198 context options detectTokens ifFalse:[ |
194 |
199 ^ self |
195 ir := PPCTokenDetector new |
200 ]. |
196 options: options; |
201 ir := (PPCTokenDetector new) |
197 visit: ir. |
202 options:context options; |
198 |
203 visit:ir. |
199 self remember: (self copyTree: ir) as: #createTokens |
204 self remember:(self copyTree:ir) as:#createTokens |
200 ! |
205 ! |
201 |
206 |
202 inline |
207 inline |
203 options inline ifFalse: [ ^ self ]. |
208 context options inline ifFalse:[ |
204 |
209 ^ self |
205 ir := PPCInliningVisitor new |
210 ]. |
206 options: options; |
211 ir := (PPCInliningVisitor new) |
207 visit: ir. |
212 options:context options; |
208 |
213 visit:ir. |
209 self remember: (self copyTree: ir) as: #inline. |
214 self remember:(self copyTree:ir) as:#inline. |
210 ! |
215 ! |
211 |
216 |
212 merge |
217 merge |
213 "Merge equivalent nodes under one object with single identity" |
218 "Merge equivalent nodes under one object with single identity" |
214 options merge ifFalse: [ ^ self ]. |
219 |
215 |
220 context options merge ifFalse:[ |
216 ir := PPCMergingVisitor new |
221 ^ self |
217 options: options; |
222 ]. |
218 visit: ir. |
223 ir := (PPCMergingVisitor new) |
219 |
224 options:context options; |
220 self remember: (self copyTree: ir) as: #merge |
225 visit:ir. |
|
226 self remember:(self copyTree:ir) as:#merge |
221 ! |
227 ! |
222 |
228 |
223 specialize |
229 specialize |
224 options specialize ifFalse: [ ^ self ]. |
230 context options specialize ifFalse:[ |
225 |
231 ^ self |
226 " |
232 ]. |
227 Invokes a visitor that creates specialized nodes |
233 " |
228 for some patterns of PPCNodes, |
234 Invokes a visitor that creates specialized nodes |
229 |
235 for some patterns of PPCNodes, |
230 e.g. $a astar can be represented by PPCCharacterStarNode |
236 |
|
237 e.g. $a astar can be represented by PPCCharacterStarNode |
231 " |
238 " |
232 ir := (PPCSpecializingVisitor new |
239 ir := ((PPCSpecializingVisitor new) |
233 options: options; |
240 options:context options; |
234 visit: ir). |
241 visit:ir). |
235 |
242 self remember:(self copyTree:ir) as:#specialize |
236 self remember: (self copyTree: ir) as: #specialize |
|
237 ! |
243 ! |
238 |
244 |
239 toPPCIr |
245 toPPCIr |
240 "Creates a PPCNodes from a PPParser" |
246 "Creates a PPCNodes from a PPParser" |
241 ir := ir asCompilerTree. |
247 ir := ir asCompilerTree. |