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; }
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; }
ir_entity *new_d_label_entity(ir_label_t label, dbg_info *dbgi) { ident *name = id_unique("label_%u"); ir_type *global_type = get_glob_type(); ir_entity *res = intern_new_entity(global_type, IR_ENTITY_LABEL, name, get_code_type(), dbgi); res->attr.code_attr.label = label; hook_new_entity(res); return res; }
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 *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; }