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 338 - (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 256 val _ = HighPP.output (Log.logFile(), highIL) (* DEBUG *)
46 : jhr 338 val highIL = HighOptimizer.optimize highIL
47 :     val _ = HighPP.output (Log.logFile(), 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 :     | doOpts (opt::r) = (defs := opt :: !defs; doOpts r)
61 :     in
62 :     doOpts args
63 :     end
64 : jhr 33
65 : jhr 238 fun main (name: string, args: string list) = let
66 :     val {log, defs, file} = doOptions args
67 :     val {base, ...} = OS.Path.splitBaseExt file
68 :     in
69 :     if Inputs.initFromArgs defs
70 :     then (Log.init(base ^ ".log"); doFile file; OS.Process.success)
71 :     handle exn => (
72 :     err (concat [
73 :     "uncaught exception ", General.exnName exn, " [", General.exnMessage exn, "]\n"]);
74 :     List.app (fn s => err (concat [" raised at ", s, "\n"]))
75 :     (SMLofNJ.exnHistory exn);
76 :     quitWithError())
77 :     else (err "invalid command-line inputs\n"; quitWithError())
78 :     end
79 :    
80 : jhr 35 fun test file = (main ("", [file]); print "** Success!!\n")
81 :    
82 : jhr 33 end

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