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 367 - (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 340 val _ = HighPP.output (Log.logFile(), "HighIL after translation", highIL) (* DEBUG *)
47 : jhr 338 val highIL = HighOptimizer.optimize highIL
48 : jhr 340 val _ = HighPP.output (Log.logFile(), "HighIL after optimization", highIL) (* DEBUG *)
49 : jhr 367 val midIL = HighToMid.translate highIL
50 :     val _ = MidPP.output (Log.logFile(), "MidIL after translation", midIL) (* DEBUG *)
51 : jhr 93 in
52 : jhr 200 ()
53 : jhr 93 end
54 : jhr 33 (* end case *);
55 :     TextIO.closeIn inS
56 :     end
57 :    
58 : jhr 238 fun doOptions args = let
59 :     val log = ref false
60 :     val defs = ref []
61 :     fun doOpts [file] = {log = !log, defs = !defs, file = file}
62 :     | doOpts ("-log"::r) = (log := true; doOpts r)
63 : jhr 340 | doOpts (opt::r) =
64 :     if Inputs.isCmdLineInput opt
65 :     then (defs := opt :: !defs; doOpts r)
66 :     else (
67 :     err(concat["invalid command-line input \"", opt, "\"\n"]);
68 :     quitWithError())
69 : jhr 238 in
70 :     doOpts args
71 :     end
72 : jhr 33
73 : jhr 238 fun main (name: string, args: string list) = let
74 :     val {log, defs, file} = doOptions args
75 :     val {base, ...} = OS.Path.splitBaseExt file
76 :     in
77 :     if Inputs.initFromArgs defs
78 :     then (Log.init(base ^ ".log"); doFile file; OS.Process.success)
79 :     handle exn => (
80 :     err (concat [
81 :     "uncaught exception ", General.exnName exn, " [", General.exnMessage exn, "]\n"]);
82 :     List.app (fn s => err (concat [" raised at ", s, "\n"]))
83 :     (SMLofNJ.exnHistory exn);
84 :     quitWithError())
85 :     else (err "invalid command-line inputs\n"; quitWithError())
86 :     end
87 :    
88 : jhr 35 fun test file = (main ("", [file]); print "** Success!!\n")
89 :    
90 : jhr 33 end

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