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

SCM Repository

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

Diff of /branches/vis15/src/compiler/driver/main.sml

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

revision 3506, Fri Dec 18 04:03:54 2015 UTC revision 3835, Sun May 8 13:10:17 2016 UTC
# Line 18  Line 18 
18    
19      fun quitWithError srcFile = raise Error.ERROR      fun quitWithError srcFile = raise Error.ERROR
20    
21      (* messages in verbose mode *)
22    (* FIXME: perhaps we should include timing info? *)
23        fun verbosePrint msg = if Controls.get Ctl.verbose
24              then TextIO.output(TextIO.stdErr, concat msg)
25              else ()
26    
27    (* check for errors and report them if there are any *)    (* check for errors and report them if there are any *)
28      fun checkForErrors errStrm =      fun checkForErrors errStrm =
29            if Error.anyErrors errStrm            if Error.anyErrors errStrm
# Line 27  Line 33 
33              else ()              else ()
34    
35    (* conditional printing of intermediate forms *)    (* conditional printing of intermediate forms *)
36      fun dump ctl output message prog = if Controls.get ctl      fun dump ctl output phase prog = if Controls.get ctl
37            then output (Log.logFile(), message, prog)            then output (Log.logFile(), "After "^phase, prog)
38            else ()            else ()
39    
40    (* compiler front end (parsing, typechecking, and simplification *)    (* compiler front end (parsing, typechecking, and simplification *)
# Line 39  Line 45 
45                    err(concat["source file \"", filename, "\" does not exist or is not readable\n"]);                    err(concat["source file \"", filename, "\" does not exist or is not readable\n"]);
46                    raise Error.ERROR)                    raise Error.ERROR)
47          (***** PARSING *****)          (***** PARSING *****)
48              val _ = verbosePrint["parsing ... "];
49            val parseTree = PhaseTimer.withTimer Timers.timeParser (fn () => let            val parseTree = PhaseTimer.withTimer Timers.timeParser (fn () => let
50                  val inS = TextIO.openIn filename                  val inS = TextIO.openIn filename
51                  val pt = Parser.parseFile (errStrm, inS)                  val pt = Parser.parseFile (errStrm, inS)
# Line 47  Line 54 
54                    checkForErrors errStrm;                    checkForErrors errStrm;
55                    valOf pt                    valOf pt
56                  end) ()                  end) ()
57            val _ = dump Ctl.dumpPT (ParseTreePP.output errStrm) "" parseTree            val _ = verbosePrint["done\n"];
58              val _ = dump Ctl.dumpPT (ParseTreePP.output errStrm) "parsing" parseTree
59          (***** TYPECHECKING *****)          (***** TYPECHECKING *****)
60              val _ = verbosePrint["type checking ... "];
61            val _ = PhaseTimer.start Timers.timeTypechecker            val _ = PhaseTimer.start Timers.timeTypechecker
62            val ast = (Typechecker.check errStrm parseTree)            val ast = (Typechecker.check errStrm parseTree)
63            val _ = PhaseTimer.stop Timers.timeTypechecker            val _ = PhaseTimer.stop Timers.timeTypechecker
64              val _ = verbosePrint["done\n"];
65            val _ = checkForErrors errStrm            val _ = checkForErrors errStrm
66  (* TODO: check AST for consistency *)  (* TODO: check AST for consistency *)
67            val _ = dump Ctl.dumpAST ASTPP.output "" ast            val _ = dump Ctl.dumpAST ASTPP.output "typechecking" ast
68          (***** SIMPLIFY *****)          (***** SIMPLIFY *****)
69            val simple = Simplify.transform (errStrm, ast)            val _ = verbosePrint["simplifying AST ... "];
70            val _ = dump Ctl.dumpSimple SimplePP.output "after simplify" simple            val simple = SimpleOpt.checkAfter ("simplify", Simplify.transform (errStrm, ast))
71            val simple = SimpleOpt.transform simple            val simple = SimpleOpt.transform simple
72            val _ = dump Ctl.dumpSimple SimplePP.output "after simple optimization" simple            val _ = verbosePrint["done\n"];
73            in            in
           (* check for warnings and report if necessary *)  
             if Error.anyWarnings errStrm  
               then Error.report (TextIO.stdErr, errStrm)  
               else ();  
74              simple              simple
75            end            end
76    
# Line 74  Line 80 
80      fun frontEnd filename = let      fun frontEnd filename = let
81            val errStrm = Error.mkErrStream filename            val errStrm = Error.mkErrStream filename
82            fun finish () = (            fun finish () = (
83                  if Error.anyErrors errStrm                  if Error.anyWarnings errStrm
                   then (  
                     Error.report (TextIO.stdErr, errStrm);  
                     quitWithError (Error.sourceFile errStrm))  
                 else if Error.anyWarnings errStrm  
84                    then Error.report (TextIO.stdErr, errStrm)                    then Error.report (TextIO.stdErr, errStrm)
85                    else ())                    else ())
86            in            in
# Line 86  Line 88 
88              before finish()              before finish()
89            end            end
90    
91      fun doFile (target : Target.desc, filename) = let      fun doFile (target : TargetOptions.t, filename) = let
92            val baseName = (case OS.Path.splitBaseExt filename            val baseName = (case OS.Path.splitBaseExt filename
93                   of {base, ext=SOME "diderot"} => base                   of {base, ext=SOME "diderot"} => base
94                    | _ => (errnl "expected diderot file"; quitWithError filename)                    | _ => (errnl "expected diderot file"; quitWithError filename)
95                  (* end case *))                  (* end case *))
96            val simple = PhaseTimer.withTimer Timers.timeFront frontEnd filename            val simple = PhaseTimer.withTimer Timers.timeFront frontEnd filename
97          (***** TRANSLATION TO HIGH IL*****)          (***** TRANSLATION TO HIGH IR*****)
98            val high = Translate.translate simple            val _ = verbosePrint["translating to HighIR ... "];
99            val _ = dump Ctl.dumpHighIL HighPP.output "after translate" high            val high = PhaseTimer.withTimer Timers.timeTranslate Translate.translate simple
100  (* TODO *)            val _ = verbosePrint["done\n"];
101          (***** HIGH-IL OPTIMIZATION *****)            val _ = dump Ctl.dumpHighIR HighPP.output "translate" high
102  (* TODO *)          (***** HIGH-IR OPTIMIZATION *****)
103          (***** TRANSLATION TO MID IL *****)            val _ = verbosePrint["optimizing HighIR ... "];
104  (* TODO *)            val high = PhaseTimer.withTimer Timers.timeHigh HighOptimizer.optimize high
105          (***** TRANSLATION TO LOW IL *****)            val _ = verbosePrint["done\n"];
106  (* TODO *)          (***** TRANSLATION TO MID IR *****)
107              val _ = verbosePrint["translating to MidIR ... "];
108              val mid = PhaseTimer.withTimer Timers.timeHighToMid HighToMid.translate high
109              val _ = verbosePrint["done\n"];
110              val _ = dump Ctl.dumpMidIR MidPP.output "high-to-mid" mid
111            (***** MID-IR OPTIMIZATION *****)
112              val _ = verbosePrint["optimizing MidIR ... "];
113              val mid = PhaseTimer.withTimer Timers.timeMid MidOptimizer.optimize mid
114              val _ = verbosePrint["done\n"];
115            (***** TRANSLATION TO LOW IR *****)
116              val _ = verbosePrint["translating to LowIR ... "];
117              val low = PhaseTimer.withTimer Timers.timeMidToLow MidToLow.translate mid
118              val _ = verbosePrint["done\n"];
119              val _ = dump Ctl.dumpLowIR LowPP.output "mid-to-low" low
120            (***** LOW-IR OPTIMIZATION *****)
121              val _ = verbosePrint["optimizing LowIR ... "];
122              val low = PhaseTimer.withTimer Timers.timeLow LowOptimizer.optimize low
123              val _ = verbosePrint["done\n"];
124            (***** TRANSLATION TO TREE IR *****)
125              val _ = verbosePrint["translating to TreeIR ... "];
126              val tree = PhaseTimer.withTimer Timers.timeLowToTree LowToTree.translate low
127              val _ = verbosePrint["done\n"];
128              val _ = dump Ctl.dumpTreeIR TreePP.output "low-to-tree" tree
129            in            in
130            (***** CODE GENERATION *****)            (***** CODE GENERATION *****)
131  (* TODO *)()  (* TODO *)()
# Line 119  Line 143 
143            OS.Process.failure)            OS.Process.failure)
144    
145      fun main (name: string, args: string list) = let      fun main (name: string, args: string list) = let
146              val _ = PhaseTimer.start Timers.timeCompiler
147            val {help, version, target, defs, file} =            val {help, version, target, defs, file} =
148                  (Options.parseCmdLine args)                  (Options.parseCmdLine args)
149                    handle Options.Usage msg => (                    handle Options.Usage msg => (
# Line 133  Line 158 
158                    then (print(Version.message ^ "\n"); OS.Process.success)                    then (print(Version.message ^ "\n"); OS.Process.success)
159                    else let                    else let
160                      val {base, ...} = OS.Path.splitBaseExt file                      val {base, ...} = OS.Path.splitBaseExt file
161                        val logging = Controls.get Ctl.enableLog
162                      in                      in
163                      (* set the default real type *)                      (* set the default real type *)
164                        if #double target then (RawTypes.realTy := RawTypes.RT_Double) else ();                        if #double target then (RawTypes.realTy := RawTypes.RT_Double) else ();
165                        if CmdLineConstants.initFromArgs defs                        if CmdLineConstants.initFromArgs defs
166                          then (                          then (
167                            if Controls.get Ctl.enableLog                            if logging
168                              then Log.init(base ^ ".log")                              then Log.init(base ^ ".log")
169                              else ();                              else ();
                           PhaseTimer.withTimer Timers.timeCompiler  
170                              doFile (target, file);                              doFile (target, file);
171                            Stats.report ();                            if Controls.get Ctl.collectStats
172                                then (
173                                  if (not logging)
174                                    then Log.init(base ^ ".stats")
175                                    else ();
176                                  Stats.report ())
177                                else ();
178                              PhaseTimer.stop Timers.timeCompiler;
179                            Log.reportTiming Timers.timeCompiler;                            Log.reportTiming Timers.timeCompiler;
180                            OS.Process.success                            OS.Process.success
181                          ) handle exn => handleExn exn                          ) handle exn => handleExn exn

Legend:
Removed from v.3506  
changed lines
  Added in v.3835

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