fix mips immediate dumper
[libfirm] / ir / tv / tv.c
index 08750fe..964af56 100644 (file)
@@ -100,6 +100,8 @@ static struct set *tarvals = NULL;   /* container for tarval structs */
 static struct set *values = NULL;    /* container for values */
 static tarval_int_overflow_mode_t int_overflow_mode = TV_OVERFLOW_WRAP;
 
+#define no_float 0
+
 /****************************************************************************
  *   private functions
  ****************************************************************************/
@@ -330,7 +332,7 @@ int tarval_is_long(tarval *tv) {
 
        if (sort != irms_int_number && sort != irms_character) return 0;
 
-       if (get_mode_size_bits(tv->mode) > (sizeof(long) << 3)) {
+       if (get_mode_size_bits(tv->mode) > (int) (sizeof(long) << 3)) {
                /* the value might be too big to fit in a long */
                sc_max_from_bits(sizeof(long) << 3, 0, NULL);
                if (sc_comp(sc_get_buffer(), tv->value) == -1) {
@@ -747,6 +749,8 @@ pn_Cmp tarval_cmp(tarval *a, tarval *b) {
                return pn_Cmp_False;
 
        case irms_float_number:
+               if(no_float)
+                       return pn_Cmp_False;
                /*
                 * BEWARE: we cannot compare a == b here, because
                 * a NaN is always Unordered to any other value, even to itself!
@@ -845,7 +849,7 @@ tarval *tarval_convert_to(tarval *src, ir_mode *m) {
                case irms_character:
                        buffer = alloca(sc_get_buffer_length());
                        memcpy(buffer, src->value, sc_get_buffer_length());
-                       sign_extend(buffer, src->mode);
+                       sign_extend(buffer, m);
                        return get_tarval_overflow(buffer, src->length, m);
 
                case irms_internal_boolean:
@@ -899,6 +903,16 @@ tarval *tarval_convert_to(tarval *src, ir_mode *m) {
                break;
 
        case irms_reference:
+               switch(get_mode_sort(m)) {
+               case irms_int_number:
+                       buffer = alloca(sc_get_buffer_length());
+                       memcpy(buffer, src->value, sc_get_buffer_length());
+                       sign_extend(buffer, src->mode);
+                       return get_tarval_overflow(buffer, src->length, m);
+               default:
+                       break;
+               }
+
                break;
        }
 
@@ -957,6 +971,9 @@ tarval *tarval_neg(tarval *a) {
                return get_tarval_overflow(buffer, a->length, a->mode);
 
        case irms_float_number:
+               if(no_float)
+                       return tarval_bad;
+
                fc_neg(a->value, NULL);
                return get_tarval_overflow(fc_get_buffer(), fc_get_buffer_length(), a->mode);
 
@@ -989,6 +1006,9 @@ tarval *tarval_add(tarval *a, tarval *b) {
                return get_tarval_overflow(buffer, a->length, a->mode);
 
        case irms_float_number:
+               if(no_float)
+                       return tarval_bad;
+
                fc_add(a->value, b->value, NULL);
                return get_tarval_overflow(fc_get_buffer(), fc_get_buffer_length(), a->mode);
 
@@ -1020,6 +1040,9 @@ tarval *tarval_sub(tarval *a, tarval *b) {
                return get_tarval_overflow(buffer, a->length, a->mode);
 
        case irms_float_number:
+               if(no_float)
+                       return tarval_bad;
+
                fc_sub(a->value, b->value, NULL);
                return get_tarval_overflow(fc_get_buffer(), fc_get_buffer_length(), a->mode);
 
@@ -1051,6 +1074,9 @@ tarval *tarval_mul(tarval *a, tarval *b) {
                return get_tarval_overflow(buffer, a->length, a->mode);
 
        case irms_float_number:
+               if(no_float)
+                       return tarval_bad;
+
                fc_mul(a->value, b->value, NULL);
                return get_tarval_overflow(fc_get_buffer(), fc_get_buffer_length(), a->mode);
 
@@ -1067,6 +1093,9 @@ tarval *tarval_quo(tarval *a, tarval *b) {
        assert(b);
        assert((a->mode == b->mode) && mode_is_float(a->mode));
 
+       if(no_float)
+               return tarval_bad;
+
        if (get_mode_n_vector_elems(a->mode) > 1) {
                /* vector arithmetic not implemented yet */
                return tarval_bad;
@@ -1142,6 +1171,9 @@ tarval *tarval_abs(tarval *a) {
                return a;
 
        case irms_float_number:
+               if(no_float)
+                       return tarval_bad;
+
                if (fc_comp(a->value, get_mode_null(a->mode)->value) == -1) {
                        fc_neg(a->value, NULL);
                        return get_tarval_overflow(fc_get_buffer(), fc_get_buffer_length(), a->mode);
@@ -1428,7 +1460,7 @@ int tarval_printf(tarval *tv) {
        int res;
 
        res = tarval_snprintf(buf, sizeof(buf), tv);
-       assert(res < sizeof(buf) && "buffer to small for tarval_snprintf");
+       assert(res < (int) sizeof(buf) && "buffer to small for tarval_snprintf");
        printf(buf);
        return res;
 }