Alien-LibJIT

 view release on metacpan or  search on metacpan

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

	}

	/* The last block is excluded from the blocks to move */
	block = last->prev;

	/* Update the init block pointer */
	func->builder->init_block = block;

	/* Move the blocks after the original init block */
	if(init->next != first)
	{
		_jit_block_detach(first, block);
		_jit_block_attach_after(init, first, block);
	}

	/* Done */
	return 1;
}

/*@
 * @deftypefun int jit_insn_mark_offset (jit_function_t @var{func}, jit_int @var{offset})
 * Mark the current position in @var{func} as corresponding to the
 * specified bytecode @var{offset}.  This value will be returned
 * by @code{jit_stack_trace_get_offset}, and is useful for associating
 * code positions with source line numbers.
 * @end deftypefun
@*/
int jit_insn_mark_offset(jit_function_t func, jit_int offset)
{
	jit_block_t block;
	jit_insn_t last;
	jit_value_t value;

	/* Ensure that we have a builder for this function */
	if(!_jit_function_ensure_builder(func))
	{
		return 0;
	}

	value = jit_value_create_nint_constant(func, jit_type_int, offset);
	if (!value)
	{
		return 0;
	}

	/* If the previous instruction is mark offset too
	   then just replace the offset value in place --
	   we are not interested in bytecodes that produce
	   no real code. */
	block = func->builder->current_block;
	last = _jit_block_get_last(block);
	if (last && last->opcode == JIT_OP_MARK_OFFSET)
	{
		last->value1 = value;
		return 1;
	}

	return create_unary_note(func, JIT_OP_MARK_OFFSET, value);
}

/* Documentation is in jit-debugger.c */
int jit_insn_mark_breakpoint_variable
	(jit_function_t func, jit_value_t data1, jit_value_t data2)
{
#if defined(JIT_BACKEND_INTERP)
	/* Use the "mark_breakpoint" instruction for the interpreter */
	if(!jit_insn_new_block(func))
	{
		return 0;
	}
	return create_note(func, JIT_OP_MARK_BREAKPOINT, data1, data2);
#else
	/* Insert a call to "_jit_debugger_hook" on native platforms */
	jit_type_t params[3];
	jit_type_t signature;
	jit_value_t values[3];
	params[0] = jit_type_void_ptr;
	params[1] = jit_type_nint;
	params[2] = jit_type_nint;
	signature = jit_type_create_signature
		(jit_abi_cdecl, jit_type_void, params, 3, 0);
	if(!signature)
	{
		return 0;
	}
	if((values[0] = jit_value_create_nint_constant
			(func, jit_type_void_ptr, (jit_nint)func)) == 0)
	{
		jit_type_free(signature);
		return 0;
	}
	values[1] = data1;
	values[2] = data2;
	jit_insn_call_native(func, "_jit_debugger_hook", (void *)_jit_debugger_hook,
						 signature, values, 3, JIT_CALL_NOTHROW);
	jit_type_free(signature);
	return 1;
#endif
}

/* Documentation is in jit-debugger.c */
int jit_insn_mark_breakpoint
	(jit_function_t func, jit_nint data1, jit_nint data2)
{
	jit_value_t value1;
	jit_value_t value2;

	value1 = jit_value_create_nint_constant(func, jit_type_nint, data1);
	value2 = jit_value_create_nint_constant(func, jit_type_nint, data2);

	if(value1 && value2)
	{
		return jit_insn_mark_breakpoint_variable(func, value1, value2);
	}
	else
	{
		return 0;
	}
}

/*@
 * @deftypefun void jit_insn_iter_init (jit_insn_iter_t *@var{iter}, jit_block_t @var{block})
 * Initialize an iterator to point to the first instruction in @var{block}.
 * @end deftypefun
@*/
void
jit_insn_iter_init(jit_insn_iter_t *iter, jit_block_t block)
{
	iter->block = block;
	iter->posn = 0;
}

/*@
 * @deftypefun void jit_insn_iter_init_last (jit_insn_iter_t *@var{iter}, jit_block_t @var{block})
 * Initialize an iterator to point to the last instruction in @var{block}.
 * @end deftypefun
@*/
void
jit_insn_iter_init_last(jit_insn_iter_t *iter, jit_block_t block)
{
	iter->block = block;
	iter->posn = block->num_insns;
}

/*@
 * @deftypefun jit_insn_t jit_insn_iter_next (jit_insn_iter_t *@var{iter})
 * Get the next instruction in an iterator's block.  Returns NULL
 * when there are no further instructions in the block.
 * @end deftypefun
@*/
jit_insn_t
jit_insn_iter_next(jit_insn_iter_t *iter)
{
	if(iter->posn < iter->block->num_insns)
	{
		return &iter->block->insns[(iter->posn)++];
	}
	else
	{
		return 0;
	}



( run in 0.961 second using v1.01-cache-2.11-cpan-02777c243ea )