3 exception WrongArguments
5 (* could do via a List.filter because cpp flags are simple as it's
6 * "-I/usr/include" not ["-I";"/usr/include"] like in ocaml so no
7 * need to look multiple args.
9 let rec cpp_flags_filter xs
=
14 | s
when x
=~
"-D.*" ->
15 s
::cpp_flags_filter xs
16 | s
when s
=~
"-I.*" ->
17 s
::cpp_flags_filter xs
22 let is_compile_command xs
=
26 xs
+> List.filter
(fun s
-> s
=~
".*\\.c$")
28 let rec fix_args args file
=
35 hd
::fix_args tail file
37 let rec get_outputfile args
=
42 let (hd'
,tail'
) = match tail
with
43 hd'
::tail'
-> (hd'
,tail'
)
44 | _
-> raise WrongArguments
48 let (ntail
, out
) = get_outputfile tail
in
52 let args = List.tl
(Array.to_list
Sys.argv
) in
53 (*args +> List.iter pr2;*)
54 if is_compile_command args
56 let file = source_file args in
59 let cpp_flags = cpp_flags_filter args in
61 (spf
"cpp %s %s > %s.i"
62 (Common.join
" " cpp_flags)
67 let ret2 = Sys.command
cmd2 in
68 if ret2 > 0 then exit
ret2;
69 let sp_args = fix_args args file in
70 let cmd = "spatch " ^
(Common.join
" " sp_args) in
72 let ret = Sys.command
cmd in
75 | [] -> failwith
"could not find name of source file"
76 | x
::y
::xs
-> failwith
"multiple source files"
81 let (nargs
, outfile
) = get_outputfile args in
84 (Common.join
" " nargs
)