Example #1
0
File: eh.c Project: MatzeB/liboo
void eh_init(void)
{
	obstack_init(&lpads);
	ir_type *type_reference = new_type_primitive(mode_P);
	exception_object_entity = new_entity(get_tls_type(), new_id_from_str("__oo_rt_exception_object__"), type_reference);
	set_entity_initializer(exception_object_entity, get_initializer_null());

	ir_type *throw_type = new_type_method(1, 0);
	set_method_param_type(throw_type, 0, type_reference);
	throw_entity = new_entity(get_glob_type(), new_id_from_str("firm_personality"), throw_type);
	set_entity_visibility(throw_entity, ir_visibility_external);

	top = NULL;
}
Example #2
0
void gcji_create_array_type(void)
{
	ident *id = new_id_from_str("array");
	type_jarray = new_type_class(id);
	assert(type_java_lang_object != NULL);
	add_class_supertype(type_jarray, type_java_lang_object);
	add_compound_member(type_jarray, superobject_ident, type_java_lang_object);
	ident *length_id = new_id_from_str("length");
	gcj_array_length = add_compound_member(type_jarray, length_id, type_int);

	default_layout_compound_type(type_jarray);
	array_header_size      = get_type_size(type_jarray);
	array_header_end_align = get_type_alignment(type_int);
}
Example #3
0
int main(void)
{
	char buf[16];
	int  r;

	ir_init();

	r = ir_snprintf(buf, sizeof(buf), "hello");
	assert(streq(buf, "hello"));
	assert(r == 5);

	r = ir_snprintf(buf, sizeof(buf), "nums: %d %u!", 32, 46);
	assert(streq(buf, "nums: 32 46!"));
	assert(r == 12);

	ir_tarval *tv = new_tarval_from_long(123, mode_Iu);
	r = ir_snprintf(buf, sizeof(buf), "tv: %+F\n", tv);
	assert(streq(buf, "tv: 0x7B\n"));
	assert(r == 9);

	r = ir_snprintf(buf, sizeof(buf), "%d %d %d %d %d %d %d", 1234, 1234, 1234, 1234, 1234, 1234, 1234);
	assert(streq(buf, "1234 1234 1234 "));
	assert(r == 34);

	r = ir_snprintf(buf, 4, "%+F\n", tv);
	assert(streq(buf, "0x7"));
	assert(r == 5);

	r = ir_snprintf(buf, 8, "%I", new_id_from_str("Hello World"));
	assert(streq(buf, "Hello W"));
	assert(r == 11);

	return 0;
}
Example #4
0
void dmemory_init(void)
{
	ir_type *type_reference = new_type_primitive(mode_P);
	ir_type *type_int       = new_type_primitive(mode_Is);
	ir_type *type_size_t    = new_type_primitive(mode_Iu);

	ir_type *calloc_type    = new_type_method(2, 1);

	set_method_param_type(calloc_type, 0, type_size_t);
	set_method_param_type(calloc_type, 1, type_size_t);
	set_method_res_type(calloc_type, 0, type_reference);
	set_method_additional_properties(calloc_type, mtp_property_malloc);

	ir_type *glob           = get_glob_type();
	ident   *calloc_id      = new_id_from_str("calloc");
	calloc_entity = new_entity(glob, calloc_id, calloc_type);
	set_entity_visibility(calloc_entity, ir_visibility_external);

	ir_type *arraylength_type = new_type_method(1, 1);
	set_method_param_type(arraylength_type, 0, type_reference);
	set_method_res_type(arraylength_type, 0, type_int);
	set_method_additional_properties(arraylength_type, mtp_property_pure);

	default_arraylength_mode = mode_Is;

	dmemory_model.alloc_object    = dmemory_default_alloc_object;
	dmemory_model.alloc_array     = dmemory_default_alloc_array;
	dmemory_model.get_arraylength = dmemory_default_get_arraylength;
}
Example #5
0
static ir_type *create_field_desc_type(void)
{
	ir_type *type_offs_addr = new_type_union(new_id_from_str("offset/address"));
	add_compound_member(type_offs_addr, "boffset", type_int);
	add_compound_member(type_offs_addr, "addr", type_reference);
	default_layout_compound_type(type_offs_addr);

	ir_type *type = new_type_struct(new_id_from_str("field_desc"));
	add_compound_member(type, "name", type_reference);
	add_compound_member(type, "type", type_reference);
	add_compound_member(type, "accflags", type_ushort);
	add_compound_member(type, "bsize", type_ushort);
	add_compound_member(type, "boffset/address", type_offs_addr);
	default_layout_compound_type(type);
	return type;
}
Example #6
0
ir_entity *be_make_va_start_entity(ir_type *const frame_type, int const offset)
{
	ident     *const id       = new_id_from_str("$va_start");
	ir_type   *const unknown  = get_unknown_type();
	ir_entity *const va_start = new_entity(frame_type, id, unknown);
	set_entity_offset(va_start, offset);
	return va_start;
}
Example #7
0
static ir_node *get_memcpy_address(ir_graph *irg)
{
	ident     *id  = new_id_from_str("memcpy");
	ir_type   *mt  = get_memcpy_methodtype();
	ir_entity *ent = create_compilerlib_entity(id, mt);

	return new_r_Address(irg, ent);
}
Example #8
0
static ir_type *create_method_desc_type(void)
{
	ir_type *type = new_type_struct(new_id_from_str("method_desc"));
	add_compound_member(type, "name", type_reference);
	add_compound_member(type, "sig", type_reference);
	add_compound_member(type, "accflags", type_ushort);
	add_compound_member(type, "index", type_ushort);
	add_compound_member(type, "ncode", type_reference);
	add_compound_member(type, "throws", type_reference);
	default_layout_compound_type(type);
	return type;
}
Example #9
0
static ir_type *create_utf8_const_type(void)
{
	ir_type *type_byte           = get_type_for_mode(mode_Bu);
	ir_type *type_var_char_array = new_type_array(type_byte, 0);

	ident *id = new_id_from_str("utf8_const");
	ir_type *type = new_type_struct(id);
	add_compound_member(type, "hash", type_ushort);
	add_compound_member(type, "len", type_ushort);
	add_compound_member(type, "data", type_var_char_array);
	default_layout_compound_type(type);
	return type;
}
Example #10
0
static void arm_create_runtime_entities(void)
{
	if (divsi3 != NULL)
		return;

	ir_mode *mode_int = new_int_mode("arm_be_int", irma_twos_complement,
	                                 ARM_MACHINE_SIZE, true, ARM_MODULO_SHIFT);
	ir_mode *mode_uint = new_int_mode("arm_be_int", irma_twos_complement,
	                                  ARM_MACHINE_SIZE, false,
	                                  ARM_MODULO_SHIFT);

	ir_type *int_tp  = get_type_for_mode(mode_int);
	ir_type *uint_tp = get_type_for_mode(mode_uint);

	ir_type *const mtps = make_divmod_type(int_tp);
	divsi3 = create_compilerlib_entity(new_id_from_str("__divsi3"), mtps);
	modsi3 = create_compilerlib_entity(new_id_from_str("__modsi3"), mtps);

	ir_type *const mtpu = make_divmod_type(uint_tp);
	udivsi3 = create_compilerlib_entity(new_id_from_str("__udivsi3"), mtpu);
	umodsi3 = create_compilerlib_entity(new_id_from_str("__umodsi3"), mtpu);
}
Example #11
0
static void arm_create_runtime_entities(void)
{
	if (divsi3 != NULL)
		return;

	ir_mode *mode_int = new_int_mode("arm_be_int", irma_twos_complement,
	                                 ARM_MACHINE_SIZE, true, ARM_MODULO_SHIFT);
	ir_mode *mode_uint = new_int_mode("arm_be_int", irma_twos_complement,
	                                  ARM_MACHINE_SIZE, false,
	                                  ARM_MODULO_SHIFT);

	ir_type *int_tp  = get_type_for_mode(mode_int);
	ir_type *uint_tp = get_type_for_mode(mode_uint);

	ir_type *tp_divsi3 = new_type_method(2, 1);
	set_method_param_type(tp_divsi3, 0, int_tp);
	set_method_param_type(tp_divsi3, 1, int_tp);
	set_method_res_type(tp_divsi3, 0, int_tp);
	divsi3 = create_compilerlib_entity(new_id_from_str("__divsi3"), tp_divsi3);

	ir_type *tp_udivsi3 = new_type_method(2, 1);
	set_method_param_type(tp_udivsi3, 0, uint_tp);
	set_method_param_type(tp_udivsi3, 1, uint_tp);
	set_method_res_type(tp_udivsi3, 0, uint_tp);
	udivsi3 = create_compilerlib_entity(new_id_from_str("__udivsi3"), tp_udivsi3);

	ir_type *tp_modsi3 = new_type_method(2, 1);
	set_method_param_type(tp_modsi3, 0, int_tp);
	set_method_param_type(tp_modsi3, 1, int_tp);
	set_method_res_type(tp_modsi3, 0, int_tp);
	modsi3 = create_compilerlib_entity(new_id_from_str("__modsi3"), tp_modsi3);

	ir_type *tp_umodsi3 = new_type_method(2, 1);
	set_method_param_type(tp_umodsi3, 0, uint_tp);
	set_method_param_type(tp_umodsi3, 1, uint_tp);
	set_method_res_type(tp_umodsi3, 0, uint_tp);
	umodsi3 = create_compilerlib_entity(new_id_from_str("__umodsi3"), tp_umodsi3);
}
Example #12
0
int main(void)
{
	ir_init();

	ir_type   *type   = new_type_primitive(get_modeIs());
	ident     *id1    = new_id_from_str("foo");
	ir_type   *glob   = get_glob_type();
	ir_entity *x      = new_global_entity(glob, id1, type, ir_visibility_external, IR_LINKAGE_DEFAULT);
	assert(get_entity_owner(x) == glob);

	ident     *id2    = new_id_from_str("bar");
	ir_type   *cls    = new_type_class(id2);
	set_entity_owner(x, cls);
	assert(get_entity_owner(x) == cls);

	ir_entity *gx = ir_get_global(id1);
	assert (NULL == gx);

	set_entity_owner(x, glob);
	assert(get_entity_owner(x) == glob);

	return 0;
}
Example #13
0
/*
 * Creates a new mode.
 */
static ir_mode *alloc_mode(const char *name, ir_mode_sort sort,
                           ir_mode_arithmetic arithmetic, unsigned bit_size,
                           int sign, unsigned modulo_shift)
{
    ir_mode *mode_tmpl = OALLOCZ(&modes, ir_mode);

    mode_tmpl->name         = new_id_from_str(name);
    mode_tmpl->sort         = sort;
    mode_tmpl->size         = bit_size;
    mode_tmpl->sign         = sign ? 1 : 0;
    mode_tmpl->modulo_shift = modulo_shift;
    mode_tmpl->arithmetic   = arithmetic;
    return mode_tmpl;
}
Example #14
0
/**
 * Completes an incomplete irprog.
 *
 * @param irp          the (yet incomplete) irp
 * @param module_name  the (module) name for this irp
 */
static void complete_ir_prog(ir_prog *irp, const char *module_name)
{
	ir_init_type(irp);
	ir_init_entity(irp);

	irp->name = new_id_from_str(module_name);
	irp->segment_types[IR_SEGMENT_GLOBAL]       = new_type_segment(NEW_IDENT("GlobalType"),          tf_global_type);
	irp->segment_types[IR_SEGMENT_THREAD_LOCAL] = new_type_segment(NEW_IDENT("ThreadLocal"),         tf_tls_type);
	irp->segment_types[IR_SEGMENT_CONSTRUCTORS] = new_type_segment(NEW_IDENT("Constructors"),        tf_info);
	irp->segment_types[IR_SEGMENT_DESTRUCTORS]  = new_type_segment(NEW_IDENT("Destructors"),         tf_info);
	irp->segment_types[IR_SEGMENT_JCR]          = new_type_segment(NEW_IDENT("Java Class Registry"), tf_info);

	irp->const_code_irg             = new_const_code_irg();
	irp->globals_entity_usage_state = ir_entity_usage_not_computed;
}
Example #15
0
static ir_entity *ia32_create_intrinsic_fkt(ir_type *method, const ir_op *op,
                                            const ir_mode *imode,
                                            const ir_mode *omode, void *context)
{
	(void)omode;
	(void)context;

	const char *name;
	if (op == op_Div) {
		name = mode_is_signed(imode) ? "__divdi3" : "__udivdi3";
	} else if (op == op_Mod) {
		name = mode_is_signed(imode) ? "__moddi3" : "__umoddi3";
	} else {
		panic("ia32: Unexpected lowering of 64bit op %s", get_op_name(op));
	}
	return create_compilerlib_entity(new_id_from_str(name), method);
}
Example #16
0
static ir_entity *make_divmod(char const *const name, ir_type *const even, ir_type *const odd)
{
	ir_type *const mtp = new_type_method(4, 4);
	set_method_param_type(mtp, 0, even);
	set_method_param_type(mtp, 1, odd);
	set_method_param_type(mtp, 2, even);
	set_method_param_type(mtp, 3, odd);
	set_method_res_type(mtp, 0, even);
	set_method_res_type(mtp, 1, odd);
	set_method_res_type(mtp, 2, even);
	set_method_res_type(mtp, 3, odd);

	ident     *const id   = new_id_from_str(name);
	ir_type   *const glob = get_glob_type();
	ir_entity *const ent  = new_entity(glob, id, mtp);
	set_entity_ld_ident(ent, id);
	set_entity_visibility(ent, ir_visibility_external);
	return ent;
}
Example #17
0
static void sparc_layout_param_entities(ir_graph *const irg, calling_convention_t *const cconv, ir_type *const non_lowered)
{
	ir_entity **const param_map  = be_collect_parameter_entities(irg);
	ir_type    *const frame_type = get_irg_frame_type(irg);
	size_t      const n_params   = cconv->n_parameters;
	/* calculate offsets/create missing entities */
	for (size_t i = 0; i < n_params; ++i) {
		reg_or_stackslot_t *const param  = &cconv->parameters[i];
		ir_entity          *      entity = param_map[i];
		if (entity == NULL) {
			if (!param->already_stored)
				continue;
			entity = new_parameter_entity(frame_type, i, param->type);
		}
		param->entity = entity;
		set_entity_offset(entity, param->offset);
	}

	ir_entity *const function      = get_irg_entity(irg);
	ir_type   *const function_type = get_entity_type(function);
	if (is_method_variadic(function_type)) {
		ir_type   *unknown       = get_unknown_type();
		ident     *id            = new_id_from_str("$va_start");
		ir_entity *va_start_addr = new_entity(frame_type, id, unknown);

		/* sparc_variadic_fixups() fiddled with our type, find out the
		 * original number of parameters */
		size_t const orig_n_params = get_method_n_params(non_lowered);
		long offset;
		if (orig_n_params < n_params) {
			assert(param_map[orig_n_params] != NULL);
			offset = get_entity_offset(param_map[orig_n_params]);
		} else {
			offset = cconv->param_stack_size + SPARC_MIN_STACKSIZE;
		}

		set_entity_offset(va_start_addr, offset);
		cconv->va_start_addr = va_start_addr;
	}

	free(param_map);
}
Example #18
0
static ir_entity *create_ent(ir_entity **const dst, int value, const char *name)
{
	if (!*dst) {
		ir_mode   *const mode = mode_Hu;
		ir_type   *const type = new_type_primitive(mode);
		set_type_alignment_bytes(type, 4);
		ir_type   *const glob = get_glob_type();
		ident     *const id   = new_id_from_str(name);
		ir_entity *const ent  = new_entity(glob, id, type);
		set_entity_ld_ident(ent, id);
		set_entity_visibility(ent, ir_visibility_local);
		add_entity_linkage(ent, IR_LINKAGE_CONSTANT);

		ir_graph *const cnst_irg = get_const_code_irg();
		ir_node  *const cnst     = new_r_Const_long(cnst_irg, mode, value);
		set_atomic_ent_value(ent, cnst);
		*dst = ent;
	}
	return *dst;
}
Example #19
0
static ir_entity *add_compound_member(ir_type *compound, const char *name,
                                      ir_type *type)
{
	ident *id = new_id_from_str(name);
	return new_entity(compound, id, type);
}
Example #20
0
static ident *make_parameter_entity_name(size_t pos)
{
	char buf[64];
	snprintf(buf, sizeof(buf), "parameter.%lu", (unsigned long) pos);
	return new_id_from_str(buf);
}
Example #21
0
void gcji_init()
{
	class_dollar_ident = new_id_from_str("class$");
	glob               = get_glob_type();

	ir_type *t_ptr  = new_type_primitive(mode_reference);
	ir_type *t_size = new_type_primitive(mode_Iu);

	// gcj_alloc
	ir_type *gcj_alloc_method_type
		= new_type_method(1, 1, false, 0, mtp_property_malloc);
	set_method_param_type(gcj_alloc_method_type, 0, t_ptr);
	set_method_res_type(gcj_alloc_method_type, 0, t_ptr);

	ident *gcj_alloc_id
		= ir_platform_mangle_global("_Jv_AllocObjectNoFinalizer");
	gcj_alloc_entity = new_entity(glob, gcj_alloc_id, gcj_alloc_method_type);
	set_entity_visibility(gcj_alloc_entity, ir_visibility_external);

	// gcj_init
	ir_type *gcj_init_method_type = new_type_method(1, 0, false, 0, 0);
	set_method_param_type(gcj_init_method_type, 0, t_ptr);

	ident *gcj_init_id = ir_platform_mangle_global("_Jv_InitClass");
	gcj_init_entity = new_entity(glob, gcj_init_id, gcj_init_method_type);
	set_entity_visibility(gcj_init_entity, ir_visibility_external);

	// gcj_new_string
	ir_type *gcj_new_string_method_type = new_type_method(1, 1, false, 0, 0);
	set_method_param_type(gcj_new_string_method_type, 0, t_ptr);
	set_method_res_type(gcj_new_string_method_type, 0, t_ptr);

	ident *gcj_new_string_id
		= ir_platform_mangle_global("_Z22_Jv_NewStringUtf8ConstP13_Jv_Utf8Const");
	gcj_new_string_entity = new_entity(glob, gcj_new_string_id, gcj_new_string_method_type);
	set_entity_visibility(gcj_new_string_entity, ir_visibility_external);

	// gcj_new_prim_array
	ir_type *gcj_new_prim_array_method_type
		= new_type_method(2, 1, false, 0, 0);
	set_method_param_type(gcj_new_prim_array_method_type, 0, t_ptr);
	set_method_param_type(gcj_new_prim_array_method_type, 1, t_size);
	set_method_res_type(gcj_new_prim_array_method_type, 0, t_ptr);

	ident *gcj_new_prim_array_id
		= ir_platform_mangle_global("_Jv_NewPrimArray");
	gcj_new_prim_array_entity = new_entity(glob, gcj_new_prim_array_id, gcj_new_prim_array_method_type);
	set_entity_visibility(gcj_new_prim_array_entity, ir_visibility_external);

	// gcj_new_object_array
	ir_type *gcj_new_object_array_method_type
		= new_type_method(3, 1, false, 0, 0);
	set_method_param_type(gcj_new_object_array_method_type, 0, t_size);
	set_method_param_type(gcj_new_object_array_method_type, 1, t_ptr);
	set_method_param_type(gcj_new_object_array_method_type, 2, t_ptr);
	set_method_res_type(gcj_new_object_array_method_type, 0, t_ptr);

	ident *gcj_new_object_array_id
		= ir_platform_mangle_global("_Jv_NewObjectArray");
	gcj_new_object_array_entity = new_entity(glob, gcj_new_object_array_id, gcj_new_object_array_method_type);
	set_entity_visibility(gcj_new_object_array_entity, ir_visibility_external);

	// gcji_abstract_method
	ir_type *gcj_abstract_method_type = new_type_method(0, 0, false, 0, 0);
	gcj_abstract_method_entity
		= new_entity(glob, ir_platform_mangle_global("_Jv_ThrowAbstractMethodError"), gcj_abstract_method_type);
	set_entity_visibility(gcj_abstract_method_entity, ir_visibility_external);

	// gcji_lookup_interface
	ir_type *gcj_lookup_interface_type = new_type_method(3, 1, false, 0, 0);
	set_method_param_type(gcj_lookup_interface_type, 0, t_ptr);
	set_method_param_type(gcj_lookup_interface_type, 1, t_ptr);
	set_method_param_type(gcj_lookup_interface_type, 2, t_ptr);
	set_method_res_type(gcj_lookup_interface_type, 0, t_ptr);
	gcj_lookup_interface_entity = new_entity(glob, ir_platform_mangle_global("_Jv_LookupInterfaceMethod"), gcj_lookup_interface_type);
	set_entity_visibility(gcj_lookup_interface_entity, ir_visibility_external);

	// gcji_instanceof
	ir_type *gcj_instanceof_type = new_type_method(2, 1, false, 0, 0);
	set_method_param_type(gcj_instanceof_type, 0, type_reference);
	set_method_param_type(gcj_instanceof_type, 1, type_reference);
	set_method_res_type(gcj_instanceof_type, 0, type_int);
	gcj_instanceof_entity = new_entity(glob, ir_platform_mangle_global("_Jv_IsInstanceOf"), gcj_instanceof_type);
	set_entity_visibility(gcj_instanceof_entity, ir_visibility_external);

	// gcji_checkcast
	ir_type *gcj_checkcast_type = new_type_method(2, 0, false, 0, 0);
	set_method_param_type(gcj_checkcast_type, 0, type_reference);
	set_method_param_type(gcj_checkcast_type, 1, type_reference);
	gcj_checkcast_entity = new_entity(glob, ir_platform_mangle_global("_Jv_CheckCast"), gcj_checkcast_type);
	set_entity_visibility(gcj_checkcast_entity, ir_visibility_external);

	// gcji_get_array_class
	ir_type *gcj_get_array_class_type = new_type_method(2, 1, false, 0, 0);
	set_method_param_type(gcj_get_array_class_type, 0, type_reference);
	set_method_param_type(gcj_get_array_class_type, 1, type_reference);
	set_method_res_type(gcj_get_array_class_type, 0, type_reference);
	gcj_get_array_class_entity
		= new_entity(glob, ir_platform_mangle_global("_Z17_Jv_GetArrayClassPN4java4lang5ClassEPNS0_11ClassLoaderE"), gcj_get_array_class_type);
	set_entity_visibility(gcj_get_array_class_entity, ir_visibility_external);

	// gcji_new_multi_array
	ir_type *gcj_new_multiarray_type = new_type_method(3, 1, false, 0, 0);
	set_method_param_type(gcj_new_multiarray_type, 0, type_reference);
	set_method_param_type(gcj_new_multiarray_type, 1, type_int);
	set_method_param_type(gcj_new_multiarray_type, 2, type_reference); // XXX: actually int[]
	set_method_res_type(gcj_new_multiarray_type, 0, type_reference);
	gcj_new_multiarray_entity
		= new_entity(glob, ir_platform_mangle_global("_Z17_Jv_NewMultiArrayPN4java4lang5ClassEiPi"), gcj_new_multiarray_type);
	set_entity_visibility(gcj_new_multiarray_entity, ir_visibility_external);

	// primitive classes
	gcj_boolean_rtti_entity= extvar("_Jv_booleanClass", type_reference);
	gcj_byte_rtti_entity   = extvar("_Jv_byteClass", type_reference);
	gcj_char_rtti_entity   = extvar("_Jv_charClass", type_reference);
	gcj_short_rtti_entity  = extvar("_Jv_shortClass", type_reference);
	gcj_int_rtti_entity    = extvar("_Jv_intClass", type_reference);
	gcj_long_rtti_entity   = extvar("_Jv_longClass", type_reference);
	gcj_float_rtti_entity  = extvar("_Jv_floatClass", type_reference);
	gcj_double_rtti_entity = extvar("_Jv_doubleClass", type_reference);

	mode_ushort = new_int_mode("US", 16, 0, 16);
	type_ushort = new_type_primitive(mode_ushort);

	cpset_init(&scp, scp_hash, scp_cmp);

	type_method_desc = create_method_desc_type();
	type_field_desc  = create_field_desc_type();
	type_utf8_const  = create_utf8_const_type();

	superobject_ident  = new_id_from_str("@base");

	ddispatch_set_vtable_layout(2, 4, 2, setup_vtable);
	ddispatch_set_abstract_method_entity(gcj_abstract_method_entity);
	ddispatch_set_interface_lookup_constructor(gcji_lookup_interface);

	/* we construct rtti right away */
	rtti_set_runtime_typeinfo_constructor(dummy);
	rtti_set_instanceof_constructor(gcji_instanceof);

	dmemory_set_allocation_methods(gcji_get_arraylength);
}