compiler/PPCConfiguration.st
changeset 438 20598d7ce9fa
child 452 9f4558b3be66
equal deleted inserted replaced
437:54b3bc9e3987 438:20598d7ce9fa
       
     1 "{ Package: 'stx:goodies/petitparser/compiler' }"
       
     2 
       
     3 "{ NameSpace: Smalltalk }"
       
     4 
       
     5 Object subclass:#PPCConfiguration
       
     6 	instanceVariableNames:'arguments ir history'
       
     7 	classVariableNames:''
       
     8 	poolDictionaries:''
       
     9 	category:'PetitCompiler-Core'
       
    10 !
       
    11 
       
    12 !PPCConfiguration class methodsFor:'as yet unclassified'!
       
    13 
       
    14 default
       
    15 	^ PPCFirstPrototype new
       
    16 !
       
    17 
       
    18 new
       
    19 	^ self basicNew
       
    20 		initialize;
       
    21 		yourself
       
    22 ! !
       
    23 
       
    24 !PPCConfiguration methodsFor:'accessing'!
       
    25 
       
    26 arguments: args
       
    27 	arguments := args
       
    28 !
       
    29 
       
    30 input: whatever
       
    31 	ir := whatever.
       
    32 	self remember: #input.
       
    33 !
       
    34 
       
    35 ir
       
    36 	^ ir
       
    37 !
       
    38 
       
    39 ir: whatever
       
    40 	ir := whatever
       
    41 ! !
       
    42 
       
    43 !PPCConfiguration methodsFor:'as yet unclassified'!
       
    44 
       
    45 compile: whatever
       
    46 	self input: whatever.
       
    47 	self invokePhases.
       
    48 	^ ir
       
    49 !
       
    50 
       
    51 compile: whatever arguments: args
       
    52 	self arguments: args.
       
    53 	^ self compile: whatever.
       
    54 !
       
    55 
       
    56 remember: key
       
    57 	arguments debug ifTrue: [ 
       
    58 		history add: key -> (ir copy).
       
    59 	]
       
    60 ! !
       
    61 
       
    62 !PPCConfiguration methodsFor:'initialization'!
       
    63 
       
    64 initialize
       
    65 	history := OrderedCollection new
       
    66 ! !
       
    67 
       
    68 !PPCConfiguration methodsFor:'phases'!
       
    69 
       
    70 check
       
    71 	ir checkTree 
       
    72 !
       
    73 
       
    74 generate
       
    75 	| compiler rootMethod compiledParser |
       
    76 	arguments generate ifFalse: [ ^ self ].
       
    77 	
       
    78 	compiler := PPCCompiler on: arguments.
       
    79 	
       
    80 	rootMethod := (PPCCodeGenerator on: compiler)
       
    81 		arguments: arguments;
       
    82 		visit: ir.
       
    83 	
       
    84 	compiler compileParser.
       
    85 	compiler compiledParser startSymbol: rootMethod methodName.
       
    86 	compiledParser := compiler compiledParser new.
       
    87 	
       
    88 	ir := compiledParser.
       
    89 !
       
    90 
       
    91 inline
       
    92 	arguments inline ifFalse: [ ^ self ].
       
    93 	
       
    94 	ir := PPCInliningVisitor new
       
    95 		arguments: arguments;
       
    96 		visit: ir.
       
    97 	self remember: #inline.
       
    98 !
       
    99 
       
   100 merge
       
   101 	arguments merge ifFalse: [ ^ self ].
       
   102 	
       
   103 	ir :=  PPCMergingVisitor new
       
   104 		arguments: arguments;
       
   105 		visit: ir.
       
   106 	self remember: #merge
       
   107 !
       
   108 
       
   109 specialize
       
   110 	arguments specialize ifFalse: [ ^ self ].
       
   111 
       
   112 	" 
       
   113 		Invokes a visitor that creates specialized nodes
       
   114 		for some patterns of PPCNodes
       
   115 	"
       
   116 	ir :=  (PPCOptimizingVisitor new
       
   117 		arguments: arguments;
       
   118 		visit: ir).
       
   119 	self remember: #specialize
       
   120 !
       
   121 
       
   122 toPPCIr
       
   123 	ir := ir asCompilerTree.
       
   124 	self remember: #ppcNodes
       
   125 !
       
   126 
       
   127 tokenize
       
   128 	arguments tokenize ifFalse: [ ^ self ] .
       
   129 	
       
   130 	ir :=  PPCTokenDetector new
       
   131 		arguments: arguments;
       
   132 		visit: ir.
       
   133 	self remember: #tokenize
       
   134 ! !
       
   135