This module contains the core API of constructing expressions.
See also the C API documentation.
Add a new global variable of the given type and name to the context.
The parameter type must be non-void.
See LeanGccJit.Core.GlobalKind
for visibility options.
Create a constructor for a struct as an rvalue.
type
specifies what the constructor will build and has to be a struct.
fields
need to have the same length as values
, or none
.
If fields is none
, the values are applied in definition order.
Otherwise, each field in fields specifies which field in the struct to set to the corresponding value in values
. fields
and values
are paired by index.
The fields in fields
have to be in definition order, but there can be gaps. Any field in the struct that is not specified in fields
will be zeroed.
The fields in fields
need to be the same objects that were used to create the struct.
Each value has to have have the same unqualified type as the field it is applied to.
A none
value element in values is a shorthand for zero initialization of the corresponding field.
Create a constructor for a union as an rvalue.
type
specifies what the constructor will build and has to be an union.
field
specifies which field to set. If it is non
, the first field in the union will be set.
field
need to be the same object that were used to create the union.
value
specifies what value to set the corresponding field to. If value is none
,
zero initialization will be used.
Each value has to have have the same unqualified type as the field it is applied to.
Create a constructor for an array as an rvalue.
type
specifies what the constructor will build and has to be an array.
values
can’t have more elements than the array type.
Each value in values
sets the corresponding value in the array. If the array type itself has more elements than values
, the left-over elements will be zeroed.
Each value in values
need to be the same unqualified type as the array type’s element type.
Set the initial value of a global with an rvalue.
The rvalue needs to be a constant expression, e.g. no function calls.
The global can’t have the kind LeanGccJit.Core.GlobalKind.Imported
.
Returns the global itself.
Set an initializer for global using the memory content pointed by value
. The global LValue
must be an array of an integral type.
Returns the global itself.
The content will be stored in the compilation unit and used as initialization value of the array.
Upcast an LValue
to an Object
.
Upcast an LValue
to an RValue
.
Upcast a RValue
to an Object
.
Get the type of this rvalue.
Create a new RValue
(integer or floating point) from a UInt32
literal.
This is a wrapper around []gcc_jit_context_new_rvalue_from_int
](https://gcc.gnu.org/onlinedocs/jit/topics/expressions.html#c.gcc_jit_context_new_rvalue_from_int).
Create a new RValue
(integer or floating point) from a UInt64
literal.
This is a wrapper around gcc_jit_context_new_rvalue_from_long
.
Given a numeric type (integer or floating point), get the rvalue for zero.
Given a numeric type (integer or floating point), get the rvalue for one.
Given a numeric type (integer or floating point), build an rvalue for the given constant Float
value.
Given a pointer type, build an rvalue for the given address (encoded in USize
).
Given a pointer type, build an rvalue for the given address.
Generate an rvalue for the given NIL-terminated string, of type const char *
.
Build a unary operation out of an input rvalue.
The parameter ty
must be a numeric type.
Build a binary operation out of two constituent rvalues.
The parameter ty
must be a numeric type.
Build a boolean rvalue out of the comparison of two other rvalues.
Given a function and the given table of argument rvalues, construct a call to the function, with the result as an rvalue.
Note #
This function merely builds a RValue
i.e. an expression that can be evaluated, perhaps as part of a more complicated expression.
The call won’t happen unless you add a statement to a function that evaluates the expression.
Given an rvalue of function pointer type, and the given table of argument rvalues, construct a call to the function pointer, with the result as an rvalue.
Given an rvalue of T, construct another rvalue of another type. Currently only a limited set of conversions are possible:
int
⇔float
int
⇔bool
P *
⇔Q *
Given an rvalue of T, bitcast it to another type, meaning that this will generate a new rvalue by interpreting the bits of rvalue to the layout of type.
The type of val
must be the same size as the size of ty
.
Set the alignment of a variable, in bytes. Analogous to:
int variable __attribute__((aligned (16)));
Return the alignment of a variable set by LValue.setAlignment
.
Return 0 if the alignment was not set. Analogous to:
_Alignof (variable)
Given an rvalue of pointer type T *
, get at the element T
at the given index,
using standard C array indexing rules i.e. each increment of index corresponds to sizeof(T)
bytes.
Analogous to:
PTR[INDEX]
Given an lvalue of struct or union type, access the given field as an lvalue. Analogous to:
(EXPR).field = ...;
Given an rvalue of struct or union type, access the given field as an rvalue. Analogous to:
(EXPR).field
Given an rvalue of pointer type T *
where T
is of struct or union type, access the given field as an lvalue. Analogous to:
(EXPR)->field
Given an rvalue of pointer type T *
, dereferencing the pointer, getting an lvalue of type T. Analogous to:
*(EXPR)
Take the address of an lvalue; analogous to:
&(EXPR)
Make a variable a thread-local variable.
The tlsModel
parameter determines the thread-local storage model of the lval
:
_Thread_local int foo __attribute__ ((tls_model("MODEL")));
See LeanGccJit.Core.TlsModel
for options.
Set the link section of a variable.
The parameter linkSection
must contain the leading dot.
Analogous to:
int variable __attribute__((section(".section")));
Set the register name of a variable.
Analogous to:
register int variable asm ("r12");
Create a new local variable within the function, of the given type and name.
The parameter type must be non-void.
Given an RValue
for a call created through Context.newCall
or Context.newCallThroughPtr
,
mark/clear the call as needing tail-call optimization. The optimizer will attempt to optimize
the call into a jump instruction; if it is unable to do do, an error will be emitted.
This may be useful when implementing functions that use the continuation-passing style
(e.g. for functional programming languages), in which every function returns
by calling a
continuation
function pointer. This call must be guaranteed to be implemented as a jump,
otherwise the program could consume an arbitrary amount of stack space as it executed.
Build a vector RValue
from an array of elements.
ty
should be a vector type, created using JitType.getVector
.
elems
should match the length and type of the vector type.