Use fold_constant_to_tarval() instead of reimplementing it badly, i.e. failing with...
authorChristoph Mallon <christoph.mallon@gmx.de>
Tue, 17 Apr 2012 10:12:36 +0000 (12:12 +0200)
committerChristoph Mallon <christoph.mallon@gmx.de>
Tue, 17 Apr 2012 10:17:05 +0000 (12:17 +0200)
ast2firm.c

index 5e55bc2..05b553e 100644 (file)
@@ -618,15 +618,14 @@ static ir_type *create_compound_type(compound_type_t *type,
        return irtype;
 }
 
+static ir_tarval *fold_constant_to_tarval(expression_t const *);
+
 static void determine_enum_values(enum_type_t *const type)
 {
        ir_mode   *const mode    = atomic_modes[type->base.akind];
        ir_tarval *const one     = get_mode_one(mode);
        ir_tarval *      tv_next = get_mode_null(mode);
 
-       bool constant_folding_old = constant_folding;
-       constant_folding = true;
-
        enum_t   *enume = type->enume;
        entity_t *entry = enume->base.next;
        for (; entry != NULL; entry = entry->base.next) {
@@ -635,18 +634,12 @@ static void determine_enum_values(enum_type_t *const type)
 
                expression_t *const init = entry->enum_value.value;
                if (init != NULL) {
-                       ir_node *const cnst = expression_to_firm(init);
-                       if (!is_Const(cnst)) {
-                               panic("couldn't fold constant");
-                       }
-                       tv_next = get_Const_tarval(cnst);
+                       tv_next = fold_constant_to_tarval(init);
                }
                assert(entry->enum_value.tv == NULL || entry->enum_value.tv == tv_next);
                entry->enum_value.tv = tv_next;
                tv_next = tarval_add(tv_next, one);
        }
-
-       constant_folding = constant_folding_old;
 }
 
 static ir_type *create_enum_type(enum_type_t *const type)