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

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