Module Melange_compiler_libs.Cmt_format

cmt and cmti files format.

The layout of a cmt file is as follows: <cmt> := {<cmi>} <cmt magic> {cmt infos} {<source info>} where <cmi> is the cmi file format: <cmi> := <cmi magic> <cmi info>. More precisely, the optional <cmi> part must be present if and only if the file is:

Thus, we provide a common reading function for cmi and cmt(i) files which returns an option for each of the three parts: cmi info, cmt info, source info.

type binary_annots =
  1. | Packed(Types.signature, list(string))
  2. | Implementation(Typedtree.structure)
  3. | Interface(Typedtree.signature)
  4. | Partial_implementation(array(binary_part))
  5. | Partial_interface(array(binary_part))
;
and binary_part =
  1. | Partial_structure(Typedtree.structure)
  2. | Partial_structure_item(Typedtree.structure_item)
  3. | Partial_expression(Typedtree.expression)
  4. | Partial_pattern(Typedtree.pattern_category('k), Typedtree.general_pattern('k)) : binary_part
  5. | Partial_class_expr(Typedtree.class_expr)
  6. | Partial_signature(Typedtree.signature)
  7. | Partial_signature_item(Typedtree.signature_item)
  8. | Partial_module_type(Typedtree.module_type)
;
type cmt_infos = {
  1. cmt_modname: Misc.modname,
  2. cmt_annots: binary_annots,
  3. cmt_value_dependencies: list((Types.value_description, Types.value_description)),
  4. cmt_comments: list((string, Location.t)),
  5. cmt_args: array(string),
  6. cmt_sourcefile: option(string),
  7. cmt_builddir: string,
  8. cmt_loadpath: list(string),
  9. cmt_source_digest: option(string),
  10. cmt_initial_env: Env.t,
  11. cmt_imports: Misc.crcs,
  12. cmt_interface_digest: option(Stdlib.Digest.t),
  13. cmt_use_summaries: bool,
  14. cmt_uid_to_loc: Shape.Uid.Tbl.t(Location.t),
  15. cmt_impl_shape: option(Shape.t),
};
type error =
  1. | Not_a_typedtree(string)
;
exception Error(error);
let read: string => (option(Cmi_format.cmi_infos), option(cmt_infos));

read filename opens filename, and extract both the cmi_infos, if it exists, and the cmt_infos, if it exists. Thus, it can be used with .cmi, .cmt and .cmti files.

.cmti files always contain a cmi_infos at the beginning. .cmt files only contain a cmi_infos at the beginning if there is no associated .cmti file.

let read_cmt: string => cmt_infos;
let read_cmi: string => Cmi_format.cmi_infos;
let save_cmt: string => string => binary_annots => option(string) => Env.t => option(Cmi_format.cmi_infos) => option(Shape.t) => unit;

save_cmt filename modname binary_annots sourcefile initial_env cmi writes a cmt(i) file.

let read_magic_number: Stdlib.in_channel => string;
let clear: unit => unit;
let add_saved_type: binary_part => unit;
let get_saved_types: unit => list(binary_part);
let set_saved_types: list(binary_part) => unit;
let record_value_dependency: Types.value_description => Types.value_description => unit;