Alien-LibJIT
view release on metacpan or search on metacpan
libjit/jit/jit-compile.c view on Meta::CPAN
# include <stdio.h>
#endif
/*
* Misc data needed for compilation
*/
typedef struct
{
jit_function_t func;
int memory_locked;
int memory_started;
int restart;
int page_factor;
struct jit_gencode gen;
} _jit_compile_t;
#define _JIT_RESULT_TO_OBJECT(x) ((void *) ((jit_nint) (x) - JIT_RESULT_OK))
libjit/jit/jit-compile.c view on Meta::CPAN
static void
memory_acquire(_jit_compile_t *state)
{
/* Store the function's context as codegen context */
state->gen.context = state->func->context;
/* Acquire the memory context lock */
_jit_memory_lock(state->gen.context);
/* Remember that the lock is acquired */
state->memory_locked = 1;
if(!_jit_memory_ensure(state->gen.context))
{
jit_exception_builtin(JIT_RESULT_OUT_OF_MEMORY);
}
}
/*
* Release the memory context.
*/
static void
memory_release(_jit_compile_t *state)
{
/* Release the lock if it was previously acquired */
if(state->memory_locked)
{
_jit_memory_unlock(state->gen.context);
state->memory_locked = 0;
}
}
/*
* Align the method code on a particular boundary if the
* difference between the current position and the aligned
* boundary is less than "diff". The "nop" value is used
* to pad unused bytes.
*/
static void
libjit/jit/jit-context.c view on Meta::CPAN
/*@
* @deftypefun void jit_context_set_on_demand_driver (jit_context_t @var{context}, jit_on_demand_driver_func @var{driver})
* Specify the C function to be called to drive on-demand compilation.
*
* When on-demand compilation is requested the default driver provided by
* @code{libjit} takes the following actions:
*
* @enumerate
* @item
* The context is locked by calling @code{jit_context_build_start}.
*
* @item
* If the function has already been compiled, @code{libjit} unlocks
* the context and returns immediately. This can happen because of race
* conditions between threads: some other thread may have beaten us
* to the on-demand compiler.
*
* @item
* The user's on-demand compiler is called. It is responsible for building
* the instructions in the function's body. It should return one of the
* result codes @code{JIT_RESULT_OK}, @code{JIT_RESULT_COMPILE_ERROR},
* or @code{JIT_RESULT_OUT_OF_MEMORY}.
*
* @item
* If the user's on-demand function hasn't already done so, @code{libjit}
* will call @code{jit_function_compile} to compile the function.
*
* @item
* The context is unlocked by calling @code{jit_context_build_end} and
* @code{libjit} jumps to the newly-compiled entry point. If an error
* occurs, a built-in exception of type @code{JIT_RESULT_COMPILE_ERROR}
* or @code{JIT_RESULT_OUT_OF_MEMORY} will be thrown.
*
* @item
* The entry point of the compiled function is returned from the driver.
* @end enumerate
*
* You may need to provide your own driver if some additional actions
* are required.
libjit/jit/jit-function.c view on Meta::CPAN
*
* You won't need an on-demand compiler if you always build and compile
* your functions before you call them. But if you can call a function
* before it is built, then you must supply an on-demand compiler.
*
* When on-demand compilation is requested, @code{libjit} takes the following
* actions:
*
* @enumerate
* @item
* The context is locked by calling @code{jit_context_build_start}.
*
* @item
* If the function has already been compiled, @code{libjit} unlocks
* the context and returns immediately. This can happen because of race
* conditions between threads: some other thread may have beaten us
* to the on-demand compiler.
*
* @item
* The user's on-demand compiler is called. It is responsible for building
* the instructions in the function's body. It should return one of the
* result codes @code{JIT_RESULT_OK}, @code{JIT_RESULT_COMPILE_ERROR},
* or @code{JIT_RESULT_OUT_OF_MEMORY}.
*
* @item
* If the user's on-demand function hasn't already done so, @code{libjit}
* will call @code{jit_function_compile} to compile the function.
*
* @item
* The context is unlocked by calling @code{jit_context_build_end} and
* @code{libjit} jumps to the newly-compiled entry point. If an error
* occurs, a built-in exception of type @code{JIT_RESULT_COMPILE_ERROR}
* or @code{JIT_RESULT_OUT_OF_MEMORY} will be thrown.
* @end enumerate
*
* Normally you will need some kind of context information to tell you
* which higher-level construct is being compiled. You can use the
* metadata facility to add this context information to the function
* just after you create it with @code{jit_function_create}.
* @end deftypefun
libjit/jit/jit-insn.c view on Meta::CPAN
insn->opcode = (short)_jit_store_opcode
(JIT_OP_COPY_INT, JIT_OP_COPY_STORE_BYTE, dest->type);
insn->dest = dest;
insn->value1 = value;
return 1;
}
/*
* Scan back through the current block, looking for an address instruction that
* involves "value" as its destination. Returns NULL if no such instruction was
* found, or it is blocked by a later use of "value".
*
* The instruction found may then be combined into a new single instruction with
* the following "load_relative", "store_relative", or another "relative_add".
*
* For instance, consider the code like this:
*
* i) y = address_of(x)
* ...
* j) z = add_relative(y, a)
*
libjit/jit/jit-thread.c view on Meta::CPAN
#endif /* No thread package */
void _jit_thread_init(void)
{
#if defined(JIT_THREADS_PTHREAD)
static pthread_once_t once_control = PTHREAD_ONCE_INIT;
pthread_once(&once_control, init_pthread);
#elif defined(JIT_THREADS_WIN32)
static LONG volatile once_control = 0;
if(!InterlockedExchange((PLONG)&once_control, 1))
{
init_win32_thread();
}
#endif
}
static void *get_raw_control(void)
{
_jit_thread_init();
#if defined(JIT_THREADS_PTHREAD)
libjit/tutorial/t3.c view on Meta::CPAN
/* Create the function object */
function = jit_function_create(context, signature);
jit_type_free(signature);
/* Make the function recompilable */
jit_function_set_recompilable(function);
/* Set the on-demand compiler for "mul_add" */
jit_function_set_on_demand_compiler(function, compile_mul_add);
/* Unlock the context. It will be automatically locked for
us when the on-demand compiler is called */
jit_context_build_end(context);
/* Execute the function and print the result. This will arrange
to call the on-demand compiler to build the function's body */
arg1 = 3;
arg2 = 5;
arg3 = 2;
args[0] = &arg1;
args[1] = &arg2;
( run in 0.570 second using v1.01-cache-2.11-cpan-49f99fa48dc )