compiler/PPCConfiguration.st
changeset 529 439c4057517f
parent 525 751532c8f3db
child 530 e36906742693
equal deleted inserted replaced
528:ebfddc82b8bb 529:439c4057517f
     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:'arguments ir history'
     6 	instanceVariableNames:'options ir history'
     7 	classVariableNames:''
     7 	classVariableNames:''
     8 	poolDictionaries:''
     8 	poolDictionaries:''
     9 	category:'PetitCompiler-Core'
     9 	category:'PetitCompiler-Core'
    10 !
    10 !
    11 
    11 
    29     ^ PPCUniversalConfiguration new
    29     ^ PPCUniversalConfiguration new
    30 ! !
    30 ! !
    31 
    31 
    32 !PPCConfiguration methodsFor:'accessing'!
    32 !PPCConfiguration methodsFor:'accessing'!
    33 
    33 
    34 arguments
       
    35      				arguments isNil ifTrue: [ arguments := self defaultArguments ].
       
    36                     ^ arguments
       
    37 !
       
    38 
       
    39 arguments: args
       
    40     arguments := args
       
    41 !
       
    42 
       
    43 defaultArguments
    34 defaultArguments
    44  				^ PPCArguments default
    35     ^ PPCCompilationOptions default
       
    36 
       
    37     "Modified: / 24-08-2015 / 23:39:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    45 !
    38 !
    46 
    39 
    47 input: whatever
    40 input: whatever
    48     ir := whatever.
    41     ir := whatever.
    49     
    42     
    54     ^ ir
    47     ^ ir
    55 !
    48 !
    56 
    49 
    57 ir: whatever
    50 ir: whatever
    58     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
    59 ! !
    61 ! !
    60 
    62 
    61 !PPCConfiguration methodsFor:'caching'!
    63 !PPCConfiguration methodsFor:'caching'!
    62 
    64 
    63 cacheFirstSet
    65 cacheFirstSet
   139 !
   141 !
   140 
   142 
   141 remember: key
   143 remember: key
   142     self deprecated: 'use remember:as:'.
   144     self deprecated: 'use remember:as:'.
   143     
   145     
   144     self arguments debug ifTrue: [ 
   146     self options debug ifTrue: [ 
   145         history add: key -> (self copy: ir).
   147         history add: key -> (self copy: ir).
   146     ]
   148     ]
   147 !
   149 !
   148 
   150 
   149 remember: value as: key
   151 remember: value as: key
   150     self arguments debug ifTrue: [ 
   152     self options debug ifTrue: [ 
   151         history add: key -> value.
   153         history add: key -> value.
   152     ]
   154     ]
   153 ! !
   155 ! !
   154 
   156 
   155 !PPCConfiguration methodsFor:'initialization'!
   157 !PPCConfiguration methodsFor:'initialization'!
   156 
   158 
   157 initialize
   159 initialize
   158     history := OrderedCollection new.
   160     history := OrderedCollection new.
   159     arguments := PPCArguments default.
   161     options := PPCCompilationOptions default.
       
   162 
       
   163     "Modified: / 24-08-2015 / 23:39:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   160 ! !
   164 ! !
   161 
   165 
   162 !PPCConfiguration methodsFor:'phases'!
   166 !PPCConfiguration methodsFor:'phases'!
   163 
   167 
   164 cacheFirstFollow
   168 cacheFirstFollow
   165     arguments cacheFirstFollow ifFalse: [ ^ self ] .
   169     options cacheFirstFollow ifFalse: [ ^ self ] .
   166     
   170     
   167     self cacheFirstSet.
   171     self cacheFirstSet.
   168     self cacheFollowSet.
   172     self cacheFollowSet.
   169     self cacheFirstSetWithTokens.
   173     self cacheFirstSetWithTokens.
   170     self cacheFollowSetWithTokens.
   174     self cacheFollowSetWithTokens.
   173 check
   177 check
   174     ir checkTree 
   178     ir checkTree 
   175 !
   179 !
   176 
   180 
   177 createRecognizingComponents
   181 createRecognizingComponents
   178     arguments recognizingComponents ifFalse: [ ^ self ] .
   182     options recognizingComponents ifFalse: [ ^ self ] .
   179     
   183     
   180     ir :=  PPCRecognizerComponentDetector new
   184     ir :=  PPCRecognizerComponentDetector new
   181         arguments: arguments;
   185         options: options;
   182         visit: ir.
   186         visit: ir.
   183 
   187 
   184     self remember: (self copyTree: ir) as: #recognizingComponents
   188     self remember: (self copyTree: ir) as: #recognizingComponents
   185 !
   189 !
   186 
   190 
   187 createTokens
   191 createTokens
   188     arguments detectTokens ifFalse: [ ^ self ] .
   192     options detectTokens ifFalse: [ ^ self ] .
   189     
   193     
   190     ir :=  PPCTokenDetector new
   194     ir :=  PPCTokenDetector new
   191         arguments: arguments;
   195         options: options;
   192         visit: ir.
   196         visit: ir.
   193 
   197 
   194     self remember: (self copyTree: ir) as: #createTokens
   198     self remember: (self copyTree: ir) as: #createTokens
   195 !
   199 !
   196 
   200 
   197 inline
   201 inline
   198     arguments inline ifFalse: [ ^ self ].
   202     options inline ifFalse: [ ^ self ].
   199     
   203     
   200     ir := PPCInliningVisitor new
   204     ir := PPCInliningVisitor new
   201         arguments: arguments;
   205         options: options;
   202         visit: ir.
   206         visit: ir.
   203         
   207         
   204     self remember: (self copyTree: ir) as: #inline.
   208     self remember: (self copyTree: ir) as: #inline.
   205 !
   209 !
   206 
   210 
   207 merge
   211 merge
   208     "Merge equivalent nodes under one object with single identity"
   212     "Merge equivalent nodes under one object with single identity"
   209     arguments merge ifFalse: [ ^ self ].
   213     options merge ifFalse: [ ^ self ].
   210     
   214     
   211     ir :=  PPCMergingVisitor new
   215     ir :=  PPCMergingVisitor new
   212         arguments: arguments;
   216         options: options;
   213         visit: ir.
   217         visit: ir.
   214         
   218         
   215     self remember: (self copyTree: ir) as: #merge
   219     self remember: (self copyTree: ir) as: #merge
   216 !
   220 !
   217 
   221 
   218 specialize
   222 specialize
   219     arguments specialize ifFalse: [ ^ self ].
   223     options specialize ifFalse: [ ^ self ].
   220 
   224 
   221     " 
   225     " 
   222         Invokes a visitor that creates specialized nodes
   226         Invokes a visitor that creates specialized nodes
   223         for some patterns of PPCNodes, 
   227         for some patterns of PPCNodes, 
   224         
   228         
   225         e.g. $a astar can be represented by PPCCharacterStarNode
   229         e.g. $a astar can be represented by PPCCharacterStarNode
   226     "
   230     "
   227     ir :=  (PPCSpecializingVisitor new
   231     ir :=  (PPCSpecializingVisitor new
   228         arguments: arguments;
   232         options: options;
   229         visit: ir).
   233         visit: ir).
   230         
   234         
   231     self remember: (self copyTree: ir) as: #specialize
   235     self remember: (self copyTree: ir) as: #specialize
   232 !
   236 !
   233 
   237 
   239 ! !
   243 ! !
   240 
   244 
   241 !PPCConfiguration methodsFor:'reporting'!
   245 !PPCConfiguration methodsFor:'reporting'!
   242 
   246 
   243 reportTime: timeInMs
   247 reportTime: timeInMs
   244     arguments profile ifTrue: [ 
   248     options profile ifTrue: [ 
   245         Transcript show: 'Time to compile: ', timeInMs asString, ' ms'; cr.
   249         Transcript show: 'Time to compile: ', timeInMs asString, ' ms'; cr.
   246     ]
   250     ]
   247 ! !
   251 ! !
   248 
   252