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 420 - (view) (download)

1 : jhr 33 (* main.sml
2 :     *
3 :     * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
4 :     * 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 256
18 : jhr 33 fun err s = TextIO.output (TextIO.stdErr, s)
19 :     fun err1 c = TextIO.output1 (TextIO.stdErr, c)
20 :     fun errnl s = (err s; err1 #"\n")
21 :    
22 : jhr 35 fun quitWithError () = raise Fail "error"
23 : jhr 33
24 :     (* check for errors and report them if there are any *)
25 :     fun checkForErrors errStrm = (
26 :     Error.report (TextIO.stdErr, errStrm);
27 :     if Error.anyErrors errStrm
28 : jhr 35 then quitWithError ()
29 : jhr 33 else ())
30 :    
31 :     fun doFile filename = let
32 :     val errStrm = Error.mkErrStream filename
33 :     val inS = TextIO.openIn filename
34 : jhr 86 val checkTypes = Typechecker.check errStrm
35 : jhr 33 in
36 :     case Parser.parseFile (errStrm, inS)
37 : jhr 35 of NONE => (checkForErrors errStrm; quitWithError ())
38 : jhr 93 | SOME pt => let
39 : jhr 174 val _ = checkForErrors errStrm
40 : jhr 93 val ast = (checkTypes pt) handle Typechecker.Error => AST.Program[]
41 : jhr 174 val _ = checkForErrors errStrm
42 : jhr 238 val _ = ASTPP.output (Log.logFile(), ast) (* DEBUG *)
43 : jhr 174 val simple = Simplify.transform ast
44 : jhr 256 val _ = SimplePP.output (Log.logFile(), simple) (* DEBUG *)
45 : jhr 200 val highIL = Translate.translate simple
46 : jhr 417 val _ = ( (* DEBUG *)
47 :     HighPP.output (Log.logFile(), "HighIL after translation", highIL);
48 :     if CheckHighIL.check ("after translation", highIL)
49 :     then raise Fail "ERROR"
50 :     else ())
51 : jhr 338 val highIL = HighOptimizer.optimize highIL
52 : jhr 417 val _ = ( (* DEBUG *)
53 :     HighPP.output (Log.logFile(), "HighIL after optimization", highIL);
54 :     if CheckHighIL.check ("after optimization", highIL)
55 :     then raise Fail "ERROR"
56 :     else ())
57 : jhr 367 val midIL = HighToMid.translate highIL
58 : jhr 420 val _ = ( (* DEBUG *)
59 :     MidPP.output (Log.logFile(), "MidIL after translation", midIL);
60 :     if CheckMidIL.check ("after translation", midIL)
61 :     then raise Fail "ERROR"
62 :     else ())
63 : jhr 367 val _ = MidPP.output (Log.logFile(), "MidIL after translation", midIL) (* DEBUG *)
64 : jhr 93 in
65 : jhr 200 ()
66 : jhr 93 end
67 : jhr 33 (* end case *);
68 :     TextIO.closeIn inS
69 :     end
70 :    
71 : jhr 238 fun doOptions args = let
72 :     val log = ref false
73 :     val defs = ref []
74 :     fun doOpts [file] = {log = !log, defs = !defs, file = file}
75 :     | doOpts ("-log"::r) = (log := true; doOpts r)
76 : jhr 340 | doOpts (opt::r) =
77 :     if Inputs.isCmdLineInput opt
78 :     then (defs := opt :: !defs; doOpts r)
79 :     else (
80 :     err(concat["invalid command-line input \"", opt, "\"\n"]);
81 :     quitWithError())
82 : jhr 238 in
83 :     doOpts args
84 :     end
85 : jhr 33
86 : jhr 238 fun main (name: string, args: string list) = let
87 :     val {log, defs, file} = doOptions args
88 :     val {base, ...} = OS.Path.splitBaseExt file
89 :     in
90 :     if Inputs.initFromArgs defs
91 :     then (Log.init(base ^ ".log"); doFile file; OS.Process.success)
92 :     handle exn => (
93 :     err (concat [
94 :     "uncaught exception ", General.exnName exn, " [", General.exnMessage exn, "]\n"]);
95 :     List.app (fn s => err (concat [" raised at ", s, "\n"]))
96 :     (SMLofNJ.exnHistory exn);
97 :     quitWithError())
98 :     else (err "invalid command-line inputs\n"; quitWithError())
99 :     end
100 :    
101 : jhr 35 fun test file = (main ("", [file]); print "** Success!!\n")
102 :    
103 : jhr 33 end

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