Ejemplo n.º 1
0
/*@
 * @deftypefun int _jit_create_entry_insns (jit_function_t @var{func})
 * Create instructions in the entry block to initialize the
 * registers and frame offsets that contain the parameters.
 * Returns zero if out of memory.
 *
 * This function is called when a builder is initialized.  It should
 * scan the signature and decide which register or frame position
 * contains each of the parameters and then call either
 * @code{jit_insn_incoming_reg} or @code{jit_insn_incoming_frame_posn}
 * to notify @code{libjit} of the location.
 * @end deftypefun
@*/
int _jit_create_entry_insns(jit_function_t func)
{
	jit_type_t signature = func->signature;
	jit_type_t type;
	jit_nint offset;
	jit_value_t value;
	unsigned int num_params;
	unsigned int param;

	/* Reset the frame size for this function */
	func->builder->frame_size = 0;

	/* The starting parameter offset.  We use negative offsets to indicate
	   an offset into the "args" block, and positive offsets to indicate
	   an offset into the "frame" block.  The negative values will be
	   flipped when we output the argument opcodes for interpretation */
	offset = -1;

	/* If the function is nested, then we need two extra parameters
	   to pass the pointer to the parent's local variables and arguments */
	if(func->nested_parent)
	{
		offset -= 2;
	}

	/* Allocate the structure return pointer */
	value = jit_value_get_struct_pointer(func);
	if(value)
	{
		if(!jit_insn_incoming_frame_posn(func, value, offset))
		{
			return 0;
		}
		--offset;
	}

	/* Allocate the parameter offsets */
	num_params = jit_type_num_params(signature);
	for(param = 0; param < num_params; ++param)
	{
		value = jit_value_get_param(func, param);
		if(!value)
		{
			continue;
		}

		type = jit_type_remove_tags(jit_value_get_type(value));
		switch(type->kind)
		{
		case JIT_TYPE_SBYTE:
		case JIT_TYPE_UBYTE:
			if(!jit_insn_incoming_frame_posn(func, value,
							 offset - _jit_int_lowest_byte()))
			{
				return 0;
			}
			--offset;
			break;

		case JIT_TYPE_SHORT:
		case JIT_TYPE_USHORT:
			if(!jit_insn_incoming_frame_posn(func, value,
							 offset - _jit_int_lowest_short()))
			{
				return 0;
			}
			--offset;
			break;

		case JIT_TYPE_INT:
		case JIT_TYPE_UINT:
		case JIT_TYPE_NINT:
		case JIT_TYPE_NUINT:
		case JIT_TYPE_SIGNATURE:
		case JIT_TYPE_PTR:
		case JIT_TYPE_LONG:
		case JIT_TYPE_ULONG:
		case JIT_TYPE_FLOAT32:
		case JIT_TYPE_FLOAT64:
		case JIT_TYPE_NFLOAT:
			if(!jit_insn_incoming_frame_posn(func, value, offset))
			{
				return 0;
			}
			--offset;
			break;

		case JIT_TYPE_STRUCT:
		case JIT_TYPE_UNION:
			if(!jit_insn_incoming_frame_posn(func, value, offset))
			{
				return 0;
			}
			offset -= JIT_NUM_ITEMS_IN_STRUCT(jit_type_get_size(type));
			break;
		}
	}
	return 1;
}
Ejemplo n.º 2
0
/*@
 * @deftypemethod 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.
 * @end deftypemethod
@*/
jit_value jit_function::get_struct_pointer()
{
	value_wrap(jit_value_get_struct_pointer(func));
}