Types can be created in several ways:
fundamental types can be accessed using gccjit::context::get_type():
gccjit::type int_type = ctxt.get_type (GCC_JIT_TYPE_INT);
or using the gccjit::context::get_int_type template:
gccjit::type t = ctxt.get_int_type <unsigned short> ();
See :c:func:`gcc_jit_context_get_type` for the available types.
derived types can be accessed by using functions such as gccjit::type::get_pointer() and gccjit::type::get_const():
gccjit::type const_int_star = int_type.get_const ().get_pointer ();
gccjit::type int_const_star = int_type.get_pointer ().get_const ();
by creating structures (see below).
Access the given integer type. For example, you could map the unsigned short type into a gccjit::type via:
gccjit::type t = ctxt.get_int_type <unsigned short> ();
Given type “T”, get type:
T __attribute__ ((aligned (ALIGNMENT_IN_BYTES)))
The alignment must be a power of two.
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.
A compound type analagous to a C struct.
gccjit::struct_ is a subclass of gccjit::type (and thus of gccjit::object in turn).
A field within a gccjit::struct_.
gccjit::field is a subclass of gccjit::object.
You can model C struct types by creating gccjit::struct_ and gccjit::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:
gccjit::field field_x = ctxt.new_field (double_type, "x");
gccjit::field field_y = ctxt.new_field (double_type, "y");
std::vector fields;
fields.push_back (field_x);
fields.push_back (field_y);
gccjit::struct_ coord = ctxt.new_struct_type ("coord", 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:
gccjit::struct_ node = ctxt.new_opaque_struct_type ("node");
gccjit::type node_ptr = node.get_pointer ();
gccjit::field field_hash = ctxt.new_field (int_type, "m_hash");
gccjit::field field_next = ctxt.new_field (node_ptr, "m_next");
std::vector fields;
fields.push_back (field_hash);
fields.push_back (field_next);
node.set_fields (fields);
Construct a new struct type, with the given name and fields.