Skip to content

Commit facfb64

Browse files
chambartalainfrisch
authored andcommitted
Fix ocamlobjinfo for flambda (ocaml#809)
* Fix printing of export_info MPR#7294 The printing function now requires a list of root symbols * Add an option to hide some information in objinfo
1 parent d8fa186 commit facfb64

File tree

4 files changed

+48
-18
lines changed

4 files changed

+48
-18
lines changed

asmcomp/export_info.ml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ let nest_eid_map map =
224224
in
225225
Export_id.Map.fold add_map map Compilation_unit.Map.empty
226226

227-
let print_approx ppf (t : t) =
227+
let print_approx ppf ((t,root_symbols) : t * Symbol.t list) =
228228
let values = t.values in
229229
let fprintf = Format.fprintf in
230230
let printed = ref Export_id.Set.empty in
@@ -329,6 +329,7 @@ let print_approx ppf (t : t) =
329329
print_recorded_symbols ();
330330
end
331331
in
332+
List.iter (fun s -> Queue.push s symbols_to_print) root_symbols;
332333
fprintf ppf "@[<hov 2>Globals:@ ";
333334
fprintf ppf "@]@ @[<hov 2>Symbols:@ ";
334335
print_recorded_symbols ();
@@ -345,10 +346,13 @@ let print_offsets ppf (t : t) =
345346
Var_within_closure.print vid off) t.offset_fv;
346347
Format.fprintf ppf "@]@ "
347348

348-
let print_all ppf (t : t) =
349+
let print_functions ppf (t : t) =
350+
Set_of_closures_id.Map.print Flambda.print_function_declarations ppf
351+
t.sets_of_closures
352+
353+
let print_all ppf ((t, root_symbols) : t * Symbol.t list) =
349354
let fprintf = Format.fprintf in
350355
fprintf ppf "approxs@ %a@.@."
351-
print_approx t;
356+
print_approx (t, root_symbols);
352357
fprintf ppf "functions@ %a@.@."
353-
(Set_of_closures_id.Map.print Flambda.print_function_declarations)
354-
t.sets_of_closures
358+
print_functions t

asmcomp/export_info.mli

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ val nest_eid_map
143143

144144
(**/**)
145145
(* Debug printing functions. *)
146-
val print_approx : Format.formatter -> t -> unit
146+
val print_approx : Format.formatter -> t * Symbol.t list -> unit
147+
val print_functions : Format.formatter -> t -> unit
147148
val print_offsets : Format.formatter -> t -> unit
148-
val print_all : Format.formatter -> t -> unit
149+
val print_all : Format.formatter -> t * Symbol.t list -> unit

asmcomp/import_approx.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ let import_set_of_closures =
5555
in
5656
let aux set_of_closures_id =
5757
let ex_info = Compilenv.approx_env () in
58+
let root_symbol = Compilenv.current_unit_symbol () in
5859
let function_declarations =
5960
try
6061
Set_of_closures_id.Map.find set_of_closures_id
@@ -63,7 +64,7 @@ let import_set_of_closures =
6364
Misc.fatal_errorf "[functions] does not map set of closures ID %a. \
6465
ex_info = %a"
6566
Set_of_closures_id.print set_of_closures_id
66-
Export_info.print_all ex_info
67+
Export_info.print_all (ex_info, [root_symbol])
6768
in
6869
import_function_declarations function_declarations
6970
in

tools/objinfo.ml

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ open Misc
2323
open Config
2424
open Cmo_format
2525

26+
(* Command line option to prevent printing approximation and function code *)
27+
let no_approx = ref false
28+
let no_code = ref false
29+
2630
let input_stringlist ic len =
2731
let get_string_list sect len =
2832
let rec fold s e acc =
@@ -122,16 +126,33 @@ let print_cmx_infos (ui, crc) =
122126
ui.ui_name crc ui.ui_defines ui.ui_imports_cmi ui.ui_imports_cmx;
123127
begin match ui.ui_export_info with
124128
| Clambda approx ->
125-
printf "Approximation:\n";
126-
Format.fprintf Format.std_formatter " %a@." Printclambda.approx approx
129+
if not !no_approx then begin
130+
printf "Clambda approximation:\n";
131+
Format.fprintf Format.std_formatter " %a@." Printclambda.approx approx
132+
end else
133+
Format.printf "Clambda unit@.";
127134
| Flambda export ->
128-
printf "Flambda export information:\n";
129-
let cu =
130-
Compilation_unit.create (Ident.create_persistent ui.ui_name)
131-
(Linkage_name.create "__dummy__")
132-
in
133-
Compilation_unit.set_current cu;
134-
Format.printf " %a\n" Export_info.print_all export
135+
if not !no_approx || not !no_code then
136+
printf "Flambda export information:\n"
137+
else
138+
printf "Flambda unit\n";
139+
if not !no_approx then begin
140+
let cu =
141+
Compilation_unit.create (Ident.create_persistent ui.ui_name)
142+
(Linkage_name.create "__dummy__")
143+
in
144+
Compilation_unit.set_current cu;
145+
let root_symbols =
146+
List.map (fun s ->
147+
Symbol.unsafe_create cu (Linkage_name.create ("caml"^s)))
148+
ui.ui_defines
149+
in
150+
Format.printf "approximations@ %a@.@."
151+
Export_info.print_approx (export, root_symbols)
152+
end;
153+
if not !no_code then
154+
Format.printf "functions@ %a@.@."
155+
Export_info.print_functions export
135156
end;
136157
let pr_funs _ fns =
137158
List.iter (fun arity -> printf " %d" arity) fns in
@@ -291,7 +312,10 @@ let dump_obj filename =
291312
end
292313
end
293314

294-
let arg_list = []
315+
let arg_list = [
316+
"-no-approx", Arg.Set no_approx, " Do not print module approximation information";
317+
"-no-code", Arg.Set no_code, " Do not print code from exported flambda functions"
318+
]
295319
let arg_usage =
296320
Printf.sprintf "%s [OPTIONS] FILES : give information on files" Sys.argv.(0)
297321

0 commit comments

Comments
 (0)