# HG changeset patch # User Jan Vrany # Date 1441609382 -3600 # Node ID 548996aca274a3154551934e6cdc8c9e4507d93f # Parent a8feb0f47574cfe8d7d5dac950d4bdf389a32a86 PPCConfiguration refactoring: [8/10]: Cleaned up compilation API. Methods in PPCConfiguration not meant for public use have been moved to private protocol to make it clear. diff -r a8feb0f47574 -r 548996aca274 compiler/PPCConfiguration.st --- a/compiler/PPCConfiguration.st Fri Sep 04 14:06:56 2015 +0100 +++ b/compiler/PPCConfiguration.st Mon Sep 07 08:03:02 2015 +0100 @@ -9,6 +9,7 @@ category:'PetitCompiler-Core' ! + !PPCConfiguration class methodsFor:'as yet unclassified'! default @@ -51,27 +52,6 @@ ^ context ! -defaultArguments - ^ PPCCompilationOptions default - - "Modified: / 24-08-2015 / 23:39:50 / Jan Vrany " -! - -input: aPPParser - ir := aPPParser asCompilerTree. - self remember: (self copyTree: ir) as: #input - - "Modified (format): / 29-08-2015 / 07:18:02 / Jan Vrany " -! - -ir - ^ ir -! - -ir: whatever - ir := whatever -! - options ^ context options @@ -133,8 +113,64 @@ "Created: / 04-09-2015 / 15:56:14 / Jan Vrany " ! ! +!PPCConfiguration methodsFor:'adding / removing passes'! + +removePass: pass + | index | + + self initializePassesIfNotAlready. + [ + index := passes indexOf: pass. + index ~~ 0 + ] whileTrue:[ + passes removeAtIndex: index + ]. + + "Created: / 04-09-2015 / 11:24:45 / Jan Vrany " + "Modified: / 04-09-2015 / 16:02:17 / Jan Vrany " +! ! + !PPCConfiguration methodsFor:'compiling'! +compile: aPPParser + | time | + self input: aPPParser. + + time := [ self compile ] timeToRun. + ((Smalltalk respondsTo:#isSmalltalkX) and:[Smalltalk isSmalltalkX]) ifFalse:[ + "Assume Pharo" + time := time asMilliSeconds. + ]. + self reportTime: time. + + ^ ir + + "Modified: / 17-08-2015 / 13:06:31 / Jan Vrany " +! ! + +!PPCConfiguration methodsFor:'initialization'! + +initialize + history := OrderedCollection new. + context := PPCCompilationContext new. + + "Modified: / 04-09-2015 / 15:56:49 / Jan Vrany " +! + +initializePassesIfNotAlready + passes isNil ifTrue:[ + context options tokenize ifTrue:[ + passes := self defaultPassesForTokenizingParser + ] ifFalse:[ + passes := self defaultPassesForUniversalParser + ]. + ]. + + "Created: / 04-09-2015 / 16:02:05 / Jan Vrany " +! ! + +!PPCConfiguration methodsFor:'private'! + buildClass: clazz | builder | builder := PPCClassBuilder new. @@ -147,20 +183,16 @@ ^ builder compileClass. ! -compile: whatever - | time | - self input: whatever. - - time := [ self invokePhases ] timeToRun. - ((Smalltalk respondsTo:#isSmalltalkX) and:[Smalltalk isSmalltalkX]) ifFalse:[ - "Assume Pharo" - time := time asMilliSeconds. - ]. - self reportTime: time. - - ^ ir +compile + self runPasses. + self generateScanner. + self generateParser. - "Modified: / 17-08-2015 / 13:06:31 / Jan Vrany " + "Modified: / 07-09-2015 / 07:53:17 / Jan Vrany " +! + +copyTree: somethingTransformable + ^ somethingTransformable transform: [ :e | e copy ] ! generateParser @@ -212,34 +244,19 @@ "Modified: / 04-09-2015 / 15:33:12 / Jan Vrany " ! -invokePhases - self initializePassesIfNotAlready. - - self runPasses: passes. - - self generateScanner. - self generateParser. +input: aPPParser + ir := aPPParser asCompilerTree. + self remember: (self copyTree: ir) as: #input - "Modified: / 04-09-2015 / 16:22:25 / Jan Vrany " -! ! - -!PPCConfiguration methodsFor:'debugging'! - -copy: somethingTransformable - self deprecated: 'copy on your own, or whatever, but dont use me'. - ^ somethingTransformable transform: [ :e | e copy ] + "Modified (format): / 29-08-2015 / 07:18:02 / Jan Vrany " ! -copyTree: somethingTransformable - ^ somethingTransformable transform: [ :e | e copy ] +ir + ^ ir ! -remember: key - self deprecated: 'use remember:as:'. - - self options debug ifTrue: [ - history add: key -> (self copy: ir). - ] +ir: whatever + ir := whatever ! remember: value as: key @@ -248,56 +265,25 @@ ] "Modified: / 28-08-2015 / 14:14:33 / Jan Vrany " -! ! - -!PPCConfiguration methodsFor:'initialization'! - -initialize - history := OrderedCollection new. - context := PPCCompilationContext new. - - "Modified: / 04-09-2015 / 15:56:49 / Jan Vrany " ! -initializePassesIfNotAlready - passes isNil ifTrue:[ - context options tokenize ifTrue:[ - passes := self defaultPassesForTokenizingParser - ] ifFalse:[ - passes := self defaultPassesForUniversalParser - ]. - ]. - - "Created: / 04-09-2015 / 16:02:05 / Jan Vrany " -! ! - -!PPCConfiguration methodsFor:'reporting'! - reportTime: timeInMs context options profile ifTrue: [ - Transcript show: 'Time to compile: ', timeInMs asString, ' ms'; cr. + Transcript show: 'Time to compile: '; show: timeInMs asString; show: ' ms'; cr. ] - "Modified: / 26-08-2015 / 16:35:13 / Jan Vrany " + "Modified: / 07-09-2015 / 07:55:37 / Jan Vrany " +! + +runPasses + self initializePassesIfNotAlready. + passes do:[:each | self runPass: each ] + + "Created: / 07-09-2015 / 07:53:05 / Jan Vrany " ! ! !PPCConfiguration methodsFor:'running'! -removePass: pass - | index | - - self initializePassesIfNotAlready. - [ - index := passes indexOf: pass. - index ~~ 0 - ] whileTrue:[ - passes removeAtIndex: index - ]. - - "Created: / 04-09-2015 / 11:24:45 / Jan Vrany " - "Modified: / 04-09-2015 / 16:02:17 / Jan Vrany " -! - runPass: pass | p | @@ -307,11 +293,12 @@ "Created: / 26-08-2015 / 22:35:39 / Jan Vrany " "Modified: / 29-08-2015 / 07:16:10 / Jan Vrany " -! - -runPasses: aCollection - aCollection do:[:each | self runPass: each ] - - "Created: / 04-09-2015 / 11:23:49 / Jan Vrany " ! ! +!PPCConfiguration class methodsFor:'documentation'! + +version_HG + + ^ '$Changeset: $' +! ! +