[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

19. Functions in C++

The jit_function class provides a C++ counterpart to the C jit_function_t type. See section Building and compiling functions with the JIT, for more information on creating and managing functions.

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.

Constructor on jit_function: jit_function (jit_context& context, jit_type_t signature)

Constructs a new function handler with the specified signature in the given context. It then calls create(signature) to create the actual function.

Constructor on jit_function: jit_function (jit_context& context)

Constructs a new function handler in the specified context. The actual function is not created until you call create().

Constructor on jit_function: jit_function (jit_function_t func)

Constructs a new function handler and wraps it around the specified raw C jit_function_t object. This can be useful for layering the C++ on-demand building facility on top of an existing C function.

Destructor on jit_function: ~jit_function ()

Destroy this function handler. The raw function will persist until the context is destroyed.

Method on jit_function: jit_function_t raw () const

Get the raw C jit_function_t value that underlies this object.

Method on jit_function: int is_valid () const

Determine if the raw C jit_function_t value that underlies this object is valid.

Method on jit_function: static jit_function * from_raw (jit_function_t func)

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:

  1. Invoke the build_start method to lock down the function builder.
  2. Build the function by calling the value-related and instruction-related methods within jit_function.
  3. Compile the function with the compile method.
  4. Unlock the function builder by invoking build_end.
Method on jit_function: int is_compiled () const

Determine if this function has already been compiled.

Method on jit_function: void set_optimization_level (unsigned int level)
Method on jit_function: unsigned int optimization_level () const

Set or get the optimization level for this function.

Method on jit_function: static unsigned int max_optimization_level ()

Get the maximum optimization level for libjit.

Method on jit_function: void * closure () const
Method on jit_function: void * vtable_pointer () const

Get the closure or vtable pointer form of this function.

Method on jit_function: int apply (void** args, void* result)
Method on jit_function: int apply (jit_type_t signature, void** args, void* return_area)

Call this function, applying the specified arguments.

Method on jit_function: static jit_type_t signature_helper (jit_type_t return_type, ...)

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.

Method on jit_function: jit_value new_constant (jit_sbyte value, jit_type_t type)
Method on jit_function: jit_value new_constant (jit_ubyte value, jit_type_t type)
Method on jit_function: jit_value new_constant (jit_short value, jit_type_t type)
Method on jit_function: jit_value new_constant (jit_ushort value, jit_type_t type)
Method on jit_function: jit_value new_constant (jit_int value, jit_type_t type)
Method on jit_function: jit_value new_constant (jit_uint value, jit_type_t type)
Method on jit_function: jit_value new_constant (jit_long value, jit_type_t type)
Method on jit_function: jit_value new_constant (jit_ulong value, jit_type_t type)
Method on jit_function: jit_value new_constant (jit_float32 value, jit_type_t type)
Method on jit_function: jit_value new_constant (jit_float64 value, jit_type_t type)
Method on jit_function: jit_value new_constant (jit_nfloat value, jit_type_t type)
Method on jit_function: jit_value new_constant (void* value, jit_type_t type)
Method on jit_function: jit_value new_constant (const jit_constant_t& value)

Create constant values of various kinds. See section Working with temporary values in the JIT, for more information on creating and managing constants.

Method on jit_function: jit_value get_param (unsigned int param)

Get the value that corresponds to parameter param.

Method on jit_function: jit_value get_struct_pointer ()

Get the value that corresponds to the structure pointer parameter, if this function has one. Returns an empty value if it does not.

Method on jit_function: jit_label new_label ()

Create a new label. This is the C++ counterpart to jit_function_reserve_label.

Method on jit_function: void insn_label (jit_label& label)
Method on jit_function: void insn_new_block ()
Method on jit_function: jit_value insn_load (const jit_value& value)
Method on jit_function: jit_value insn_dup (const jit_value& value)
Method on jit_function: jit_value insn_load_small (const jit_value& value)
Method on jit_function: void store (const jit_value& dest, const jit_value& value)
Method on jit_function: jit_value insn_load_relative (const jit_value& value, jit_nint offset, jit_type_t type)
Method on jit_function: void insn_store_relative (const jit_value& dest, jit_nint offset, const jit_value& value)
Method on jit_function: jit_value insn_add_relative (const jit_value& value, jit_nint offset)
Method on jit_function: jit_value insn_load_elem (const jit_value& base_addr, const jit_value& index, jit_type_t elem_type)
Method on jit_function: jit_value insn_load_elem_address (const jit_value& base_addr, const jit_value& index, jit_type_t elem_type)
Method on jit_function: void insn_store_elem (const jit_value& base_addr, const jit_value& index, const jit_value& value)
Method on jit_function: void insn_check_null (const jit_value& value)
Method on jit_function: jit_value insn_add (const jit_value& value1, const jit_value& value2)
Method on jit_function: jit_value insn_add_ovf (const jit_value& value1, const jit_value& value2)
Method on jit_function: jit_value insn_sub (const jit_value& value1, const jit_value& value2)
Method on jit_function: jit_value insn_sub_ovf (const jit_value& value1, const jit_value& value2)
Method on jit_function: jit_value insn_mul (const jit_value& value1, const jit_value& value2)
Method on jit_function: jit_value insn_mul_ovf (const jit_value& value1, const jit_value& value2)
Method on jit_function: jit_value insn_div (const jit_value& value1, const jit_value& value2)
Method on jit_function: jit_value insn_rem (const jit_value& value1, const jit_value& value2)
Method on jit_function: jit_value insn_rem_ieee (const jit_value& value1, const jit_value& value2)
Method on jit_function: jit_value insn_neg (const jit_value& value1)
Method on jit_function: jit_value insn_and (const jit_value& value1, const jit_value& value2)
Method on jit_function: jit_value insn_or (const jit_value& value1, const jit_value& value2)
Method on jit_function: jit_value insn_xor (const jit_value& value1, const jit_value& value2)
Method on jit_function: jit_value insn_not (const jit_value& value1)
Method on jit_function: jit_value insn_shl (const jit_value& value1, const jit_value& value2)
Method on jit_function: jit_value insn_shr (const jit_value& value1, const jit_value& value2)
Method on jit_function: jit_value insn_ushr (const jit_value& value1, const jit_value& value2)
Method on jit_function: jit_value insn_sshr (const jit_value& value1, const jit_value& value2)
Method on jit_function: jit_value insn_eq (const jit_value& value1, const jit_value& value2)
Method on jit_function: jit_value insn_ne (const jit_value& value1, const jit_value& value2)
Method on jit_function: jit_value insn_lt (const jit_value& value1, const jit_value& value2)
Method on jit_function: jit_value insn_le (const jit_value& value1, const jit_value& value2)
Method on jit_function: jit_value insn_gt (const jit_value& value1, const jit_value& value2)
Method on jit_function: jit_value insn_ge (const jit_value& value1, const jit_value& value2)
Method on jit_function: jit_value insn_cmpl (const jit_value& value1, const jit_value& value2)
Method on jit_function: jit_value insn_cmpg (const jit_value& value1, const jit_value& value2)
Method on jit_function: jit_value insn_to_bool (const jit_value& value1)
Method on jit_function: jit_value insn_to_not_bool (const jit_value& value1)
Method on jit_function: jit_value insn_acos (const jit_value& value1)
Method on jit_function: jit_value insn_asin (const jit_value& value1)
Method on jit_function: jit_value insn_atan (const jit_value& value1)
Method on jit_function: jit_value insn_atan2 (const jit_value& value1, const jit_value& value2)
Method on jit_function: jit_value insn_ceil (const jit_value& value1)
Method on jit_function: jit_value insn_cos (const jit_value& value1)
Method on jit_function: jit_value insn_cosh (const jit_value& value1)
Method on jit_function: jit_value insn_exp (const jit_value& value1)
Method on jit_function: jit_value insn_floor (const jit_value& value1)
Method on jit_function: jit_value insn_log (const jit_value& value1)
Method on jit_function: jit_value insn_log10 (const jit_value& value1)
Method on jit_function: jit_value insn_pow (const jit_value& value1, const jit_value& value2)
Method on jit_function: jit_value insn_rint (const jit_value& value1)
Method on jit_function: jit_value insn_round (const jit_value& value1)
Method on jit_function: jit_value insn_sin (const jit_value& value1)
Method on jit_function: jit_value insn_sinh (const jit_value& value1)
Method on jit_function: jit_value insn_sqrt (const jit_value& value1)
Method on jit_function: jit_value insn_tan (const jit_value& value1)
Method on jit_function: jit_value insn_tanh (const jit_value& value1)
Method on jit_function: jit_value insn_is_nan (const jit_value& value1)
Method on jit_function: jit_value insn_is_finite (const jit_value& value1)
Method on jit_function: jit_value insn_is_inf (const jit_value& value1)
Method on jit_function: jit_value insn_abs (const jit_value& value1)
Method on jit_function: jit_value insn_min (const jit_value& value1, const jit_value& value2)
Method on jit_function: jit_value insn_max (const jit_value& value1, const jit_value& value2)
Method on jit_function: jit_value insn_sign (const jit_value& value1)
Method on jit_function: void insn_branch (jit_label& label)
Method on jit_function: void insn_branch_if (const jit_value& value, jit_label& label)
Method on jit_function: void insn_branch_if_not (const jit_value& value, jit_label& label)
Method on jit_function: jit_value insn_address_of (const jit_value& value1)
Method on jit_function: jit_value insn_address_of_label (jit_label& label)
Method on jit_function: jit_value insn_convert (const jit_value& value, jit_type_t type, int overflow_check)
Method on jit_function: jit_value insn_call (const char* name, jit_function_t jit_func, jit_type_t signature, jit_value_t* args, unsigned int num_args, int flags)
Method on jit_function: jit_value insn_call_indirect (const jit_value& value, jit_type_t signature, jit_value_t* args, unsigned int num_args, int flags)
Method on jit_function: jit_value insn_call_indirect_vtable (const jit_value& value, jit_type_t signature, jit_value_t * args, unsigned int num_args, int flags)
Method on jit_function: jit_value insn_call_native (const char* name, void* native_func, jit_type_t signature, jit_value_t* args, unsigned int num_args, int flags)
Method on jit_function: jit_value insn_call_intrinsic (const char* name, void* intrinsic_func, const jit_intrinsic_descr_t& descriptor, const jit_value& arg1, const jit_value& arg2)
Method on jit_function: void insn_incoming_reg (const jit_value& value, int reg)
Method on jit_function: void insn_incoming_frame_posn (const jit_value& value, jit_nint posn)
Method on jit_function: void insn_outgoing_reg (const jit_value& value, int reg)
Method on jit_function: void insn_outgoing_frame_posn (const jit_value& value, jit_nint posn)
Method on jit_function: void insn_return_reg (const jit_value& value, int reg)
Method on jit_function: void insn_setup_for_nested (int nested_level, int reg)
Method on jit_function: void insn_flush_struct (const jit_value& value)
Method on jit_function: jit_value insn_import (jit_value value)
Method on jit_function: void insn_push (const jit_value& value)
Method on jit_function: void insn_push_ptr (const jit_value& value, jit_type_t type)
Method on jit_function: void insn_set_param (const jit_value& value, jit_nint offset)
Method on jit_function: void insn_set_param_ptr (const jit_value& value, jit_type_t type, jit_nint offset)
Method on jit_function: void insn_push_return_area_ptr ()
Method on jit_function: void insn_return (const jit_value& value)
Method on jit_function: void insn_return ()
Method on jit_function: void insn_return_ptr (const jit_value& value, jit_type_t type)
Method on jit_function: void insn_default_return ()
Method on jit_function: void insn_throw (const jit_value& value)
Method on jit_function: jit_value insn_get_call_stack ()
Method on jit_function: jit_value insn_thrown_exception ()
Method on jit_function: void insn_uses_catcher ()
Method on jit_function: jit_value insn_start_catcher ()
Method on jit_function: void insn_branch_if_pc_not_in_range (const jit_label& start_label, const jit_label& end_label, jit_label& label)
Method on jit_function: void insn_rethrow_unhandled ()
Method on jit_function: void insn_start_finally (jit_label& label)
Method on jit_function: void insn_return_from_finally ()
Method on jit_function: void insn_call_finally (jit_label& label)
Method on jit_function: jit_value insn_start_filter (jit_label& label, jit_type_t type)
Method on jit_function: void insn_return_from_filter (const jit_value& value)
Method on jit_function: jit_value insn_call_filter (jit_label& label, const jit_value& value, jit_type_t type)
Method on jit_function: void insn_memcpy (const jit_value& dest, const jit_value& src, const jit_value& size)
Method on jit_function: void insn_memmove (const jit_value& dest, const jit_value& src, const jit_value& size)
Method on jit_function: void jit_insn_memset (const jit_value& dest, const jit_value& value, const jit_value& size)
Method on jit_function: jit_value jit_insn_alloca (const jit_value& size)
Method on jit_function: void insn_move_blocks_to_end (const jit_label& from_label, const jit_label& to_label)
Method on jit_function: void insn_move_blocks_to_start (const jit_label& from_label, const jit_label& to_label)
Method on jit_function: void insn_mark_offset (jit_int offset)
Method on jit_function: void insn_mark_breakpoint (jit_nint data1, jit_nint data2)

Create instructions of various kinds. See section Working with instructions in the JIT, for more information on the individual instructions and their arguments.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by Klaus Treichel on May, 11 2008 using texi2html 1.78.