summaryrefslogtreecommitdiff
path: root/tools/dumpobj.ml
diff options
context:
space:
mode:
Diffstat (limited to 'tools/dumpobj.ml')
-rw-r--r--tools/dumpobj.ml49
1 files changed, 30 insertions, 19 deletions
diff --git a/tools/dumpobj.ml b/tools/dumpobj.ml
index ff7ff688a4..5a40cfc395 100644
--- a/tools/dumpobj.ml
+++ b/tools/dumpobj.ml
@@ -26,6 +26,8 @@ open Opnames
open Cmo_format
open Printf
+let print_locations = ref true
+
(* Read signed and unsigned integers *)
let inputu ic =
@@ -399,11 +401,12 @@ let op_shapes = [
];;
let print_event ev =
- let ls = ev.ev_loc.loc_start in
- let le = ev.ev_loc.loc_end in
- printf "File \"%s\", line %d, characters %d-%d:\n" ls.Lexing.pos_fname
- ls.Lexing.pos_lnum (ls.Lexing.pos_cnum - ls.Lexing.pos_bol)
- (le.Lexing.pos_cnum - ls.Lexing.pos_bol)
+ if !print_locations then
+ let ls = ev.ev_loc.loc_start in
+ let le = ev.ev_loc.loc_end in
+ printf "File \"%s\", line %d, characters %d-%d:\n" ls.Lexing.pos_fname
+ ls.Lexing.pos_lnum (ls.Lexing.pos_cnum - ls.Lexing.pos_bol)
+ (le.Lexing.pos_cnum - ls.Lexing.pos_bol)
let print_instr ic =
let pos = currpos ic in
@@ -539,20 +542,28 @@ let dump_exe ic =
let code_size = Bytesections.seek_section ic "CODE" in
print_code ic code_size
-let main() =
- for i = 1 to Array.length Sys.argv - 1 do
- let filnam = Sys.argv.(i) in
- let ic = open_in_bin filnam in
- if i>1 then print_newline ();
- printf "## start of ocaml dump of %S\n%!" filnam;
- begin try
- objfile := false; dump_exe ic
+let arg_list = [
+ "-noloc", Arg.Clear print_locations, " : don't print source information";
+]
+let arg_usage = Printf.sprintf "%s [OPTIONS] FILES : dump content of bytecode files" Sys.argv.(0)
+
+let first_file = ref true
+
+let arg_fun filename =
+ let ic = open_in_bin filename in
+ if not !first_file then print_newline ();
+ first_file := false;
+ printf "## start of ocaml dump of %S\n%!" filename;
+ begin try
+ objfile := false; dump_exe ic
with Bytesections.Bad_magic_number ->
- objfile := true; seek_in ic 0; dump_obj (Sys.argv.(i)) ic
- end;
- close_in ic;
- printf "## end of ocaml dump of %S\n%!" filnam;
- done;
- exit 0
+ objfile := true; seek_in ic 0; dump_obj filename ic
+ end;
+ close_in ic;
+ printf "## end of ocaml dump of %S\n%!" filename
+
+let main() =
+ Arg.parse arg_list arg_fun arg_usage;
+ exit 0
let _ = main ()