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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3998 - (view) (download)

1 : jhr 33 (* main.sml
2 :     *
3 : jhr 3349 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     *
5 :     * COPYRIGHT (c) 2015 The University of Chicago
6 : jhr 33 * All rights reserved.
7 :     *)
8 :    
9 :     structure Main : sig
10 :    
11 :     val main : (string * string list) -> OS.Process.status
12 :    
13 :     end = struct
14 :    
15 : jhr 1116 (* exception tracing magic *)
16 : jhr 1166 (*
17 : jhr 1116 val _ = (
18 :     SMLofNJ.Internals.TDP.mode := true;
19 :     Coverage.install ();
20 :     BackTrace.install ())
21 : jhr 1166 *)
22 : jhr 256
23 : jhr 33 fun err s = TextIO.output (TextIO.stdErr, s)
24 :     fun err1 c = TextIO.output1 (TextIO.stdErr, c)
25 :     fun errnl s = (err s; err1 #"\n")
26 :    
27 : jhr 429 exception ERROR
28 : jhr 33
29 : jhr 2356 fun quitWithError srcFile = raise ERROR
30 : jhr 429
31 : cchiw 3998 val testing = 0
32 : cchiw 3325 fun testp e = (case testing
33 :     of 0 => ()
34 :     | _=> print(String.concat ["\n\t\t------------",e,"-----------\n"]))
35 : cchiw 2845
36 : cchiw 3325 (* modules for count the size of the program at various stages *)
37 :     structure SizeOfHigh = SizeOfProgramFn(HighIL)
38 :     structure SizeOfMid = SizeOfProgramFn(MidIL)
39 :     structure SizeOfLow = SizeOfProgramFn(LowIL)
40 :    
41 : jhr 33 (* check for errors and report them if there are any *)
42 : jhr 2356 fun checkForErrors errStrm =
43 : jhr 3003 if Error.anyErrors errStrm
44 :     then (
45 :     Error.report (TextIO.stdErr, errStrm);
46 :     quitWithError (Error.sourceFile errStrm))
47 :     else ()
48 : jhr 33
49 : jhr 1116 (* compiler front end (parsing, typechecking, and simplification *)
50 :     fun frontEnd filename = let
51 : jhr 3003 val errStrm = Error.mkErrStream filename
52 :     val _ = if OS.FileSys.access(filename, [OS.FileSys.A_READ])
53 :     then ()
54 :     else (
55 :     err(concat["source file \"", filename, "\" does not exist or is not readable\n"]);
56 :     raise ERROR)
57 :     (***** PARSING *****)
58 :     val parseTree = PhaseTimer.withTimer Timers.timeParser (fn () => let
59 :     val inS = TextIO.openIn filename
60 :     val pt = Parser.parseFile (errStrm, inS)
61 :     in
62 :     TextIO.closeIn inS;
63 :     checkForErrors errStrm;
64 :     valOf pt
65 :     end) ()
66 :     (***** TYPECHECKING *****)
67 :     val _ = PhaseTimer.start Timers.timeTypechecker
68 :     val ast = (Typechecker.check errStrm parseTree)
69 :     val _ = PhaseTimer.stop Timers.timeTypechecker
70 :     val _ = checkForErrors errStrm
71 :     val _ = ASTPP.output (Log.logFile(), ast) (* DEBUG *)
72 :     (***** SIMPLIFY *****)
73 :     val _ = PhaseTimer.start Timers.timeSimplify
74 :     val simple = Simplify.transform (errStrm, ast)
75 :     val _ = checkForErrors errStrm
76 :     val _ = PhaseTimer.stop Timers.timeSimplify
77 : jhr 2356 (* currently handled by Simplify
78 : jhr 3003 val _ = SimplePP.output (Log.logFile(), simple) (* DEBUG *)
79 : jhr 2356 *)
80 : jhr 3003 in
81 :     (* check for warnings and report if necessary *)
82 :     if Error.anyWarnings errStrm
83 :     then Error.report (TextIO.stdErr, errStrm)
84 :     else ();
85 :     simple
86 :     end
87 : jhr 1116
88 : jhr 2451 fun doFile (target : TargetUtil.target_desc, filename, optOutput) = let
89 : jhr 3003 val baseName = (case OS.Path.splitBaseExt filename
90 :     of {base, ext=SOME "diderot"} => base
91 :     | _ => (errnl "expected diderot file"; quitWithError filename)
92 :     (* end case *))
93 :     val simple = PhaseTimer.withTimer Timers.timeFront frontEnd filename
94 :     (***** TRANSLATION TO HIGH IL*****)
95 : cchiw 3947
96 : cchiw 3325 val _ = PhaseTimer.start Timers.timeTranslate
97 : jhr 3003 val highIL = Translate.translate simple
98 : cchiw 3998 (*
99 :     val _ = SizeOfHigh.count ("", highIL)*)
100 : cchiw 3325 val _ = PhaseTimer.stop Timers.timeTranslate
101 : jhr 3003 (***** HIGH-IL OPTIMIZATION *****)
102 :     val _=testp"In HighIL"
103 :     val _ = PhaseTimer.start Timers.timeHigh
104 : cchiw 3557
105 : cchiw 3667 (* val _=testp "High Op"*)
106 : cchiw 3557
107 : jhr 3003 val highIL = HighOptimizer.optimize highIL
108 : cchiw 3998 (*
109 : cchiw 3947 val _ = SizeOfHigh.count ("", highIL)
110 : cchiw 3998 *)
111 : cchiw 3557
112 : cchiw 3595 val _ = PhaseTimer.stop Timers.timeHigh
113 : cchiw 3325 (*val _=PhaseTimer.report(TextIO.stdOut,Timers.timeHigh)*)
114 : jhr 3003 (***** TRANSLATION TO MID IL *****)
115 : cchiw 3667 (* val _=testp "High to mid"*)
116 : cchiw 2845 val midIL = PhaseTimer.withTimer Timers.timeMid HighToMid.translate highIL
117 : cchiw 3998 (* val _ = SizeOfMid.count ("", midIL)*)
118 : cchiw 2845 val _=testp "Mid Op"
119 : jhr 3003 val midIL = PhaseTimer.withTimer Timers.timeMid MidOptimizer.optimize midIL
120 : cchiw 3998 (* val _ = SizeOfMid.count ("", midIL)*)
121 : cchiw 3325 (*val _=PhaseTimer.report(TextIO.stdOut,Timers.timeMid)*)
122 : jhr 3003 (***** TRANSLATION TO LOW IL *****)
123 : cchiw 2845 val _=testp "Mid to Low IL"
124 : jhr 3003 val lowIL = PhaseTimer.withTimer Timers.timeLow MidToLow.translate midIL
125 : cchiw 3998 (* val _ = SizeOfLow.count ("", lowIL)*)
126 : cchiw 2845 val _=testp "Low IL Op"
127 : jhr 3003 val lowIL = PhaseTimer.withTimer Timers.timeLow LowOptimizer.optimize lowIL
128 : cchiw 3541 val lowIL = Normalize.transform lowIL
129 : cchiw 3998 (* val _ = SizeOfLow.count ("", lowIL)*)
130 : cchiw 3667 (* val _ = testp "Code Gen"*)
131 : cchiw 3541 (*val _=PhaseTimer.report(TextIO.stdOut,Timers.timeLow)*)
132 : jhr 3003 in
133 :     (***** CODE GENERATION *****)
134 :     PhaseTimer.withTimer Timers.timeCodegen
135 :     (BackEnd.generate target)
136 : jhr 2451 (Option.getOpt(optOutput, baseName), lowIL)
137 : jhr 3003 end
138 : cchiw 2615
139 : jhr 1232 fun usage cmd = TextIO.output(TextIO.stdErr, Options.usage cmd)
140 : jhr 33
141 : jhr 2356 fun handleExn ERROR = OS.Process.failure
142 :     | handleExn exn = (
143 : jhr 3003 err (concat [
144 :     "uncaught exception ", General.exnName exn,
145 :     " [", General.exnMessage exn, "]\n"
146 :     ]);
147 :     List.app (fn s => err (concat [" raised at ", s, "\n"])) (SMLofNJ.exnHistory exn);
148 :     OS.Process.failure)
149 : jhr 2356
150 : jhr 238 fun main (name: string, args: string list) = let
151 : jhr 3003 val {help, version, log, target, output, defs, file} =
152 :     (Options.parseCmdLine args)
153 :     handle Options.Usage msg => (
154 :     err(concat[msg, "\n"]);
155 :     usage name;
156 :     OS.Process.exit OS.Process.failure)
157 :     in
158 :     if help
159 :     then (usage name; OS.Process.success)
160 :     else if version
161 :     then (print(Version.message ^ "\n"); OS.Process.success)
162 :     else let
163 :     val {base, ...} = OS.Path.splitBaseExt file
164 :     in
165 :     if CmdLineInputs.initFromArgs defs
166 :     then (
167 :     if log then Log.init(base ^ ".log") else ();
168 :     PhaseTimer.withTimer Timers.timeCompiler
169 : jhr 2451 doFile (target, file, output);
170 : jhr 3003 Stats.report ();
171 :     Log.reportTiming Timers.timeCompiler;
172 : cchiw 3174
173 : jhr 3003 OS.Process.success
174 :     ) handle exn => handleExn exn
175 :     else (err "invalid command-line inputs\n"; OS.Process.failure)
176 :     end
177 :     end
178 : jhr 238
179 : jhr 33 end

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