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

SCM Repository

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

Annotation of /trunk/src/compiler/driver/main.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 460 - (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 : jhr 35 val test : string -> unit
12 :    
13 : jhr 33 end = struct
14 :    
15 : jhr 256 structure HighPP = SSAPPFn (HighIL)
16 : jhr 367 structure MidPP = SSAPPFn (MidIL)
17 : jhr 460 structure LowPP = SSAPPFn (LowIL)
18 : jhr 256
19 : jhr 33 fun err s = TextIO.output (TextIO.stdErr, s)
20 :     fun err1 c = TextIO.output1 (TextIO.stdErr, c)
21 :     fun errnl s = (err s; err1 #"\n")
22 :    
23 : jhr 429 exception ERROR
24 : jhr 33
25 : jhr 429 fun quitWithError srcFile = raise Fail("Error in compiling " ^ srcFile)
26 :    
27 : jhr 33 (* check for errors and report them if there are any *)
28 :     fun checkForErrors errStrm = (
29 :     Error.report (TextIO.stdErr, errStrm);
30 :     if Error.anyErrors errStrm
31 : jhr 429 then quitWithError (Error.sourceFile errStrm)
32 : jhr 33 else ())
33 :    
34 :     fun doFile filename = let
35 :     val errStrm = Error.mkErrStream filename
36 :     val inS = TextIO.openIn filename
37 : jhr 86 val checkTypes = Typechecker.check errStrm
38 : jhr 460 (***** PARSING *****)
39 :     val parseTree = let
40 :     val pt = Parser.parseFile (errStrm, inS)
41 :     in
42 :     TextIO.closeIn inS;
43 :     checkForErrors errStrm;
44 :     valOf pt
45 :     end
46 :     val _ = checkForErrors errStrm
47 :     (***** TYPECHECKING *****)
48 :     val ast = (checkTypes parseTree) handle Typechecker.Error => AST.Program[]
49 :     val _ = checkForErrors errStrm
50 :     val _ = ASTPP.output (Log.logFile(), ast) (* DEBUG *)
51 :     (***** SIMPLIFY *****)
52 :     val simple = Simplify.transform ast
53 :     val _ = SimplePP.output (Log.logFile(), simple) (* DEBUG *)
54 :     (***** TRANSLATION TO HIGH IL*****)
55 :     val highIL = Translate.translate simple
56 :     val _ = ( (* DEBUG *)
57 :     HighPP.output (Log.logFile(), "HighIL after translation", highIL);
58 :     if CheckHighIL.check ("after translation", highIL)
59 :     then quitWithError filename
60 :     else ())
61 :     (***** HIGH-IL OPTIMIZATION *****)
62 :     val highIL = HighOptimizer.optimize highIL
63 :     val _ = ( (* DEBUG *)
64 :     HighPP.output (Log.logFile(), "HighIL after optimization", highIL);
65 :     if CheckHighIL.check ("after optimization", highIL)
66 :     then quitWithError filename
67 :     else ())
68 :     (***** TRANSLATION TO MID IL *****)
69 :     val midIL = HighToMid.translate highIL
70 :     val _ = ( (* DEBUG *)
71 :     MidPP.output (Log.logFile(), "MidIL after translation", midIL);
72 :     if CheckMidIL.check ("after translation", midIL)
73 :     then quitWithError filename
74 :     else ())
75 :     (***** TRANSLATION TO LOW IL *****)
76 :     val lowIL = MidToLow.translate midIL
77 :     val _ = ( (* DEBUG *)
78 :     LowPP.output (Log.logFile(), "LowIL after translation", lowIL);
79 :     if CheckLowIL.check ("after translation", lowIL)
80 :     then quitWithError filename
81 :     else ())
82 : jhr 33 in
83 : jhr 460 () (* FIXME *)
84 : jhr 33 end
85 :    
86 : jhr 238 fun doOptions args = let
87 :     val log = ref false
88 :     val defs = ref []
89 :     fun doOpts [file] = {log = !log, defs = !defs, file = file}
90 :     | doOpts ("-log"::r) = (log := true; doOpts r)
91 : jhr 340 | doOpts (opt::r) =
92 :     if Inputs.isCmdLineInput opt
93 :     then (defs := opt :: !defs; doOpts r)
94 :     else (
95 :     err(concat["invalid command-line input \"", opt, "\"\n"]);
96 : jhr 429 raise ERROR)
97 : jhr 238 in
98 :     doOpts args
99 :     end
100 : jhr 33
101 : jhr 238 fun main (name: string, args: string list) = let
102 :     val {log, defs, file} = doOptions args
103 :     val {base, ...} = OS.Path.splitBaseExt file
104 :     in
105 :     if Inputs.initFromArgs defs
106 :     then (Log.init(base ^ ".log"); doFile file; OS.Process.success)
107 :     handle exn => (
108 :     err (concat [
109 :     "uncaught exception ", General.exnName exn, " [", General.exnMessage exn, "]\n"]);
110 :     List.app (fn s => err (concat [" raised at ", s, "\n"]))
111 :     (SMLofNJ.exnHistory exn);
112 : jhr 429 OS.Process.failure)
113 :     else (err "invalid command-line inputs\n"; OS.Process.failure)
114 : jhr 238 end
115 : jhr 429 handle ERROR => OS.Process.failure
116 : jhr 238
117 : jhr 35 fun test file = (main ("", [file]); print "** Success!!\n")
118 :    
119 : jhr 33 end

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