Commits

Anonymous committed ffe23b0

Introduction de dumpapprox pour imprimer les infos d'un .cmx.

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@57f963ae5c-01c2-4b8c-9fe0-0dff7051ff02

  • Participants
  • Parent commits c078fb1

Comments (0)

Files changed (3)

File tools/Makefile

 CAMLC=../boot/camlrun ../boot/camlc -I ../boot
-INCLUDES=-I ../utils -I ../parsing -I ../typing -I ../bytecomp
+INCLUDES=-I ../utils -I ../parsing -I ../typing -I ../bytecomp -I ../asmcomp
 COMPFLAGS=$(INCLUDES)
 LINKFLAGS=$(INCLUDES)
 
 
 beforedepend:: opnames.ml
 
+dumpapprox: dumpapprox.cmo
+	$(CAMLC) $(LINKFLAGS) -o dumpapprox config.cmo dumpapprox.cmo
+
+clean::
+	rm -f dumpapprox
+
 .SUFFIXES:
 .SUFFIXES: .ml .cmo .mli .cmi
 

File tools/dumpapprox.ml

+(* Dump a .cmx file *)
+
+open Config
+open Format
+open Clambda
+open Compilenv
+
+let rec print_approx = function
+    Value_closure(fundesc, approx) ->
+      open_hovbox 2;
+      print_string "function "; print_string fundesc.fun_label;
+      print_space(); print_string "arity "; print_int fundesc.fun_arity;
+      if fundesc.fun_closed then begin
+        print_space(); print_string "(closed)"
+      end;
+      print_space(); print_string "->"; print_space();
+      print_approx approx;
+      close_box()
+  | Value_tuple approx ->
+      open_hvbox 1;
+      print_string "[";
+      for i = 0 to Array.length approx - 1 do
+        if i > 0 then (print_string ";"; print_space());
+        print_int i; print_string ": "; print_approx approx.(i)
+      done;
+      print_string "]";
+      close_box()
+  | Value_unknown ->
+      print_string "_"
+
+let print_infos ui =
+  print_string "Name: "; print_string ui.ui_name; print_newline();
+  open_hovbox 2;
+  print_string "Interfaces imported:";
+  List.iter
+    (fun (name, crc) -> print_space(); print_string name)
+    ui.ui_interfaces;
+  close_box(); print_newline();
+  open_hovbox 2;
+  print_string "Implementations imported:";
+  List.iter
+    (fun (name, crc) -> print_space(); print_string name)
+    ui.ui_interfaces;
+  close_box(); print_newline();
+  open_hovbox 2;
+  print_string "Approximation:"; print_space(); print_approx ui.ui_approx;
+  close_box(); print_newline();
+  open_hovbox 2;
+  print_string "Currying functions:";
+  List.iter
+    (fun arity -> print_space(); print_int arity)
+    ui.ui_curry_fun;
+  close_box(); print_newline();
+  open_hovbox 2;
+  print_string "Apply functions:";
+  List.iter
+    (fun arity -> print_space(); print_int arity)
+    ui.ui_apply_fun;
+  close_box(); print_newline()
+
+let read_unit_info filename =
+  let ic = open_in_bin filename in
+  try
+    let buffer = String.create (String.length cmx_magic_number) in
+    really_input ic buffer 0 (String.length cmx_magic_number);
+    if buffer <> cmx_magic_number then begin
+      close_in ic;
+      prerr_endline "Wrong magic number";
+      exit 2
+    end;
+    let ui = (input_value ic : unit_infos) in
+    let crc = input_binary_int ic in
+    close_in ic;
+    ui
+  with End_of_file | Failure _ ->
+    close_in ic;
+    prerr_endline "Error reading file";
+    exit 2
+
+let main () =
+  print_infos(read_unit_info Sys.argv.(1));
+  exit 0
+
+let _ = main ()
+
+
+    

File tools/dumpobj.ml

       printf "\"%s\"" (String.escaped s)
   | Const_base(Const_char c) ->
       printf "'%s'" (Char.escaped c)
+  | Const_pointer n ->
+      printf "%da" n
   | Const_block(tag, args) ->
       printf "<%d>" tag;
       begin match args with