2 * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen
3 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
4 * This file is part of Coccinelle.
6 * Coccinelle is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, according to version 2 of the License.
10 * Coccinelle is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
18 * The authors reserve the right to distribute this or future versions of
19 * Coccinelle under other licenses.
24 * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen
25 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
26 * This file is part of Coccinelle.
28 * Coccinelle is free software: you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License as published by
30 * the Free Software Foundation, according to version 2 of the License.
32 * Coccinelle is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 * GNU General Public License for more details.
37 * You should have received a copy of the GNU General Public License
38 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
40 * The authors reserve the right to distribute this or future versions of
41 * Coccinelle under other licenses.
47 exception WrongArguments
49 (* could do via a List.filter because cpp flags are simple as it's
50 * "-I/usr/include" not ["-I";"/usr/include"] like in ocaml so no
51 * need to look multiple args.
53 let rec cpp_flags_filter xs
=
58 | s
when x
=~
"-D.*" ->
59 s
::cpp_flags_filter xs
60 | s
when s
=~
"-I.*" ->
61 s
::cpp_flags_filter xs
66 let is_compile_command xs
=
70 xs
+> List.filter
(fun s
-> s
=~
".*\\.c$")
72 let rec fix_args args file
=
79 hd
::fix_args tail file
81 let rec get_outputfile args
=
86 let (hd'
,tail'
) = match tail
with
87 hd'
::tail'
-> (hd'
,tail'
)
88 | _
-> raise WrongArguments
92 let (ntail
, out
) = get_outputfile tail
in
96 let args = List.tl
(Array.to_list
Sys.argv
) in
97 (*args +> List.iter pr2;*)
98 if is_compile_command args
100 let file = source_file args in
103 let cpp_flags = cpp_flags_filter args in
105 (spf
"cpp %s %s > %s.i"
106 (Common.join
" " cpp_flags)
111 let ret2 = Sys.command
cmd2 in
112 if ret2 > 0 then exit
ret2;
113 let sp_args = fix_args args file in
114 let cmd = "spatch " ^
(Common.join
" " sp_args) in
116 let ret = Sys.command
cmd in
119 | [] -> failwith
"could not find name of source file"
120 | x
::y
::xs
-> failwith
"multiple source files"
125 let (nargs
, outfile
) = get_outputfile args in
128 (Common.join
" " nargs
)