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; }
ir_entity *create_compilerlib_entity(ident *id, ir_type *mt) { ir_entity *entity = pmap_get(ir_entity, irp->compilerlib_entities, id); if (entity != NULL) return entity; /* let frontend mangle the name */ ident *ld_name = compilerlib_mangler(id, mt); /* search for an existing entity */ ir_type *glob = get_glob_type(); for (size_t i = 0, n_members = get_compound_n_members(glob); i < n_members; ++i) { ir_entity *member = get_compound_member(glob, i); if (get_entity_ld_ident(member) == ld_name) { entity = member; goto found; } } entity = new_entity(glob, id, mt); set_entity_ld_ident(entity, ld_name); set_entity_visibility(entity, ir_visibility_external); found: pmap_insert(irp->compilerlib_entities, id, entity); return entity; }
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; }
static ir_entity *emit_field_table(ir_type *classtype) { class_t *linked_class = (class_t*) oo_get_type_link(classtype); assert(linked_class); uint16_t n_fields = linked_class->n_fields; if (n_fields == 0) return NULL; ir_type *type_array = new_type_array(type_field_desc, n_fields); unsigned size = n_fields * get_type_size(type_field_desc); set_type_size(type_array, size); ir_initializer_t *init = create_initializer_compound(n_fields); for (uint16_t i = 0; i < n_fields; i++) { ir_entity *field = linked_class->fields[i]->link; ir_initializer_t *desc = get_field_desc(classtype, field); set_initializer_compound_value(init, i, desc); } ident *id = id_unique("_FT"); ir_entity *ft_ent = new_entity(get_glob_type(), id, type_array); set_entity_initializer(ft_ent, init); set_entity_ld_ident(ft_ent, id); return ft_ent; }
static ir_entity *emit_interface_table(ir_type *classtype) { class_t *linked_class = (class_t*) oo_get_type_link(classtype); assert(linked_class); uint16_t n_interfaces = linked_class->n_interfaces; if (n_interfaces == 0) return NULL; ir_type *type_array = new_type_array(type_reference, n_interfaces); unsigned size = n_interfaces * get_type_size(type_reference); set_type_size(type_array, size); ir_initializer_t *init = create_initializer_compound(n_interfaces); for (uint16_t i = 0; i < n_interfaces; i++) { uint16_t iface_ref = linked_class->interfaces[i]; constant_classref_t *clsref = (constant_classref_t*) linked_class->constants[iface_ref]; constant_utf8_string_t *clsname = (constant_utf8_string_t*) linked_class->constants[clsref->name_index]; ir_type *type = class_registry_get(clsname->bytes); assert(type); ir_entity *rtti_entity = gcji_get_rtti_entity(type); assert(rtti_entity != NULL); set_compound_init_entref(init, i, rtti_entity); } ident *id = id_unique("_IF"); ir_entity *if_ent = new_entity(get_glob_type(), id, type_array); set_entity_initializer(if_ent, init); set_entity_ld_ident(if_ent, id); return if_ent; }
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; }
void gcji_create_rtti_entity(ir_type *type) { const char *name = get_compound_name(type); /* create RTTI object entity (actual initializer is constructed in liboo) */ ident *rtti_ident = mangle_rtti_name(name); ir_type *unknown = get_unknown_type(); ir_entity *rtti_entity = new_entity(glob, rtti_ident, unknown); oo_set_class_rtti_entity(type, rtti_entity); }
void gcji_create_vtable_entity(ir_type *type) { const char *name = get_compound_name(type); ident *vtable_ident = mangle_vtable_name(name); ir_type *unknown = get_unknown_type(); ir_type *glob = get_glob_type(); ir_entity *vtable = new_entity(glob, vtable_ident, unknown); oo_set_class_vtable_entity(type, vtable); }
/** * Create a trampoline entity for the given method. */ static ir_entity *create_trampoline(be_main_env_t *be, ir_entity *method) { ir_type *type = get_entity_type(method); ident *old_id = get_entity_ld_ident(method); ident *id = new_id_fmt("%s$stub", old_id); ir_type *parent = be->pic_trampolines_type; ir_entity *ent = new_entity(parent, old_id, type); set_entity_ld_ident(ent, id); set_entity_visibility(ent, ir_visibility_private); return ent; }
static ir_entity *create_pic_symbol(be_main_env_t *be, ir_entity *entity) { ident *old_id = get_entity_ld_ident(entity); ident *id = new_id_fmt("%s$non_lazy_ptr", old_id); ir_type *e_type = get_entity_type(entity); ir_type *type = new_type_pointer(e_type); ir_type *parent = be->pic_symbols_type; ir_entity *ent = new_entity(parent, old_id, type); set_entity_ld_ident(ent, id); set_entity_visibility(ent, ir_visibility_private); return ent; }
ir_entity *create_compilerlib_entity(ident *id, ir_type *mt) { ident *ld_name = compilerlib_mangler(id, mt); /* Look for existing entity. */ ir_entity *entity = ir_get_global(ld_name); if (entity != NULL) return entity; /* Create a new one */ ir_type *glob = get_glob_type(); entity = new_entity(glob, ld_name, mt); return entity; }
static void add_pointer_in_jcr_segment(ir_entity *entity) { if (!create_jcr_segment) return; ir_type *segment = get_segment_type(IR_SEGMENT_JCR); ident *id = id_unique("jcr_ptr"); ir_entity *ptr = new_entity(segment, id, type_reference); ir_graph *irg = get_const_code_irg(); ir_node *val = new_r_Address(irg, entity); set_entity_ld_ident(ptr, new_id_from_chars("", 0)); set_entity_visibility(ptr, ir_visibility_private); set_entity_linkage(ptr, IR_LINKAGE_CONSTANT|IR_LINKAGE_HIDDEN_USER); set_entity_alignment(ptr, 1); ir_initializer_t *const init = create_initializer_const(val); set_entity_initializer(ptr, init); }
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; }
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); }
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; }
static ir_entity *do_emit_utf8_const(const char *bytes, size_t len) { size_t len0 = len + 1; // incl. the '\0' byte int hash = java_style_hash(bytes) & 0xFFFF; scp_entry test_scpe; test_scpe.s = (char*)bytes; scp_entry *found_scpe = cpset_find(&scp, &test_scpe); if (found_scpe != NULL) { ir_entity *utf8const = found_scpe->utf8c; return utf8const; } ir_initializer_t *data_init = create_initializer_compound(len0); for (size_t i = 0; i < len0; ++i) { set_compound_init_num(data_init, i, mode_Bu, bytes[i]); } ir_initializer_t *cinit = create_initializer_compound(3); set_compound_init_num(cinit, 0, mode_ushort, hash); set_compound_init_num(cinit, 1, mode_ushort, len); set_initializer_compound_value(cinit, 2, data_init); ident *id = id_unique("_Utf8"); ir_entity *utf8c = new_entity(get_glob_type(), id, type_utf8_const); set_entity_initializer(utf8c, cinit); set_entity_ld_ident(utf8c, id); add_entity_linkage(utf8c, IR_LINKAGE_CONSTANT); scp_entry *new_scpe = XMALLOC(scp_entry); new_scpe->s = XMALLOCN(char, len0); memcpy(new_scpe->s, bytes, len0); new_scpe->utf8c = utf8c; cpset_insert(&scp, new_scpe); return utf8c; }
static ir_entity *emit_method_table(ir_type *classtype) { class_t *linked_class = (class_t*) oo_get_type_link(classtype); assert(linked_class); uint16_t n_methods = linked_class->n_methods; ir_type *array_type = new_type_array(type_method_desc, n_methods); unsigned size = n_methods * get_type_size(type_method_desc); set_type_size(array_type, size); ir_initializer_t *cinit = create_initializer_compound(n_methods); for (uint16_t i = 0; i < n_methods; i++) { ir_entity *method = linked_class->methods[i]->link; ir_initializer_t *method_desc = get_method_desc(classtype, method); set_initializer_compound_value(cinit, i, method_desc); } ident *id = id_unique("_MT"); ir_entity *mt_ent = new_entity(get_glob_type(), id, array_type); set_entity_initializer(mt_ent, cinit); set_entity_ld_ident(mt_ent, id); return mt_ent; }
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); }
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); }