19. Functions in C++

The jit_function class also provides a large number of methods
for creating the instructions within a function body. See section Working with instructions in the JIT,
for more information on creating and managing instructions.

Find the C++ jit_function object that is associated with a
raw C jit_function_t pointer. Returns NULL if there is
no such object.

Method on jit_function: jit_type_t signature () const

Get the signature type for this function.

Method on jit_function: void create (jit_type_t signature)

Create this function if it doesn't already exist.

Method on jit_function: void create ()

Create this function if it doesn't already exist. This version will
call the virtual create_signature() method to obtain the
signature from the subclass.

Method on jit_function: int compile ()

Compile this function explicity. You normally don't need to use this
method because the function will be compiled on-demand. If you do
choose to build the function manually, then the correct sequence of
operations is as follows:

Invoke the build_start method to lock down the function builder.

Build the function by calling the value-related and instruction-related
methods within jit_function.

You can call this method from create_signature() to help build the
correct signature for your function. The first parameter is the return
type, following by zero or more types for the parameters. The parameter
list is terminated with the special value jit_function::end_params.

A maximum of 32 parameter types can be supplied, and the signature
ABI is always set to jit_abi_cdecl.

Method on jit_function: void build ()

This method is called when the function has to be build on-demand,
or in response to an explicit recompile request. You build the
function by calling the value-related and instruction-related
methods within jit_function that are described below.

The default implementation of build will fail, so you must
override it if you didn't build the function manually and call
compile.

Method on jit_function: jit_type_t create_signature ()

This method is called by create() to create the function's
signature. The default implementation creates a signature that
returns void and has no parameters.

Method on jit_function: void fail ()

This method can be called by build to fail the on-demand
compilation process. It throws an exception to unwind the build.

Method on jit_function: void out_of_memory ()

This method can be called by build to indicate that the on-demand
compilation process ran out of memory. It throws an exception to
unwind the build.

Method on jit_function: void build_start ()

Start an explicit build process. Not needed if you will be using
on-demand compilation.

Method on jit_function: void build_end ()

End an explicit build process.

Method on jit_function: jit_value new_value (jit_type_t type)

Create a new temporary value. This is the C++ counterpart to
jit_value_create.