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 3854, Fri May 13 19:21:27 2016 UTC
# Line 6  Line 6 
6   * All rights reserved.   * All rights reserved.
7   *)   *)
8    
9    (* this is a dummy target for debugging purposes *)
10    structure DummyTarget =
11      struct
12    
13        fun info double = {
14                layout = DefaultLayout.layout (DefaultLayout.gccVectorSizes double),
15                isInline =
16                   fn LowOps.EigenVecs2x2 => false
17                    | LowOps.EigenVecs3x3 => false
18                    | LowOps.EigenVals2x2 => false
19                    | LowOps.EigenVals3x3 => false
20                    | _ => true
21              }
22    
23      end
24    
25  structure Main : sig  structure Main : sig
26    
27      val main : (string * string list) -> OS.Process.status      val main : (string * string list) -> OS.Process.status
# Line 18  Line 34 
34    
35      fun quitWithError srcFile = raise Error.ERROR      fun quitWithError srcFile = raise Error.ERROR
36    
37      (* messages in verbose mode *)
38    (* FIXME: perhaps we should include timing info? *)
39        fun verbosePrint msg = if Controls.get Ctl.verbose
40              then TextIO.output(TextIO.stdErr, concat msg)
41              else ()
42    
43    (* check for errors and report them if there are any *)    (* check for errors and report them if there are any *)
44      fun checkForErrors errStrm =      fun checkForErrors errStrm =
45            if Error.anyErrors errStrm            if Error.anyErrors errStrm
# Line 27  Line 49 
49              else ()              else ()
50    
51    (* conditional printing of intermediate forms *)    (* conditional printing of intermediate forms *)
52      fun dump ctl output message prog = if Controls.get ctl      fun dump ctl output phase prog = if Controls.get ctl
53            then output (Log.logFile(), message, prog)            then output (Log.logFile(), "After "^phase, prog)
54            else ()            else ()
55    
56    (* compiler front end (parsing, typechecking, and simplification *)    (* compiler front end (parsing, typechecking, and simplification *)
# Line 39  Line 61 
61                    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"]);
62                    raise Error.ERROR)                    raise Error.ERROR)
63          (***** PARSING *****)          (***** PARSING *****)
64              val _ = verbosePrint["parsing ... "];
65            val parseTree = PhaseTimer.withTimer Timers.timeParser (fn () => let            val parseTree = PhaseTimer.withTimer Timers.timeParser (fn () => let
66                  val inS = TextIO.openIn filename                  val inS = TextIO.openIn filename
67                  val pt = Parser.parseFile (errStrm, inS)                  val pt = Parser.parseFile (errStrm, inS)
# Line 47  Line 70 
70                    checkForErrors errStrm;                    checkForErrors errStrm;
71                    valOf pt                    valOf pt
72                  end) ()                  end) ()
73            val _ = dump Ctl.dumpPT (ParseTreePP.output errStrm) "" parseTree            val _ = verbosePrint["done\n"];
74              val _ = dump Ctl.dumpPT (ParseTreePP.output errStrm) "parsing" parseTree
75          (***** TYPECHECKING *****)          (***** TYPECHECKING *****)
76              val _ = verbosePrint["type checking ... "];
77            val _ = PhaseTimer.start Timers.timeTypechecker            val _ = PhaseTimer.start Timers.timeTypechecker
78            val ast = (Typechecker.check errStrm parseTree)            val ast = (Typechecker.check errStrm parseTree)
79            val _ = PhaseTimer.stop Timers.timeTypechecker            val _ = PhaseTimer.stop Timers.timeTypechecker
80              val _ = verbosePrint["done\n"];
81            val _ = checkForErrors errStrm            val _ = checkForErrors errStrm
82  (* TODO: check AST for consistency *)  (* TODO: check AST for consistency *)
83            val _ = dump Ctl.dumpAST ASTPP.output "" ast            val _ = dump Ctl.dumpAST ASTPP.output "typechecking" ast
84          (***** SIMPLIFY *****)          (***** SIMPLIFY *****)
85            val simple = Simplify.transform (errStrm, ast)            val _ = verbosePrint["simplifying AST ... "];
86            val _ = dump Ctl.dumpSimple SimplePP.output "after simplify" simple            val simple = SimpleOpt.checkAfter ("simplify", Simplify.transform (errStrm, ast))
87            val simple = SimpleOpt.transform simple            val simple = SimpleOpt.transform simple
88            val _ = dump Ctl.dumpSimple SimplePP.output "after simple optimization" simple            val _ = verbosePrint["done\n"];
89            in            in
           (* check for warnings and report if necessary *)  
             if Error.anyWarnings errStrm  
               then Error.report (TextIO.stdErr, errStrm)  
               else ();  
90              simple              simple
91            end            end
92    
# Line 74  Line 96 
96      fun frontEnd filename = let      fun frontEnd filename = let
97            val errStrm = Error.mkErrStream filename            val errStrm = Error.mkErrStream filename
98            fun finish () = (            fun finish () = (
99                  if Error.anyErrors errStrm                  if Error.anyWarnings errStrm
                   then (  
                     Error.report (TextIO.stdErr, errStrm);  
                     quitWithError (Error.sourceFile errStrm))  
                 else if Error.anyWarnings errStrm  
100                    then Error.report (TextIO.stdErr, errStrm)                    then Error.report (TextIO.stdErr, errStrm)
101                    else ())                    else ())
102            in            in
# Line 86  Line 104 
104              before finish()              before finish()
105            end            end
106    
107      fun doFile (target : Target.desc, filename) = let      fun doFile (target : TargetOptions.t, filename) = let
108            val baseName = (case OS.Path.splitBaseExt filename            val baseName = (case OS.Path.splitBaseExt filename
109                   of {base, ext=SOME "diderot"} => base                   of {base, ext=SOME "diderot"} => base
110                    | _ => (errnl "expected diderot file"; quitWithError filename)                    | _ => (errnl "expected diderot file"; quitWithError filename)
111                  (* end case *))                  (* end case *))
112            val simple = PhaseTimer.withTimer Timers.timeFront frontEnd filename            val simple = PhaseTimer.withTimer Timers.timeFront frontEnd filename
113          (***** TRANSLATION TO HIGH IL*****)          (***** TRANSLATION TO HIGH IR*****)
114            val high = Translate.translate simple            val _ = verbosePrint["translating to HighIR ... "];
115            val _ = dump Ctl.dumpHighIL HighPP.output "after translate" high            val high = PhaseTimer.withTimer Timers.timeTranslate Translate.translate simple
116  (* TODO *)            val _ = verbosePrint["done\n"];
117          (***** HIGH-IL OPTIMIZATION *****)            val _ = dump Ctl.dumpHighIR HighPP.output "translate" high
118  (* TODO *)          (***** HIGH-IR OPTIMIZATION *****)
119          (***** TRANSLATION TO MID IL *****)            val _ = verbosePrint["optimizing HighIR ... "];
120  (* TODO *)            val high = PhaseTimer.withTimer Timers.timeHigh HighOptimizer.optimize high
121          (***** TRANSLATION TO LOW IL *****)            val _ = verbosePrint["done\n"];
122  (* TODO *)          (***** TRANSLATION TO MID IR *****)
123              val _ = verbosePrint["translating to MidIR ... "];
124              val mid = PhaseTimer.withTimer Timers.timeHighToMid HighToMid.translate high
125              val _ = verbosePrint["done\n"];
126              val _ = dump Ctl.dumpMidIR MidPP.output "high-to-mid" mid
127            (***** MID-IR OPTIMIZATION *****)
128              val _ = verbosePrint["optimizing MidIR ... "];
129              val mid = PhaseTimer.withTimer Timers.timeMid MidOptimizer.optimize mid
130              val _ = verbosePrint["done\n"];
131            (***** TRANSLATION TO LOW IR *****)
132              val _ = verbosePrint["translating to LowIR ... "];
133              val low = PhaseTimer.withTimer Timers.timeMidToLow MidToLow.translate mid
134              val _ = verbosePrint["done\n"];
135              val _ = dump Ctl.dumpLowIR LowPP.output "mid-to-low" low
136            (***** LOW-IR OPTIMIZATION *****)
137              val _ = verbosePrint["optimizing LowIR ... "];
138              val low = PhaseTimer.withTimer Timers.timeLow LowOptimizer.optimize low
139              val _ = verbosePrint["done\n"];
140            (***** TRANSLATION TO TREE IR *****)
141              val _ = verbosePrint["translating to TreeIR ... "];
142              val tree = PhaseTimer.withTimer Timers.timeLowToTree LowToTree.translate
143                    (low, DummyTarget.info (#double target))
144              val _ = verbosePrint["done\n"];
145              val _ = dump Ctl.dumpTreeIR TreePP.output "low-to-tree" tree
146            in            in
147            (***** CODE GENERATION *****)            (***** CODE GENERATION *****)
148  (* TODO *)()  (* TODO *)()
# Line 119  Line 160 
160            OS.Process.failure)            OS.Process.failure)
161    
162      fun main (name: string, args: string list) = let      fun main (name: string, args: string list) = let
163              val _ = PhaseTimer.start Timers.timeCompiler
164            val {help, version, target, defs, file} =            val {help, version, target, defs, file} =
165                  (Options.parseCmdLine args)                  (Options.parseCmdLine args)
166                    handle Options.Usage msg => (                    handle Options.Usage msg => (
# Line 133  Line 175 
175                    then (print(Version.message ^ "\n"); OS.Process.success)                    then (print(Version.message ^ "\n"); OS.Process.success)
176                    else let                    else let
177                      val {base, ...} = OS.Path.splitBaseExt file                      val {base, ...} = OS.Path.splitBaseExt file
178                        val logging = Controls.get Ctl.enableLog
179                      in                      in
180                      (* set the default real type *)                      (* set the default real type *)
181                        if #double target then (RawTypes.realTy := RawTypes.RT_Double) else ();                        if #double target then (RawTypes.realTy := RawTypes.RT_Double) else ();
182                        if CmdLineConstants.initFromArgs defs                        if CmdLineConstants.initFromArgs defs
183                          then (                          then (
184                            if Controls.get Ctl.enableLog                            if logging
185                              then Log.init(base ^ ".log")                              then Log.init(base ^ ".log")
186                              else ();                              else ();
                           PhaseTimer.withTimer Timers.timeCompiler  
187                              doFile (target, file);                              doFile (target, file);
188                            Stats.report ();                            if Controls.get Ctl.collectStats
189                                then (
190                                  if (not logging)
191                                    then Log.init(base ^ ".stats")
192                                    else ();
193                                  Stats.report ())
194                                else ();
195                              PhaseTimer.stop Timers.timeCompiler;
196                            Log.reportTiming Timers.timeCompiler;                            Log.reportTiming Timers.timeCompiler;
197                            OS.Process.success                            OS.Process.success
198                          ) handle exn => handleExn exn                          ) handle exn => handleExn exn

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

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