gcc_jit_type represents a type within the library.
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 (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() and gcc_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).
Access a specific type. The available types are:
enum gcc_jit_types value | Meaning |
---|---|
GCC_JIT_TYPE_VOID | C’s void type. |
GCC_JIT_TYPE_VOID_PTR | C’s void *. |
GCC_JIT_TYPE_BOOL | C++’s bool type; also C99’s _Bool type, aka bool if using stdbool.h. |
GCC_JIT_TYPE_CHAR | C’s char (of some signedness) |
GCC_JIT_TYPE_SIGNED_CHAR | C’s signed char |
GCC_JIT_TYPE_UNSIGNED_CHAR | C’s unsigned char |
GCC_JIT_TYPE_SHORT | C’s short (signed) |
GCC_JIT_TYPE_UNSIGNED_SHORT | C’s unsigned short |
GCC_JIT_TYPE_INT | C’s int (signed) |
GCC_JIT_TYPE_UNSIGNED_INT | C’s unsigned int |
GCC_JIT_TYPE_LONG | C’s long (signed) |
GCC_JIT_TYPE_UNSIGNED_LONG | C’s unsigned long |
GCC_JIT_TYPE_LONG_LONG | C99’s long long (signed) |
GCC_JIT_TYPE_UNSIGNED_LONG_LONG | C99’s unsigned long long |
GCC_JIT_TYPE_FLOAT | |
GCC_JIT_TYPE_DOUBLE | |
GCC_JIT_TYPE_LONG_DOUBLE | |
GCC_JIT_TYPE_CONST_CHAR_PTR | C type: (const char *) |
GCC_JIT_TYPE_SIZE_T | C’s size_t type |
GCC_JIT_TYPE_FILE_PTR | C type: (FILE *) |
Access the integer type of the given size.
Given type “T”, get type “T*”.
Given type “T”, get type “const T”.
Given type “T”, get type “volatile T”.
Given type “T”, get type “T[N]” (for a constant N).
A compound type analagous to a C struct.
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);
Construct a new field, with the given type and name.
Upcast from field to object.
Construct a new struct type, with the given name and fields.
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().
Upcast from struct to type.
Populate the fields of a formerly-opaque struct type.
This can only be called once on a given struct type.