Skip to content

Commit af707f0

Browse files
authored
Merge pull request #585 from goblint/preprocessing-adaptations
Adaptations to preprocessing
2 parents a0bb640 + c44bcd6 commit af707f0

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

src/incremental/makefileUtil.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ let run_cilly (path: string) ~all_cppflags =
6161
remove_comb_files path;
6262
(* Combine source files with make using cilly as compiler *)
6363
let gcc_path = GobConfig.get_string "exp.gcc_path" in
64-
let (exit_code, output) = exec_command ~path ("make CC=\"cilly --gcc=" ^ gcc_path ^ " --merge --keepmerged\" CFLAGS+=" ^ String.join " " (List.map Filename.quote all_cppflags) ^ " " ^
64+
let cflags = if all_cppflags = [] then "" else " CFLAGS+=" ^ Filename.quote (String.join " " all_cppflags) in
65+
let (exit_code, output) = exec_command ~path ("make CC=\"cilly --gcc=" ^ gcc_path ^ " --merge --keepmerged\"" ^cflags ^ " " ^
6566
"LD=\"cilly --gcc=" ^ gcc_path ^ " --merge --keepmerged\"") in
6667
print_string output;
6768
(* fail if make failed *)
@@ -80,9 +81,9 @@ let generate_and_combine makefile ~all_cppflags =
8081
let generate_makefile_with (name, command, file) = if Sys.file_exists file then (
8182
print_endline ("Trying to run " ^ name ^ " to generate Makefile");
8283
let exit_code, output = exec_command ~path command in
83-
print_endline (command ^ GobUnix.string_of_process_status exit_code ^ ". Output: " ^ output);
84+
print_endline (command ^ " " ^ GobUnix.string_of_process_status exit_code ^ ". Output: " ^ output);
8485
if not (Sys.file_exists makefile) then raise MakefileNotGenerated
85-
); raise MakefileNotGenerated in
86+
) else raise MakefileNotGenerated in
8687
try generate_makefile_with configure
8788
with MakefileNotGenerated ->
8889
try generate_makefile_with autogen

src/util/compilationDatabase.ml

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,31 @@ let load_and_preprocess ~all_cppflags filename =
6060
(* TODO: extract o_file *)
6161
let command = reroot command in
6262
let preprocess_command = Str.replace_first command_program_regexp ("\\1 " ^ String.join " " (List.map Filename.quote all_cppflags) ^ " -E") command in
63-
let preprocess_command = Str.replace_first command_o_regexp ("-o " ^ preprocessed_file) preprocess_command in
6463
if preprocess_command = command then (* easier way to check if match was found (and replaced) *)
65-
failwith "CompilationDatabase.preprocess: no -o argument found for " ^ file
64+
failwith ("CompilationDatabase.preprocess: no program found for " ^ file)
6665
else
67-
preprocess_command
66+
let preprocess_command_o = Str.replace_first command_o_regexp ("-o " ^ preprocessed_file) preprocess_command in
67+
if preprocess_command_o = preprocess_command then (* easier way to check if match was found (and replaced) *)
68+
preprocess_command ^ " -o " ^ preprocessed_file
69+
else
70+
preprocess_command_o
6871
| None, Some arguments ->
69-
let arguments = List.map reroot arguments in
70-
begin match List.findi (fun i e -> e = "-o") arguments with
72+
let arguments_program, arguments =
73+
match List.map reroot arguments with
74+
| arguments_program :: arguments -> arguments_program, arguments
75+
| _ -> failwith ("CompilationDatabase.preprocess: no program found for " ^ file)
76+
in
77+
let preprocess_arguments =
78+
match List.findi (fun i e -> e = "-o") arguments with
7179
| (o_i, _) ->
7280
begin match List.split_at o_i arguments with
73-
| (arguments_program :: arguments_init, _ :: o_file :: arguments_tl) ->
74-
let preprocess_arguments = all_cppflags @ "-E" :: arguments_init @ "-o" :: preprocessed_file :: arguments_tl in
75-
Filename.quote_command arguments_program preprocess_arguments
76-
| _ ->
77-
failwith "CompilationDatabase.preprocess: no -o argument value found for " ^ file
81+
| (arguments_init, _ :: o_file :: arguments_tl) -> arguments_init @ "-o" :: preprocessed_file :: arguments_tl
82+
| _ -> failwith ("CompilationDatabase.preprocess: no argument found for -o option for " ^ file)
7883
end
79-
| exception Not_found ->
80-
failwith "CompilationDatabase.preprocess: no -o argument found for " ^ file
81-
end
84+
| exception Not_found -> arguments @ "-o" :: [preprocessed_file]
85+
in
86+
let preprocess_arguments = all_cppflags @ "-E" :: preprocess_arguments in
87+
Filename.quote_command arguments_program preprocess_arguments
8288
| Some _, Some _ ->
8389
failwith "CompilationDatabase.preprocess: both command and arguments specified for " ^ file
8490
| None, None ->
@@ -89,6 +95,6 @@ let load_and_preprocess ~all_cppflags filename =
8995
Printf.printf "Preprocessing %s\n to %s\n using %s\n in %s\n" file preprocessed_file preprocess_command cwd;
9096
system ~cwd preprocess_command; (* command/arguments might have paths relative to directory *)
9197
Some preprocessed_file
92-
in
98+
in
9399
parse_file filename
94100
|> BatList.filter_map preprocess

0 commit comments

Comments
 (0)