-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMake.sml
More file actions
142 lines (109 loc) · 3.6 KB
/
Make.sml
File metadata and controls
142 lines (109 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
(* A cross-platform Fasto compiler compiler. *)
(*
Get going on *nix by typing the following at the command line:
$ mosmlc -o make Make.sml
$ ./make help
Get going on Windows by typing the following at the command line:
$ mosmlc -o make.exe Make.sml
$ .\make.exe help
*)
structure Make = struct
fun isBadOS () = Path.getVolume "C:" = "C:"
local
val wd = FileSys.getDir ()
val absPath = Path.concat (Path.getParent wd, "bin")
in
val BIN_DIR = Path.mkRelative { path = absPath, relativeTo = wd }
end
local
val binName = if isBadOS () then "fasto.exe" else "fasto"
in
val FASTO_BIN = Path.concat (BIN_DIR, binName)
end
fun rmIfExists filename =
FileSys.remove filename handle
(e as SysErr(m, _)) =>
if String.isSuffix "No such file or directory" m
then () else raise e
fun filesWithExt ext =
let
val dstr = FileSys.openDir "."
fun loop () =
case FileSys.readDir dstr of
SOME s => if Path.ext s = SOME ext
then s :: (loop ())
else loop ()
| NONE => (FileSys.closeDir dstr ; [])
in
loop ()
end
fun rmAllWithExt ext =
map rmIfExists (filesWithExt ext)
fun printLn s =
( TextIO.output (TextIO.stdOut, s ^ "\n") ; TextIO.flushOut TextIO.stdOut )
fun clean () =
( printLn ("Deleting *.ui *.uo Parser.sig Parser.sml Parser.output Lexer.sml \"" ^ FASTO_BIN ^ "\"")
; rmAllWithExt "ui"
; rmAllWithExt "uo"
; rmIfExists "Parser.sig"
; rmIfExists "Parser.sml"
; rmIfExists "Parser.output"
; rmIfExists "Lexer.sml"
; rmIfExists FASTO_BIN
; true
)
fun exec (cmd, retval) = if (not retval) then retval
else ( printLn cmd ; Process.isSuccess (Process.system cmd) )
fun compile () = foldl exec true
[ "mosmlc -c -liberal Fasto.sml"
, "mosmlyac Parser.grm"
, "mosmlc -liberal Parser.sig"
, "mosmlc -c Parser.sml"
, "mosmllex Lexer.lex"
, "mosmlc -c Lexer.sml"
, "mosmlc -c SymTab.sig"
, "mosmlc -c SymTab.sml"
, "mosmlc -c Interpreter.sml"
, "mosmlc -c TypeChecker.sml"
, "mosmlc -c Mips.sml"
, "mosmlc -c RegAlloc.sml"
, "mosmlc -c CodeGen.sml"
, "mosmlc -c CallGraph.sig"
, "mosmlc -c CallGraph.sml"
, "mosmlc -c Inlining.sml"
, "mosmlc -c DeadFunctionRemoval.sml"
, "mosmlc -c DeadBindingRemoval.sml"
, "mosmlc -c CopyConstPropFold.sml"
, "mosmlc -o FastoC FastoC.sml"
]
fun moveBin () =
( printLn ("Moving FastoC to \"" ^ FASTO_BIN ^ "\"...")
; FileSys.mkDir BIN_DIR handle SysErr _ => ()
; FileSys.rename { old = "FastoC", new = FASTO_BIN }
; true
)
fun all () =
clean () andalso compile () andalso moveBin ()
fun execRule rule = ( rule () ; () )
val usage = String.concatWith "\n"
[ "A cross-platform Fasto compiler compiler."
, ""
, "By default, all autogenerated files are deleted, the entire"
, "compiler is compiled generating, an executable FastoC. The"
, "executable is then moved to the sibling bin directory, and"
, "renamed to either fasto or fasto.exe, depending on whether"
, "you are running *nix or Windows."
, ""
, "You can change the default behaviour by passing an option:"
, ""
, " clean Delete the autogenerated files only."
, " help Print this message, and halt."
] ^ "\n"
fun showUsage str = ( TextIO.output (str, usage) ; TextIO.flushOut str )
val _ =
case Mosml.argv () of
[_, "clean"] => execRule clean
| [_, "help"] => showUsage TextIO.stdOut
| [_] => execRule all
| _ => showUsage TextIO.stdErr
end