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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1693 - (view) (download)

1 : jhr 33 (* main.sml
2 :     *
3 : jhr 435 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 : jhr 33 * All rights reserved.
5 :     *)
6 :    
7 :     structure Main : sig
8 :    
9 :     val main : (string * string list) -> OS.Process.status
10 :    
11 :     end = struct
12 :    
13 : jhr 1116 (* exception tracing magic *)
14 : jhr 1166 (*
15 : jhr 1116 val _ = (
16 :     SMLofNJ.Internals.TDP.mode := true;
17 :     Coverage.install ();
18 :     BackTrace.install ())
19 : jhr 1166 *)
20 : jhr 256
21 : jhr 33 fun err s = TextIO.output (TextIO.stdErr, s)
22 :     fun err1 c = TextIO.output1 (TextIO.stdErr, c)
23 :     fun errnl s = (err s; err1 #"\n")
24 :    
25 : jhr 429 exception ERROR
26 : jhr 33
27 : jhr 429 fun quitWithError srcFile = raise Fail("Error in compiling " ^ srcFile)
28 :    
29 : jhr 33 (* check for errors and report them if there are any *)
30 :     fun checkForErrors errStrm = (
31 :     Error.report (TextIO.stdErr, errStrm);
32 :     if Error.anyErrors errStrm
33 : jhr 429 then quitWithError (Error.sourceFile errStrm)
34 : jhr 33 else ())
35 :    
36 : jhr 1116
37 :     (* compiler front end (parsing, typechecking, and simplification *)
38 :     fun frontEnd filename = let
39 : jhr 33 val errStrm = Error.mkErrStream filename
40 : jhr 1116 val _ = if OS.FileSys.access(filename, [OS.FileSys.A_READ])
41 :     then ()
42 :     else (
43 :     err(concat["source file \"", filename, "\" does not exist or is not readable\n"]);
44 :     raise ERROR)
45 : jhr 460 (***** PARSING *****)
46 : jhr 1116 val parseTree = PhaseTimer.withTimer Timers.timeParser (fn () => let
47 :     val inS = TextIO.openIn filename
48 : jhr 460 val pt = Parser.parseFile (errStrm, inS)
49 :     in
50 :     TextIO.closeIn inS;
51 :     checkForErrors errStrm;
52 :     valOf pt
53 : jhr 1116 end) ()
54 : jhr 460 (***** TYPECHECKING *****)
55 : jhr 1116 val _ = PhaseTimer.start Timers.timeTypechecker
56 :     val ast = (Typechecker.check errStrm parseTree) handle Typechecker.Error => AST.Program[]
57 :     val _ = PhaseTimer.stop Timers.timeTypechecker
58 : jhr 460 val _ = checkForErrors errStrm
59 :     val _ = ASTPP.output (Log.logFile(), ast) (* DEBUG *)
60 :     (***** SIMPLIFY *****)
61 : jhr 1116 val _ = PhaseTimer.start Timers.timeSimplify
62 : jhr 1140 val simple = Simplify.transform (errStrm, ast)
63 :     val _ = checkForErrors errStrm
64 : jhr 1116 val _ = PhaseTimer.stop Timers.timeSimplify
65 : jhr 460 val _ = SimplePP.output (Log.logFile(), simple) (* DEBUG *)
66 : jhr 1116 in
67 :     simple
68 :     end
69 :    
70 : jhr 1693 fun doFile (target : TargetUtil.target_desc, filename, exec, optOutput) = let
71 : jhr 1640 val baseName = (case OS.Path.splitBaseExt filename
72 :     of {base, ext=SOME "diderot"} => base
73 :     | _ => (errnl "expected diderot file"; quitWithError filename)
74 :     (* end case *))
75 :     val simple = PhaseTimer.withTimer Timers.timeFront frontEnd filename
76 :     (***** TRANSLATION TO HIGH IL*****)
77 :     val _ = PhaseTimer.start Timers.timeTranslate
78 :     val highIL = Translate.translate simple
79 :     val _ = PhaseTimer.stop Timers.timeTranslate
80 :     (***** HIGH-IL OPTIMIZATION *****)
81 :     val _ = PhaseTimer.start Timers.timeHigh
82 :     val highIL = HighOptimizer.optimize highIL
83 :     val _ = PhaseTimer.stop Timers.timeHigh
84 :     (***** TRANSLATION TO MID IL *****)
85 :     val midIL = PhaseTimer.withTimer Timers.timeMid HighToMid.translate highIL
86 :     val midIL = PhaseTimer.withTimer Timers.timeMid MidOptimizer.optimize midIL
87 :     (***** TRANSLATION TO LOW IL *****)
88 :     val lowIL = PhaseTimer.withTimer Timers.timeLow MidToLow.translate midIL
89 :     val lowIL = PhaseTimer.withTimer Timers.timeLow LowOptimizer.optimize lowIL
90 :     in
91 : jhr 1693 (* FIXME: if exec flag is false, then we generate a library, otherwise an executable *)
92 : jhr 1640 (***** CODE GENERATION *****)
93 :     PhaseTimer.withTimer Timers.timeCodegen
94 :     (BackEnd.generate target)
95 : jhr 1570 (Option.getOpt(optOutput, baseName), lowIL)
96 : jhr 1640 end
97 : jhr 33
98 : jhr 1232 fun usage cmd = TextIO.output(TextIO.stdErr, Options.usage cmd)
99 : jhr 33
100 : jhr 238 fun main (name: string, args: string list) = let
101 : jhr 1693 val {help, log, target, standalone, output, defs, file} =
102 : jhr 1232 (Options.parseCmdLine args)
103 :     handle Options.Usage msg => (
104 :     err(concat[msg, "\n"]);
105 :     usage name;
106 :     OS.Process.exit OS.Process.failure)
107 : jhr 238 in
108 : jhr 1232 if help
109 : jhr 1116 then (
110 : jhr 1232 usage name;
111 : jhr 1116 OS.Process.success)
112 : jhr 1232 else let
113 :     val {base, ...} = OS.Path.splitBaseExt file
114 :     in
115 :     if Inputs.initFromArgs defs
116 :     then (
117 :     if log then Log.init(base ^ ".log") else ();
118 : jhr 1570 PhaseTimer.withTimer Timers.timeCompiler
119 : jhr 1693 doFile (target, file, standalone, output);
120 : jhr 1232 Stats.report ();
121 :     Log.reportTiming Timers.timeCompiler;
122 :     OS.Process.success
123 :     ) handle exn => (
124 :     err (concat [
125 : jhr 1570 "uncaught exception ", General.exnName exn,
126 :     " [", General.exnMessage exn, "]\n"
127 :     ]);
128 :     List.app (fn s => err (concat [" raised at ", s, "\n"]))
129 :     (SMLofNJ.exnHistory exn);
130 :     OS.Process.failure)
131 : jhr 1232 else (err "invalid command-line inputs\n"; OS.Process.failure)
132 :     end
133 : jhr 238 end
134 : jhr 429 handle ERROR => OS.Process.failure
135 : jhr 238
136 : jhr 33 end

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