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

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