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 3417, Thu Nov 12 23:41:06 2015 UTC revision 3814, Wed May 4 14:26:07 2016 UTC
# Line 16  Line 16 
16      fun err1 c =  TextIO.output1 (TextIO.stdErr, c)      fun err1 c =  TextIO.output1 (TextIO.stdErr, c)
17      fun errnl s = (err s; err1 #"\n")      fun errnl s = (err s; err1 #"\n")
18    
19      exception ERROR      fun quitWithError srcFile = raise Error.ERROR
20    
21      fun quitWithError srcFile = raise ERROR    (* 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 =
# Line 28  Line 32 
32                quitWithError (Error.sourceFile errStrm))                quitWithError (Error.sourceFile errStrm))
33              else ()              else ()
34    
35      (* conditional printing of intermediate forms *)
36        fun dump ctl output phase prog = if Controls.get ctl
37              then output (Log.logFile(), "After "^phase, prog)
38              else ()
39    
40    (* compiler front end (parsing, typechecking, and simplification *)    (* compiler front end (parsing, typechecking, and simplification *)
41      fun frontEnd filename = let      fun frontEnd' (errStrm, filename) = let
           val errStrm = Error.mkErrStream filename  
42            val _ = if OS.FileSys.access(filename, [OS.FileSys.A_READ])            val _ = if OS.FileSys.access(filename, [OS.FileSys.A_READ])
43                  then ()                  then ()
44                  else (                  else (
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)                    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 45  Line 54 
54                    checkForErrors errStrm;                    checkForErrors errStrm;
55                    valOf pt                    valOf pt
56                  end) ()                  end) ()
57              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 _ = if Controls.get Ctl.dumpAST            val _ = dump Ctl.dumpAST ASTPP.output "typechecking" ast
                     then ASTPP.output (Log.logFile(), ast)  
                     else ()  
68          (***** SIMPLIFY *****)          (***** SIMPLIFY *****)
69  (* TODO *)            val _ = verbosePrint["simplifying AST ... "];
70              val simple = SimpleOpt.checkAfter ("simplify", Simplify.transform (errStrm, ast))
71              val simple = SimpleOpt.transform simple
72              val _ = verbosePrint["done\n"];
73            in            in
74            (* check for warnings and report if necessary *)              simple
75              end
76    
77      (* a wrapper around the front-end that handles the Error.ERROR exception and reports
78       * the error messages.
79       *)
80        fun frontEnd filename = let
81              val errStrm = Error.mkErrStream filename
82              fun finish () = (
83              if Error.anyWarnings errStrm              if Error.anyWarnings errStrm
84                then Error.report (TextIO.stdErr, errStrm)                then Error.report (TextIO.stdErr, errStrm)
85                else ();                    else ())
86              ()            in
87                (frontEnd' (errStrm, filename) handle exn => (finish (); raise exn))
88                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  (* TODO *)            val _ = verbosePrint["translating to HighIR ... "];
99          (***** HIGH-IL OPTIMIZATION *****)            val high = PhaseTimer.withTimer Timers.timeTranslate Translate.translate simple
100  (* TODO *)            val _ = verbosePrint["done\n"];
101          (***** TRANSLATION TO MID IL *****)            val _ = dump Ctl.dumpHighIR HighPP.output "translate" high
102  (* TODO *)          (***** HIGH-IR OPTIMIZATION *****)
103          (***** TRANSLATION TO LOW IL *****)            val _ = verbosePrint["optimizing HighIR ... "];
104  (* TODO *)            val high = PhaseTimer.withTimer Timers.timeHigh HighOptimizer.optimize high
105              val _ = verbosePrint["done\n"];
106            (***** 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    (* TODO *
126              val _ = verbosePrint["translating to TreeIR ... "];
127              val tree = PhaseTimer.withTimer Timers.timeLowToTree LowToTree.translate low
128              val _ = verbosePrint["done\n"];
129              val _ = dump Ctl.dumpLowIR TreePP.output "low-to-tree" tree
130    *)
131            in            in
132            (***** CODE GENERATION *****)            (***** CODE GENERATION *****)
133  (* TODO *)()  (* TODO *)()
# Line 85  Line 135 
135    
136      fun usage (cmd, long) = TextIO.output(TextIO.stdErr, Options.usage (cmd, long))      fun usage (cmd, long) = TextIO.output(TextIO.stdErr, Options.usage (cmd, long))
137    
138      fun handleExn ERROR = OS.Process.failure      fun handleExn Error.ERROR = OS.Process.failure
139        | handleExn exn = (        | handleExn exn = (
140            err (concat [            err (concat [
141                "uncaught exception ", General.exnName exn,                "uncaught exception ", General.exnName exn,
# Line 95  Line 145 
145            OS.Process.failure)            OS.Process.failure)
146    
147      fun main (name: string, args: string list) = let      fun main (name: string, args: string list) = let
148              val _ = PhaseTimer.start Timers.timeCompiler
149            val {help, version, target, defs, file} =            val {help, version, target, defs, file} =
150                  (Options.parseCmdLine args)                  (Options.parseCmdLine args)
151                    handle Options.Usage msg => (                    handle Options.Usage msg => (
# Line 109  Line 160 
160                    then (print(Version.message ^ "\n"); OS.Process.success)                    then (print(Version.message ^ "\n"); OS.Process.success)
161                    else let                    else let
162                      val {base, ...} = OS.Path.splitBaseExt file                      val {base, ...} = OS.Path.splitBaseExt file
163                        val logging = Controls.get Ctl.enableLog
164                      in                      in
165                      (* set the default real type *)                      (* set the default real type *)
166                        if #double target then (RawTypes.realTy := RawTypes.RT_Double) else ();                        if #double target then (RawTypes.realTy := RawTypes.RT_Double) else ();
167                        if CmdLineConstants.initFromArgs defs                        if CmdLineConstants.initFromArgs defs
168                          then (                          then (
169                            if Controls.get Ctl.enableLog                            if logging
170                              then Log.init(base ^ ".log")                              then Log.init(base ^ ".log")
171                              else ();                              else ();
                           PhaseTimer.withTimer Timers.timeCompiler  
172                              doFile (target, file);                              doFile (target, file);
173                            Stats.report ();                            if Controls.get Ctl.collectStats
174                                then (
175                                  if (not logging)
176                                    then Log.init(base ^ ".stats")
177                                    else ();
178                                  Stats.report ())
179                                else ();
180                              PhaseTimer.stop Timers.timeCompiler;
181                            Log.reportTiming Timers.timeCompiler;                            Log.reportTiming Timers.timeCompiler;
182                            OS.Process.success                            OS.Process.success
183                          ) handle exn => handleExn exn                          ) handle exn => handleExn exn

Legend:
Removed from v.3417  
changed lines
  Added in v.3814

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