- renamed modifier to decl_modifier
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Sat, 22 Mar 2008 18:02:30 +0000 (18:02 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Sat, 22 Mar 2008 18:02:30 +0000 (18:02 +0000)
- fixed ld_name for win32 build

[r19018]

ast.c
ast2firm.c
ast_t.h
parser.c

diff --git a/ast.c b/ast.c
index 6a44eab..7284a5b 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -1273,7 +1273,7 @@ static void print_ms_modifiers(const declaration_t *declaration) {
        if((c_mode & _MS) == 0)
                return;
 
-       decl_modifiers_t modifiers = declaration->modifiers;
+       decl_modifiers_t modifiers = declaration->decl_modifiers;
 
        /* DM_FORCEINLINE handled outside. */
        if((modifiers & ~DM_FORCEINLINE) != 0 ||
@@ -1347,10 +1347,10 @@ static void print_normal_declaration(const declaration_t *declaration)
 {
        print_storage_class((storage_class_tag_t) declaration->declared_storage_class);
        if(declaration->is_inline) {
-               if(declaration->modifiers & DM_FORCEINLINE)
+               if(declaration->decl_modifiers & DM_FORCEINLINE)
                        fputs("__forceinline ", out);
                else {
-                       if(declaration->modifiers & DM_MICROSOFT_INLINE)
+                       if(declaration->decl_modifiers & DM_MICROSOFT_INLINE)
                                fputs("__inline ", out);
                        else
                                fputs("inline ", out);
index 695b4cb..d6981ef 100644 (file)
@@ -897,6 +897,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 +953,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);
@@ -2855,7 +2896,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;
@@ -3534,7 +3575,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);
@@ -4625,7 +4666,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);
diff --git a/ast_t.h b/ast_t.h
index 3bc1974..d227dcb 100644 (file)
--- a/ast_t.h
+++ b/ast_t.h
@@ -531,7 +531,7 @@ struct declaration_t {
        unsigned char       declared_storage_class;
        unsigned char       storage_class;
        unsigned char       alignment;          /**< Alignment of the declaration, 0 for default. */
-       decl_modifiers_t    modifiers;          /**< MS __declspec modifiers. */
+       decl_modifiers_t    decl_modifiers;     /**< MS __declspec modifiers. */
        const char         *deprecated_string;  /**< MS deprecated string if any. */
        symbol_t           *get_property_sym;   /**< MS get property. */
        symbol_t           *put_property_sym;   /**< MS put property. */
@@ -549,7 +549,7 @@ struct declaration_t {
                expression_t   *enum_value;
        } init;
        scope_t             scope;              /**< The scope that this declaration opens. */
-       scope_t            *parent_scope;       /**< The parant scope where this declaration lives. */
+       scope_t            *parent_scope;       /**< The parent scope where this declaration lives. */
 
        /** next declaration in a scope */
        declaration_t      *next;
index e2808b0..0271b72 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -3637,7 +3637,7 @@ static declaration_t *parse_declarator(
 {
        declaration_t *const declaration    = allocate_declaration_zero();
        declaration->declared_storage_class = specifiers->declared_storage_class;
-       declaration->modifiers              = specifiers->decl_modifiers;
+       declaration->decl_modifiers         = specifiers->decl_modifiers;
        declaration->deprecated             = specifiers->deprecated;
        declaration->deprecated_string      = specifiers->deprecated_string;
        declaration->get_property_sym       = specifiers->get_property_sym;
@@ -3985,7 +3985,7 @@ static void parse_anonymous_declaration_rest(
        declaration->type                   = specifiers->type;
        declaration->declared_storage_class = specifiers->declared_storage_class;
        declaration->source_position        = specifiers->source_position;
-       declaration->modifiers              = specifiers->decl_modifiers;
+       declaration->decl_modifiers         = specifiers->decl_modifiers;
 
        if (declaration->declared_storage_class != STORAGE_CLASS_NONE) {
                warningf(&declaration->source_position,
@@ -4438,7 +4438,7 @@ static void parse_compound_declarators(declaration_t *struct_declaration,
                        declaration->declared_storage_class = STORAGE_CLASS_NONE;
                        declaration->storage_class          = STORAGE_CLASS_NONE;
                        declaration->source_position        = source_position;
-                       declaration->modifiers              = specifiers->decl_modifiers;
+                       declaration->decl_modifiers         = specifiers->decl_modifiers;
                        declaration->type                   = type;
                } else {
                        declaration = parse_declarator(specifiers,/*may_be_abstract=*/true);