compiler/PPCConfiguration.st
changeset 531 dc3d13c2837d
parent 530 e36906742693
child 532 132d7898a2a1
equal deleted inserted replaced
530:e36906742693 531:dc3d13c2837d
     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 
    47     ^ ir
    47     ^ ir
    48 !
    48 !
    49 
    49 
    50 ir: whatever
    50 ir: whatever
    51     ir := whatever
    51     ir := whatever
    52 !
       
    53 
       
    54 options
       
    55      				options isNil ifTrue: [ options := self defaultArguments ].
       
    56                     ^ options
       
    57 !
       
    58 
       
    59 options: args
       
    60     options := args
       
    61 ! !
    52 ! !
    62 
    53 
    63 !PPCConfiguration methodsFor:'caching'!
    54 !PPCConfiguration methodsFor:'caching'!
    64 
    55 
    65 cacheFirstSet
    56 cacheFirstSet
   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.
   244 ! !
   250 ! !
   245 
   251 
   246 !PPCConfiguration methodsFor:'reporting'!
   252 !PPCConfiguration methodsFor:'reporting'!
   247 
   253 
   248 reportTime: timeInMs
   254 reportTime: timeInMs
   249     options profile ifTrue: [ 
   255     context options profile ifTrue: [ 
   250         Transcript show: 'Time to compile: ', timeInMs asString, ' ms'; cr.
   256         Transcript show: 'Time to compile: ', timeInMs asString, ' ms'; cr.
   251     ]
   257     ]
   252 ! !
   258 
   253 
   259     "Modified: / 26-08-2015 / 16:35:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   260 ! !
       
   261