Warning! The packages available in OPAM are beta-version of the version 2 of typerex. These versions rely of the cmt files generated by the 4.00 OCaml compiler, with the -bin-annot option. Thus, most of the instructions given on this website are outdated. We are planning to improve the documentation.

TypeRex tools

This chapter summarizes the command-line tools which are provided together with the TypeRex environment.

ocp-type

The ocp-type command-line tool is the “type-only” OCaml compiler which is used to extract the binary annotations needed by the TypeRex environment. It may be invoked directly or through the ocp-wrapper tools (see below). It accepts the same options and arguments as ocamlc, and the specific option -save-types, to actually write the binary data to a file.

Pre-processing

ocp-type also accepts pre-processors through the -pp option, which should output either

  • an OCaml source file (if possible with line-number directives to allow an accurate use of TypeRex), or
  • an OCaml dumped AST of one of the supported versions (this is the default behavior of camlp4), or
  • a Camlp4 dumped AST of one of the supported versions, which can be achieved by passing the option -printer Camlp4AstDumper to camlp4 (this is done automatically if you use ocp-wrapper).

Note that the third option is better than the second one with respect to locations (the accuracy of which is instrumental to TypeRex working).

Libraries

ocp-type accepts the special form

    ocp-type -save-types -a <units> -o <target>
where
  • the argument units may be cmi, cmo, cmti, cmt, mli, or ml files, and
  • the target is ignored.
Only arguments ending in ml or mli will be considered, and typed into cmt or cmti files.

Module packs

ocp-type accepts the special form

    ocp-type -save-types -pack <units> -o <target>
where
  • the argument units may be cmi, cmo, cmti, cmt, mli, or ml files, and
  • the target may be a cmo or cmt file.
Howerver, input will always look at cmt or cmti (or cmi as a fallback) files (possibly generating them if ml or mli are given), and the output will always be written in a cmt file. If a mli file exists for the name of the pack, then ocp-type will look for a compiled interface file for it in cmti format (or cmi as a fallback) and match the result of packing the arguments against this signature.

ocp-wrapper

The command ocp-wrapper and the specialized commands ocp-ocamlc, ocp-ocamlopt, ocp-ocamlc.opt, and ocp-ocamlopt.opt simplify the generation of binary annotations by invoking ocp-type with the appropriate options, as part of the usual compilation commands. Calling

 ocp-wrapper -save-types <command> <options and arguments>
where <command> is one of the OCaml compilers first invokes this compiler with the exact same options and arguments, and then runs ocp-type (unless the command-line was a linking-only phase) with the right options and arguments which are deduced from the original command ones.

Shortcuts

The four ocp-* commands are shortcuts for ocp-wrapper -save-types <command> which are useful when a single executable program is required as compiling command.

Options

  • -with-ocp-type, -with-ocamlc, …: allow to customize the ocp-type, ocamlc, …commands which are run.
  • -v print the ocp-type command which is executed on stderr.

Pre-processing

Any -pp option appearing in the command line is transformed as follows when passed to ocp-type:

  • if the pre-processor command is (a variant of) camlp4, and unless option -no-wrap-camlp4 is passed to ocp-wrapper, then the option -printer Camlp4AstDumper is added, which yields more accurate location information,
  • otherwise, the command is left unchanged.

Libraries and Module Packs

ocp-wrapper accepts the special forms

    ocp-wrapper -save-types <compiler> -a <units> -o <target>
    ocp-wrapper -save-types <compiler> -pack <units> -o <target>
Arguments and targets ending in cmx are converted into cmo and targets into cmt as appropriate (see the documentation for ocp-type).