Types — libgccjit v6.1.0 ( ) documentation (original) (raw)

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:

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_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 *)
GCC_JIT_TYPE_COMPLEX_FLOAT C99’s _Complex float
GCC_JIT_TYPE_COMPLEX_DOUBLE C99’s _Complex double
GCC_JIT_TYPE_COMPLEX_LONG_DOUBLE C99’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 type “T”, get type “T[N]” (for a constant N).

Structures and unions

gcc_jit_struct

A compound type analagous to a C struct.

gcc_jit_field

A field within a gcc_jit_struct.

You can model C struct types by creating gcc_jit_struct * andgcc_jit_field instances, in either order:

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 name must 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_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 name must 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 usinggcc_jit_struct_set_fields().

The parameter name must 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 name must be non-NULL. It is copied, so the input buffer does not need to outlive the call.

Example of use: