always transmit const source_position_t * instead of source_position_t
[cparser] / ast2firm.c
index 09aa949..be8549e 100644 (file)
@@ -82,7 +82,7 @@ ir_node *uninitialized_local_var(ir_graph *irg, ir_mode *mode, int pos)
 {
        const declaration_t *declaration = get_irg_loc_description(irg, pos);
 
-       warningf(declaration->source_position,
+       warningf(&declaration->source_position,
                 "variable '%#T' might be used uninitialized",
                 declaration->type, declaration->symbol);
        return new_r_Unknown(irg, mode);
@@ -1169,12 +1169,13 @@ static ir_node *wide_string_literal_to_firm(
        return create_symconst(dbgi, mode_P_data, entity);
 }
 
-static ir_node *deref_address(ir_type *const irtype, ir_node *const addr,
+static ir_node *deref_address(type_t *const type, ir_node *const addr,
                               dbg_info *const dbgi)
 {
-       if (is_compound_type(irtype) ||
-                       is_Method_type(irtype)   ||
-                       is_Array_type(irtype)) {
+       ir_type *irtype = get_ir_type(type);
+       if (is_compound_type(irtype)
+                       || is_Method_type(irtype)
+                       || is_Array_type(irtype)) {
                return addr;
        }
 
@@ -1183,6 +1184,11 @@ static ir_node *deref_address(ir_type *const irtype, ir_node *const addr,
        ir_node *const load     = new_d_Load(dbgi, memory, addr, mode);
        ir_node *const load_mem = new_d_Proj(dbgi, load, mode_M, pn_Load_M);
        ir_node *const load_res = new_d_Proj(dbgi, load, mode,   pn_Load_res);
+
+       if(type->base.qualifiers & TYPE_QUALIFIER_VOLATILE) {
+               set_Load_volatility(load, volatility_is_volatile);
+       }
+
        set_store(load_mem);
        return load_res;
 }
@@ -1270,16 +1276,14 @@ static ir_node *reference_expression_to_firm(const reference_expression_t *ref)
        }
        case DECLARATION_KIND_GLOBAL_VARIABLE: {
                ir_node *const addr   = get_global_var_address(dbgi, declaration);
-               ir_type *const irtype = get_entity_type(declaration->v.entity);
-               return deref_address(irtype, addr, dbgi);
+               return deref_address(declaration->type, addr, dbgi);
        }
 
        case DECLARATION_KIND_LOCAL_VARIABLE_ENTITY: {
                ir_entity *entity = declaration->v.entity;
                ir_node   *frame  = get_local_frame(entity);
                ir_node   *sel    = new_d_simpleSel(dbgi, new_NoMem(), frame, entity);
-               ir_type   *irtype = get_entity_type(entity);
-               return deref_address(irtype, sel, dbgi);
+               return deref_address(declaration->type, sel, dbgi);
        }
 
        case DECLARATION_KIND_VARIABLE_LENGTH_ARRAY:
@@ -1489,6 +1493,8 @@ static void assign_value(dbg_info *dbgi, ir_node *addr, type_t *type,
        if(is_type_scalar(type)) {
                ir_node  *store     = new_d_Store(dbgi, memory, addr, value);
                ir_node  *store_mem = new_d_Proj(dbgi, store, mode_M, pn_Store_M);
+               if(type->base.qualifiers & TYPE_QUALIFIER_VOLATILE)
+                       set_Store_volatility(store, volatility_is_volatile);
                set_store(store_mem);
        } else {
                ir_type *irtype    = get_ir_type(type);
@@ -1561,6 +1567,11 @@ static void bitfield_store_to_firm(const unary_expression_t *expression,
        ir_node *store     = new_d_Store(dbgi, load_mem, addr, new_val);
        ir_node *store_mem = new_d_Proj(dbgi, store, mode_M, pn_Store_M);
        set_store(store_mem);
+
+       if(type->base.qualifiers & TYPE_QUALIFIER_VOLATILE) {
+               set_Load_volatility(load, volatility_is_volatile);
+               set_Store_volatility(store, volatility_is_volatile);
+       }
 }
 
 static void set_value_for_expression(const expression_t *expression,
@@ -1849,9 +1860,8 @@ static ir_node *unary_expression_to_firm(const unary_expression_t *expression)
        case EXPR_UNARY_DEREFERENCE: {
                ir_node *value_node = expression_to_firm(value);
                type_t  *value_type = skip_typeref(value->base.type);
-               ir_type *irtype     = get_ir_type(value_type);
-               assert(is_Pointer_type(irtype));
-               ir_type *points_to  = get_pointer_points_to_type(irtype);
+               assert(is_type_pointer(value_type));
+               type_t  *points_to  = value_type->pointer.points_to;
                return deref_address(points_to, value_node, dbgi);
        }
        case EXPR_UNARY_POSTFIX_INCREMENT:
@@ -2280,9 +2290,8 @@ static ir_node *array_access_to_firm(
        type_t   *type   = revert_automatic_type_conversion(
                        (const expression_t*) expression);
        type             = skip_typeref(type);
-       ir_type  *irtype = get_ir_type(type);
 
-       return deref_address(irtype, addr, dbgi);
+       return deref_address(type, addr, dbgi);
 }
 
 static long get_offsetof_offset(const offsetof_expression_t *expression)
@@ -2520,9 +2529,8 @@ static ir_node *select_to_firm(const select_expression_t *expression)
        type_t   *type   = revert_automatic_type_conversion(
                        (const expression_t*) expression);
        type             = skip_typeref(type);
-       ir_type  *irtype = get_ir_type(type);
 
-       return deref_address(irtype, addr, dbgi);
+       return deref_address(type, addr, dbgi);
 }
 
 /* Values returned by __builtin_classify_type. */
@@ -2633,30 +2641,30 @@ make_const: ;
 }
 
 static ir_node *function_name_to_firm(
-               const string_literal_expression_t *const expr)
-{
-       if (current_function_name == NULL) {
-               const source_position_t *const src_pos = &expr->base.source_position;
-               const char *const name = current_function_decl->symbol->string;
-               const string_t string = { name, strlen(name) + 1 };
-               current_function_name = string_to_firm(src_pos, "__func__", &string);
-       }
-
-       return current_function_name;
-}
-
-static ir_node *funcsig_to_firm(
-               const string_literal_expression_t *const expr)
-{
-       if (current_funcsig == NULL) {
-               const source_position_t *const src_pos = &expr->base.source_position;
-               ir_entity *ent = get_irg_entity(current_ir_graph);
-               const char *const name = get_entity_ld_name(ent);
-               const string_t string = { name, strlen(name) + 1 };
-               current_funcsig = string_to_firm(src_pos, "__FUNCSIG__", &string);
+               const funcname_expression_t *const expr)
+{
+       switch(expr->kind) {
+       case FUNCNAME_FUNCTION:
+       case FUNCNAME_PRETTY_FUNCTION:
+       case FUNCNAME_FUNCDNAME:
+               if (current_function_name == NULL) {
+                       const source_position_t *const src_pos = &expr->base.source_position;
+                       const char *const name = current_function_decl->symbol->string;
+                       const string_t string = { name, strlen(name) + 1 };
+                       current_function_name = string_to_firm(src_pos, "__func__", &string);
+               }
+               return current_function_name;
+       case FUNCNAME_FUNCSIG:
+               if (current_funcsig == NULL) {
+                       const source_position_t *const src_pos = &expr->base.source_position;
+                       ir_entity *ent = get_irg_entity(current_ir_graph);
+                       const char *const name = get_entity_ld_name(ent);
+                       const string_t string = { name, strlen(name) + 1 };
+                       current_funcsig = string_to_firm(src_pos, "__FUNCSIG__", &string);
+               }
+               return current_funcsig;
        }
-
-       return current_funcsig;
+       panic("Unsupported function name");
 }
 
 static ir_node *statement_expression_to_firm(const statement_expression_t *expr)
@@ -2688,13 +2696,13 @@ static ir_node *va_start_expression_to_firm(
 
 static ir_node *va_arg_expression_to_firm(const va_arg_expression_t *const expr)
 {
-       ir_type  *const irtype = get_ir_type(expr->base.type);
+       type_t   *const type   = expr->base.type;
        ir_node  *const ap     = expression_to_firm(expr->ap);
        dbg_info *const dbgi   = get_dbg_info(&expr->base.source_position);
-       ir_node  *const res    = deref_address(irtype, ap, dbgi);
+       ir_node  *const res    = deref_address(type, ap, dbgi);
 
-       ir_node  *const cnst      = get_type_size(expr->base.type);
-       ir_node  *const add       = new_d_Add(dbgi, ap, cnst, mode_P_data);
+       ir_node  *const cnst   = get_type_size(expr->base.type);
+       ir_node  *const add    = new_d_Add(dbgi, ap, cnst, mode_P_data);
        set_value_for_expression(expr->ap, add);
 
        return res;
@@ -2782,12 +2790,8 @@ static ir_node *_expression_to_firm(const expression_t *expression)
                return select_to_firm(&expression->select);
        case EXPR_CLASSIFY_TYPE:
                return classify_type_to_firm(&expression->classify_type);
-       case EXPR_FUNCTION:
-       case EXPR_PRETTY_FUNCTION:
-       case EXPR_FUNCDNAME:
-               return function_name_to_firm(&expression->string);
-       case EXPR_FUNCSIG:
-               return funcsig_to_firm(&expression->string);
+       case EXPR_FUNCNAME:
+               return function_name_to_firm(&expression->funcname);
        case EXPR_STATEMENT:
                return statement_expression_to_firm(&expression->statement);
        case EXPR_VA_START:
@@ -2921,7 +2925,8 @@ static void create_declaration_entity(declaration_t *declaration,
                                       ir_type *parent_type)
 {
        ident     *const id     = new_id_from_str(declaration->symbol->string);
-       ir_type   *const irtype = get_ir_type(declaration->type);
+       type_t    *const type   = skip_typeref(declaration->type);
+       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);
@@ -2933,7 +2938,10 @@ static void create_declaration_entity(declaration_t *declaration,
                set_entity_allocation(entity, allocation_automatic);
        else if(declaration_kind == DECLARATION_KIND_GLOBAL_VARIABLE)
                set_entity_allocation(entity, allocation_static);
-       /* TODO: visibility? */
+
+       if(type->base.qualifiers & TYPE_QUALIFIER_VOLATILE) {
+               set_entity_volatility(entity, volatility_is_volatile);
+       }
 }
 
 
@@ -2963,7 +2971,7 @@ static __attribute__((unused)) void debug_print_type_path(const type_path_t *pat
                if(is_type_compound(type)) {
                        fprintf(stderr, ".%s", entry->compound_entry->symbol->string);
                } else if(is_type_array(type)) {
-                       fprintf(stderr, "[%u]", entry->index);
+                       fprintf(stderr, "[%zd]", entry->index);
                } else {
                        fprintf(stderr, "-INVALID-");
                }
@@ -3557,6 +3565,8 @@ static void create_local_variable(declaration_t *declaration)
                return;
        } else if(is_type_array(type) || is_type_compound(type)) {
                needs_entity = true;
+       } else if(type->base.qualifiers & TYPE_QUALIFIER_VOLATILE) {
+               needs_entity = true;
        }
 
        if(needs_entity) {
@@ -3586,6 +3596,10 @@ static void create_local_static_variable(declaration_t *declaration)
        ir_entity *const entity      = new_d_entity(global_type, id, irtype, dbgi);
        set_entity_ld_ident(entity, id);
 
+       if(type->base.qualifiers & TYPE_QUALIFIER_VOLATILE) {
+               set_entity_volatility(entity, volatility_is_volatile);
+       }
+
        declaration->declaration_kind = DECLARATION_KIND_GLOBAL_VARIABLE;
        declaration->v.entity         = entity;
        set_entity_variability(entity, variability_uninitialized);
@@ -4417,10 +4431,7 @@ static int count_decls_in_expression(const expression_t *expression) {
        case EXPR_WIDE_CHARACTER_CONSTANT:
        case EXPR_STRING_LITERAL:
        case EXPR_WIDE_STRING_LITERAL:
-       case EXPR_FUNCTION:
-       case EXPR_PRETTY_FUNCTION:
-       case EXPR_FUNCSIG:
-       case EXPR_FUNCDNAME:
+       case EXPR_FUNCNAME:
        case EXPR_BUILTIN_SYMBOL:
        case EXPR_VA_START:
        case EXPR_VA_ARG: