View on GitHub

OCamlverse

Documenting everything about OCaml

Edit

Compiler

The OCaml compiler is a complicated software artifact. Below is an attempt to document information that could not fit easily into the codebase, including relevant papers. Feel free to break this up into pages as the need arises.

Articles

Interesting Branches of the Compiler

Commands

  • ocamlc -config: show all configuration parameters for the compiler. Very useful.

Compiler Internals

  • hacking.adoc: a basic guide to the compiler’s internals.

Driver

The compiler driver, residing in the /driver directory, runs the entire compilation process from start to finish. The 2 entry points into the system are optmain.ml for the native compiler and main.ml for the bytecode compiler, setting up 2 separate execution paths through the code.

Both paths go through the pparse.ml file, which handles PPX rewriters. This file dumps the current parsed AST, calls a given PPX executable, and reloads the resulting AST.

The two compilation files are compile.ml for bytecode, and optcompile.ml for native. Both files pipe the different kinds of data through all the compilation stages. While native compilation has options for either clambda (naive) or flambda (optimized) compilation, bytecode compilation currently has only one mode, which is equivalent to clambda compilation.

Parser

ppx

Typechecker

Lambda

Pattern Matching

Flambda

Clambda

cmm

Register Coloring

assembly