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; }
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; }
/** * 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; }
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; }
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 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; }
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); }