diff options
author | Fabrice Le Fessant <Fabrice.Le_fessant@inria.fr> | 2012-05-30 14:52:37 +0000 |
---|---|---|
committer | Fabrice Le Fessant <Fabrice.Le_fessant@inria.fr> | 2012-05-30 14:52:37 +0000 |
commit | d39d43e55fab716fbe05cec3c89233f0dd208835 (patch) | |
tree | bf5c56aa9bb32a0e3d49509b8b2863a9ec407563 /tools | |
parent | e3d82817909dd7bc69dff4f75aa63c5ba606d9c8 (diff) | |
download | ocaml-d39d43e55fab716fbe05cec3c89233f0dd208835.tar.gz |
merge with branch bin-annot
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@12516 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'tools')
-rw-r--r-- | tools/.depend | 131 | ||||
-rw-r--r-- | tools/.ignore | 1 | ||||
-rw-r--r-- | tools/Makefile.shared | 50 | ||||
-rw-r--r-- | tools/addlabels.ml | 54 | ||||
-rw-r--r-- | tools/depend.ml | 65 | ||||
-rw-r--r-- | tools/dumpobj.ml | 49 | ||||
-rw-r--r-- | tools/objinfo.ml | 15 | ||||
-rw-r--r-- | tools/ocamlcp.ml | 1 | ||||
-rw-r--r-- | tools/ocamlprof.ml | 21 |
9 files changed, 246 insertions, 141 deletions
diff --git a/tools/.depend b/tools/.depend index 36c177ed43..ad310b457e 100644 --- a/tools/.depend +++ b/tools/.depend @@ -1,62 +1,97 @@ -depend.cmi: ../parsing/parsetree.cmi -profiling.cmi: -addlabels.cmo: ../parsing/parsetree.cmi ../parsing/parse.cmi \ +depend.cmi : ../parsing/parsetree.cmi +profiling.cmi : +typedtreeIter.cmi : ../typing/typedtree.cmi ../parsing/asttypes.cmi +untypeast.cmi : ../typing/typedtree.cmi ../typing/path.cmi \ + ../parsing/parsetree.cmi ../parsing/longident.cmi +addlabels.cmo : ../parsing/parsetree.cmi ../parsing/parse.cmi \ ../parsing/longident.cmi ../parsing/location.cmi ../parsing/asttypes.cmi -addlabels.cmx: ../parsing/parsetree.cmi ../parsing/parse.cmx \ +addlabels.cmx : ../parsing/parsetree.cmi ../parsing/parse.cmx \ ../parsing/longident.cmx ../parsing/location.cmx ../parsing/asttypes.cmi -cvt_emit.cmo: -cvt_emit.cmx: -depend.cmo: ../parsing/parsetree.cmi ../parsing/longident.cmi \ - ../parsing/location.cmi depend.cmi -depend.cmx: ../parsing/parsetree.cmi ../parsing/longident.cmx \ - ../parsing/location.cmx depend.cmi -dumpobj.cmo: ../utils/tbl.cmi opnames.cmo ../bytecomp/opcodes.cmo \ - ../parsing/location.cmi ../bytecomp/lambda.cmi ../bytecomp/instruct.cmi \ - ../typing/ident.cmi ../bytecomp/emitcode.cmi ../utils/config.cmi \ - ../bytecomp/cmo_format.cmi ../bytecomp/bytesections.cmi \ - ../parsing/asttypes.cmi -dumpobj.cmx: ../utils/tbl.cmx opnames.cmx ../bytecomp/opcodes.cmx \ - ../parsing/location.cmx ../bytecomp/lambda.cmx ../bytecomp/instruct.cmx \ - ../typing/ident.cmx ../bytecomp/emitcode.cmx ../utils/config.cmx \ - ../bytecomp/cmo_format.cmi ../bytecomp/bytesections.cmx \ - ../parsing/asttypes.cmi -myocamlbuild_config.cmo: -myocamlbuild_config.cmx: -objinfo.cmo: ../utils/misc.cmi ../utils/config.cmi ../asmcomp/cmx_format.cmi \ - ../bytecomp/cmo_format.cmi ../asmcomp/clambda.cmi \ - ../bytecomp/bytesections.cmi -objinfo.cmx: ../utils/misc.cmx ../utils/config.cmx ../asmcomp/cmx_format.cmi \ - ../bytecomp/cmo_format.cmi ../asmcomp/clambda.cmx \ - ../bytecomp/bytesections.cmx -ocaml299to3.cmo: -ocaml299to3.cmx: -ocamlcp.cmo: ../driver/main_args.cmi -ocamlcp.cmx: ../driver/main_args.cmx -ocamldep.cmo: ../parsing/syntaxerr.cmi ../parsing/parsetree.cmi \ +cmt2annot.cmo : typedtreeIter.cmi ../typing/typedtree.cmi \ + ../typing/stypes.cmi ../typing/path.cmi ../typing/oprint.cmi \ + ../parsing/location.cmi ../typing/ident.cmi ../typing/env.cmi \ + ../typing/cmt_format.cmi ../parsing/asttypes.cmi ../typing/annot.cmi +cmt2annot.cmx : typedtreeIter.cmx ../typing/typedtree.cmx \ + ../typing/stypes.cmx ../typing/path.cmx ../typing/oprint.cmx \ + ../parsing/location.cmx ../typing/ident.cmx ../typing/env.cmx \ + ../typing/cmt_format.cmx ../parsing/asttypes.cmi ../typing/annot.cmi +cmt2ml.cmo : untypeast.cmi ../typing/typedtree.cmi pprintast.cmo \ + ../typing/cmt_format.cmi +cmt2ml.cmx : untypeast.cmx ../typing/typedtree.cmx pprintast.cmx \ + ../typing/cmt_format.cmx +cvt_emit.cmo : +cvt_emit.cmx : +depend.cmo : ../parsing/parsetree.cmi ../utils/misc.cmi \ + ../parsing/longident.cmi ../parsing/location.cmi ../parsing/asttypes.cmi \ + depend.cmi +depend.cmx : ../parsing/parsetree.cmi ../utils/misc.cmx \ + ../parsing/longident.cmx ../parsing/location.cmx ../parsing/asttypes.cmi \ + depend.cmi +dumpobj.cmo : ../utils/tbl.cmi opnames.cmo ../bytecomp/opcodes.cmo \ + ../utils/misc.cmi ../parsing/location.cmi ../bytecomp/lambda.cmi \ + ../bytecomp/instruct.cmi ../typing/ident.cmi ../bytecomp/emitcode.cmi \ + ../utils/config.cmi ../bytecomp/cmo_format.cmi \ + ../bytecomp/bytesections.cmi ../parsing/asttypes.cmi +dumpobj.cmx : ../utils/tbl.cmx opnames.cmx ../bytecomp/opcodes.cmx \ + ../utils/misc.cmx ../parsing/location.cmx ../bytecomp/lambda.cmx \ + ../bytecomp/instruct.cmx ../typing/ident.cmx ../bytecomp/emitcode.cmx \ + ../utils/config.cmx ../bytecomp/cmo_format.cmi \ + ../bytecomp/bytesections.cmx ../parsing/asttypes.cmi +myocamlbuild_config.cmo : +myocamlbuild_config.cmx : +objinfo.cmo : ../utils/misc.cmi ../utils/config.cmi \ + ../asmcomp/cmx_format.cmi ../bytecomp/cmo_format.cmi \ + ../asmcomp/clambda.cmi ../bytecomp/bytesections.cmi +objinfo.cmx : ../utils/misc.cmx ../utils/config.cmx \ + ../asmcomp/cmx_format.cmi ../bytecomp/cmo_format.cmi \ + ../asmcomp/clambda.cmx ../bytecomp/bytesections.cmx +ocaml299to3.cmo : +ocaml299to3.cmx : +ocamlcp.cmo : ../driver/main_args.cmi +ocamlcp.cmx : ../driver/main_args.cmx +ocamldep.cmo : ../parsing/syntaxerr.cmi ../parsing/parsetree.cmi \ ../parsing/parse.cmi ../utils/misc.cmi ../parsing/longident.cmi \ ../parsing/location.cmi ../parsing/lexer.cmi depend.cmi \ ../utils/config.cmi ../utils/clflags.cmi -ocamldep.cmx: ../parsing/syntaxerr.cmx ../parsing/parsetree.cmi \ +ocamldep.cmx : ../parsing/syntaxerr.cmx ../parsing/parsetree.cmi \ ../parsing/parse.cmx ../utils/misc.cmx ../parsing/longident.cmx \ ../parsing/location.cmx ../parsing/lexer.cmx depend.cmx \ ../utils/config.cmx ../utils/clflags.cmx -ocamlmklib.cmo: myocamlbuild_config.cmo -ocamlmklib.cmx: myocamlbuild_config.cmx -ocamlmktop.cmo: ../utils/ccomp.cmi -ocamlmktop.cmx: ../utils/ccomp.cmx -ocamlprof.cmo: ../utils/warnings.cmi ../parsing/syntaxerr.cmi \ +ocamlmklib.cmo : myocamlbuild_config.cmo +ocamlmklib.cmx : myocamlbuild_config.cmx +ocamlmktop.cmo : ../utils/ccomp.cmi +ocamlmktop.cmx : ../utils/ccomp.cmx +ocamloptp.cmo : ../driver/main_args.cmi +ocamloptp.cmx : ../driver/main_args.cmx +ocamlprof.cmo : ../utils/warnings.cmi ../parsing/syntaxerr.cmi \ ../parsing/parsetree.cmi ../parsing/parse.cmi ../utils/misc.cmi \ ../parsing/location.cmi ../parsing/lexer.cmi ../utils/config.cmi \ ../utils/clflags.cmi -ocamlprof.cmx: ../utils/warnings.cmx ../parsing/syntaxerr.cmx \ +ocamlprof.cmx : ../utils/warnings.cmx ../parsing/syntaxerr.cmx \ ../parsing/parsetree.cmi ../parsing/parse.cmx ../utils/misc.cmx \ ../parsing/location.cmx ../parsing/lexer.cmx ../utils/config.cmx \ ../utils/clflags.cmx -opnames.cmo: -opnames.cmx: -primreq.cmo: ../utils/config.cmi ../bytecomp/cmo_format.cmi -primreq.cmx: ../utils/config.cmx ../bytecomp/cmo_format.cmi -profiling.cmo: profiling.cmi -profiling.cmx: profiling.cmi -scrapelabels.cmo: -scrapelabels.cmx: +opnames.cmo : +opnames.cmx : +pprintast.cmo : ../parsing/parsetree.cmi ../parsing/longident.cmi \ + ../parsing/location.cmi ../parsing/asttypes.cmi +pprintast.cmx : ../parsing/parsetree.cmi ../parsing/longident.cmx \ + ../parsing/location.cmx ../parsing/asttypes.cmi +primreq.cmo : ../utils/config.cmi ../bytecomp/cmo_format.cmi +primreq.cmx : ../utils/config.cmx ../bytecomp/cmo_format.cmi +profiling.cmo : profiling.cmi +profiling.cmx : profiling.cmi +read_cmt.cmo : ../typing/cmt_format.cmi cmt2annot.cmo ../utils/clflags.cmi +read_cmt.cmx : ../typing/cmt_format.cmx cmt2annot.cmx ../utils/clflags.cmx +scrapelabels.cmo : +scrapelabels.cmx : +typedtreeIter.cmo : ../typing/typedtree.cmi ../utils/misc.cmi \ + ../parsing/asttypes.cmi typedtreeIter.cmi +typedtreeIter.cmx : ../typing/typedtree.cmx ../utils/misc.cmx \ + ../parsing/asttypes.cmi typedtreeIter.cmi +untypeast.cmo : ../typing/typedtree.cmi ../typing/path.cmi \ + ../parsing/parsetree.cmi ../utils/misc.cmi ../parsing/longident.cmi \ + ../typing/ident.cmi ../parsing/asttypes.cmi untypeast.cmi +untypeast.cmx : ../typing/typedtree.cmx ../typing/path.cmx \ + ../parsing/parsetree.cmi ../utils/misc.cmx ../parsing/longident.cmx \ + ../typing/ident.cmx ../parsing/asttypes.cmi untypeast.cmi diff --git a/tools/.ignore b/tools/.ignore index cf3c69515d..d8b1412d63 100644 --- a/tools/.ignore +++ b/tools/.ignore @@ -23,3 +23,4 @@ scrapelabels addlabels myocamlbuild_config.ml objinfo_helper +read_cmt diff --git a/tools/Makefile.shared b/tools/Makefile.shared index 02af98f0c3..72f1262051 100644 --- a/tools/Makefile.shared +++ b/tools/Makefile.shared @@ -24,6 +24,7 @@ COMPFLAGS= -warn-error A $(INCLUDES) LINKFLAGS=$(INCLUDES) all: ocamldep ocamlprof ocamlcp ocamlmktop ocamlmklib dumpobj objinfo + # scrapelabels addlabels .PHONY: all @@ -184,6 +185,51 @@ clean:: beforedepend:: cvt_emit.ml + +# Reading cmt files + +READ_CMT= \ + ../utils/misc.cmo \ + ../utils/warnings.cmo \ + ../utils/tbl.cmo \ + ../utils/consistbl.cmo \ + ../utils/config.cmo \ + ../utils/clflags.cmo \ + ../parsing/location.cmo \ + ../parsing/longident.cmo \ + ../parsing/lexer.cmo \ + ../typing/ident.cmo \ + ../typing/path.cmo \ + ../typing/types.cmo \ + ../typing/typedtree.cmo \ + ../typing/btype.cmo \ + ../typing/subst.cmo \ + ../typing/predef.cmo \ + ../typing/datarepr.cmo \ + ../typing/cmi_format.cmo \ + ../typing/env.cmo \ + ../typing/ctype.cmo \ + ../typing/oprint.cmo \ + ../typing/primitive.cmo \ + ../typing/printtyp.cmo \ + ../typing/cmt_format.cmo \ + ../typing/stypes.cmo \ + \ + pprintast.cmo untypeast.cmo typedtreeIter.cmo \ + cmt2annot.cmo read_cmt.cmo + +read_cmt: $(READ_CMT) + $(CAMLC) $(LINKFLAGS) -o read_cmt $(READ_CMT) + +# read_cmt is precious: sometimes we are stuck in the middle of a +# bootstrap and we need to remake the dependencies +clean:: + if test -f read_cmt; then mv -f read_cmt read_cmt.bak; else :; fi + +clean:: + +beforedepend:: + # The bytecode disassembler DUMPOBJ=opnames.cmo dumpobj.cmo @@ -219,7 +265,9 @@ objinfo_helper$(EXE): objinfo_helper.c ../config/s.h $(BYTECC) -o objinfo_helper$(EXE) $(BYTECCCOMPOPTS) \ objinfo_helper.c $(LIBBFD_LINK) -OBJINFO=../utils/misc.cmo ../utils/config.cmo ../bytecomp/bytesections.cmo \ +OBJINFO=../utils/misc.cmo ../utils/config.cmo \ + ../utils/warnings.cmo ../parsing/location.cmo \ + ../typing/cmi_format.cmo ../bytecomp/bytesections.cmo \ objinfo.cmo objinfo: objinfo_helper$(EXE) $(OBJINFO) diff --git a/tools/addlabels.ml b/tools/addlabels.ml index c057e72ca8..c12bde8470 100644 --- a/tools/addlabels.ml +++ b/tools/addlabels.ml @@ -49,11 +49,11 @@ let rec labels_of_cty cty = Pcty_fun (lab, _, rem) -> let (labs, meths) = labels_of_cty rem in (lab :: labs, meths) - | Pcty_signature (_, fields) -> + | Pcty_signature { pcsig_fields = fields } -> ([], List.fold_left fields ~init:[] ~f: begin fun meths -> function - Pctf_meth (s, _, sty, _) -> (s, labels_of_sty sty)::meths + { pctf_desc = Pctf_meth (s, _, sty) } -> (s, labels_of_sty sty)::meths | _ -> meths end) | _ -> @@ -61,9 +61,9 @@ let rec labels_of_cty cty = let rec pattern_vars pat = match pat.ppat_desc with - Ppat_var s -> [s] + Ppat_var s -> [s.txt] | Ppat_alias (pat, s) -> - s :: pattern_vars pat + s.txt :: pattern_vars pat | Ppat_tuple l | Ppat_array l -> List.concat (List.map pattern_vars l) @@ -124,7 +124,7 @@ let rec insert_labels ~labels ~text expr = let start_c = pat.ppat_loc.Location.loc_start.Lexing.pos_cnum in let pos = insertion_point start_c ~text in match pattern_name pat with - | Some name when l = name -> add_insertion pos "~" + | Some name when l = name.txt -> add_insertion pos "~" | _ -> add_insertion pos ("~" ^ l ^ ":") end; insert_labels ~labels ~text rem @@ -164,7 +164,7 @@ let rec insert_labels_class ~labels ~text expr = let start_c = pat.ppat_loc.Location.loc_start.Lexing.pos_cnum in let pos = insertion_point start_c ~text in match pattern_name pat with - | Some name when l = name -> add_insertion pos "~" + | Some name when l = name.txt -> add_insertion pos "~" | _ -> add_insertion pos ("~" ^ l ^ ":") end; insert_labels_class ~labels ~text rem @@ -192,7 +192,7 @@ let rec insert_labels_app ~labels ~text args = let pos0 = arg.pexp_loc.Location.loc_start.Lexing.pos_cnum in let pos = insertion_point pos0 ~text in match arg.pexp_desc with - | Pexp_ident(Longident.Lident name) when l = name && pos = pos0 -> + | Pexp_ident({ txt = Longident.Lident name }) when l = name && pos = pos0 -> add_insertion pos "~" | _ -> add_insertion pos ("~" ^ l ^ ":") end; @@ -218,7 +218,7 @@ let rec add_labels_expr ~text ~values ~classes expr = let add_labels_rec ?(values=values) expr = add_labels_expr ~text ~values ~classes expr in match expr.pexp_desc with - Pexp_apply ({pexp_desc=Pexp_ident(Longident.Lident s)}, args) -> + Pexp_apply ({pexp_desc=Pexp_ident({ txt = Longident.Lident s })}, args) -> begin try let labels = SMap.find s values in insert_labels_app ~labels ~text args @@ -226,14 +226,14 @@ let rec add_labels_expr ~text ~values ~classes expr = end; List.iter args ~f:(fun (_,e) -> add_labels_rec e) | Pexp_apply ({pexp_desc=Pexp_send - ({pexp_desc=Pexp_ident(Longident.Lident s)},meth)}, args) -> + ({pexp_desc=Pexp_ident({ txt = Longident.Lident s })},meth)}, args) -> begin try if SMap.find s values = ["<object>"] then let labels = SMap.find (s ^ "#" ^ meth) values in insert_labels_app ~labels ~text args with Not_found -> () end - | Pexp_apply ({pexp_desc=Pexp_new (Longident.Lident s)}, args) -> + | Pexp_apply ({pexp_desc=Pexp_new ({ txt = Longident.Lident s })}, args) -> begin try let labels = SMap.find s classes in insert_labels_app ~labels ~text args @@ -288,7 +288,7 @@ let rec add_labels_expr ~text ~values ~classes expr = add_labels_rec e1; add_labels_rec e2; add_labels_rec e3 | Pexp_for (s, e1, e2, _, e3) -> add_labels_rec e1; add_labels_rec e2; - add_labels_rec e3 ~values:(SMap.removes [s] values) + add_labels_rec e3 ~values:(SMap.removes [s.txt] values) | Pexp_override lst -> List.iter lst ~f:(fun (_,e) -> add_labels_rec e) | Pexp_ident _ | Pexp_constant _ | Pexp_construct _ | Pexp_variant _ @@ -298,23 +298,23 @@ let rec add_labels_expr ~text ~values ~classes expr = let rec add_labels_class ~text ~classes ~values ~methods cl = match cl.pcl_desc with Pcl_constr _ -> () - | Pcl_structure (p, l) -> + | Pcl_structure { pcstr_pat = p; pcstr_fields = l } -> let values = SMap.removes (pattern_vars p) values in let values = match pattern_name p with None -> values | Some s -> List.fold_left methods - ~init:(SMap.add s ["<object>"] values) - ~f:(fun m (k,l) -> SMap.add (s^"#"^k) l m) + ~init:(SMap.add s.txt ["<object>"] values) + ~f:(fun m (k,l) -> SMap.add (s.txt^"#"^k) l m) in ignore (List.fold_left l ~init:values ~f: - begin fun values -> function - | Pcf_val (s, _, _, e, _) -> + begin fun values -> function e -> match e.pcf_desc with + | Pcf_val (s, _, _, e) -> add_labels_expr ~text ~classes ~values e; - SMap.removes [s] values - | Pcf_meth (s, _, _, e, _) -> + SMap.removes [s.txt] values + | Pcf_meth (s, _, _, e) -> begin try - let labels = List.assoc s methods in + let labels = List.assoc s.txt methods in insert_labels ~labels ~text e with Not_found -> () end; @@ -323,7 +323,7 @@ let rec add_labels_class ~text ~classes ~values ~methods cl = | Pcf_init e -> add_labels_expr ~text ~classes ~values e; values - | Pcf_inher _ | Pcf_valvirt _ | Pcf_virt _ | Pcf_cstr _ -> values + | Pcf_inher _ | Pcf_valvirt _ | Pcf_virt _ | Pcf_constr _ -> values end) | Pcl_fun (_, opt, pat, cl) -> begin match opt with None -> () @@ -353,12 +353,12 @@ let add_labels ~intf ~impl ~file = begin fun (values, classes as acc) item -> match item.psig_desc with Psig_value (name, {pval_type = sty}) -> - (SMap.add name (labels_of_sty sty) values, classes) + (SMap.add name.txt (labels_of_sty sty) values, classes) | Psig_class l -> (values, List.fold_left l ~init:classes ~f: begin fun classes {pci_name=name; pci_expr=cty} -> - SMap.add name (labels_of_cty cty) classes + SMap.add name.txt (labels_of_cty cty) classes end) | _ -> acc @@ -376,7 +376,7 @@ let add_labels ~intf ~impl ~file = begin match pattern_name pat with | Some s -> begin try - let labels = SMap.find s values in + let labels = SMap.find s.txt values in insert_labels ~labels ~text expr; if !norec then () else let values = @@ -393,17 +393,17 @@ let add_labels ~intf ~impl ~file = (SMap.removes names values, classes) | Pstr_primitive (s, {pval_type=sty}) -> begin try - let labels = SMap.find s values in + let labels = SMap.find s.txt values in insert_labels_type ~labels ~text sty; - (SMap.removes [s] values, classes) + (SMap.removes [s.txt] values, classes) with Not_found -> acc end | Pstr_class l -> - let names = List.map l ~f:(fun pci -> pci.pci_name) in + let names = List.map l ~f:(fun pci -> pci.pci_name.txt) in List.iter l ~f: begin fun {pci_name=name; pci_expr=expr} -> try - let (labels, methods) = SMap.find name classes in + let (labels, methods) = SMap.find name.txt classes in insert_labels_class ~labels ~text expr; if !norec then () else let classes = diff --git a/tools/depend.ml b/tools/depend.ml index 948646a823..2015f937e5 100644 --- a/tools/depend.ml +++ b/tools/depend.ml @@ -12,6 +12,7 @@ (* $Id$ *) +open Asttypes open Format open Location open Longident @@ -21,6 +22,8 @@ module StringSet = Set.Make(struct type t = string let compare = compare end) (* Collect free module identifiers in the a.s.t. *) +let fst3 (x, _, _) = x + let free_structure_names = ref StringSet.empty let rec addmodule bv lid = @@ -32,10 +35,12 @@ let rec addmodule bv lid = | Lapply(l1, l2) -> addmodule bv l1; addmodule bv l2 let add bv lid = - match lid with + match lid.txt with Ldot(l, s) -> addmodule bv l | _ -> () +let addmodule bv lid = addmodule bv lid.txt + let rec add_type bv ty = match ty.ptyp_desc with Ptyp_any -> () @@ -56,7 +61,7 @@ let rec add_type bv ty = and add_package_type bv (lid, l) = add bv lid; - List.iter (add_type bv) (List.map snd l) + List.iter (add_type bv) (List.map (fun (_, e) -> e) l) and add_field_type bv ft = match ft.pfield_desc with @@ -84,18 +89,19 @@ let rec add_class_type bv cty = match cty.pcty_desc with Pcty_constr(l, tyl) -> add bv l; List.iter (add_type bv) tyl - | Pcty_signature (ty, fieldl) -> + | Pcty_signature { pcsig_self = ty; pcsig_fields = fieldl } -> add_type bv ty; List.iter (add_class_type_field bv) fieldl | Pcty_fun(_, ty1, cty2) -> add_type bv ty1; add_class_type bv cty2 -and add_class_type_field bv = function +and add_class_type_field bv pctf = + match pctf.pctf_desc with Pctf_inher cty -> add_class_type bv cty - | Pctf_val(_, _, _, ty, _) -> add_type bv ty - | Pctf_virt(_, _, ty, _) -> add_type bv ty - | Pctf_meth(_, _, ty, _) -> add_type bv ty - | Pctf_cstr(ty1, ty2, _) -> add_type bv ty1; add_type bv ty2 + | Pctf_val(_, _, _, ty) -> add_type bv ty + | Pctf_virt(_, _, ty) -> add_type bv ty + | Pctf_meth(_, _, ty) -> add_type bv ty + | Pctf_cstr(ty1, ty2) -> add_type bv ty1; add_type bv ty2 let add_class_description bv infos = add_class_type bv infos.pci_expr @@ -116,7 +122,7 @@ let rec add_pattern bv pat = | Ppat_or(p1, p2) -> add_pattern bv p1; add_pattern bv p2 | Ppat_constraint(p, ty) -> add_pattern bv p; add_type bv ty | Ppat_variant(_, op) -> add_opt add_pattern bv op - | Ppat_type (li) -> add bv li + | Ppat_type li -> add bv li | Ppat_lazy p -> add_pattern bv p | Ppat_unpack _ -> () @@ -144,7 +150,7 @@ let rec add_expr bv exp = add_expr bv e1; add_expr bv e2; add_opt add_expr bv opte3 | Pexp_sequence(e1, e2) -> add_expr bv e1; add_expr bv e2 | Pexp_while(e1, e2) -> add_expr bv e1; add_expr bv e2 - | Pexp_for(_, e1, e2, _, e3) -> + | Pexp_for( _, e1, e2, _, e3) -> add_expr bv e1; add_expr bv e2; add_expr bv e3 | Pexp_constraint(e1, oty2, oty3) -> add_expr bv e1; @@ -152,16 +158,16 @@ let rec add_expr bv exp = add_opt add_type bv oty3 | Pexp_when(e1, e2) -> add_expr bv e1; add_expr bv e2 | Pexp_send(e, m) -> add_expr bv e - | Pexp_new l -> add bv l + | Pexp_new li -> add bv li | Pexp_setinstvar(v, e) -> add_expr bv e | Pexp_override sel -> List.iter (fun (s, e) -> add_expr bv e) sel | Pexp_letmodule(id, m, e) -> - add_module bv m; add_expr (StringSet.add id bv) e + add_module bv m; add_expr (StringSet.add id.txt bv) e | Pexp_assert (e) -> add_expr bv e | Pexp_assertfalse -> () | Pexp_lazy (e) -> add_expr bv e | Pexp_poly (e, t) -> add_expr bv e; add_opt add_type bv t - | Pexp_object (pat, fieldl) -> + | Pexp_object { pcstr_pat = pat; pcstr_fields = fieldl } -> add_pattern bv pat; List.iter (add_class_field bv) fieldl | Pexp_newtype (_, e) -> add_expr bv e | Pexp_pack m -> add_module bv m @@ -174,14 +180,14 @@ and add_modtype bv mty = Pmty_ident l -> add bv l | Pmty_signature s -> add_signature bv s | Pmty_functor(id, mty1, mty2) -> - add_modtype bv mty1; add_modtype (StringSet.add id bv) mty2 + add_modtype bv mty1; add_modtype (StringSet.add id.txt bv) mty2 | Pmty_with(mty, cstrl) -> add_modtype bv mty; List.iter (function (_, Pwith_type td) -> add_type_declaration bv td - | (_, Pwith_module lid) -> addmodule bv lid + | (_, Pwith_module (lid)) -> addmodule bv lid | (_, Pwith_typesubst td) -> add_type_declaration bv td - | (_, Pwith_modsubst lid) -> addmodule bv lid) + | (_, Pwith_modsubst (lid)) -> addmodule bv lid) cstrl | Pmty_typeof m -> add_module bv m @@ -198,12 +204,12 @@ and add_sig_item bv item = | Psig_exception(id, args) -> List.iter (add_type bv) args; bv | Psig_module(id, mty) -> - add_modtype bv mty; StringSet.add id bv + add_modtype bv mty; StringSet.add id.txt bv | Psig_recmodule decls -> - let bv' = List.fold_right StringSet.add (List.map fst decls) bv in + let bv' = List.fold_right StringSet.add (List.map (fun (x,_) -> x.txt) decls) bv in List.iter (fun (id, mty) -> add_modtype bv' mty) decls; bv' - | Psig_modtype(id, mtyd) -> + | Psig_modtype(id,mtyd) -> begin match mtyd with Pmodtype_abstract -> () | Pmodtype_manifest mty -> add_modtype bv mty @@ -224,7 +230,7 @@ and add_module bv modl = | Pmod_structure s -> ignore (add_structure bv s) | Pmod_functor(id, mty, modl) -> add_modtype bv mty; - add_module (StringSet.add id bv) modl + add_module (StringSet.add id.txt bv) modl | Pmod_apply(mod1, mod2) -> add_module bv mod1; add_module bv mod2 | Pmod_constraint(modl, mty) -> @@ -250,11 +256,11 @@ and add_struct_item bv item = | Pstr_exn_rebind(id, l) -> add bv l; bv | Pstr_module(id, modl) -> - add_module bv modl; StringSet.add id bv + add_module bv modl; StringSet.add id.txt bv | Pstr_recmodule bindings -> let bv' = List.fold_right StringSet.add - (List.map (fun (id,_,_) -> id) bindings) bv in + (List.map (fun (id,_,_) -> id.txt) bindings) bv in List.iter (fun (id, mty, modl) -> add_modtype bv' mty; add_module bv' modl) bindings; @@ -281,7 +287,7 @@ and add_class_expr bv ce = match ce.pcl_desc with Pcl_constr(l, tyl) -> add bv l; List.iter (add_type bv) tyl - | Pcl_structure(pat, fieldl) -> + | Pcl_structure { pcstr_pat = pat; pcstr_fields = fieldl } -> add_pattern bv pat; List.iter (add_class_field bv) fieldl | Pcl_fun(_, opte, pat, ce) -> add_opt add_expr bv opte; add_pattern bv pat; add_class_expr bv ce @@ -292,13 +298,14 @@ and add_class_expr bv ce = | Pcl_constraint(ce, ct) -> add_class_expr bv ce; add_class_type bv ct -and add_class_field bv = function +and add_class_field bv pcf = + match pcf.pcf_desc with Pcf_inher(_, ce, _) -> add_class_expr bv ce - | Pcf_val(_, _, _, e, _) -> add_expr bv e - | Pcf_valvirt(_, _, ty, _) - | Pcf_virt(_, _, ty, _) -> add_type bv ty - | Pcf_meth(_, _, _, e, _) -> add_expr bv e - | Pcf_cstr(ty1, ty2, _) -> add_type bv ty1; add_type bv ty2 + | Pcf_val(_, _, _, e) -> add_expr bv e + | Pcf_valvirt(_, _, ty) + | Pcf_virt(_, _, ty) -> add_type bv ty + | Pcf_meth(_, _, _, e) -> add_expr bv e + | Pcf_constr(ty1, ty2) -> add_type bv ty1; add_type bv ty2 | Pcf_init e -> add_expr bv e and add_class_declaration bv decl = 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 () diff --git a/tools/objinfo.ml b/tools/objinfo.ml index 42fa8ee9c2..1e0a38e108 100644 --- a/tools/objinfo.ml +++ b/tools/objinfo.ml @@ -97,7 +97,7 @@ let print_cma_infos (lib : Cmo_format.library) = printf "\n"; List.iter print_cmo_infos lib.lib_units -let print_cmi_infos name sign comps crcs = +let print_cmi_infos name sign crcs = printf "Unit name: %s\n" name; printf "Interfaces imported:\n"; List.iter print_name_crc crcs @@ -231,10 +231,10 @@ let dump_obj filename = close_in ic; print_cma_infos toc end else if magic_number = cmi_magic_number then begin - let (name, sign, comps) = input_value ic in - let crcs = input_value ic in + let cmi = Cmi_format.input_cmi ic in close_in ic; - print_cmi_infos name sign comps crcs + print_cmi_infos cmi.Cmi_format.cmi_name cmi.Cmi_format.cmi_sign + cmi.Cmi_format.cmi_crcs end else if magic_number = cmx_magic_number then begin let ui = (input_value ic : unit_infos) in let crc = Digest.input ic in @@ -269,10 +269,11 @@ let dump_obj filename = end end +let arg_list = [] +let arg_usage = Printf.sprintf "%s [OPTIONS] FILES : give information on files" Sys.argv.(0) + let main() = - for i = 1 to Array.length Sys.argv - 1 do - dump_obj Sys.argv.(i) - done; + Arg.parse arg_list dump_obj arg_usage; exit 0 let _ = main () diff --git a/tools/ocamlcp.ml b/tools/ocamlcp.ml index e9c6c05990..8f09cc1344 100644 --- a/tools/ocamlcp.ml +++ b/tools/ocamlcp.ml @@ -45,6 +45,7 @@ module Options = Main_args.Make_bytecomp_options (struct let _a () = make_archive := true; option "-a" () let _absname = option "-absname" let _annot = option "-annot" + let _binannot = option "-bin-annot" let _c = option "-c" let _cc s = option_with_arg "-cc" s let _cclib s = option_with_arg "-cclib" s diff --git a/tools/ocamlprof.ml b/tools/ocamlprof.ml index b8a6b3fa40..1fd123ceab 100644 --- a/tools/ocamlprof.ml +++ b/tools/ocamlprof.ml @@ -282,8 +282,8 @@ and rw_exp iflag sexp = | Pexp_poly (sexp, _) -> rewrite_exp iflag sexp - | Pexp_object (_, fieldl) -> - List.iter (rewrite_class_field iflag) fieldl + | Pexp_object cl -> + List.iter (rewrite_class_field iflag) cl.pcstr_fields | Pexp_newtype (_, sexp) -> rewrite_exp iflag sexp | Pexp_open (_, e) -> rewrite_exp iflag e @@ -319,24 +319,25 @@ and rewrite_trymatching l = (* Rewrite a class definition *) -and rewrite_class_field iflag = - function +and rewrite_class_field iflag cf = + match cf.pcf_desc with Pcf_inher (_, cexpr, _) -> rewrite_class_expr iflag cexpr - | Pcf_val (_, _, _, sexp, _) -> rewrite_exp iflag sexp - | Pcf_meth (_, _, _, ({pexp_desc = Pexp_function _} as sexp), _) -> + | Pcf_val (_, _, _, sexp) -> rewrite_exp iflag sexp + | Pcf_meth (_, _, _, ({pexp_desc = Pexp_function _} as sexp)) -> rewrite_exp iflag sexp - | Pcf_meth (_, _, _, sexp, loc) -> + | Pcf_meth (_, _, _, sexp) -> + let loc = cf.pcf_loc in if !instr_fun && not loc.loc_ghost then insert_profile rw_exp sexp else rewrite_exp iflag sexp | Pcf_init sexp -> rewrite_exp iflag sexp - | Pcf_valvirt _ | Pcf_virt _ | Pcf_cstr _ -> () + | Pcf_valvirt _ | Pcf_virt _ | Pcf_constr _ -> () and rewrite_class_expr iflag cexpr = match cexpr.pcl_desc with Pcl_constr _ -> () - | Pcl_structure (_, fields) -> - List.iter (rewrite_class_field iflag) fields + | Pcl_structure st -> + List.iter (rewrite_class_field iflag) st.pcstr_fields | Pcl_fun (_, _, _, cexpr) -> rewrite_class_expr iflag cexpr | Pcl_apply (cexpr, exprs) -> |