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

SCM Repository

[diderot] Diff of /trunk/src/compiler/driver/main.sml
ViewVC logotype

Diff of /trunk/src/compiler/driver/main.sml

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

revision 1115, Thu May 5 04:42:18 2011 UTC revision 1116, Thu May 5 04:49:02 2011 UTC
# Line 12  Line 12 
12    
13    end = struct    end = struct
14    
15      structure HighPP = SSAPPFn (HighIL)    (* exception tracing magic *)
16      structure MidPP = SSAPPFn (MidIL)      val _ = (
17      structure LowPP = SSAPPFn (LowIL)          SMLofNJ.Internals.TDP.mode := true;
18            Coverage.install ();
19            BackTrace.install ())
20    
21      fun err s = TextIO.output (TextIO.stdErr, s)      fun err s = TextIO.output (TextIO.stdErr, s)
22      fun err1 c =  TextIO.output1 (TextIO.stdErr, c)      fun err1 c =  TextIO.output1 (TextIO.stdErr, c)
# Line 31  Line 33 
33              then quitWithError (Error.sourceFile errStrm)              then quitWithError (Error.sourceFile errStrm)
34              else ())              else ())
35    
36      fun doFile filename = let  
37      (* compiler front end (parsing, typechecking, and simplification *)
38        fun frontEnd filename = let
39            val errStrm = Error.mkErrStream filename            val errStrm = Error.mkErrStream filename
40            val inS = TextIO.openIn filename            val _ = if OS.FileSys.access(filename, [OS.FileSys.A_READ])
41            val checkTypes = Typechecker.check errStrm                  then ()
42                    else (
43                      err(concat["source file \"", filename, "\" does not exist or is not readable\n"]);
44                      raise ERROR)
45          (***** PARSING *****)          (***** PARSING *****)
46            val parseTree = let            val parseTree = PhaseTimer.withTimer Timers.timeParser (fn () => let
47                    val inS = TextIO.openIn filename
48                  val pt = Parser.parseFile (errStrm, inS)                  val pt = Parser.parseFile (errStrm, inS)
49                  in                  in
50                    TextIO.closeIn inS;                    TextIO.closeIn inS;
51                    checkForErrors errStrm;                    checkForErrors errStrm;
52                    valOf pt                    valOf pt
53                  end                  end) ()
           val _ = checkForErrors errStrm  
54          (***** TYPECHECKING *****)          (***** TYPECHECKING *****)
55            val ast = (checkTypes parseTree) handle Typechecker.Error => AST.Program[]            val _ = PhaseTimer.start Timers.timeTypechecker
56              val ast = (Typechecker.check errStrm parseTree) handle Typechecker.Error => AST.Program[]
57              val _ = PhaseTimer.stop Timers.timeTypechecker
58            val _ = checkForErrors errStrm            val _ = checkForErrors errStrm
59            val _ = ASTPP.output (Log.logFile(), ast) (* DEBUG *)            val _ = ASTPP.output (Log.logFile(), ast) (* DEBUG *)
60          (***** SIMPLIFY *****)          (***** SIMPLIFY *****)
61              val _ = PhaseTimer.start Timers.timeSimplify
62            val simple = Simplify.transform ast            val simple = Simplify.transform ast
63              val _ = PhaseTimer.stop Timers.timeSimplify
64            val _ = SimplePP.output (Log.logFile(), simple) (* DEBUG *)            val _ = SimplePP.output (Log.logFile(), simple) (* DEBUG *)
65              in
66                simple
67              end
68    
69        fun doFile filename = BackTrace.monitor (fn () => let
70              val baseName = (case OS.Path.splitBaseExt filename
71                     of {base, ext=SOME "diderot"} => base
72                      | _ => (errnl "expected diderot file"; quitWithError filename)
73                    (* end case *))
74              val simple = PhaseTimer.withTimer Timers.timeFront frontEnd filename
75          (***** TRANSLATION TO HIGH IL*****)          (***** TRANSLATION TO HIGH IL*****)
76              val _ = PhaseTimer.start Timers.timeTranslate
77            val highIL = Translate.translate simple            val highIL = Translate.translate simple
78              val _ = PhaseTimer.stop Timers.timeTranslate
79            val _ = ( (* DEBUG *)            val _ = ( (* DEBUG *)
80                  HighPP.output (Log.logFile(), "HighIL after translation", highIL);                  HighPP.output (Log.logFile(), "HighIL after translation", highIL);
81                  if CheckHighIL.check ("after translation", highIL)                  if CheckHighIL.check ("after translation to HighIL", highIL)
82                    then quitWithError filename                    then quitWithError filename
83                    else ())                    else ())
84          (***** HIGH-IL OPTIMIZATION *****)          (***** HIGH-IL OPTIMIZATION *****)
85              val _ = PhaseTimer.start Timers.timeHigh
86            val highIL = HighOptimizer.optimize highIL            val highIL = HighOptimizer.optimize highIL
87              val _ = PhaseTimer.stop Timers.timeHigh
88            val _ = ( (* DEBUG *)            val _ = ( (* DEBUG *)
89                  HighPP.output (Log.logFile(), "HighIL after optimization", highIL);                  HighPP.output (Log.logFile(), "HighIL after optimization", highIL);
90                  if CheckHighIL.check ("after optimization", highIL)                  if CheckHighIL.check ("after HighIL optimization", highIL)
91                    then quitWithError filename                    then quitWithError filename
92                    else ())                    else ())
93          (***** TRANSLATION TO MID IL *****)          (***** TRANSLATION TO MID IL *****)
94            val midIL = HighToMid.translate highIL            val midIL = PhaseTimer.withTimer Timers.timeMid HighToMid.translate highIL
95            val _ = ( (* DEBUG *)            val _ = ( (* DEBUG *)
96                  MidPP.output (Log.logFile(), "MidIL after translation", midIL);                  MidPP.output (Log.logFile(), "MidIL after translation", midIL);
97                  if CheckMidIL.check ("after translation", midIL)                  if CheckMidIL.check ("after translation to MidIL", midIL)
98                      then quitWithError filename
99                      else ())
100              val midIL = PhaseTimer.withTimer Timers.timeMid MidOptimizer.optimize midIL
101    (* no optimization for mid-il so don't print
102              val _ = ( (* DEBUG *)
103                    MidPP.output (Log.logFile(), "MidIL after optimization", midIL);
104                    if CheckMidIL.check ("after MidIL optimization", midIL)
105                    then quitWithError filename                    then quitWithError filename
106                    else ())                    else ())
107    *)
108          (***** TRANSLATION TO LOW IL *****)          (***** TRANSLATION TO LOW IL *****)
109            val lowIL = MidToLow.translate midIL            val lowIL = PhaseTimer.withTimer Timers.timeLow MidToLow.translate midIL
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", lowIL)                  if CheckLowIL.check ("after translation to LowIL", lowIL)
113                    then quitWithError filename                    then quitWithError filename
114                    else ())                    else ())
115              val lowIL = PhaseTimer.withTimer Timers.timeLow LowOptimizer.optimize lowIL
116    (* no optimization for low-il so don't print
117              val _ = ( (* DEBUG *)
118                    LowPP.output (Log.logFile(), "LowIL after optimization", lowIL);
119                    if CheckLowIL.check ("after LowIL optimization", lowIL)
120                      then quitWithError filename
121                      else ())
122    *)
123            in            in
124              () (* FIXME *)            (***** CODE GENERATION *****)
125            end              PhaseTimer.withTimer Timers.timeCodegen CBackEnd.generate (baseName, lowIL)
126              end)
127    
128      fun doOptions args = let      fun doOptions args = let
129            val log = ref false            val log = ref false
# Line 103  Line 145 
145            val {base, ...} = OS.Path.splitBaseExt file            val {base, ...} = OS.Path.splitBaseExt file
146            in            in
147              if Inputs.initFromArgs defs              if Inputs.initFromArgs defs
148                then (Log.init(base ^ ".log"); doFile file; OS.Process.success)                then (
149                    Log.init(base ^ ".log");
150                    PhaseTimer.withTimer Timers.timeCompiler doFile file;
151                    Log.reportTiming Timers.timeCompiler;
152                    OS.Process.success)
153                  handle exn => (                  handle exn => (
154                    err (concat [                    err (concat [
155                        "uncaught exception ", General.exnName exn, " [", General.exnMessage exn, "]\n"]);                        "uncaught exception ", General.exnName exn, " [", General.exnMessage exn, "]\n"]);

Legend:
Removed from v.1115  
changed lines
  Added in v.1116

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