compiler/PPCConfiguration.st
changeset 535 a8feb0f47574
parent 534 a949c4fe44df
child 536 548996aca274
--- a/compiler/PPCConfiguration.st	Sat Aug 29 07:56:14 2015 +0100
+++ b/compiler/PPCConfiguration.st	Fri Sep 04 14:06:56 2015 +0100
@@ -3,7 +3,7 @@
 "{ NameSpace: Smalltalk }"
 
 Object subclass:#PPCConfiguration
-	instanceVariableNames:'context ir history'
+	instanceVariableNames:'context ir history passes'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'PetitCompiler-Core'
@@ -22,11 +22,27 @@
 !
 
 tokenizing
-    ^ PPCTokenizingConfiguration new
+    | options |
+
+    options := PPCCompilationOptions default.
+    options tokenize: true.
+    ^ PPCConfiguration new
+        options: options;
+        yourself
+
+    "Modified: / 04-09-2015 / 16:21:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 universal
-    ^ PPCUniversalConfiguration new
+    | options |
+
+    options := PPCCompilationOptions default.
+    options tokenize: false.
+    ^ PPCConfiguration new
+        options: options;
+        yourself
+
+    "Modified: / 04-09-2015 / 16:21:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !PPCConfiguration methodsFor:'accessing'!
@@ -54,14 +70,67 @@
 
 ir: whatever
     ir := whatever
+!
+
+options
+    ^ context options
+
+    "Modified: / 26-08-2015 / 19:48:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+options: aPPCCompilationOptions
+    context options: aPPCCompilationOptions
+
+    "Created: / 26-08-2015 / 19:56:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+passes
+    ^ passes
+!
+
+passes:aCollection
+    passes := aCollection asOrderedCollection
+
+    "Modified: / 04-09-2015 / 14:14:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !PPCConfiguration methodsFor:'accessing - defaults'!
 
-defaultParserSuperclass
-    self subclassResponsibility
+defaultPassesForTokenizingParser
+    ^  {
+        PPCTokenDetector .
+        PPCCacheFirstFollowPass .
+        PPCLL1Visitor .
+        PPCTokenizingVisitor .
+        PPCMergingVisitor .
+        PPCSpecializingVisitor .
+        PPCInliningVisitor .
+        PPCMergingVisitor .
+        PPCCheckingVisitor .
+        PPCCacheFirstFollowPass .
+        PPCTokenizingCodeGenerator .
+        PPCFSAVisitor .
+        PPCTokenCodeGenerator .
+        PPCScannerCodeGenerator .    
+    } asOrderedCollection.
 
-    "Created: / 01-09-2015 / 08:46:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Created: / 04-09-2015 / 15:56:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+defaultPassesForUniversalParser
+    ^ {
+        PPCTokenDetector.
+        PPCCacheFirstFollowPass. 
+        PPCSpecializingVisitor .
+        PPCRecognizerComponentDetector .
+        PPCSpecializingVisitor .
+        PPCInliningVisitor .
+        PPCMergingVisitor .
+        PPCCheckingVisitor .
+        PPCUniversalCodeGenerator
+    } asOrderedCollection.
+
+    "Created: / 04-09-2015 / 15:56:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !PPCConfiguration methodsFor:'compiling'!
@@ -100,9 +169,15 @@
     context options generate ifFalse:[
         ^ self
     ].
+    context parserClass methodDictionary isEmpty ifTrue:[ 
+        ^ self
+    ].
+
     parserSuper := context options parserSuperclass.
     parserSuper isNil ifTrue:[ 
-        parserSuper := self defaultParserSuperclass.
+        parserSuper := context options tokenize 
+                        ifTrue:[ PPTokenizingCompiledParser ]
+                        ifFalse:[ PPCompiledParser ]   
     ].
     rootMethod := context parserClass propertyAt:#rootMethod.
     context parserClass name:context options parserName.
@@ -113,7 +188,7 @@
     ir := parserClass new
 
     "Modified: / 25-08-2015 / 00:05:49 / Jan Vrany"
-    "Modified: / 01-09-2015 / 08:46:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 04-09-2015 / 16:07:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 generateScanner
@@ -122,6 +197,10 @@
     context options generate ifFalse:[
         ^ self
     ].
+    context scannerClass methodDictionary isEmpty ifTrue:[ 
+        ^ self
+    ].
+
     context scannerClass name:context options scannerName.
     context scannerClass superclass:context options scannerSuperclass.
     scanner := (self buildClass:context scannerClass).
@@ -130,11 +209,18 @@
     self remember:scanner as:#scanner
 
     "Modified: / 25-08-2015 / 00:06:49 / Jan Vrany"
-    "Modified: / 26-08-2015 / 19:58:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 04-09-2015 / 15:33:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 invokePhases
-    self subclassResponsibility
+    self initializePassesIfNotAlready.
+
+    self runPasses: passes.
+
+    self generateScanner.
+    self generateParser.
+
+    "Modified: / 04-09-2015 / 16:22:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !PPCConfiguration methodsFor:'debugging'!
@@ -164,27 +250,25 @@
     "Modified: / 28-08-2015 / 14:14:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
-!PPCConfiguration methodsFor:'error handling'!
-
-options
-    ^ context options
-
-    "Modified: / 26-08-2015 / 19:48:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-options: aPPCCompilationOptions
-    context options: aPPCCompilationOptions
-
-    "Created: / 26-08-2015 / 19:56:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
 !PPCConfiguration methodsFor:'initialization'!
 
 initialize
     history := OrderedCollection new.
     context := PPCCompilationContext new.
 
-    "Modified: / 26-08-2015 / 19:49:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 04-09-2015 / 15:56:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+initializePassesIfNotAlready
+    passes isNil ifTrue:[ 
+        context options tokenize ifTrue:[ 
+            passes := self defaultPassesForTokenizingParser
+        ] ifFalse:[ 
+            passes := self defaultPassesForUniversalParser
+        ].
+    ].
+
+    "Created: / 04-09-2015 / 16:02:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !PPCConfiguration methodsFor:'reporting'!
@@ -199,6 +283,21 @@
 
 !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 <jan.vrany@fit.cvut.cz>"
+    "Modified: / 04-09-2015 / 16:02:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 runPass: pass
     | p |
 
@@ -208,5 +307,11 @@
 
     "Created: / 26-08-2015 / 22:35:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 29-08-2015 / 07:16:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+runPasses: aCollection
+    aCollection do:[:each | self runPass: each  ]
+
+    "Created: / 04-09-2015 / 11:23:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !