Alien-LibJIT
view release on metacpan or search on metacpan
libjit/jitplus/jit-plus-function.cpp view on Meta::CPAN
* list is terminated with the special value @code{jit_function::end_params}.
*
* A maximum of 32 parameter types can be supplied, and the signature
* ABI is always set to @code{jit_abi_cdecl}.
* @end deftypemethod
@*/
jit_type_t jit_function::signature_helper(jit_type_t return_type, ...)
{
va_list va;
jit_type_t params[32];
unsigned int num_params = 0;
jit_type_t type;
#ifdef HAVE_STDARG_H
va_start(va, return_type);
#else
va_start(va);
#endif
while(num_params < 32 && (type = va_arg(va, jit_type_t)) != 0)
{
params[num_params++] = type;
}
va_end(va);
return jit_type_create_signature
(jit_abi_cdecl, return_type, params, num_params, 1);
}
/*@
* @deftypemethod jit_function void build ()
* This method is called when the function has to be build on-demand,
* or in response to an explicit @code{recompile} request. You build the
* function by calling the value-related and instruction-related
* methods within @code{jit_function} that are described below.
*
* The default implementation of @code{build} will fail, so you must
* override it if you didn't build the function manually and call
* @code{compile}.
* @end deftypemethod
@*/
void jit_function::build()
{
// Normally overridden by subclasses.
fail();
}
/*@
* @deftypemethod jit_function jit_type_t create_signature ()
* This method is called by @code{create()} to create the function's
* signature. The default implementation creates a signature that
* returns @code{void} and has no parameters.
* @end deftypemethod
@*/
jit_type_t jit_function::create_signature()
{
// Normally overridden by subclasses.
return signature_helper(jit_type_void, end_params);
}
/*@
* @deftypemethod jit_function void fail ()
* This method can be called by @code{build} to fail the on-demand
* compilation process. It throws an exception to unwind the build.
* @end deftypemethod
@*/
void jit_function::fail()
{
throw jit_build_exception(JIT_RESULT_COMPILE_ERROR);
}
/*@
* @deftypemethod jit_function void out_of_memory ()
* This method can be called by @code{build} to indicate that the on-demand
* compilation process ran out of memory. It throws an exception to
* unwind the build.
* @end deftypemethod
@*/
void jit_function::out_of_memory()
{
throw jit_build_exception(JIT_RESULT_OUT_OF_MEMORY);
}
/*@
* @deftypemethod jit_function void build_start ()
* Start an explicit build process. Not needed if you will be using
* on-demand compilation.
* @end deftypemethod
*
* @deftypemethod jit_function void build_end ()
* End an explicit build process.
* @end deftypemethod
@*/
#define value_wrap(x) \
jit_value val((x)); \
if(!(val.raw())) \
out_of_memory(); \
return val
/*@
* @deftypemethod jit_function jit_value new_value (jit_type_t @var{type})
* Create a new temporary value. This is the C++ counterpart to
* @code{jit_value_create}.
* @end deftypemethod
@*/
jit_value jit_function::new_value(jit_type_t type)
{
value_wrap(jit_value_create(func, type));
}
/*@
* @deftypemethod jit_function jit_value new_constant (jit_sbyte @var{value}, jit_type_t @var{type})
* @deftypemethodx jit_function jit_value new_constant (jit_ubyte @var{value}, jit_type_t @var{type})
* @deftypemethodx jit_function jit_value new_constant (jit_short @var{value}, jit_type_t @var{type})
* @deftypemethodx jit_function jit_value new_constant (jit_ushort @var{value}, jit_type_t @var{type})
* @deftypemethodx jit_function jit_value new_constant (jit_int @var{value}, jit_type_t @var{type})
* @deftypemethodx jit_function jit_value new_constant (jit_uint @var{value}, jit_type_t @var{type})
* @deftypemethodx jit_function jit_value new_constant (jit_long @var{value}, jit_type_t @var{type})
* @deftypemethodx jit_function jit_value new_constant (jit_ulong @var{value}, jit_type_t @var{type})
* @deftypemethodx jit_function jit_value new_constant (jit_float32 @var{value}, jit_type_t @var{type})
* @deftypemethodx jit_function jit_value new_constant (jit_float64 @var{value}, jit_type_t @var{type})
* @deftypemethodx jit_function jit_value new_constant (jit_nfloat @var{value}, jit_type_t @var{type})
* @deftypemethodx jit_function jit_value new_constant (void* @var{value}, jit_type_t @var{type})
* @deftypemethodx jit_function jit_value new_constant (const jit_constant_t& @var{value})
* Create constant values of various kinds. @xref{Values}, for more
* information on creating and managing constants.
* @end deftypemethod
@*/
jit_value jit_function::new_constant(jit_sbyte value, jit_type_t type)
{
if(!type)
{
type = jit_type_sbyte;
}
value_wrap(jit_value_create_nint_constant(func, type, (jit_nint)value));
}
jit_value jit_function::new_constant(jit_ubyte value, jit_type_t type)
{
if(!type)
{
type = jit_type_ubyte;
}
value_wrap(jit_value_create_nint_constant(func, type, (jit_nint)value));
}
jit_value jit_function::new_constant(jit_short value, jit_type_t type)
{
if(!type)
{
( run in 0.397 second using v1.01-cache-2.11-cpan-5a3173703d6 )