module Gccjit:sig
..end
libgccjit
.
See GCC wiki page for more information.
exception Error of string
type
context
type
result
Gccjit.result
encapsulates the result of an in-memory compilation.type
location
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
type
lvalue
type
rvalue
type
field
type
struct_
type
type_
type
function_
type
block
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 |
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
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
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:
struct coord {double x; double y; };
you could call:
let field_x = Field.create ctx double_type "x" in
let field_y = Field.create ctx double_type "y" in
let coord = Struct.create ctx "coord" [ field_x ; field_y ]
struct node { int m_hash; struct node *m_next; };
like this:
let node = Struct.create_opaque ctx "node" in
let node_ptr = Type.pointer node in
let field_hash = Field.create ctx int_type "m_hash" in
let field_next = Field.create ctx node_ptr "m_next" in
Struct.set_fields node [ field_hash; field_next ]
module Struct:sig
..end
module Type:sig
..end
A Gccjit.rvalue
is an expression that can be computed.
It can be simple, e.g.:
0
or 42
"Hello world"
i
. These are also lvalues (see below).!cond
(a + b)
get_distance (&player_ship, &target)
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
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
A value of type Gccjit.param
represents a parameter to a
function.
module Param:sig
..end
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
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
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.
Gccjit.location
instances are optional: you can always omit them to any API
entrypoint accepting one.Gccjit.Location.create
.Debuginfo
on the Gccjit.context
for these
locations to actually be usable by the debugger.
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
module Result:sig
..end