From b659d27f1f9a397c3073a2304f6102ffe2c328c6 Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Thu, 7 Sep 2006 12:41:35 +0000 Subject: [PATCH] Add intermediate phase, and a pass to gather declarations --- fco/Main.hs | 3 ++- fco/Makefile | 3 ++- fco/PhaseIntermediate.hs | 26 ++++++++++++++++++++++++++ fco/PhaseOutput.hs | 2 +- fco/Tree.hs | 4 ++++ 5 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 fco/PhaseIntermediate.hs diff --git a/fco/Main.hs b/fco/Main.hs index bacdf62..e80d796 100644 --- a/fco/Main.hs +++ b/fco/Main.hs @@ -8,9 +8,10 @@ import Parse import Tree import Pass import PhaseSource +import PhaseIntermediate import PhaseOutput -phaseList = [phaseSource, phaseOutput] +phaseList = [phaseSource, phaseIntermediate, phaseOutput] doPhases :: [Phase] -> Node -> IO Node doPhases [] n = do return n diff --git a/fco/Makefile b/fco/Makefile index 47995fe..ec882de 100644 --- a/fco/Makefile +++ b/fco/Makefile @@ -1,6 +1,7 @@ all: fco -fco: Main.hs Parse.hs Tree.hs Pass.hs PhaseSource.hs PhaseOutput.hs BasePasses.hs +fco: Main.hs Parse.hs Tree.hs Pass.hs BasePasses.hs \ + PhaseSource.hs PhaseIntermediate.hs PhaseOutput.hs ghc -o fco --make Main BasePasses.hs: Tree.hs make-passthrough.py diff --git a/fco/PhaseIntermediate.hs b/fco/PhaseIntermediate.hs new file mode 100644 index 0000000..ab52491 --- /dev/null +++ b/fco/PhaseIntermediate.hs @@ -0,0 +1,26 @@ +-- Intermediate passes + +module PhaseIntermediate (phaseIntermediate) where + +import Tree +import Pass +import BasePasses + +phaseIntermediate + = (Phase "Intermediate mangling" + [basePassOc, basePassInt] + [ + ("Gather declarations", gatherDecls) + ]) + +gatherDecls :: Pass +gatherDecls next top node + = case node of + OcDecl d c -> let c' = top c + d' = top d + in + case c' of + IntDeclSet ds cs -> IntDeclSet (d':ds) cs + _ -> IntDeclSet [d'] c' + _ -> next node + diff --git a/fco/PhaseOutput.hs b/fco/PhaseOutput.hs index 6a37a68..c71c9a8 100644 --- a/fco/PhaseOutput.hs +++ b/fco/PhaseOutput.hs @@ -8,7 +8,7 @@ import BasePasses phaseOutput = (Phase "C output" - [basePassOc, basePassC] + [basePassOc, basePassInt, basePassC] [ ("Convert expressions", convExpressions) ]) diff --git a/fco/Tree.hs b/fco/Tree.hs index 74c1e96..67170fe 100644 --- a/fco/Tree.hs +++ b/fco/Tree.hs @@ -139,6 +139,10 @@ data Node = | OcName String -- }}} END +-- {{{ BEGIN basePassInt + | IntDeclSet [Node] Node +-- }}} END + -- {{{ BEGIN basePassC | CCode String -- }}} END