blob: 78ca877685f93e91ee7cbf08aa445e26e6fef325 (
plain)
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
|
functor Driver(P: CPP): DRIVER = struct
structure P = P
type config = {
file: string option,
includeDirs: string list
}
val initConfig: config = { file = NONE, includeDirs = [] }
fun die msg = (printLn msg; Posix.Process.exit $ Word8.fromInt 1)
fun parseCmdArgs { file, includeDirs } [] =
if file = NONE then
die "missing input file"
else
{ file, includeDirs = rev includeDirs }
| parseCmdArgs _ ("-I" :: []) =
die "-I: expected directory path after flag"
| parseCmdArgs { file, includeDirs } ("-I" :: path :: tail) =
parseCmdArgs { file, includeDirs = path :: includeDirs } tail
| parseCmdArgs { file, includeDirs } (arg :: tail) =
if String.sub (arg, 0) = #"-" then
die $ arg ^ ": unknown flag"
else
case file of
NONE => parseCmdArgs { file = SOME arg, includeDirs } tail
| SOME _ => die $ arg ^ ": file already specified"
fun exec () =
let
val config = parseCmdArgs initConfig (CommandLine.arguments ())
val cpp = P.create (valOf $ #file config) (#includeDirs config)
in
P.debugPrint cpp
end
end
|