X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ast2firm.c;h=ffddd487db7ca07792a95f417f9793e81fb529af;hb=fe9aa8a20c3fc2be53a9486916d4d25db76e7368;hp=aa98938a32ef9ee8eac5d5aa7ed38a6013ec53a2;hpb=70abad8ade78c811d76cc79741fccfc6bd7d58ab;p=cparser diff --git a/ast2firm.c b/ast2firm.c index aa98938..ffddd48 100644 --- a/ast2firm.c +++ b/ast2firm.c @@ -221,6 +221,10 @@ static unsigned get_type_size_const(type_t *type) panic("error type occured"); case TYPE_ATOMIC: return get_atomic_type_size(type->atomic.akind); + case TYPE_COMPLEX: + return 2 * get_atomic_type_size(type->complex.akind); + case TYPE_IMAGINARY: + return get_atomic_type_size(type->imaginary.akind); case TYPE_ENUM: return get_mode_size_bytes(mode_int); case TYPE_COMPOUND_UNION: @@ -281,19 +285,48 @@ static unsigned count_parameters(const function_type_t *function_type) return count; } +/** + * Creates a Firm type for an atomic type + */ static ir_type *create_atomic_type(const atomic_type_t *type) { dbg_info *dbgi = get_dbg_info(&type->base.source_position); atomic_type_kind_t kind = type->akind; ir_mode *mode = _atomic_modes[kind]; - unsigned alignment = get_atomic_type_alignment(kind); ident *id = get_mode_ident(mode); ir_type *irtype = new_d_type_primitive(id, mode, dbgi); - if(type->base.alignment > alignment) - alignment = type->base.alignment; + set_type_alignment_bytes(irtype, type->base.alignment); + + return irtype; +} + +/** + * Creates a Firm type for a complex type + */ +static ir_type *create_complex_type(const complex_type_t *type) +{ + dbg_info *dbgi = get_dbg_info(&type->base.source_position); + atomic_type_kind_t kind = type->akind; + ir_mode *mode = _atomic_modes[kind]; + ident *id = get_mode_ident(mode); + + /* FIXME: finish the array */ + return NULL; +} + +/** + * Creates a Firm type for an imaginary type + */ +static ir_type *create_imaginary_type(const imaginary_type_t *type) +{ + dbg_info *dbgi = get_dbg_info(&type->base.source_position); + atomic_type_kind_t kind = type->akind; + ir_mode *mode = _atomic_modes[kind]; + ident *id = get_mode_ident(mode); + ir_type *irtype = new_d_type_primitive(id, mode, dbgi); - set_type_alignment_bytes(irtype, alignment); + set_type_alignment_bytes(irtype, type->base.alignment); return irtype; } @@ -759,10 +792,16 @@ static ir_type *get_ir_type(type_t *type) ir_type *firm_type = NULL; switch(type->kind) { case TYPE_ERROR: - panic("error type occured"); + panic("error type occurred"); case TYPE_ATOMIC: firm_type = create_atomic_type(&type->atomic); break; + case TYPE_COMPLEX: + firm_type = create_complex_type(&type->complex); + break; + case TYPE_IMAGINARY: + firm_type = create_imaginary_type(&type->imaginary); + break; case TYPE_FUNCTION: firm_type = create_method_type(&type->function); break; @@ -897,6 +936,47 @@ static const struct { { rts_strncmp, 1, "strncmp", 3, _C89 } }; +/** + * Mangles an entity linker (ld) name for win32 usage. + * + * @param ent the entity to be mangled + * @param decl_modifiers the set of modifiers for this entity + */ +static ir_ident_ptr decorate_win32(ir_entity_ptr ent, decl_modifiers_t decl_modifiers) { + ir_ident_ptr id; + + if (is_Method_type(get_entity_type(ent))) + id = decorate_win32_c_fkt(ent, get_entity_ident(ent)); + else { + /* always add an underscore in win32 */ + id = mangle(new_id_from_chars("_", 1), get_entity_ident(ent)); + } + + if (decl_modifiers & DM_DLLIMPORT) { + /* add prefix for imported symbols */ + id = mangle(new_id_from_chars("__imp_", 6), id); + } + return id; +} + +/** + * Mangles an entity linker (ld) name from a declaration. + * + * @param ent the entity to be mangled + * @param declaration the declaration + */ +static void mangle_ent_from_decl(ir_entity *ent, declaration_t *declaration) +{ + ident *id; + + if (firm_opt.os_support == OS_SUPPORT_MINGW) + id = decorate_win32(ent, declaration->decl_modifiers); + else + id = get_entity_ident(ent); + + set_entity_ld_ident(ent, id); +} + static ir_entity* get_function_entity(declaration_t *declaration) { if(declaration->declaration_kind == DECLARATION_KIND_FUNCTION) @@ -912,7 +992,7 @@ static ir_entity* get_function_entity(declaration_t *declaration) dbg_info *const dbgi = get_dbg_info(&declaration->source_position); ir_entity *const entity = new_d_entity(global_type, id, ir_type_method, dbgi); - set_entity_ld_ident(entity, id); + mangle_ent_from_decl(entity, declaration); if(declaration->storage_class == STORAGE_CLASS_STATIC || declaration->is_inline) { set_entity_visibility(entity, visibility_local); @@ -2493,7 +2573,7 @@ static ir_node *classify_type_to_firm(const classify_type_expression_t *const ex { case TYPE_ATOMIC: { const atomic_type_t *const atomic_type = &type->atomic; - switch ((atomic_type_kind_t) atomic_type->akind) { + switch (atomic_type->akind) { /* should not be reached */ case ATOMIC_TYPE_INVALID: tc = no_type_class; @@ -2524,21 +2604,12 @@ static ir_node *classify_type_to_firm(const classify_type_expression_t *const ex case ATOMIC_TYPE_LONG_DOUBLE: tc = real_type_class; goto make_const; - - case ATOMIC_TYPE_FLOAT_COMPLEX: - case ATOMIC_TYPE_DOUBLE_COMPLEX: - case ATOMIC_TYPE_LONG_DOUBLE_COMPLEX: - tc = complex_type_class; - goto make_const; - case ATOMIC_TYPE_FLOAT_IMAGINARY: - case ATOMIC_TYPE_DOUBLE_IMAGINARY: - case ATOMIC_TYPE_LONG_DOUBLE_IMAGINARY: - tc = complex_type_class; - goto make_const; } panic("Unexpected atomic type in classify_type_to_firm()."); } + case TYPE_COMPLEX: tc = complex_type_class; goto make_const; + case TYPE_IMAGINARY: tc = complex_type_class; goto make_const; case TYPE_BITFIELD: tc = integer_type_class; goto make_const; case TYPE_ARRAY: /* gcc handles this as pointer */ case TYPE_FUNCTION: /* gcc handles this as pointer */ @@ -2855,7 +2926,7 @@ static void create_declaration_entity(declaration_t *declaration, ir_type *const irtype = get_ir_type(type); dbg_info *const dbgi = get_dbg_info(&declaration->source_position); ir_entity *const entity = new_d_entity(parent_type, id, irtype, dbgi); - set_entity_ld_ident(entity, id); + mangle_ent_from_decl(entity, declaration); declaration->declaration_kind = (unsigned char) declaration_kind; declaration->v.entity = entity; @@ -3248,6 +3319,20 @@ static ir_initializer_t *create_ir_initializer( panic("unknown initializer"); } +static void create_dynamic_null_initializer(ir_type *type, dbg_info *dbgi, + ir_node *base_addr) +{ + ir_mode *mode = get_type_mode(type); + tarval *zero = get_mode_null(mode); + ir_node *cnst = new_d_Const(dbgi, mode, zero); + + /* TODO: bitfields */ + ir_node *mem = get_store(); + ir_node *store = new_d_Store(dbgi, mem, base_addr, cnst); + ir_node *proj_m = new_Proj(store, mode_M, pn_Store_M); + set_store(proj_m); +} + static void create_dynamic_initializer_sub(ir_initializer_t *initializer, ir_type *type, dbg_info *dbgi, ir_node *base_addr) { @@ -3520,7 +3605,7 @@ static void create_local_static_variable(declaration_t *declaration) ir_type *const irtype = get_ir_type(type); dbg_info *const dbgi = get_dbg_info(&declaration->source_position); ir_entity *const entity = new_d_entity(global_type, id, irtype, dbgi); - set_entity_ld_ident(entity, id); + mangle_ent_from_decl(entity, declaration); if(type->base.qualifiers & TYPE_QUALIFIER_VOLATILE) { set_entity_volatility(entity, volatility_is_volatile); @@ -4611,7 +4696,7 @@ static void create_function(declaration_t *declaration) /* set inline flags */ if (declaration->is_inline) set_irg_inline_property(irg, irg_inline_recomended); - handle_decl_modifier_irg(irg, declaration->modifiers); + handle_decl_modifier_irg(irg, declaration->decl_modifiers); next_value_number_function = 0; initialize_function_parameters(declaration);