Fixed boolean value of Proj(Cmp) againm, old version did not work as expected ...
[libfirm] / ir / tv / strcalc.c
index dd2e6a3..ec80238 100644 (file)
 #define fail_char(a, b, c, d) _fail_char((a), (b), (c), (d), __FILE__,  __LINE__)
 
 /* shortcut output for debugging */
-#  define sc_print_hex(a) sc_print((a), 0, SC_HEX)
-#  define sc_print_dec(a) sc_print((a), 0, SC_DEC)
-#  define sc_print_oct(a) sc_print((a), 0, SC_OCT)
-#  define sc_print_bin(a) sc_print((a), 0, SC_BIN)
+#  define sc_print_hex(a) sc_print((a), 0, SC_HEX, 0)
+#  define sc_print_dec(a) sc_print((a), 0, SC_DEC, 1)
+#  define sc_print_oct(a) sc_print((a), 0, SC_OCT, 0)
+#  define sc_print_bin(a) sc_print((a), 0, SC_BIN, 0)
 
 #ifdef STRCALC_DEBUG_PRINTCOMP
 #  define DEBUGPRINTF_COMPUTATION(x) printf x
@@ -850,7 +850,6 @@ static void _shr(const char *val1, char *buffer, long offset, int radius, unsign
   int bitoffset = 0;
 
   assert((offset >= 0) || (0 && "negative rightshift"));
-  assert(((_sign(val1) != -1) || is_signed) || (0 && "unsigned mode and negative value"));
   assert(((!_bitisset(val1[(radius-1)/4], (radius-1)%4)) || !is_signed || (_sign(val1) == -1)) || (0 && "value is positive, should be negative"));
   assert(((_bitisset(val1[(radius-1)/4], (radius-1)%4)) || !is_signed || (_sign(val1) == 1)) || (0 && "value is negative, should be positive"));
 
@@ -975,7 +974,7 @@ void sign_extend(char *calc_buffer, ir_mode *mode) {
 
       for (i = ofs + 1; i < calc_buffer_size; ++i)
         calc_buffer[i] = SC_F;
-      calc_buffer[ofs] = or_table[calc_buffer[ofs]][sex_digit[bits & 3]];
+      calc_buffer[ofs] = or_table[(int) calc_buffer[ofs]][(int) sex_digit[bits & 3]];
     }
   }
 }
@@ -1445,7 +1444,7 @@ unsigned char sc_sub_bits(const void *value, int len, unsigned byte_ofs)
  * convert to a string
  * FIXME: Doesn't check buffer bounds
  */
-const char *sc_print(const void *value, unsigned bits, enum base_t base)
+const char *sc_print(const void *value, unsigned bits, enum base_t base, int signed_mode)
 {
   static const char big_digits[]   = "0123456789ABCDEF";
   static const char small_digits[] = "0123456789abcdef";
@@ -1463,7 +1462,7 @@ const char *sc_print(const void *value, unsigned bits, enum base_t base)
   base_val = alloca(calc_buffer_size);
   div1_res = alloca(calc_buffer_size);
   div2_res = alloca(calc_buffer_size);
-  rem_res = alloca(calc_buffer_size);
+  rem_res  = alloca(calc_buffer_size);
 
   pos = output_buffer + bit_pattern_size;
   *(--pos) = '\0';
@@ -1540,7 +1539,7 @@ const char *sc_print(const void *value, unsigned bits, enum base_t base)
 
     p    = val;
     sign = 0;
-    if (base == SC_DEC) {
+    if (signed_mode && base == SC_DEC) {
       /* check for negative values */
       if (_bit(val, bits - 1)) {
         _negate(val, div2_res);
@@ -1571,7 +1570,7 @@ const char *sc_print(const void *value, unsigned bits, enum base_t base)
       *(--pos) = digits[_val(rem_res[0])];
 
       x = 0;
-      for (i = 0; i < sizeof(div1_res); ++i)
+      for (i = 0; i < calc_buffer_size; ++i)
        x |= _val(m[i]);
 
       if (x == 0)