2 * Copyright 2010, INRIA, University of Copenhagen
3 * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
4 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
5 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
6 * This file is part of Coccinelle.
8 * Coccinelle is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, according to version 2 of the License.
12 * Coccinelle is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
20 * The authors reserve the right to distribute this or future versions of
21 * Coccinelle under other licenses.
26 * Copyright 2010, INRIA, University of Copenhagen
27 * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
28 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
29 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
30 * This file is part of Coccinelle.
32 * Coccinelle is free software: you can redistribute it and/or modify
33 * it under the terms of the GNU General Public License as published by
34 * the Free Software Foundation, according to version 2 of the License.
36 * Coccinelle is distributed in the hope that it will be useful,
37 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 * GNU General Public License for more details.
41 * You should have received a copy of the GNU General Public License
42 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
44 * The authors reserve the right to distribute this or future versions of
45 * Coccinelle under other licenses.
51 exception WrongArguments
53 (* could do via a List.filter because cpp flags are simple as it's
54 * "-I/usr/include" not ["-I";"/usr/include"] like in ocaml so no
55 * need to look multiple args.
57 let rec cpp_flags_filter xs
=
62 | s
when x
=~
"-D.*" ->
63 s
::cpp_flags_filter xs
64 | s
when s
=~
"-I.*" ->
65 s
::cpp_flags_filter xs
70 let is_compile_command xs
=
74 xs
+> List.filter
(fun s
-> s
=~
".*\\.c$")
76 let rec fix_args args file
=
83 hd
::fix_args tail file
85 let rec get_outputfile args
=
90 let (hd'
,tail'
) = match tail
with
91 hd'
::tail'
-> (hd'
,tail'
)
92 | _
-> raise WrongArguments
96 let (ntail
, out
) = get_outputfile tail
in
100 let args = List.tl
(Array.to_list
Sys.argv
) in
101 (*args +> List.iter pr2;*)
102 if is_compile_command args
104 let file = source_file args in
107 let cpp_flags = cpp_flags_filter args in
109 (spf
"cpp %s %s > %s.i"
110 (Common.join
" " cpp_flags)
115 let ret2 = Sys.command
cmd2 in
116 if ret2 > 0 then exit
ret2;
117 let sp_args = fix_args args file in
118 let cmd = "spatch " ^
(Common.join
" " sp_args) in
120 let ret = Sys.command
cmd in
123 | [] -> failwith
"could not find name of source file"
124 | x
::y
::xs
-> failwith
"multiple source files"
129 let (nargs
, outfile
) = get_outputfile args in
132 (Common.join
" " nargs
)