Skip to content

Commit e1d65b2

Browse files
Merge pull request #587 from goblint/deps_from_cil
Compute dependencies of file via CIL instead of from `.d` files generated during pre-processing
2 parents 809a644 + 074ca0b commit e1d65b2

File tree

10 files changed

+20
-71
lines changed

10 files changed

+20
-71
lines changed

goblint.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ dev-repo: "git+https://github.com/goblint/analyzer.git"
6363
# on `dune build` goblint.opam will be generated from goblint.opam.template and dune-project
6464
# also remember to generate/adjust goblint.opam.locked!
6565
pin-depends: [
66-
[ "goblint-cil.1.8.2" "git+https://github.com/goblint/cil.git#f8c8fe4da12ebe59a7b87851366dfc49b6e4b9ae" ]
66+
[ "goblint-cil.1.8.2" "git+https://github.com/goblint/cil.git#908790cb6c85f5ce053a0616bcc6b327758b8966" ]
6767
# TODO: add back after release, only pinned for optimization (https://github.com/ocaml-ppx/ppx_deriving/pull/252)
6868
[ "ppx_deriving.5.2.1" "git+https://github.com/ocaml-ppx/ppx_deriving.git#0a89b619f94cbbfc3b0fb3255ab4fe5bc77d32d6" ]
6969
# quoter workaround reverted for release, so no pin needed

goblint.opam.locked

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ version: "dev"
110110
pin-depends: [
111111
[
112112
"goblint-cil.1.8.2"
113-
"git+https://github.com/goblint/cil.git#f8c8fe4da12ebe59a7b87851366dfc49b6e4b9ae"
113+
"git+https://github.com/goblint/cil.git#908790cb6c85f5ce053a0616bcc6b327758b8966"
114114
]
115115
[
116116
"apron.v0.9.13"

goblint.opam.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# on `dune build` goblint.opam will be generated from goblint.opam.template and dune-project
22
# also remember to generate/adjust goblint.opam.locked!
33
pin-depends: [
4-
[ "goblint-cil.1.8.2" "git+https://github.com/goblint/cil.git#f8c8fe4da12ebe59a7b87851366dfc49b6e4b9ae" ]
4+
[ "goblint-cil.1.8.2" "git+https://github.com/goblint/cil.git#908790cb6c85f5ce053a0616bcc6b327758b8966" ]
55
# TODO: add back after release, only pinned for optimization (https://github.com/ocaml-ppx/ppx_deriving/pull/252)
66
[ "ppx_deriving.5.2.1" "git+https://github.com/ocaml-ppx/ppx_deriving.git#0a89b619f94cbbfc3b0fb3255ab4fe5bc77d32d6" ]
77
# quoter workaround reverted for release, so no pin needed

src/framework/analyses.ml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -268,19 +268,10 @@ struct
268268
printf "Writing Sarif to file: %s\n%!" (get_string "outfile");
269269
Yojson.Safe.pretty_to_channel ~std:true out (Sarif.to_yojson (List.rev !Messages.Table.messages_list));
270270
| "json-messages" ->
271-
let files =
272-
let module SH = BatHashtbl.Make (Basetype.RawStrings) in
273-
let files = SH.create 100 in
274-
iterGlobals file (function
275-
| GFun (_, loc)
276-
| GVar (_, _, loc) ->
277-
SH.replace files loc.file (Hashtbl.find_option Preprocessor.dependencies loc.file)
278-
| _ -> () (* TODO: add locs from everything else? would also include system headers *)
279-
);
280-
files |> SH.to_list
281-
in
271+
let files = Hashtbl.to_list Preprocessor.dependencies in
272+
let filter_system = List.filter_map (fun (f,system) -> if system then None else Some f) in
282273
let json = `Assoc [
283-
("files", `Assoc (List.map (Tuple2.map2 [%to_yojson: string list option]) files));
274+
("files", `Assoc (List.map (Tuple2.map2 (fun deps -> [%to_yojson:string list] @@ filter_system deps)) files));
284275
("messages", Messages.Table.to_yojson ());
285276
]
286277
in

src/maingoblint.ml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,11 @@ let basic_preprocess ~all_cppflags fname =
159159
else
160160
(* Preprocess using cpp. *)
161161
(* ?? what is __BLOCKS__? is it ok to just undef? this? http://en.wikipedia.org/wiki/Blocks_(C_language_extension) *)
162-
let deps_file = Filename.chop_extension nname ^ ".d" in
163-
let command = (Preprocessor.get_cpp ()) ^ " --undef __BLOCKS__ " ^ String.join " " (List.map Filename.quote all_cppflags) ^ " -MMD -MT " ^ fname ^ " \"" ^ fname ^ "\" -o \"" ^ nname ^ "\"" in
162+
let command = (Preprocessor.get_cpp ()) ^ " --undef __BLOCKS__ " ^ String.join " " (List.map Filename.quote all_cppflags) ^ " \"" ^ fname ^ "\" -o \"" ^ nname ^ "\"" in
164163
if get_bool "dbg.verbose" then print_endline command;
165164

166165
try match Unix.system command with
167-
| Unix.WEXITED 0 ->
168-
Preprocessor.parse_makefile_deps deps_file;
169-
nname
166+
| Unix.WEXITED 0 -> nname
170167
| _ -> eprintf "Goblint: Preprocessing failed."; raise Exit
171168
with Unix.Unix_error (e, f, a) ->
172169
eprintf "%s at syscall %s with argument \"%s\".\n" (Unix.error_message e) f a; raise Exit
@@ -291,7 +288,13 @@ let preprocess_files () =
291288
let merge_preprocessed cpp_file_names =
292289
(* get the AST *)
293290
if get_bool "dbg.verbose" then print_endline "Parsing files.";
294-
let files_AST = List.map Cilfacade.getAST cpp_file_names in
291+
let get_ast_and_record_deps f =
292+
let file = Cilfacade.getAST f in
293+
(* Drop <built-in> and <command-line> from dependencies *)
294+
Hashtbl.add Preprocessor.dependencies f @@ List.filter (fun (n,_) -> n <> "<built-in>" && n <> "<command-line>") file.files;
295+
file
296+
in
297+
let files_AST = List.map (get_ast_and_record_deps) cpp_file_names in
295298

296299
let cilout =
297300
if get_string "dbg.cilout" = "" then Legacy.stderr else Legacy.open_out (get_string "dbg.cilout")

src/util/compilationDatabase.ml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,11 @@ let load_and_preprocess ~all_cppflags filename =
5555
else
5656
let preprocessed_file = Filename.concat preprocessed_dir (Filename.chop_extension (GobFilename.chop_common_prefix database_dir file) ^ ".i") in
5757
GobSys.mkdir_parents preprocessed_file;
58-
let deps_file = Filename.chop_extension preprocessed_file ^ ".d" in
5958
let preprocess_command = match obj.command, obj.arguments with
6059
| Some command, None ->
6160
(* TODO: extract o_file *)
6261
let command = reroot command in
63-
let preprocess_command = Str.replace_first command_program_regexp ("\\1 " ^ String.join " " (List.map Filename.quote all_cppflags) ^ " -E -MMD -MT " ^ file) command in
62+
let preprocess_command = Str.replace_first command_program_regexp ("\\1 " ^ String.join " " (List.map Filename.quote all_cppflags) ^ " -E") command in
6463
let preprocess_command = Str.replace_first command_o_regexp ("-o " ^ preprocessed_file) preprocess_command in
6564
if preprocess_command = command then (* easier way to check if match was found (and replaced) *)
6665
failwith "CompilationDatabase.preprocess: no -o argument found for " ^ file
@@ -72,7 +71,7 @@ let load_and_preprocess ~all_cppflags filename =
7271
| (o_i, _) ->
7372
begin match List.split_at o_i arguments with
7473
| (arguments_program :: arguments_init, _ :: o_file :: arguments_tl) ->
75-
let preprocess_arguments = all_cppflags @ "-E" :: "-MMD" :: "-MT" :: file :: arguments_init @ "-o" :: preprocessed_file :: arguments_tl in
74+
let preprocess_arguments = all_cppflags @ "-E" :: arguments_init @ "-o" :: preprocessed_file :: arguments_tl in
7675
Filename.quote_command arguments_program preprocess_arguments
7776
| _ ->
7877
failwith "CompilationDatabase.preprocess: no -o argument value found for " ^ file
@@ -89,7 +88,6 @@ let load_and_preprocess ~all_cppflags filename =
8988
if GobConfig.get_bool "dbg.verbose" then
9089
Printf.printf "Preprocessing %s\n to %s\n using %s\n in %s\n" file preprocessed_file preprocess_command cwd;
9190
system ~cwd preprocess_command; (* command/arguments might have paths relative to directory *)
92-
Preprocessor.parse_makefile_deps deps_file;
9391
Some preprocessed_file
9492
in
9593
parse_file filename

src/util/dune

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
(ocamllex oilLexer makefileLexer)
2-
(ocamlyacc oilParser makefileParser)
1+
(ocamllex oilLexer)
2+
(ocamlyacc oilParser)

src/util/makefileLexer.mll

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/util/makefileParser.mly

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/util/preprocessor.ml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,4 @@ let cpp =
3737
let get_cpp () = Lazy.force cpp
3838

3939

40-
let dependencies: (string, string list) Hashtbl.t = Hashtbl.create 3
41-
42-
let parse_makefile_deps makefile =
43-
BatFile.with_file_in makefile (fun input ->
44-
let lexbuf = Lexing.from_channel input in
45-
let (rule, deps) = MakefileParser.deps MakefileLexer.token lexbuf in
46-
let deps = List.remove deps rule in
47-
Hashtbl.replace dependencies rule deps
48-
)
40+
let dependencies: (string, (string*bool) list) Hashtbl.t = Hashtbl.create 3

0 commit comments

Comments
 (0)