Documentation

LeanGccJit.Core.Values

This module contains the core API of constructing expressions.

See also the C API documentation.

@[extern lean_gcc_jit_context_new_global]

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.

@[extern lean_gcc_jit_context_new_struct_constructor]

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.

@[extern lean_gcc_jit_context_new_union_constructor]

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.

@[extern lean_gcc_jit_context_new_array_constructor]

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.

@[extern lean_gcc_jit_global_set_initializer_rvalue]

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.

@[extern lean_gcc_jit_global_set_initializer]

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.

@[extern lean_gcc_jit_lvalue_as_object]

Upcast an LValue to an Object.

@[extern lean_gcc_jit_lvalue_as_rvalue]

Upcast an LValue to an RValue.

@[extern lean_gcc_jit_rvalue_as_object]

Upcast a RValue to an Object.

@[extern lean_gcc_jit_rvalue_get_type]

Get the type of this rvalue.

@[extern lean_gcc_jit_context_new_rvalue_from_uint32]

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).

@[extern lean_gcc_jit_context_new_rvalue_from_uint64]

Create a new RValue (integer or floating point) from a UInt64 literal.

This is a wrapper around gcc_jit_context_new_rvalue_from_long.

@[extern lean_gcc_jit_context_zero]

Given a numeric type (integer or floating point), get the rvalue for zero.

@[extern lean_gcc_jit_context_one]

Given a numeric type (integer or floating point), get the rvalue for one.

@[extern lean_gcc_jit_context_new_rvalue_from_double]

Given a numeric type (integer or floating point), build an rvalue for the given constant Float value.

@[extern lean_gcc_jit_context_new_rvalue_from_addr]

Given a pointer type, build an rvalue for the given address (encoded in USize).

@[extern lean_gcc_jit_context_null]

Given a pointer type, build an rvalue for the given address.

@[extern lean_gcc_jit_context_new_string_literal]

Generate an rvalue for the given NIL-terminated string, of type const char *.

@[extern lean_gcc_jit_context_new_unary_op]

Build a unary operation out of an input rvalue.

The parameter ty must be a numeric type.

@[extern lean_gcc_jit_context_new_binary_op]

Build a binary operation out of two constituent rvalues. The parameter ty must be a numeric type.

@[extern lean_gcc_jit_context_new_comparison]

Build a boolean rvalue out of the comparison of two other rvalues.

@[extern lean_gcc_jit_context_new_call]

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.

@[extern lean_gcc_jit_context_new_call_through_ptr]

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.

@[extern lean_gcc_jit_context_new_cast]

Given an rvalue of T, construct another rvalue of another type. Currently only a limited set of conversions are possible:

  • intfloat
  • intbool
  • P *Q *
@[extern lean_gcc_jit_context_new_bitcast]

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.

@[extern lean_gcc_jit_lvalue_set_alignment]

Set the alignment of a variable, in bytes. Analogous to:

int variable __attribute__((aligned (16)));
@[extern lean_gcc_jit_lvalue_get_alignment]

Return the alignment of a variable set by LValue.setAlignment. Return 0 if the alignment was not set. Analogous to:

_Alignof (variable)
@[extern lean_gcc_jit_context_new_array_access]

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]
@[extern lean_gcc_jit_lvalue_access_field]

Given an lvalue of struct or union type, access the given field as an lvalue. Analogous to:

(EXPR).field = ...;
@[extern lean_gcc_jit_rvalue_access_field]

Given an rvalue of struct or union type, access the given field as an rvalue. Analogous to:

(EXPR).field
@[extern lean_gcc_jit_rvalue_dereference_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
@[extern lean_gcc_jit_rvalue_dereference]

Given an rvalue of pointer type T *, dereferencing the pointer, getting an lvalue of type T. Analogous to:

*(EXPR)
@[extern lean_gcc_jit_lvalue_get_address]

Take the address of an lvalue; analogous to:

&(EXPR)
@[extern lean_gcc_jit_lvalue_set_tls_model]

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.

@[extern lean_gcc_jit_lvalue_set_register_name]

Set the register name of a variable.

Analogous to:

register int variable asm ("r12");
@[extern lean_gcc_jit_function_new_local]

Create a new local variable within the function, of the given type and name.

The parameter type must be non-void.

@[extern lean_gcc_jit_rvalue_set_bool_require_tail_call]

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.

@[extern lean_gcc_jit_context_new_rvalue_from_vector]

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.