Пример #1
0
/*
 * Flush the current encode buffer.
 */
static int
flush_encoder(jit_varint_encoder_t *encoder)
{
	jit_varint_data_t data;

	/* Allocate a new jit_varint_data structure to hold the data */
	data = jit_malloc(sizeof(struct jit_varint_data) + encoder->len);
	if(!data)
	{
		return 0;
	}

	/* Copy the temporary debug data into the new structure */
	jit_memcpy(data->data, encoder->buf, encoder->len);

	/* Link the structure into the debug list */
	data->next = 0;
	if(encoder->last)
	{
		encoder->last->next = data;
	}
	else
	{
		encoder->data = data;
	}
	encoder->last = data;

	/* Reset the temporary debug buffer */
	encoder->len = 0;
	return 1;
}
Пример #2
0
void loop_start(jit_function_t function, bf_loop_t *loop) {
    bf_loop_t newloop = (bf_loop_t)jit_malloc(sizeof(struct bf_loop));
    newloop->start = jit_label_undefined;
    newloop->stop = jit_label_undefined;
    newloop->parent = *loop;
    jit_insn_label(function, &newloop->start);
    *loop = newloop;
}
Пример #3
0
/*@
 * @deftypefun jit_value_t jit_value_create_nfloat_constant (jit_function_t @var{func}, jit_type_t @var{type}, jit_nfloat @var{const_value})
 * Create a new native floating-point constant in the specified
 * function.  Returns NULL if out of memory.
 * @end deftypefun
@*/
jit_value_t
jit_value_create_nfloat_constant(jit_function_t func, jit_type_t type, jit_nfloat const_value)
{
	jit_value_t value = alloc_value(func, type);
	if(!value)
	{
		return 0;
	}
	value->is_constant = 1;
	value->address = (jit_nint) jit_malloc(sizeof(jit_nfloat));
	if(!value->address)
	{
		return 0;
	}
	*((jit_nfloat *) value->address) = const_value;
	value->free_address = 1;
	return value;
}
Пример #4
0
/*@
 * @deftypefun jit_value_t jit_value_create_long_constant (jit_function_t @var{func}, jit_type_t @var{type}, jit_long @var{const_value})
 * Create a new 64-bit integer constant in the specified
 * function.  This can also be used to create constants of
 * type @code{jit_type_ulong}.  Returns NULL if out of memory.
 * @end deftypefun
@*/
jit_value_t
jit_value_create_long_constant(jit_function_t func, jit_type_t type, jit_long const_value)
{
	jit_value_t value = alloc_value(func, type);
	if(!value)
	{
		return 0;
	}
	value->is_constant = 1;
#ifdef JIT_NATIVE_INT64
	value->is_nint_constant = 1;
	value->address = (jit_nint) const_value;
#else
	value->address = (jit_nint) jit_malloc(sizeof(jit_long));
	if(!value->address)
	{
		return 0;
	}
	*((jit_long *) value->address) = const_value;
	value->free_address = 1;
#endif
	return value;
}
Пример #5
0
/*
 * Get or add a section.
 */
static jit_section_t get_section
	(jit_writeelf_t writeelf, const char *name, jit_int type,
	 Elf_Word flags, Elf_Word entry_size, Elf_Word alignment)
{
	int index;
	jit_section_t section;

	/* Search the section table for an existing section by this name */
	for(index = 0; index < writeelf->num_sections; ++index)
	{
		section = &(writeelf->sections[index]);
		if(!jit_strcmp(get_string(writeelf, section->shdr.sh_name), name))
		{
			return section;
		}
	}

	/* Create a new section and clear it */
	section = (jit_section_t)jit_realloc
		(writeelf->sections,
		 (writeelf->num_sections + 1) * sizeof(struct jit_section));
	if(!section)
	{
		return 0;
	}
	writeelf->sections = section;
	section += writeelf->num_sections;
	jit_memzero(section, sizeof(struct jit_section));

	/* Set the section's name.  If this is the first section created,
	   then it is the string table itself, and we have to add the
	   name to the section itself to start the ball rolling */
	if(writeelf->regular_string_section < 0)
	{
		section->data = (char *)jit_malloc(jit_strlen(name) + 2);
		if(!(section->data))
		{
			return 0;
		}
		section->data_len = jit_strlen(name) + 2;
		section->data[0] = '\0';	/* Empty string is always first */
		jit_strcpy(section->data + 1, name);
		section->shdr.sh_name = 1;
		writeelf->regular_string_section = writeelf->num_sections;
	}
	else
	{
		section->shdr.sh_name = add_string(writeelf, name);
		if(!(section->shdr.sh_name))
		{
			return 0;
		}
	}

	/* Set the other section properties */
	section->shdr.sh_type = (Elf_Word)type;
	section->shdr.sh_flags = flags;
	section->shdr.sh_entsize = entry_size;
	section->shdr.sh_addralign = alignment;

	/* Increase the section count and return */
	++(writeelf->num_sections);
	return section;
}