Add EXPR_LITERAL_BOOLEAN to get_expression_struct_size().
[cparser] / ast2firm.c
index f124790..c214587 100644 (file)
@@ -49,7 +49,6 @@
 #include "printer.h"
 #include "entitymap_t.h"
 #include "driver/firm_opt.h"
-#include "driver/firm_cmdline.h"
 
 typedef struct trampoline_region trampoline_region;
 struct trampoline_region {
@@ -57,6 +56,8 @@ struct trampoline_region {
        ir_entity        *region;      /**< created region for the trampoline */
 };
 
+fp_model_t firm_fp_model = fp_model_precise;
+
 static const backend_params *be_params;
 
 static ir_type *ir_type_char;
@@ -146,7 +147,7 @@ static const char *dbg_retrieve(const dbg_info *dbg, unsigned *line)
        if (pos == NULL)
                return NULL;
        if (line != NULL)
-               *line = pos->linenr;
+               *line = pos->lineno;
        return pos->input_name;
 }
 
@@ -170,6 +171,18 @@ static type_dbg_info *get_type_dbg_info_(const type_t *type)
        return (type_dbg_info*) type;
 }
 
+/* is the current block a reachable one? */
+static bool currently_reachable(void)
+{
+       ir_node *const block = get_cur_block();
+       return block != NULL && !is_Bad(block);
+}
+
+static void set_unreachable_now(void)
+{
+       set_cur_block(NULL);
+}
+
 static ir_mode *atomic_modes[ATOMIC_TYPE_LAST+1];
 
 static ir_mode *mode_int, *mode_uint;
@@ -743,9 +756,6 @@ ir_type *get_ir_type(type_t *type)
        case TYPE_ENUM:
                firm_type = create_enum_type(&type->enumt);
                break;
-       case TYPE_BUILTIN:
-               firm_type = get_ir_type(type->builtin.real_type);
-               break;
        case TYPE_BITFIELD:
                firm_type = create_bitfield_type(&type->bitfield);
                break;
@@ -1079,7 +1089,7 @@ static ir_node *create_conv(dbg_info *dbgi, ir_node *value, ir_mode *dest_mode)
 {
        ir_mode *value_mode = get_irn_mode(value);
 
-       if (value_mode == dest_mode || is_Bad(value))
+       if (value_mode == dest_mode)
                return value;
 
        if (dest_mode == mode_b) {
@@ -1940,7 +1950,7 @@ static ir_node *process_builtin_call(const call_expression_t *call)
 static ir_node *call_expression_to_firm(const call_expression_t *const call)
 {
        dbg_info *const dbgi = get_dbg_info(&call->base.source_position);
-       assert(get_cur_block() != NULL);
+       assert(currently_reachable());
 
        expression_t *function = call->function;
        if (function->kind == EXPR_REFERENCE) {
@@ -2657,7 +2667,7 @@ static ir_node *create_op(dbg_info *dbgi, const binary_expression_t *expression,
        case EXPR_BINARY_SHIFTRIGHT:
        case EXPR_BINARY_SHIFTLEFT_ASSIGN:
        case EXPR_BINARY_SHIFTRIGHT_ASSIGN:
-               mode  = get_irn_mode(left);
+               mode  = get_ir_mode_arithmetic(expression->base.type);
                right = create_conv(dbgi, right, mode_uint);
                break;
 
@@ -3317,7 +3327,6 @@ static ir_node *classify_type_to_firm(const classify_type_expression_t *const ex
                        /* gcc classifies the referenced type */
                        case TYPE_REFERENCE: type = type->reference.refers_to; continue;
 
-                       case TYPE_BUILTIN:
                        /* typedef/typeof should be skipped already */
                        case TYPE_TYPEDEF:
                        case TYPE_TYPEOF:
@@ -3711,14 +3720,8 @@ static ir_node *create_condition_evaluation(const expression_t *expression,
        if (is_builtin_expect(expression) && is_Cond(cond)) {
                call_argument_t *argument = expression->call.arguments->next;
                if (is_constant_expression(argument->expression) == EXPR_CLASS_CONSTANT) {
-                       bool             cnst = fold_constant_to_bool(argument->expression);
-                       cond_jmp_predicate pred;
-
-                       if (cnst == false) {
-                               pred = COND_JMP_PRED_FALSE;
-                       } else {
-                               pred = COND_JMP_PRED_TRUE;
-                       }
+                       bool               const cnst = fold_constant_to_bool(argument->expression);
+                       cond_jmp_predicate const pred = cnst ? COND_JMP_PRED_TRUE : COND_JMP_PRED_FALSE;
                        set_Cond_jmp_pred(cond, pred);
                }
        }
@@ -3726,7 +3729,7 @@ static ir_node *create_condition_evaluation(const expression_t *expression,
        add_immBlock_pred(true_block, true_proj);
        add_immBlock_pred(false_block, false_proj);
 
-       set_cur_block(NULL);
+       set_unreachable_now();
        return cond_expr;
 }
 
@@ -4498,7 +4501,7 @@ static void allocate_variable_length_array(entity_t *entity)
 {
        assert(entity->kind == ENTITY_VARIABLE);
        assert(entity->variable.initializer == NULL);
-       assert(get_cur_block() != NULL);
+       assert(currently_reachable());
 
        dbg_info *dbgi      = get_dbg_info(&entity->base.source_position);
        type_t   *type      = entity->declaration.type;
@@ -4593,7 +4596,7 @@ static void create_local_static_variable(entity_t *entity)
 
 static void return_statement_to_firm(return_statement_t *statement)
 {
-       if (get_cur_block() == NULL)
+       if (!currently_reachable())
                return;
 
        dbg_info *dbgi        = get_dbg_info(&statement->base.source_position);
@@ -4639,12 +4642,12 @@ static void return_statement_to_firm(return_statement_t *statement)
        ir_node *end_block = get_irg_end_block(current_ir_graph);
        add_immBlock_pred(end_block, ret);
 
-       set_cur_block(NULL);
+       set_unreachable_now();
 }
 
 static ir_node *expression_statement_to_firm(expression_statement_t *statement)
 {
-       if (get_cur_block() == NULL)
+       if (!currently_reachable())
                return NULL;
 
        return expression_to_firm(statement->expression);
@@ -4765,7 +4768,7 @@ static void initialize_local_declaration(entity_t *entity)
 
        // no need to emit code in dead blocks
        if (entity->declaration.storage_class != STORAGE_CLASS_STATIC
-                       && get_cur_block() == NULL)
+                       && !currently_reachable())
                return;
 
        switch ((declaration_kind_t) entity->declaration.kind) {
@@ -4822,7 +4825,7 @@ static void if_statement_to_firm(if_statement_t *statement)
        /* Create the condition. */
        ir_node *true_block  = NULL;
        ir_node *false_block = NULL;
-       if (get_cur_block() != NULL) {
+       if (currently_reachable()) {
                true_block  = new_immBlock();
                false_block = new_immBlock();
                create_condition_evaluation(statement->condition, true_block, false_block);
@@ -4839,7 +4842,7 @@ static void if_statement_to_firm(if_statement_t *statement)
                }
                set_cur_block(false_block);
                statement_to_firm(statement->false_statement);
-               if (get_cur_block() != NULL) {
+               if (currently_reachable()) {
                        fallthrough_block = new_immBlock();
                        add_immBlock_pred(fallthrough_block, new_Jmp());
                }
@@ -4850,7 +4853,7 @@ static void if_statement_to_firm(if_statement_t *statement)
        /* Create the true statement. */
        set_cur_block(true_block);
        statement_to_firm(statement->true_statement);
-       if (get_cur_block() != NULL) {
+       if (currently_reachable()) {
                if (fallthrough_block == NULL) {
                        fallthrough_block = new_immBlock();
                }
@@ -4868,9 +4871,8 @@ static void if_statement_to_firm(if_statement_t *statement)
  * reachable. */
 static void jump_if_reachable(ir_node *const target_block)
 {
-       if (get_cur_block() != NULL) {
-               add_immBlock_pred(target_block, new_Jmp());
-       }
+       ir_node *const pred = currently_reachable() ? new_Jmp() : new_Bad(mode_X);
+       add_immBlock_pred(target_block, pred);
 }
 
 static void while_statement_to_firm(while_statement_t *statement)
@@ -4977,7 +4979,7 @@ static void for_statement_to_firm(for_statement_t *statement)
                create_local_declaration(entity);
        }
 
-       if (get_cur_block() != NULL) {
+       if (currently_reachable()) {
                entity = statement->scope.entities;
                for ( ; entity != NULL; entity = entity->base.next) {
                        if (!is_declaration(entity))
@@ -5055,14 +5057,14 @@ static void for_statement_to_firm(for_statement_t *statement)
 static void create_jump_statement(const statement_t *statement,
                                   ir_node *target_block)
 {
-       if (get_cur_block() == NULL)
+       if (!currently_reachable())
                return;
 
        dbg_info *dbgi = get_dbg_info(&statement->base.source_position);
        ir_node  *jump = new_d_Jmp(dbgi);
        add_immBlock_pred(target_block, jump);
 
-       set_cur_block(NULL);
+       set_unreachable_now();
 }
 
 static void switch_statement_to_firm(switch_statement_t *statement)
@@ -5071,13 +5073,13 @@ static void switch_statement_to_firm(switch_statement_t *statement)
        dbg_info *dbgi        = get_dbg_info(&statement->base.source_position);
        ir_node  *cond        = NULL;
 
-       if (get_cur_block() != NULL) {
+       if (currently_reachable()) {
                ir_node *expression = expression_to_firm(statement->expression);
                cond                = new_d_Cond(dbgi, expression);
                first_block         = get_cur_block();
        }
 
-       set_cur_block(NULL);
+       set_unreachable_now();
 
        ir_node *const old_switch_cond       = current_switch_cond;
        ir_node *const old_break_label       = break_label;
@@ -5102,7 +5104,7 @@ static void switch_statement_to_firm(switch_statement_t *statement)
                        default_proj_nr = l->last_case;
        }
 
-       if (default_proj_nr == INT_MAX) {
+       if (default_proj_nr == LONG_MAX) {
                /* Bad: an overflow will occur, we cannot be sure that the
                 * maximum + 1 is a free number. Scan the values a second
                 * time to find a free number.
@@ -5216,7 +5218,7 @@ static void label_to_firm(const label_statement_t *statement)
 
 static void goto_to_firm(const goto_statement_t *statement)
 {
-       if (get_cur_block() == NULL)
+       if (!currently_reachable())
                return;
 
        if (statement->expression) {
@@ -5231,7 +5233,7 @@ static void goto_to_firm(const goto_statement_t *statement)
                ir_node *jmp   = new_Jmp();
                add_immBlock_pred(block, jmp);
        }
-       set_cur_block(NULL);
+       set_unreachable_now();
 }
 
 static void asm_statement_to_firm(const asm_statement_t *statement)
@@ -5802,7 +5804,7 @@ static void create_function(entity_t *entity)
        ir_graph *old_current_function = current_function;
        current_function = irg;
 
-       set_irg_fp_model(irg, firm_opt.fp_model);
+       set_irg_fp_model(irg, firm_fp_model);
        tarval_enable_fp_ops(1);
        set_irn_dbg_info(get_irg_start_block(irg),
                         get_entity_dbg_info(function_entity));
@@ -5823,7 +5825,7 @@ static void create_function(entity_t *entity)
        ir_node *end_block = get_irg_end_block(irg);
 
        /* do we have a return statement yet? */
-       if (get_cur_block() != NULL) {
+       if (currently_reachable()) {
                type_t *type = skip_typeref(entity->declaration.type);
                assert(is_type_function(type));
                const function_type_t *func_type   = &type->function;