Adapted tokens.inc for Cygwin and MinGW
[cparser] / ast2firm.c
index f8f7f5e..581b983 100644 (file)
@@ -201,7 +201,7 @@ static void init_atomic_modes(void)
        mode_uint = atomic_modes[ATOMIC_TYPE_UINT];
 
        /* there's no real void type in firm */
-       atomic_modes[ATOMIC_TYPE_VOID] = mode_int;
+       atomic_modes[ATOMIC_TYPE_VOID] = atomic_modes[ATOMIC_TYPE_CHAR];
 
        /* initialize pointer modes */
        char            name[64];
@@ -1596,6 +1596,8 @@ static ir_node *process_builtin_call(const call_expression_t *call)
                return _expression_to_firm(argument);
        }
        case T___builtin_va_end:
+               /* evaluate the argument of va_end for its side effects */
+               _expression_to_firm(call->arguments->expression);
                return NULL;
        default:
                panic("Unsupported builtin found\n");
@@ -2392,12 +2394,24 @@ static ir_node *create_lazy_op(const binary_expression_t *expression)
                long val = fold_constant(expression->left);
                expression_kind_t ekind = expression->base.kind;
                assert(ekind == EXPR_BINARY_LOGICAL_AND || ekind == EXPR_BINARY_LOGICAL_OR);
-               if ((ekind == EXPR_BINARY_LOGICAL_AND && val != 0) ||
-                   (ekind == EXPR_BINARY_LOGICAL_OR  && val == 0)) {
-                       return produce_condition_result(expression->right, mode, dbgi);
+               if (ekind == EXPR_BINARY_LOGICAL_AND) {
+                       if (val == 0) {
+                               return new_Const(get_mode_null(mode));
+                       }
                } else {
-                       return new_Const(get_mode_one(mode));
+                       if (val != 0) {
+                               return new_Const(get_mode_one(mode));
+                       }
+               }
+
+               if (is_constant_expression(expression->right)) {
+                       long const valr = fold_constant(expression->left);
+                       return valr != 0 ?
+                               new_Const(get_mode_one(mode)) :
+                               new_Const(get_mode_null(mode));
                }
+
+               return produce_condition_result(expression->right, mode, dbgi);
        }
 
        return produce_condition_result((const expression_t*) expression, mode,
@@ -2766,13 +2780,17 @@ static ir_node *select_addr(const select_expression_t *expression)
        entity_t *entry = expression->compound_entry;
        assert(entry->kind == ENTITY_COMPOUND_MEMBER);
        assert(entry->declaration.kind == DECLARATION_KIND_COMPOUND_MEMBER);
-       ir_entity *irentity = entry->compound_member.entity;
-
-       assert(irentity != NULL);
-
-       ir_node *sel = new_d_simpleSel(dbgi, new_NoMem(), compound_addr, irentity);
 
-       return sel;
+       if (constant_folding) {
+               ir_mode *mode = get_irn_mode(compound_addr);
+               /* FIXME: here, we need an integer mode with the same number of bits as mode */
+               ir_node *ofs  = new_Const_long(mode_uint, entry->compound_member.offset);
+               return new_d_Add(dbgi, compound_addr, ofs, mode);
+       } else {
+               ir_entity *irentity = entry->compound_member.entity;
+               assert(irentity != NULL);
+               return new_d_simpleSel(dbgi, new_NoMem(), compound_addr, irentity);
+       }
 }
 
 static ir_node *select_to_firm(const select_expression_t *expression)
@@ -2983,17 +3001,18 @@ static ir_node *dereference_addr(const unary_expression_t *const expression)
 static ir_node *expression_to_addr(const expression_t *expression)
 {
        switch(expression->kind) {
-       case EXPR_REFERENCE:
-               return reference_addr(&expression->reference);
        case EXPR_ARRAY_ACCESS:
                return array_access_addr(&expression->array_access);
-       case EXPR_SELECT:
-               return select_addr(&expression->select);
        case EXPR_CALL:
                return call_expression_to_firm(&expression->call);
-       case EXPR_UNARY_DEREFERENCE: {
+       case EXPR_COMPOUND_LITERAL:
+               return compound_literal_to_firm(&expression->compound_literal);
+       case EXPR_REFERENCE:
+               return reference_addr(&expression->reference);
+       case EXPR_SELECT:
+               return select_addr(&expression->select);
+       case EXPR_UNARY_DEREFERENCE:
                return dereference_addr(&expression->unary);
-       }
        default:
                break;
        }
@@ -3298,9 +3317,7 @@ static ir_node *create_condition_evaluation(const expression_t *expression,
        }
 
        add_immBlock_pred(true_block, true_proj);
-       if (false_block != NULL) {
-               add_immBlock_pred(false_block, false_proj);
-       }
+       add_immBlock_pred(false_block, false_proj);
 
        set_cur_block(NULL);
        return cond_expr;
@@ -4480,9 +4497,7 @@ static void do_while_statement_to_firm(do_while_statement_t *statement)
        create_condition_evaluation(statement->condition, body_block, false_block);
        mature_immBlock(body_block);
        mature_immBlock(header_block);
-       if (false_block != NULL) {
-               mature_immBlock(false_block);
-       }
+       mature_immBlock(false_block);
 
        set_cur_block(false_block);
 }
@@ -4535,7 +4550,7 @@ static void for_statement_to_firm(for_statement_t *statement)
        ir_node *const false_block = new_immBlock();
 
        /* the loop body */
-       ir_node * body_block;
+       ir_node *body_block;
        if (statement->body != NULL) {
                ir_node *const old_continue_label = continue_label;
                ir_node *const old_break_label    = break_label;