Chapter 24 The compiler front-end
This chapter describes the OCaml front-end, which declares the abstractsyntax tree used by the compiler, provides a way to parse, printand pretty-print OCaml code, and ultimately allows to write abstractsyntax tree preprocessors invoked via the -ppx flag (see chapters 9and 12) and plugins invoked via the -plugin flag(see chapter 22).
It is important to note that the exported front-end interface follows the evolution of the OCaml language and implementation, and thus does not provide any backwards compatibility guarantees.
The front-end is a part of compiler-libs library.Programs that use the compiler-libs library should be built as follows:
- ocamlfind ocamlc other options -package compiler-libs.common other files
- ocamlfind ocamlopt other options -package compiler-libs.common other files
Use of the ocamlfind utility is recommended. However, if this is not possible, an alternative method may be used:
- ocamlc other options -I +compiler-libs ocamlcommon.cma other files
- ocamlopt other options -I +compiler-libs ocamlcommon.cmxa other files
For interactive use of the compiler-libs library, start ocaml andtype#load "compiler-libs/ocamlcommon.cma";;.
- Module Ast_helper: helper functions for AST construction
- Module Ast_mapper: -ppx rewriter interface
- Module Asttypes: auxiliary types used by Parsetree
- Module Location: source code locations
- Module Longident: long identifiers
- Module Parse: OCaml syntax parsing
- Module Parsetree: OCaml syntax tree
Module Pprintast: OCaml syntax printingThe following modules provides hooks for compiler plugins:
- Module Typemod:OCaml module type checking
- Module Simplif: Lambda simplification
- Module Clflags: command line flags