compiler/PPCConfiguration.st
changeset 524 f6f68d32de73
parent 515 b5316ef15274
child 525 751532c8f3db
equal deleted inserted replaced
515:b5316ef15274 524:f6f68d32de73
    30 ! !
    30 ! !
    31 
    31 
    32 !PPCConfiguration methodsFor:'accessing'!
    32 !PPCConfiguration methodsFor:'accessing'!
    33 
    33 
    34 arguments
    34 arguments
    35  				arguments isNil ifTrue: [ arguments := self defaultArguments ].
    35      				arguments isNil ifTrue: [ arguments := self defaultArguments ].
    36 				^ arguments
    36                     ^ arguments
    37 !
    37 !
    38 
    38 
    39 arguments: args
    39 arguments: args
    40     arguments := args
    40     arguments := args
    41 !
    41 !
    44  				^ PPCArguments default
    44  				^ PPCArguments default
    45 !
    45 !
    46 
    46 
    47 input: whatever
    47 input: whatever
    48     ir := whatever.
    48     ir := whatever.
    49     self remember: #input.
    49     
       
    50     self remember: (self copyTree: ir) as: #input
    50 !
    51 !
    51 
    52 
    52 ir
    53 ir
    53     ^ ir
    54     ^ ir
    54 !
    55 !
   103         node followSetWithTokens: (followSets at: node)
   104         node followSetWithTokens: (followSets at: node)
   104     ]
   105     ]
   105 ! !
   106 ! !
   106 
   107 
   107 !PPCConfiguration methodsFor:'compiling'!
   108 !PPCConfiguration methodsFor:'compiling'!
   108 
       
   109 buildClass: compiler
       
   110     self subclassResponsibility
       
   111 !
       
   112 
   109 
   113 compile: whatever
   110 compile: whatever
   114     | time |
   111     | time |
   115     self input: whatever.
   112     self input: whatever.
   116     
   113     
   125 ! !
   122 ! !
   126 
   123 
   127 !PPCConfiguration methodsFor:'debugging'!
   124 !PPCConfiguration methodsFor:'debugging'!
   128 
   125 
   129 copy: somethingTransformable
   126 copy: somethingTransformable
       
   127     self deprecated: 'copy on your own, or whatever, but dont use me'.
   130     ^ somethingTransformable transform: [ :e | e copy ]
   128     ^ somethingTransformable transform: [ :e | e copy ]
   131 !
   129 !
   132 
   130 
       
   131 copyTree: somethingTransformable
       
   132     ^ somethingTransformable transform: [ :e | e copy ]
       
   133 !
       
   134 
   133 remember: key
   135 remember: key
       
   136     self deprecated: 'use remember:as:'.
       
   137     
   134     self arguments debug ifTrue: [ 
   138     self arguments debug ifTrue: [ 
   135         history add: key -> (self copy: ir).
   139         history add: key -> (self copy: ir).
   136     ]
   140     ]
   137 ! !
   141 !
   138 
   142 
   139 !PPCConfiguration methodsFor:'hooks'!
   143 remember: value as: key
   140 
   144     self arguments debug ifTrue: [ 
   141 codeCompiler
   145         history add: key -> value.
   142     ^ PPCCodeGen on: arguments 
   146     ]
   143 !
       
   144 
       
   145 codeCompilerOn: args
       
   146     ^ PPCCodeGen on: args
       
   147 !
       
   148 
       
   149 codeGeneratorVisitorOn: compiler
       
   150     ^ arguments codeGenerator on: compiler
       
   151 ! !
   147 ! !
   152 
   148 
   153 !PPCConfiguration methodsFor:'initialization'!
   149 !PPCConfiguration methodsFor:'initialization'!
   154 
   150 
   155 initialize
   151 initialize
   156     history := OrderedCollection new
   152     history := OrderedCollection new.
       
   153     arguments := PPCArguments default.
   157 ! !
   154 ! !
   158 
   155 
   159 !PPCConfiguration methodsFor:'phases'!
   156 !PPCConfiguration methodsFor:'phases'!
   160 
   157 
   161 cacheFirstFollow
   158 cacheFirstFollow
   175     arguments recognizingComponents ifFalse: [ ^ self ] .
   172     arguments recognizingComponents ifFalse: [ ^ self ] .
   176     
   173     
   177     ir :=  PPCRecognizerComponentDetector new
   174     ir :=  PPCRecognizerComponentDetector new
   178         arguments: arguments;
   175         arguments: arguments;
   179         visit: ir.
   176         visit: ir.
   180     self remember: #recognizingComponents
   177 
       
   178     self remember: (self copyTree: ir) as: #recognizingComponents
   181 !
   179 !
   182 
   180 
   183 createTokens
   181 createTokens
   184     arguments detectTokens ifFalse: [ ^ self ] .
   182     arguments detectTokens ifFalse: [ ^ self ] .
   185     
   183     
   186     ir :=  PPCTokenDetector new
   184     ir :=  PPCTokenDetector new
   187         arguments: arguments;
   185         arguments: arguments;
   188         visit: ir.
   186         visit: ir.
   189     self remember: #createTokens
   187 
   190 !
   188     self remember: (self copyTree: ir) as: #createTokens
   191 
       
   192 generate
       
   193     |  compiler rootMethod compiledParser |
       
   194     arguments generate ifFalse: [ ^ self ].
       
   195     
       
   196     compiler := self codeCompiler.
       
   197     
       
   198     rootMethod := (self codeGeneratorVisitorOn: compiler)
       
   199         arguments: arguments;
       
   200         visit: ir.
       
   201     
       
   202     compiledParser := self buildClass: compiler.
       
   203     compiledParser startSymbol: rootMethod methodName.
       
   204     compiledParser := compiledParser new.
       
   205     
       
   206     ir := compiledParser.
       
   207 !
   189 !
   208 
   190 
   209 inline
   191 inline
   210     arguments inline ifFalse: [ ^ self ].
   192     arguments inline ifFalse: [ ^ self ].
   211     
   193     
   212     ir := PPCInliningVisitor new
   194     ir := PPCInliningVisitor new
   213         arguments: arguments;
   195         arguments: arguments;
   214         visit: ir.
   196         visit: ir.
   215     self remember: #inline.
   197         
       
   198     self remember: (self copyTree: ir) as: #inline.
   216 !
   199 !
   217 
   200 
   218 merge
   201 merge
   219     "Merge equivalent nodes under one object with single identity"
   202     "Merge equivalent nodes under one object with single identity"
   220     arguments merge ifFalse: [ ^ self ].
   203     arguments merge ifFalse: [ ^ self ].
   221     
   204     
   222     ir :=  PPCMergingVisitor new
   205     ir :=  PPCMergingVisitor new
   223         arguments: arguments;
   206         arguments: arguments;
   224         visit: ir.
   207         visit: ir.
   225     self remember: #merge
   208         
       
   209     self remember: (self copyTree: ir) as: #merge
   226 !
   210 !
   227 
   211 
   228 specialize
   212 specialize
   229     arguments specialize ifFalse: [ ^ self ].
   213     arguments specialize ifFalse: [ ^ self ].
   230 
   214 
   235         e.g. $a astar can be represented by PPCCharacterStarNode
   219         e.g. $a astar can be represented by PPCCharacterStarNode
   236     "
   220     "
   237     ir :=  (PPCSpecializingVisitor new
   221     ir :=  (PPCSpecializingVisitor new
   238         arguments: arguments;
   222         arguments: arguments;
   239         visit: ir).
   223         visit: ir).
   240     self remember: #specialize
   224         
       
   225     self remember: (self copyTree: ir) as: #specialize
   241 !
   226 !
   242 
   227 
   243 toPPCIr
   228 toPPCIr
   244     "Creates a PPCNodes from a PPParser"
   229     "Creates a PPCNodes from a PPParser"
   245     ir := ir asCompilerTree.
   230     ir := ir asCompilerTree.
   246     self remember: #ppcNodes
   231     
       
   232     self remember: (self copyTree: ir) as: #ppcNodes
   247 ! !
   233 ! !
   248 
   234 
   249 !PPCConfiguration methodsFor:'reporting'!
   235 !PPCConfiguration methodsFor:'reporting'!
   250 
   236 
   251 reportTime: timeInMs
   237 reportTime: timeInMs