Alien-LibJIT

 view release on metacpan or  search on metacpan

libjit/jit/jit-compile.c  view on Meta::CPAN

			goto restart;
		}

		/* Release allocated code space and exit */
		memory_abort(state);
		goto exit;
	}

	if(state->restart == 0)
	{
		/* Start compilation */

		/* Perform machine-independent optimizations */
		optimize(state->func);

		/* Prepare data needed for code generation */
		codegen_prepare(state);

		/* Allocate some space */
		memory_acquire(state);
		memory_alloc(state);
	}
	else
	{
		/* Restart compilation */

		/* Clean up the compilation state */
		cleanup_on_restart(&state->gen, state->func);

		/* Allocate more space */
		memory_realloc(state);
	}

#ifdef _JIT_COMPILE_DEBUG
	if(state->restart == 0)
	{
		printf("\n*** Start code generation ***\n\n");
	}
	else
	{
		printf("\n*** Restart code generation ***\n\n");
	}
	state->func->builder->block_count = 0;
	state->func->builder->insn_count = 0;
#endif

#ifdef jit_extra_gen_init
	/* Initialize information that may need to be reset both
	   on start and restart */
	jit_extra_gen_init(&state->gen);
#endif

	/* Perform code generation */
	codegen(state);

#ifdef jit_extra_gen_cleanup
	/* Clean up the extra code generation state */
	jit_extra_gen_cleanup(&state->gen);
#endif

	/* End the function's output process */
	memory_flush(state);

	/* Compilation done, no exceptions occurred */
	result = JIT_RESULT_OK;

 exit:
	/* Release the memory context */
	memory_release(state);

	/* Restore the "setjmp" context */
	_jit_unwind_pop_setjmp();

	/* Restore user's exception handler */
	jit_exception_set_handler(handler);

	return result;
}

/*@
 * @deftypefun int jit_compile (jit_function_t @var{func})
 * Compile a function to its executable form.  If the function was
 * already compiled, then do nothing.  Returns zero on error.
 *
 * If an error occurs, you can use @code{jit_function_abandon} to
 * completely destroy the function.  Once the function has been compiled
 * successfully, it can no longer be abandoned.
 *
 * Sometimes you may wish to recompile a function, to apply greater
 * levels of optimization the second time around.  You must call
 * @code{jit_function_set_recompilable} before you compile the function
 * the first time.  On the second time around, build the function's
 * instructions again, and call @code{jit_compile} a second time.
 * @end deftypefun
@*/
int
jit_compile(jit_function_t func)
{
	_jit_compile_t state;
	int result;

	/* Bail out on invalid parameter */
	if(!func)
	{
		return JIT_RESULT_NULL_FUNCTION;
	}

	/* Bail out if there is nothing to do here */
	if(!func->builder)
	{
		if(func->is_compiled)
		{
			/* The function is already compiled, and we don't need to recompile */
			return JIT_RESULT_OK;
		}
		else
		{
			/* We don't have anything to compile at all */
			return JIT_RESULT_NULL_FUNCTION;
		}
	}



( run in 0.472 second using v1.01-cache-2.11-cpan-5b529ec07f3 )