14 |
|
|
15 |
structure HighPP = SSAPPFn (HighIL) |
structure HighPP = SSAPPFn (HighIL) |
16 |
structure MidPP = SSAPPFn (MidIL) |
structure MidPP = SSAPPFn (MidIL) |
17 |
|
structure LowPP = SSAPPFn (LowIL) |
18 |
|
|
19 |
fun err s = TextIO.output (TextIO.stdErr, s) |
fun err s = TextIO.output (TextIO.stdErr, s) |
20 |
fun err1 c = TextIO.output1 (TextIO.stdErr, c) |
fun err1 c = TextIO.output1 (TextIO.stdErr, c) |
35 |
val errStrm = Error.mkErrStream filename |
val errStrm = Error.mkErrStream filename |
36 |
val inS = TextIO.openIn filename |
val inS = TextIO.openIn filename |
37 |
val checkTypes = Typechecker.check errStrm |
val checkTypes = Typechecker.check errStrm |
38 |
|
(***** PARSING *****) |
39 |
|
val parseTree = let |
40 |
|
val pt = Parser.parseFile (errStrm, inS) |
41 |
in |
in |
42 |
case Parser.parseFile (errStrm, inS) |
TextIO.closeIn inS; |
43 |
of NONE => (checkForErrors errStrm; quitWithError filename) |
checkForErrors errStrm; |
44 |
| SOME pt => let |
valOf pt |
45 |
|
end |
46 |
val _ = checkForErrors errStrm |
val _ = checkForErrors errStrm |
47 |
val ast = (checkTypes pt) handle Typechecker.Error => AST.Program[] |
(***** TYPECHECKING *****) |
48 |
|
val ast = (checkTypes parseTree) handle Typechecker.Error => AST.Program[] |
49 |
val _ = checkForErrors errStrm |
val _ = checkForErrors errStrm |
50 |
val _ = ASTPP.output (Log.logFile(), ast) (* DEBUG *) |
val _ = ASTPP.output (Log.logFile(), ast) (* DEBUG *) |
51 |
|
(***** SIMPLIFY *****) |
52 |
val simple = Simplify.transform ast |
val simple = Simplify.transform ast |
53 |
val _ = SimplePP.output (Log.logFile(), simple) (* DEBUG *) |
val _ = SimplePP.output (Log.logFile(), simple) (* DEBUG *) |
54 |
|
(***** TRANSLATION TO HIGH IL*****) |
55 |
val highIL = Translate.translate simple |
val highIL = Translate.translate simple |
56 |
val _ = ( (* DEBUG *) |
val _ = ( (* DEBUG *) |
57 |
HighPP.output (Log.logFile(), "HighIL after translation", highIL); |
HighPP.output (Log.logFile(), "HighIL after translation", highIL); |
58 |
if CheckHighIL.check ("after translation", highIL) |
if CheckHighIL.check ("after translation", highIL) |
59 |
then quitWithError filename |
then quitWithError filename |
60 |
else ()) |
else ()) |
61 |
|
(***** HIGH-IL OPTIMIZATION *****) |
62 |
val highIL = HighOptimizer.optimize highIL |
val highIL = HighOptimizer.optimize highIL |
63 |
val _ = ( (* DEBUG *) |
val _ = ( (* DEBUG *) |
64 |
HighPP.output (Log.logFile(), "HighIL after optimization", highIL); |
HighPP.output (Log.logFile(), "HighIL after optimization", highIL); |
65 |
if CheckHighIL.check ("after optimization", highIL) |
if CheckHighIL.check ("after optimization", highIL) |
66 |
then quitWithError filename |
then quitWithError filename |
67 |
else ()) |
else ()) |
68 |
|
(***** TRANSLATION TO MID IL *****) |
69 |
val midIL = HighToMid.translate highIL |
val midIL = HighToMid.translate highIL |
70 |
val _ = ( (* DEBUG *) |
val _ = ( (* DEBUG *) |
71 |
MidPP.output (Log.logFile(), "MidIL after translation", midIL); |
MidPP.output (Log.logFile(), "MidIL after translation", midIL); |
72 |
if CheckMidIL.check ("after translation", midIL) |
if CheckMidIL.check ("after translation", midIL) |
73 |
then quitWithError filename |
then quitWithError filename |
74 |
else ()) |
else ()) |
75 |
|
(***** TRANSLATION TO LOW IL *****) |
76 |
|
val lowIL = MidToLow.translate midIL |
77 |
|
val _ = ( (* DEBUG *) |
78 |
|
LowPP.output (Log.logFile(), "LowIL after translation", lowIL); |
79 |
|
if CheckLowIL.check ("after translation", lowIL) |
80 |
|
then quitWithError filename |
81 |
|
else ()) |
82 |
in |
in |
83 |
() |
() (* FIXME *) |
|
end |
|
|
(* end case *); |
|
|
TextIO.closeIn inS |
|
84 |
end |
end |
85 |
|
|
86 |
fun doOptions args = let |
fun doOptions args = let |