Module Gccjit

module Gccjit: sig .. end
OCaml bindings for libgccjit.

See GCC wiki page for more information.


exception Error of string
This exception (containing an explanatory string) is raised if an error occurs.
type context 
The type of compilation contexts. See Compilation Contexts.
type result 
A Gccjit.result encapsulates the result of an in-memory compilation.
type location 
A Gccjit.location encapsulates a source code location, so that you can (optionally) associate locations in your languages with statements in the JIT-compiled code, alowing the debugger to single-step through your language. See Source locations.
type param 
A Gccjit.param is a function parameter. See Parameters.
type lvalue 
An Gccjit.lvalue is something that can of the left-hand side of an assignment. See Lvalues.
type rvalue 
A rvalue is an expression within your code, with some type. See RValues.
type field 
The type of fields of structs and unions. See Fields.
type struct_ 
The type of structure types. See Structure Types.
type type_ 
The type of C types, e.g. int or a struct foo*. See Types.
type function_ 
The type of functios. See Functions.
type block 
The type of basic blocks. See Basic Blocks.
type unary_op = 
| Negate
| Bitwise_negate
| Logical_negate
type binary_op = 
| Plus
| Minus
| Mult
| Divide
| Modulo
| Bitwise_and
| Bitwise_xor
| Bitwise_or
| Logical_and
| Logical_or
type comparison = 
| Eq
| Ne
| Lt
| Le
| Gt
| Ge

Compilation Contexts

A Gccjit.context encapsulates the state of a compilation. You can set up options on it, add types, functions and code, using the API below.

Invoking Gccjit.Context.compile on it gives you a Gccjit.result, representing in-memory machine-code.

You can call Gccjit.Context.compile repeatedly on one context, giving multiple independent results.

Similarly, you can call Gccjit.Context.compile_to_file on a context to compile to disk.

Eventually you can call Gccjit.Context.release to clean up the context; any in-memory results created from it are still usable.

module Context: sig .. end

Fields

A field encapsulates a field within a struct; it is used when creating a struct type (using Gccjit.Struct.create). Fields cannot be shared between structs.

module Field: sig .. end

Structure Types

A struct_ encapsulates a struct type, either one that we have the layout for, or an opaque type.

You can model C struct types by creating struct_ and field instances, in either order:


module Struct: sig .. end

Types


module Type: sig .. end

Rvalues

A Gccjit.rvalue is an expression that can be computed.

It can be simple, e.g.:

or compound e.g.: Every Gccjit.rvalue has an associated type, and the API will check to ensure that types match up correctly (otherwise the context will emit an error).
module RValue: sig .. end

Lvalues

An Gccjit.lvalue is something that can of the left-hand side of an assignment: a storage area (such as a variable). It is also usable as an Gccjit.rvalue, where the Gccjit.rvalue is computed by reading from the storage area.

module LValue: sig .. end

Parameters

A value of type Gccjit.param represents a parameter to a function.

module Param: sig .. end

Functions

A values of type function_ encapsulates a function: either one that you're creating yourself, or a reference to one that you're dynamically linking to within the rest of the process.

module Function: sig .. end

Basic Blocks

A block encapsulates a basic block of statements within a function (i.e. with one entry point and one exit point).


module Block: sig .. end

Source Locations

A Gccjit.location encapsulates a source code location, so that you can (optionally) associate locations in your language with statements in the JIT-compiled code, allowing the debugger to single-step through your language.

Faking it

If you don't have source code for your internal representation, but need to debug, you can generate a C-like representation of the functions in your context using Gccjit.Context.dump_to_file. This will dump C-like code to the given path. If the update_locations argument is true, this will also set up Gccjit.location information throughout the context, pointing at the dump file as if it were a source file, giving you something you can step through in the debugger.

module Location: sig .. end

In-memory compilation


module Result: sig .. end