SCM Repository
Annotation of /trunk/src/compiler/driver/main.sml
Parent Directory
|
Revision Log
Revision 230 - (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 : | val _ = ASTPP.output (TextIO.stdOut, ast) (* DEBUG *) | ||
40 : | val simple = Simplify.transform ast | ||
41 : | jhr | 200 | val _ = SimplePP.output (TextIO.stdOut, simple) |
42 : | 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 : | fun main (name: string, args: string list) = | ||
51 : | jhr | 230 | if Inputs.initFromArgs args |
52 : | then | ||
53 : | (List.app doFile args; OS.Process.success) | ||
54 : | handle exn => ( | ||
55 : | err (concat [ | ||
56 : | "uncaught exception ", General.exnName exn, " [", General.exnMessage exn, "]\n"]); | ||
57 : | List.app (fn s => err (concat [" raised at ", s, "\n"])) | ||
58 : | (SMLofNJ.exnHistory exn); | ||
59 : | quitWithError()) | ||
60 : | else (err "invalid command-line inputs\n"; quitWithError()) | ||
61 : | jhr | 33 | |
62 : | jhr | 35 | fun test file = (main ("", [file]); print "** Success!!\n") |
63 : | |||
64 : | jhr | 33 | end |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |