Alien-LibJIT

 view release on metacpan or  search on metacpan

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

{
	unsigned int index = passing->index;
	jit_value_t value;
	while(index < passing->max_regs && passing->word_regs[index] != -1)
	{
		if(passing->word_values[index] != 0)
		{
			/* We've already done this before */
			return 1;
		}
		value = jit_value_create(func, jit_type_void_ptr);
		if(!value)
		{
			return 0;
		}
		if(!jit_insn_incoming_reg(func, value, passing->word_regs[index]))
		{
			return 0;
		}
		passing->word_values[index] = value;
		++index;
	}
	return 1;
}

int _jit_create_entry_insns(jit_function_t func)
{
	jit_type_t signature = func->signature;
	jit_type_t type;
	jit_value_t value;
	jit_value_t temp;
	jit_value_t addr_of;
	unsigned int num_params;
	unsigned int param;
	unsigned int size;
	jit_param_passing_t passing;
	jit_nint partial_offset;

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

	/* Initialize the parameter passing information block */
	passing.offset = JIT_INITIAL_STACK_OFFSET;
	passing.index = 0;
#ifdef JIT_FASTCALL_WORD_REG_PARAMS
	if(jit_type_get_abi(signature) == jit_abi_fastcall)
	{
		passing.word_regs = fastcall_word_regs;
	}
	else
#endif
	{
		passing.word_regs = cdecl_word_regs;
	}
	for(size = 0; size < JIT_MAX_WORD_REG_PARAMS; ++size)
	{
		passing.word_values[size] = 0;
	}

	/* If the function is nested, then we need an extra parameter
	   to pass the pointer to the parent's local variable frame */
	if(func->nested_parent)
	{
		value = jit_value_create(func, jit_type_void_ptr);
		if(!value)
		{
			return 0;
		}
		func->builder->parent_frame = value;
		if(!alloc_incoming_word(func, &passing, value, 0))
		{
			return 0;
		}
	}

	/* Allocate the structure return pointer */
	value = jit_value_get_struct_pointer(func);
	if(value)
	{
		if(!alloc_incoming_word(func, &passing, value, 0))
		{
			return 0;
		}
	}

	/* Determine the maximum number of registers that may be needed
	   to pass the function's parameters */
	num_params = jit_type_num_params(signature);
	passing.max_regs = passing.index;
	for(param = 0; param < num_params; ++param)
	{
		value = jit_value_get_param(func, param);
		if(value)
		{
			size = STACK_WORDS(jit_type_get_size(jit_value_get_type(value)));
			passing.max_regs += size;
		}
	}

	/* Allocate the parameter offsets */
	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(!alloc_incoming_word
					(func, &passing, value, _jit_nint_lowest_byte()))
				{
					return 0;
				}
			}
			break;

			case JIT_TYPE_SHORT:
			case JIT_TYPE_USHORT:
			{
				if(!alloc_incoming_word
					(func, &passing, value, _jit_nint_lowest_short()))
				{
					return 0;
				}



( run in 0.464 second using v1.01-cache-2.11-cpan-3d66aa2751a )