2.5.2 Functions

C Type: gcc_jit_function

A gcc_jit_function represents a function - either one that we’re creating ourselves, or one that we’re referencing.

C Function: gcc_jit_function * gcc_jit_context_new_function (gcc_jit_context *ctxt, gcc_jit_location *loc, enum gcc_jit_function_kind kind, gcc_jit_type *return_type, const char *name, int num_params, gcc_jit_param **params, int is_variadic)

Create a gcc_jit_function with the given name and parameters.

C Type: enum gcc_jit_function_kind

This enum controls the kind of function created, and has the following values:

C Macro: GCC_JIT_FUNCTION_EXPORTED

Function is defined by the client code and visible by name outside of the JIT.

This value is required if you want to extract machine code for this function from a gcc_jit_result via gcc_jit_result_get_code().

C Macro: GCC_JIT_FUNCTION_INTERNAL

Function is defined by the client code, but is invisible outside of the JIT. Analogous to a “static” function.

C Macro: GCC_JIT_FUNCTION_IMPORTED

Function is not defined by the client code; we’re merely referring to it. Analogous to using an “extern” function from a header file.

C Macro: GCC_JIT_FUNCTION_ALWAYS_INLINE

Function is only ever inlined into other functions, and is invisible outside of the JIT.

Analogous to prefixing with inline and adding __attribute__((always_inline))

Inlining will only occur when the optimization level is above 0; when optimization is off, this is essentially the same as GCC_JIT_FUNCTION_INTERNAL.

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.

C Function: gcc_jit_function * gcc_jit_context_get_builtin_function (gcc_jit_context *ctxt, const char *name)

Get the gcc_jit_function for the built-in function with the given name. For example:

gcc_jit_function *fn
  = gcc_jit_context_get_builtin_function (ctxt, "__builtin_memcpy");

Note: Due to technical limitations with how libgccjit interacts with the insides of GCC, not all built-in functions are supported. More precisely, not all types are supported for parameters of built-in functions from libgccjit. Attempts to get a built-in function that uses such a parameter will lead to an error being emitted within the context.

C Function: gcc_jit_object * gcc_jit_function_as_object (gcc_jit_function *func)

Upcasting from function to object.

C Function: gcc_jit_param * gcc_jit_function_get_param (gcc_jit_function *func, int index)

Get the param of the given index (0-based).

C Function: void gcc_jit_function_dump_to_dot (gcc_jit_function *func, const char *path)

Emit the function in graphviz format to the given path.

C Function: gcc_jit_lvalue * gcc_jit_function_new_local (gcc_jit_function *func, gcc_jit_location *loc, gcc_jit_type *type, const char *name)

Create a new local variable within the function, of the given type and name.

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.

C Function: size_t gcc_jit_function_get_param_count (gcc_jit_function *func)

Get the number of parameters of the function.

C Function: gcc_jit_type * gcc_jit_function_get_return_type (gcc_jit_function *func)

Get the return type of the function.

The API entrypoints relating to getting info about parameters and return types:

were added in LIBGCCJIT_ABI_16; you can test for their presence using

#ifdef LIBGCCJIT_HAVE_REFLECTION
C Type: gcc_jit_case