cleanup: Remove unnecessary #include "beirg.h".
[libfirm] / ir / tv / tv.c
index b6bb770..8552fc8 100644 (file)
@@ -77,11 +77,11 @@ static float_to_int_mode current_float_to_int_mode = TRUNCATE;
 #  define TARVAL_VERIFY(a) ((void)0)
 #endif
 
-#define INSERT_TARVAL(tv) ((ir_tarval*)set_insert(tarvals, (tv), sizeof(ir_tarval), hash_tv((tv))))
-#define FIND_TARVAL(tv) ((ir_tarval*)set_find(tarvals, (tv), sizeof(ir_tarval), hash_tv((tv))))
+#define INSERT_TARVAL(tv) (set_insert(ir_tarval, tarvals, (tv), sizeof(ir_tarval), hash_tv((tv))))
+#define FIND_TARVAL(tv) (set_find(ir_tarval, tarvals, (tv), sizeof(ir_tarval), hash_tv((tv))))
 
-#define INSERT_VALUE(val, size) (set_insert(values, (val), size, hash_val((val), size)))
-#define FIND_VALUE(val, size) (set_find(values, (val), size, hash_val((val), size)))
+#define INSERT_VALUE(val, size) (set_insert(char, values, (val), size, hash_val((val), size)))
+#define FIND_VALUE(val, size) (set_find(char, values, (val), size, hash_val((val), size)))
 
 #define fail_verify(a) _fail_verify((a), __FILE__, __LINE__)
 
@@ -199,7 +199,7 @@ static ir_tarval *get_tarval(const void *value, size_t length, ir_mode *mode)
        }
        /* if there is such a tarval, it is returned, else tv is copied
         * into the set */
-       return (ir_tarval *)INSERT_TARVAL(&tv);
+       return INSERT_TARVAL(&tv);
 }
 
 /**
@@ -344,6 +344,10 @@ static ir_tarval *new_tarval_from_str_int(const char *str, size_t len,
                        str += 2;
                        len -= 2;
                        base = 16;
+               } else if (str[1] == 'b' || str[1] == 'B') {
+                       str += 2;
+                       len -= 2;
+                       base = 2;
                } else {
                        ++str;
                        --len;
@@ -1287,6 +1291,17 @@ ir_tarval *tarval_shl(ir_tarval *a, ir_tarval *b)
        return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
 }
 
+ir_tarval *tarval_shl_unsigned(ir_tarval *a, unsigned b)
+{
+       ir_mode *mode   = a->mode;
+       unsigned modulo = get_mode_modulo_shift(mode);
+       if (modulo != 0)
+               b %= modulo;
+       assert((unsigned)(long)b==b);
+       sc_shlI(a->value, (long)b, get_mode_size_bits(mode), mode_is_signed(mode), NULL);
+       return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
+}
+
 /*
  * bitwise unsigned right shift
  */
@@ -1310,6 +1325,17 @@ ir_tarval *tarval_shr(ir_tarval *a, ir_tarval *b)
        return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
 }
 
+ir_tarval *tarval_shr_unsigned(ir_tarval *a, unsigned b)
+{
+       ir_mode *mode   = a->mode;
+       unsigned modulo = get_mode_modulo_shift(mode);
+       if (modulo != 0)
+               b %= modulo;
+       assert((unsigned)(long)b==b);
+       sc_shrI(a->value, (long)b, get_mode_size_bits(mode), mode_is_signed(mode), NULL);
+       return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
+}
+
 /*
  * bitwise signed right shift
  */
@@ -1333,6 +1359,17 @@ ir_tarval *tarval_shrs(ir_tarval *a, ir_tarval *b)
        return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
 }
 
+ir_tarval *tarval_shrs_unsigned(ir_tarval *a, unsigned b)
+{
+       ir_mode *mode   = a->mode;
+       unsigned modulo = get_mode_modulo_shift(mode);
+       if (modulo != 0)
+               b %= modulo;
+       assert((unsigned)(long)b==b);
+       sc_shrsI(a->value, (long)b, get_mode_size_bits(mode), mode_is_signed(mode), NULL);
+       return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
+}
+
 /*
  * bitwise rotation to left
  */
@@ -1437,7 +1474,16 @@ int tarval_snprintf(char *buf, size_t len, ir_tarval *tv)
                }
 
        default:
-               return snprintf(buf, len, "<TV_??""?>");
+               if (tv == tarval_bad)
+                       return snprintf(buf, len, "<TV_BAD>");
+               else if (tv == tarval_undefined)
+                       return snprintf(buf, len, "<TV_UNDEFINED>");
+               else if (tv == tarval_reachable)
+                       return snprintf(buf, len, "<TV_REACHABLE>");
+               else if (tv == tarval_unreachable)
+                       return snprintf(buf, len, "<TV_UNREACHABLE>");
+               else
+                       return snprintf(buf, len, "<TV_??""?>");
        }
 }
 
@@ -1487,7 +1533,7 @@ unsigned char get_tarval_sub_bits(ir_tarval *tv, unsigned byte_ofs)
        case irma_x86_extended_float:
                return fc_sub_bits((const fp_value*) tv->value, get_mode_size_bits(tv->mode), byte_ofs);
        default:
-               panic("get_tarval_sub_bits(): arithmetic mode not supported");
+               panic("arithmetic mode not supported");
        }
 }