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:#PPCScannerCodeGenerator |
5 PPCPass subclass:#PPCScannerCodeGenerator |
6 instanceVariableNames:'codeGen fsa options incommingTransitions resultStrategy fsaCache' |
6 instanceVariableNames:'codeGen fsa incommingTransitions resultStrategy fsaCache' |
7 classVariableNames:'' |
7 classVariableNames:'' |
8 poolDictionaries:'' |
8 poolDictionaries:'' |
9 category:'PetitCompiler-Scanner' |
9 category:'PetitCompiler-Scanner' |
10 ! |
10 ! |
11 |
11 |
407 self setMaxNumericId. |
398 self setMaxNumericId. |
408 self setTokens. |
399 self setTokens. |
409 |
400 |
410 builder := PPCClassBuilder new. |
401 builder := PPCClassBuilder new. |
411 |
402 |
412 builder compiledClassName: options scannerName. |
403 builder compiledClassName: context options scannerName. |
413 builder compiledSuperclass: options scannerSuperclass. |
404 builder compiledSuperclass: context options scannerSuperclass. |
414 builder methodDictionary: codeGen clazz methodDictionary. |
405 builder methodDictionary: codeGen clazz methodDictionary. |
415 builder constants: codeGen clazz constants. |
406 builder constants: codeGen clazz constants. |
416 |
407 |
417 ^ builder compileClass. |
408 ^ builder compileClass. |
|
409 |
|
410 "Modified: / 03-09-2015 / 22:00:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
418 ! ! |
411 ! ! |
419 |
412 |
420 !PPCScannerCodeGenerator methodsFor:'initialization'! |
413 !PPCScannerCodeGenerator methodsFor:'initialization'! |
421 |
414 |
422 initialize |
415 initialize |
423 super initialize. |
416 super initialize. |
424 |
417 |
425 codeGen := PPCFSACodeGen new. |
418 codeGen := PPCFSACodeGen new. |
426 options := PPCCompilationOptions default. |
419 context := PPCCompilationContext new. |
427 fsaCache := IdentityDictionary new. |
420 fsaCache := IdentityDictionary new. |
428 |
421 |
429 "Modified: / 24-08-2015 / 23:39:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
422 "Modified: / 03-09-2015 / 22:27:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
430 ! ! |
423 ! ! |
431 |
424 |
|
425 !PPCScannerCodeGenerator methodsFor:'running'! |
|
426 |
|
427 run: ir |
|
428 "Actually run the pass on given IR (tree of PPCNode) and return |
|
429 (possibly transformed or completely new) another IR." |
|
430 |
|
431 | fsas | |
|
432 |
|
433 fsas := IdentitySet new. |
|
434 fsaCache := IdentityDictionary new. |
|
435 fsas addAll:(ir allNodes |
|
436 select:[:node | node hasFsa ] |
|
437 thenCollect:[:node | node fsa ]). |
|
438 fsas addAll:(ir allNodes |
|
439 select:[:node | node hasNextFsa ] |
|
440 thenCollect:[:node | node nextFsa ]). |
|
441 fsas := fsas select:[:each | each hasDistinctRetvals]. |
|
442 codeGen clazz:context scannerClass. |
|
443 codeGen options: context options. |
|
444 |
|
445 fsas do:[:each | |
|
446 self generate:each |
|
447 ]. |
|
448 ^ ir |
|
449 |
|
450 "Created: / 03-09-2015 / 21:55:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
451 "Modified: / 04-09-2015 / 06:21:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
452 ! ! |
|
453 |