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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3861 - (view) (download)

1 : jhr 3394 (* main.sml
2 :     *
3 :     * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     *
5 :     * COPYRIGHT (c) 2015 The University of Chicago
6 :     * All rights reserved.
7 :     *)
8 :    
9 : jhr 3854 (* 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 : jhr 3394 structure Main : sig
26 :    
27 :     val main : (string * string list) -> OS.Process.status
28 :    
29 :     end = struct
30 :    
31 :     fun err s = TextIO.output (TextIO.stdErr, s)
32 :     fun err1 c = TextIO.output1 (TextIO.stdErr, c)
33 :     fun errnl s = (err s; err1 #"\n")
34 :    
35 : jhr 3445 fun quitWithError srcFile = raise Error.ERROR
36 : jhr 3394
37 : jhr 3731 (* 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 : jhr 3394 (* check for errors and report them if there are any *)
44 :     fun checkForErrors errStrm =
45 :     if Error.anyErrors errStrm
46 :     then (
47 :     Error.report (TextIO.stdErr, errStrm);
48 :     quitWithError (Error.sourceFile errStrm))
49 :     else ()
50 :    
51 : jhr 3437 (* conditional printing of intermediate forms *)
52 : jhr 3508 fun dump ctl output phase prog = if Controls.get ctl
53 :     then output (Log.logFile(), "After "^phase, prog)
54 : jhr 3437 else ()
55 :    
56 : jhr 3394 (* compiler front end (parsing, typechecking, and simplification *)
57 : jhr 3445 fun frontEnd' (errStrm, filename) = let
58 : jhr 3394 val _ = if OS.FileSys.access(filename, [OS.FileSys.A_READ])
59 :     then ()
60 :     else (
61 :     err(concat["source file \"", filename, "\" does not exist or is not readable\n"]);
62 : jhr 3445 raise Error.ERROR)
63 : jhr 3394 (***** PARSING *****)
64 : jhr 3731 val _ = verbosePrint["parsing ... "];
65 : jhr 3394 val parseTree = PhaseTimer.withTimer Timers.timeParser (fn () => let
66 :     val inS = TextIO.openIn filename
67 :     val pt = Parser.parseFile (errStrm, inS)
68 :     in
69 :     TextIO.closeIn inS;
70 :     checkForErrors errStrm;
71 :     valOf pt
72 :     end) ()
73 : jhr 3731 val _ = verbosePrint["done\n"];
74 : jhr 3508 val _ = dump Ctl.dumpPT (ParseTreePP.output errStrm) "parsing" parseTree
75 : jhr 3394 (***** TYPECHECKING *****)
76 : jhr 3731 val _ = verbosePrint["type checking ... "];
77 : jhr 3394 val _ = PhaseTimer.start Timers.timeTypechecker
78 :     val ast = (Typechecker.check errStrm parseTree)
79 :     val _ = PhaseTimer.stop Timers.timeTypechecker
80 : jhr 3731 val _ = verbosePrint["done\n"];
81 : jhr 3394 val _ = checkForErrors errStrm
82 : jhr 3417 (* TODO: check AST for consistency *)
83 : jhr 3508 val _ = dump Ctl.dumpAST ASTPP.output "typechecking" ast
84 : jhr 3394 (***** SIMPLIFY *****)
85 : jhr 3731 val _ = verbosePrint["simplifying AST ... "];
86 : jhr 3508 val simple = SimpleOpt.checkAfter ("simplify", Simplify.transform (errStrm, ast))
87 : jhr 3437 val simple = SimpleOpt.transform simple
88 : jhr 3731 val _ = verbosePrint["done\n"];
89 : jhr 3394 in
90 : jhr 3506 simple
91 : jhr 3394 end
92 :    
93 : jhr 3445 (* a wrapper around the front-end that handles the Error.ERROR exception and reports
94 :     * the error messages.
95 :     *)
96 :     fun frontEnd filename = let
97 :     val errStrm = Error.mkErrStream filename
98 :     fun finish () = (
99 : jhr 3585 if Error.anyWarnings errStrm
100 : jhr 3445 then Error.report (TextIO.stdErr, errStrm)
101 :     else ())
102 :     in
103 :     (frontEnd' (errStrm, filename) handle exn => (finish (); raise exn))
104 :     before finish()
105 :     end
106 :    
107 : jhr 3813 fun doFile (target : TargetOptions.t, filename) = let
108 : jhr 3394 val baseName = (case OS.Path.splitBaseExt filename
109 :     of {base, ext=SOME "diderot"} => base
110 :     | _ => (errnl "expected diderot file"; quitWithError filename)
111 :     (* end case *))
112 :     val simple = PhaseTimer.withTimer Timers.timeFront frontEnd filename
113 : jhr 3521 (***** TRANSLATION TO HIGH IR*****)
114 : jhr 3731 val _ = verbosePrint["translating to HighIR ... "];
115 : jhr 3814 val high = PhaseTimer.withTimer Timers.timeTranslate Translate.translate simple
116 : jhr 3731 val _ = verbosePrint["done\n"];
117 : jhr 3860 val high = HighOptimizer.checkAfter ("simple-to-high translation", high)
118 : jhr 3521 (***** HIGH-IR OPTIMIZATION *****)
119 : jhr 3731 val _ = verbosePrint["optimizing HighIR ... "];
120 : jhr 3814 val high = PhaseTimer.withTimer Timers.timeHigh HighOptimizer.optimize high
121 : jhr 3731 val _ = verbosePrint["done\n"];
122 : jhr 3521 (***** TRANSLATION TO MID IR *****)
123 : jhr 3731 val _ = verbosePrint["translating to MidIR ... "];
124 : jhr 3814 val mid = PhaseTimer.withTimer Timers.timeHighToMid HighToMid.translate high
125 : jhr 3731 val _ = verbosePrint["done\n"];
126 : jhr 3861 val mid = MidOptimizer.checkAfter ("high-to-mid translation", mid)
127 : jhr 3586 (***** MID-IR OPTIMIZATION *****)
128 : jhr 3731 val _ = verbosePrint["optimizing MidIR ... "];
129 : jhr 3814 val mid = PhaseTimer.withTimer Timers.timeMid MidOptimizer.optimize mid
130 : jhr 3731 val _ = verbosePrint["done\n"];
131 : jhr 3521 (***** TRANSLATION TO LOW IR *****)
132 : jhr 3731 val _ = verbosePrint["translating to LowIR ... "];
133 : jhr 3814 val low = PhaseTimer.withTimer Timers.timeMidToLow MidToLow.translate mid
134 : jhr 3731 val _ = verbosePrint["done\n"];
135 : jhr 3861 val low = LowOptimizer.checkAfter ("mid-to-low translation", low)
136 : jhr 3747 (***** LOW-IR OPTIMIZATION *****)
137 :     val _ = verbosePrint["optimizing LowIR ... "];
138 : jhr 3814 val low = PhaseTimer.withTimer Timers.timeLow LowOptimizer.optimize low
139 : jhr 3747 val _ = verbosePrint["done\n"];
140 : jhr 3753 (***** TRANSLATION TO TREE IR *****)
141 :     val _ = verbosePrint["translating to TreeIR ... "];
142 : jhr 3854 val tree = PhaseTimer.withTimer Timers.timeLowToTree LowToTree.translate
143 :     (low, DummyTarget.info (#double target))
144 : jhr 3753 val _ = verbosePrint["done\n"];
145 : jhr 3861 val tree = TreeOptimizer.checkAfter ("low-to-tree translation", tree)
146 :     (***** TREE-IR OPTIMIZATION *****)
147 :     val _ = verbosePrint["optimizing TreeIR ... "];
148 :     val tree = PhaseTimer.withTimer Timers.timeTree TreeOptimizer.optimize tree
149 :     val _ = verbosePrint["done\n"];
150 : jhr 3394 in
151 :     (***** CODE GENERATION *****)
152 :     (* TODO *)()
153 :     end
154 :    
155 : jhr 3411 fun usage (cmd, long) = TextIO.output(TextIO.stdErr, Options.usage (cmd, long))
156 : jhr 3394
157 : jhr 3445 fun handleExn Error.ERROR = OS.Process.failure
158 : jhr 3394 | handleExn exn = (
159 :     err (concat [
160 :     "uncaught exception ", General.exnName exn,
161 :     " [", General.exnMessage exn, "]\n"
162 :     ]);
163 :     List.app (fn s => err (concat [" raised at ", s, "\n"])) (SMLofNJ.exnHistory exn);
164 :     OS.Process.failure)
165 :    
166 :     fun main (name: string, args: string list) = let
167 : jhr 3814 val _ = PhaseTimer.start Timers.timeCompiler
168 : jhr 3411 val {help, version, target, defs, file} =
169 : jhr 3394 (Options.parseCmdLine args)
170 :     handle Options.Usage msg => (
171 :     err(concat[msg, "\n"]);
172 : jhr 3411 usage (name, false);
173 : jhr 3394 OS.Process.exit OS.Process.failure)
174 :     in
175 : jhr 3417 Ctl.resolve();
176 : jhr 3411 case help
177 :     of SOME long => (usage (name, long); OS.Process.success)
178 :     | NONE => if version
179 :     then (print(Version.message ^ "\n"); OS.Process.success)
180 :     else let
181 :     val {base, ...} = OS.Path.splitBaseExt file
182 : jhr 3731 val logging = Controls.get Ctl.enableLog
183 : jhr 3411 in
184 :     (* set the default real type *)
185 :     if #double target then (RawTypes.realTy := RawTypes.RT_Double) else ();
186 :     if CmdLineConstants.initFromArgs defs
187 :     then (
188 : jhr 3731 if logging
189 : jhr 3411 then Log.init(base ^ ".log")
190 :     else ();
191 : jhr 3814 doFile (target, file);
192 : jhr 3731 if Controls.get Ctl.collectStats
193 :     then (
194 :     if (not logging)
195 :     then Log.init(base ^ ".stats")
196 :     else ();
197 :     Stats.report ())
198 :     else ();
199 : jhr 3814 PhaseTimer.stop Timers.timeCompiler;
200 : jhr 3411 Log.reportTiming Timers.timeCompiler;
201 :     OS.Process.success
202 :     ) handle exn => handleExn exn
203 :     else (err "invalid command-line inputs\n"; OS.Process.failure)
204 :     end
205 :     (* end case *)
206 : jhr 3394 end
207 :    
208 :     end

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