blob: 02eadccdec73264db9795a4eb5aae8215a08dcce (
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
|
functor Driver(P: PPC): 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 fname = valOf $ #file config
in
P.debugPrint fname (#includeDirs config)
end
end
|