2 * Copyright 2012, INRIA
3 * Julia Lawall, Gilles Muller
4 * Copyright 2010-2011, INRIA, University of Copenhagen
5 * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
6 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
7 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
8 * This file is part of Coccinelle.
10 * Coccinelle is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, according to version 2 of the License.
14 * Coccinelle is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
22 * The authors reserve the right to distribute this or future versions of
23 * Coccinelle under other licenses.
30 exception WrongArguments
32 (* could do via a List.filter because cpp flags are simple as it's
33 * "-I/usr/include" not ["-I";"/usr/include"] like in ocaml so no
34 * need to look multiple args.
36 let rec cpp_flags_filter xs
=
41 | s
when x
=~
"-D.*" ->
42 s
::cpp_flags_filter xs
43 | s
when s
=~
"-I.*" ->
44 s
::cpp_flags_filter xs
49 let is_compile_command xs
=
53 xs
+> List.filter
(fun s
-> s
=~
".*\\.c$")
55 let rec fix_args args file
=
62 hd
::fix_args tail file
64 let rec get_outputfile args
=
69 let (hd'
,tail'
) = match tail
with
70 hd'
::tail'
-> (hd'
,tail'
)
71 | _
-> raise WrongArguments
75 let (ntail
, out
) = get_outputfile tail
in
79 let args = List.tl
(Array.to_list
Sys.argv
) in
80 (*args +> List.iter pr2;*)
81 if is_compile_command args
83 let file = source_file args in
86 let cpp_flags = cpp_flags_filter args in
88 (spf
"cpp %s %s > %s.i"
89 (Common.join
" " cpp_flags)
94 let ret2 = Sys.command
cmd2 in
95 if ret2 > 0 then exit
ret2;
96 let sp_args = fix_args args file in
97 let cmd = "spatch " ^
(Common.join
" " sp_args) in
99 let ret = Sys.command
cmd in
102 | [] -> failwith
"could not find name of source file"
103 | x
::y
::xs
-> failwith
"multiple source files"
108 let (nargs
, outfile
) = get_outputfile args in
111 (Common.join
" " nargs
)