2012-05-30 08:25:49 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
2012-08-01 05:38:51 -07:00
|
|
|
(* OCaml *)
|
2012-05-30 08:25:49 -07:00
|
|
|
(* *)
|
|
|
|
(* Fabrice Le Fessant, INRIA Saclay *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 2012 Institut National de Recherche en Informatique et *)
|
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
let gen_annot = ref false
|
|
|
|
let gen_ml = ref false
|
|
|
|
let print_info_arg = ref false
|
|
|
|
let target_filename = ref None
|
|
|
|
|
|
|
|
let arg_list = [
|
2014-04-12 03:17:02 -07:00
|
|
|
"-o", Arg.String (fun s -> target_filename := Some s),
|
|
|
|
" FILE (or -) : dump to file FILE (or stdout)";
|
2012-05-30 08:25:49 -07:00
|
|
|
"-annot", Arg.Set gen_annot, " : generate the corresponding .annot file";
|
2014-04-12 03:17:02 -07:00
|
|
|
"-src", Arg.Set gen_ml,
|
|
|
|
" : convert .cmt or .cmti back to source code (without comments)";
|
2012-05-30 08:25:49 -07:00
|
|
|
"-info", Arg.Set print_info_arg, " : print information on the file";
|
|
|
|
]
|
|
|
|
|
2014-04-12 03:17:02 -07:00
|
|
|
let arg_usage =
|
|
|
|
"read_cmt [OPTIONS] FILE.cmt : read FILE.cmt and print related information"
|
2012-05-30 08:25:49 -07:00
|
|
|
|
|
|
|
let print_info cmt =
|
|
|
|
let open Cmt_format in
|
|
|
|
Printf.printf "module name: %s\n" cmt.cmt_modname;
|
|
|
|
begin match cmt.cmt_annots with
|
2014-04-12 03:17:02 -07:00
|
|
|
Packed (_, list) ->
|
|
|
|
Printf.printf "pack: %s\n" (String.concat " " list)
|
2012-05-30 08:25:49 -07:00
|
|
|
| Implementation _ -> Printf.printf "kind: implementation\n"
|
|
|
|
| Interface _ -> Printf.printf "kind: interface\n"
|
2014-04-12 03:17:02 -07:00
|
|
|
| Partial_implementation _ ->
|
|
|
|
Printf.printf "kind: implementation with errors\n"
|
2012-05-30 08:25:49 -07:00
|
|
|
| Partial_interface _ -> Printf.printf "kind: interface with errors\n"
|
|
|
|
end;
|
2014-04-12 03:17:02 -07:00
|
|
|
Printf.printf "command: %s\n"
|
|
|
|
(String.concat " " (Array.to_list cmt.cmt_args));
|
2012-05-30 08:25:49 -07:00
|
|
|
begin match cmt.cmt_sourcefile with
|
|
|
|
None -> ()
|
|
|
|
| Some name ->
|
|
|
|
Printf.printf "sourcefile: %s\n" name;
|
|
|
|
end;
|
|
|
|
Printf.printf "build directory: %s\n" cmt.cmt_builddir;
|
2014-04-12 03:17:02 -07:00
|
|
|
List.iter (Printf.printf "load path: %s\n%!") cmt.cmt_loadpath;
|
2012-05-30 08:25:49 -07:00
|
|
|
begin
|
|
|
|
match cmt.cmt_source_digest with
|
|
|
|
None -> ()
|
2014-04-12 03:17:02 -07:00
|
|
|
| Some digest ->
|
|
|
|
Printf.printf "source digest: %s\n" (Digest.to_hex digest);
|
2012-05-30 08:25:49 -07:00
|
|
|
end;
|
|
|
|
begin
|
|
|
|
match cmt.cmt_interface_digest with
|
|
|
|
None -> ()
|
2014-04-12 03:17:02 -07:00
|
|
|
| Some digest ->
|
|
|
|
Printf.printf "interface digest: %s\n" (Digest.to_hex digest);
|
2012-05-30 08:25:49 -07:00
|
|
|
end;
|
2014-05-01 23:19:55 -07:00
|
|
|
List.iter (fun (name, digest) ->
|
|
|
|
Printf.printf "import: %s %s\n" name (Digest.to_hex digest);
|
2012-05-30 08:25:49 -07:00
|
|
|
) (List.sort compare cmt.cmt_imports);
|
|
|
|
Printf.printf "%!";
|
|
|
|
()
|
|
|
|
|
|
|
|
let _ =
|
|
|
|
Clflags.annotations := true;
|
|
|
|
|
|
|
|
Arg.parse arg_list (fun filename ->
|
|
|
|
if
|
|
|
|
Filename.check_suffix filename ".cmt" ||
|
|
|
|
Filename.check_suffix filename ".cmti"
|
|
|
|
then begin
|
|
|
|
(* init_path(); *)
|
|
|
|
let cmt = Cmt_format.read_cmt filename in
|
|
|
|
if !gen_annot then Cmt2annot.gen_annot !target_filename filename cmt;
|
|
|
|
if !gen_ml then Cmt2annot.gen_ml !target_filename filename cmt;
|
|
|
|
if !print_info_arg || not (!gen_ml || !gen_annot) then print_info cmt;
|
|
|
|
end else begin
|
2014-04-12 03:17:02 -07:00
|
|
|
Printf.fprintf stderr
|
|
|
|
"Error: the file's extension must be .cmt or .cmti.\n%!";
|
2012-05-30 08:25:49 -07:00
|
|
|
Arg.usage arg_list arg_usage
|
|
|
|
end
|
|
|
|
) arg_usage
|