Types¶
-
type gcc_jit_type¶
gcc_jit_type represents a type within the library.
-
gcc_jit_object *gcc_jit_type_as_object(gcc_jit_type *type)¶
Upcast a type to an object.
Types can be created in several ways:
fundamental types can be accessed using
gcc_jit_context_get_type():gcc_jit_type *int_type = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
See
gcc_jit_context_get_type()for the available types.derived types can be accessed by using functions such as
gcc_jit_type_get_pointer()andgcc_jit_type_get_const():gcc_jit_type *const_int_star = gcc_jit_type_get_pointer (gcc_jit_type_get_const (int_type)); gcc_jit_type *int_const_star = gcc_jit_type_get_const (gcc_jit_type_get_pointer (int_type));
by creating structures (see below).
Standard types¶
-
gcc_jit_type *gcc_jit_context_get_type(gcc_jit_context *ctxt, enum gcc_jit_types type_)¶
Access a specific type. The available types are:
enum gcc_jit_types value
Meaning
GCC_JIT_TYPE_VOIDC’s
voidtype.GCC_JIT_TYPE_VOID_PTRC’s
void *.GCC_JIT_TYPE_BOOLC++’s
booltype; also C99’s_Booltype, akaboolif using stdbool.h.GCC_JIT_TYPE_CHARC’s
char(of some signedness)GCC_JIT_TYPE_SIGNED_CHARC’s
signed charGCC_JIT_TYPE_UNSIGNED_CHARC’s
unsigned charGCC_JIT_TYPE_SHORTC’s
short(signed)GCC_JIT_TYPE_UNSIGNED_SHORTC’s
unsigned shortGCC_JIT_TYPE_INTC’s
int(signed)GCC_JIT_TYPE_UNSIGNED_INTC’s
unsigned intGCC_JIT_TYPE_LONGC’s
long(signed)GCC_JIT_TYPE_UNSIGNED_LONGC’s
unsigned longGCC_JIT_TYPE_LONG_LONGC99’s
long long(signed)GCC_JIT_TYPE_UNSIGNED_LONG_LONGC99’s
unsigned long longGCC_JIT_TYPE_FLOATGCC_JIT_TYPE_DOUBLEGCC_JIT_TYPE_LONG_DOUBLEGCC_JIT_TYPE_CONST_CHAR_PTRC type:
(const char *)GCC_JIT_TYPE_SIZE_TC’s
size_ttypeGCC_JIT_TYPE_FILE_PTRC type:
(FILE *)GCC_JIT_TYPE_COMPLEX_FLOATC99’s
_Complex floatGCC_JIT_TYPE_COMPLEX_DOUBLEC99’s
_Complex doubleGCC_JIT_TYPE_COMPLEX_LONG_DOUBLEC99’s
_Complex long double
-
gcc_jit_type *gcc_jit_context_get_int_type(gcc_jit_context *ctxt, int num_bytes, int is_signed)¶
Access the integer type of the given size.
Pointers, const, and volatile¶
-
gcc_jit_type *gcc_jit_type_get_pointer(gcc_jit_type *type)¶
Given type “T”, get type “T*”.
-
gcc_jit_type *gcc_jit_type_get_const(gcc_jit_type *type)¶
Given type “T”, get type “const T”.
-
gcc_jit_type *gcc_jit_type_get_volatile(gcc_jit_type *type)¶
Given type “T”, get type “volatile T”.
-
gcc_jit_type *gcc_jit_context_new_array_type(gcc_jit_context *ctxt, gcc_jit_location *loc, gcc_jit_type *element_type, int num_elements)¶
Given non-void type “T”, get type “T[N]” (for a constant N).
-
gcc_jit_type *gcc_jit_type_get_aligned(gcc_jit_type *type, size_t alignment_in_bytes)¶
Given non-void type “T”, get type:
T __attribute__ ((aligned (ALIGNMENT_IN_BYTES)))
The alignment must be a power of two.
This entrypoint was added in LIBGCCJIT_ABI_7; you can test for its presence using
#ifdef LIBGCCJIT_HAVE_gcc_jit_type_get_aligned
Vector types¶
-
gcc_jit_type *gcc_jit_type_get_vector(gcc_jit_type *type, size_t num_units)¶
Given type “T”, get type:
T __attribute__ ((vector_size (sizeof(T) * num_units))
T must be integral or floating point; num_units must be a power of two.
This can be used to construct a vector type in which operations are applied element-wise. The compiler will automatically use SIMD instructions where possible. See: https://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html
For example, assuming 4-byte
ints, then:typedef int v4si __attribute__ ((vector_size (16)));
can be obtained using:
gcc_jit_type *int_type = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT); gcc_jit_type *v4si_type = gcc_jit_type_get_vector (int_type, 4);
This API entrypoint was added in LIBGCCJIT_ABI_8; you can test for its presence using
#ifdef LIBGCCJIT_HAVE_gcc_jit_type_get_vectorVector rvalues can be generated using
gcc_jit_context_new_rvalue_from_vector().
Structures and unions¶
-
type gcc_jit_struct¶
A compound type analagous to a C struct.
-
type gcc_jit_field¶
A field within a gcc_jit_struct.
You can model C struct types by creating gcc_jit_struct * and
gcc_jit_field instances, in either order:
by creating the fields, then the structure. For example, to model:
struct coord {double x; double y; };
you could call:
gcc_jit_field *field_x = gcc_jit_context_new_field (ctxt, NULL, double_type, "x"); gcc_jit_field *field_y = gcc_jit_context_new_field (ctxt, NULL, double_type, "y"); gcc_jit_field *fields[2] = {field_x, field_y}; gcc_jit_struct *coord = gcc_jit_context_new_struct_type (ctxt, NULL, "coord", 2, fields);
by creating the structure, then populating it with fields, typically to allow modelling self-referential structs such as:
struct node { int m_hash; struct node *m_next; };
like this:
gcc_jit_type *node = gcc_jit_context_new_opaque_struct (ctxt, NULL, "node"); gcc_jit_type *node_ptr = gcc_jit_type_get_pointer (node); gcc_jit_field *field_hash = gcc_jit_context_new_field (ctxt, NULL, int_type, "m_hash"); gcc_jit_field *field_next = gcc_jit_context_new_field (ctxt, NULL, node_ptr, "m_next"); gcc_jit_field *fields[2] = {field_hash, field_next}; gcc_jit_struct_set_fields (node, NULL, 2, fields);
-
gcc_jit_field *gcc_jit_context_new_field(gcc_jit_context *ctxt, gcc_jit_location *loc, gcc_jit_type *type, const char *name)¶
Construct a new field, with the given type and name.
The parameter
typemust be non-void.The parameter
namemust be non-NULL. The call takes a copy of the underlying string, so it is valid to pass in a pointer to an on-stack buffer.
-
gcc_jit_field *gcc_jit_context_new_bitfield(gcc_jit_context *ctxt, gcc_jit_location *loc, gcc_jit_type *type, int width, const char *name)¶
Construct a new bit field, with the given type width and name.
The parameter
namemust be non-NULL. The call takes a copy of the underlying string, so it is valid to pass in a pointer to an on-stack buffer.The parameter
typemust be an integer type.The parameter
widthmust be a positive integer that does not exceed the size oftype.This API entrypoint was added in LIBGCCJIT_ABI_12; you can test for its presence using
#ifdef LIBGCCJIT_HAVE_gcc_jit_context_new_bitfield
-
gcc_jit_object *gcc_jit_field_as_object(gcc_jit_field *field)¶
Upcast from field to object.
-
gcc_jit_struct *gcc_jit_context_new_struct_type(gcc_jit_context *ctxt, gcc_jit_location *loc, const char *name, int num_fields, gcc_jit_field **fields)¶
Construct a new struct type, with the given name and fields.
The parameter
namemust be non-NULL. The call takes a copy of the underlying string, so it is valid to pass in a pointer to an on-stack buffer.
-
gcc_jit_struct *gcc_jit_context_new_opaque_struct(gcc_jit_context *ctxt, gcc_jit_location *loc, const char *name)¶
Construct a new struct type, with the given name, but without specifying the fields. The fields can be omitted (in which case the size of the struct is not known), or later specified using
gcc_jit_struct_set_fields().The parameter
namemust be non-NULL. The call takes a copy of the underlying string, so it is valid to pass in a pointer to an on-stack buffer.
-
gcc_jit_type *gcc_jit_struct_as_type(gcc_jit_struct *struct_type)¶
Upcast from struct to type.
-
void gcc_jit_struct_set_fields(gcc_jit_struct *struct_type, gcc_jit_location *loc, int num_fields, gcc_jit_field **fields)¶
Populate the fields of a formerly-opaque struct type.
This can only be called once on a given struct type.
-
gcc_jit_type *gcc_jit_context_new_union_type(gcc_jit_context *ctxt, gcc_jit_location *loc, const char *name, int num_fields, gcc_jit_field **fields)¶
Construct a new union type, with the given name and fields.
The parameter
namemust be non-NULL. It is copied, so the input buffer does not need to outlive the call.Example of use:
Function pointer types¶
Function pointer types can be created using
gcc_jit_context_new_function_ptr_type().