Add a new global variable of the given type and name to the context.
The parameter type
must be non-void.
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.
The “kind” parameter determines the visibility of the “global” outside of the gcc_jit_result:
Global is defined by the client code and is visible by name outside of this JIT context via gcc_jit_result_get_global() (and this value is required for the global to be accessible via that entrypoint).
Global is defined by the client code, but is invisible outside of it. Analogous to a “static” global within a .c file. Specifically, the variable will only be visible within this context and within child contexts.
Global is not defined by the client code; we’re merely referring to it. Analogous to using an “extern” global from a header file.
Set an initializer for global
using the memory content pointed
by blob
for num_bytes
. global
must be an array of an
integral type. Return the global itself.
The parameter blob
must be non-NULL. The call copies the memory
pointed by blob
for num_bytes
bytes, so it is valid to pass
in a pointer to an on-stack buffer. The content will be stored in
the compilation unit and used as initialization value of the array.
This entrypoint was added in LIBGCCJIT_ABI_14; you can test for its presence using
#ifdef LIBGCCJIT_HAVE_gcc_jit_global_set_initializer
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
GCC_JIT_GLOBAL_IMPORTED.
As a non-comprehensive example it is OK to do the equivalent of:
int foo = 3 * 2; /* rvalue from gcc_jit_context_new_binary_op. */ int arr[] = {1,2,3,4}; /* rvalue from gcc_jit_context_new_constructor. */ int *bar = &arr[2] + 1; /* rvalue from nested "get address" of "array access". */ const int baz = 3; /* rvalue from gcc_jit_context_rvalue_from_int. */ int boz = baz; /* rvalue from gcc_jit_lvalue_as_rvalue. */
Use together with gcc_jit_context_new_struct_constructor(), gcc_jit_context_new_union_constructor(), gcc_jit_context_new_array_constructor() to initialize structs, unions and arrays.
On success, returns the global
parameter unchanged. Otherwise, NULL
.
This entrypoint was added in LIBGCCJIT_ABI_19; you can test for its presence using:
#ifdef LIBGCCJIT_HAVE_CTORS