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; }