Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/pure-cfg/src/compiler/driver/main.sml
ViewVC logotype

Diff of /branches/pure-cfg/src/compiler/driver/main.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1006, Thu Apr 28 21:19:33 2011 UTC revision 1007, Thu Apr 28 22:10:12 2011 UTC
# Line 37  Line 37 
37              then quitWithError (Error.sourceFile errStrm)              then quitWithError (Error.sourceFile errStrm)
38              else ())              else ())
39    
40      fun doFile filename = let  
41      (* compiler front end (parsing, typechecking, and simplification *)
42        fun frontEnd filename = let
43            val errStrm = Error.mkErrStream filename            val errStrm = Error.mkErrStream filename
44            val baseName = (case OS.Path.splitBaseExt filename            val _ = if OS.FileSys.access(filename, [OS.FileSys.A_READ])
45                   of {base, ext=SOME "diderot"} => base                  then ()
46                    | _ => (errnl "expected diderot file"; quitWithError filename)                  else (
47                  (* end case *))                    err(concat["source file \"", filename, "\" does not exist or is not readable\n"]);
48            val inS = TextIO.openIn filename                    raise ERROR)
           val checkTypes = Typechecker.check errStrm  
49          (***** PARSING *****)          (***** PARSING *****)
50            val parseTree = let            val parseTree = PhaseTimer.withTimer Timers.timeParser (fn () => let
51                    val inS = TextIO.openIn filename
52                  val pt = Parser.parseFile (errStrm, inS)                  val pt = Parser.parseFile (errStrm, inS)
53                  in                  in
54                    TextIO.closeIn inS;                    TextIO.closeIn inS;
55                    checkForErrors errStrm;                    checkForErrors errStrm;
56                    valOf pt                    valOf pt
57                  end                  end) ()
           val _ = checkForErrors errStrm  
58          (***** TYPECHECKING *****)          (***** TYPECHECKING *****)
59            val ast = (checkTypes parseTree) handle Typechecker.Error => AST.Program[]            val _ = PhaseTimer.start Timers.timeTypechecker
60              val ast = (Typechecker.check errStrm parseTree) handle Typechecker.Error => AST.Program[]
61              val _ = PhaseTimer.stop Timers.timeTypechecker
62            val _ = checkForErrors errStrm            val _ = checkForErrors errStrm
63            val _ = ASTPP.output (Log.logFile(), ast) (* DEBUG *)            val _ = ASTPP.output (Log.logFile(), ast) (* DEBUG *)
64          (***** SIMPLIFY *****)          (***** SIMPLIFY *****)
65              val _ = PhaseTimer.start Timers.timeSimplify
66            val simple = Simplify.transform ast            val simple = Simplify.transform ast
67              val _ = PhaseTimer.stop Timers.timeSimplify
68            val _ = SimplePP.output (Log.logFile(), simple) (* DEBUG *)            val _ = SimplePP.output (Log.logFile(), simple) (* DEBUG *)
69              in
70                simple
71              end
72    
73        fun doFile filename = let
74              val baseName = (case OS.Path.splitBaseExt filename
75                     of {base, ext=SOME "diderot"} => base
76                      | _ => (errnl "expected diderot file"; quitWithError filename)
77                    (* end case *))
78              val simple = PhaseTimer.withTimer Timers.timeFront frontEnd filename
79          (***** TRANSLATION TO HIGH IL*****)          (***** TRANSLATION TO HIGH IL*****)
80              val _ = PhaseTimer.start Timers.timeTranslate
81            val highIL = Translate.translate simple            val highIL = Translate.translate simple
82              val _ = PhaseTimer.stop Timers.timeTranslate
83            val _ = ( (* DEBUG *)            val _ = ( (* DEBUG *)
84                  HighPP.output (Log.logFile(), "HighIL after translation", highIL);                  HighPP.output (Log.logFile(), "HighIL after translation", highIL);
85                  if CheckHighIL.check ("after translation to HighIL", highIL)                  if CheckHighIL.check ("after translation to HighIL", highIL)
86                    then quitWithError filename                    then quitWithError filename
87                    else ())                    else ())
88          (***** HIGH-IL OPTIMIZATION *****)          (***** HIGH-IL OPTIMIZATION *****)
89              val _ = PhaseTimer.start Timers.timeHigh
90            val highIL = HighOptimizer.optimize highIL            val highIL = HighOptimizer.optimize highIL
91              val _ = PhaseTimer.stop Timers.timeHigh
92            val _ = ( (* DEBUG *)            val _ = ( (* DEBUG *)
93                  HighPP.output (Log.logFile(), "HighIL after optimization", highIL);                  HighPP.output (Log.logFile(), "HighIL after optimization", highIL);
94                  if CheckHighIL.check ("after HighIL optimization", highIL)                  if CheckHighIL.check ("after HighIL optimization", highIL)
95                    then quitWithError filename                    then quitWithError filename
96                    else ())                    else ())
97          (***** TRANSLATION TO MID IL *****)          (***** TRANSLATION TO MID IL *****)
98              val _ = PhaseTimer.start Timers.timeMid
99            val midIL = HighToMid.translate highIL            val midIL = HighToMid.translate highIL
100              val _ = PhaseTimer.stop Timers.timeMid
101            val _ = ( (* DEBUG *)            val _ = ( (* DEBUG *)
102                  MidPP.output (Log.logFile(), "MidIL after translation", midIL);                  MidPP.output (Log.logFile(), "MidIL after translation", midIL);
103                  if CheckMidIL.check ("after translation to MidIL", midIL)                  if CheckMidIL.check ("after translation to MidIL", midIL)
104                    then quitWithError filename                    then quitWithError filename
105                    else ())                    else ())
106          (***** TRANSLATION TO LOW IL *****)          (***** TRANSLATION TO LOW IL *****)
107              val _ = PhaseTimer.start Timers.timeLow
108            val lowIL = MidToLow.translate midIL            val lowIL = MidToLow.translate midIL
109              val _ = PhaseTimer.stop Timers.timeLow
110            val _ = ( (* DEBUG *)            val _ = ( (* DEBUG *)
111                  LowPP.output (Log.logFile(), "LowIL after translation", lowIL);                  LowPP.output (Log.logFile(), "LowIL after translation", lowIL);
112                  if CheckLowIL.check ("after translation to LowIL", lowIL)                  if CheckLowIL.check ("after translation to LowIL", lowIL)
# Line 91  Line 114 
114                    else ())                    else ())
115            in            in
116            (***** CODE GENERATION *****)            (***** CODE GENERATION *****)
117              CBackEnd.generate (baseName, lowIL)              PhaseTimer.withTimer Timers.timeCodegen CBackEnd.generate (baseName, lowIL)
118            end            end
119    
120      fun doOptions args = let      fun doOptions args = let
# Line 114  Line 137 
137            val {base, ...} = OS.Path.splitBaseExt file            val {base, ...} = OS.Path.splitBaseExt file
138            in            in
139              if Inputs.initFromArgs defs              if Inputs.initFromArgs defs
140                then (Log.init(base ^ ".log"); doFile file; OS.Process.success)                then (
141                    Log.init(base ^ ".log");
142                    PhaseTimer.withTimer Timers.timeCompiler doFile file;
143                    Log.reportTiming Timers.timeCompiler;
144                    OS.Process.success)
145                  handle exn => (                  handle exn => (
146                    err (concat [                    err (concat [
147                        "uncaught exception ", General.exnName exn, " [", General.exnMessage exn, "]\n"]);                        "uncaught exception ", General.exnName exn, " [", General.exnMessage exn, "]\n"]);

Legend:
Removed from v.1006  
changed lines
  Added in v.1007

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0