- Fixed masking of upper nibble of bitfield constants for tarval string output.
authorMoritz Kroll <Moritz.Kroll@gmx.de>
Mon, 2 Mar 2009 16:05:56 +0000 (16:05 +0000)
committerMoritz Kroll <Moritz.Kroll@gmx.de>
Mon, 2 Mar 2009 16:05:56 +0000 (16:05 +0000)
- Report an error if reading a tarval string with unappropriate characters
  for the base indicated by the base prefix
- Use "0x" prefix, when writing irms_int_number native (hex) values.

[r25594]

ir/tv/strcalc.c
ir/tv/tv.c

index 0ea940a..804a071 100644 (file)
@@ -1019,7 +1019,7 @@ void sc_val_from_str(const char *str, unsigned int len, void *buffer, ir_mode *m
                case 'c':
                case 'b':
                case 'a':
-                       if (base[0] > SC_9 || base[1] > SC_0) { /* (base > 10) */
+                       if (base[0] > SC_A || base[1] > SC_0) { /* (base > 10) */
                                val[0] = _digit((*str)-'a'+10);
                        }
                        else
@@ -1032,7 +1032,7 @@ void sc_val_from_str(const char *str, unsigned int len, void *buffer, ir_mode *m
                case 'C':
                case 'B':
                case 'A':
-                       if (base[0] > SC_9 || base[1] > SC_0) { /* (base > 10) */
+                       if (base[0] > SC_A || base[1] > SC_0) { /* (base > 10) */
                                val[0] = _digit((*str)-'A'+10);
                        }
                        else
@@ -1041,7 +1041,7 @@ void sc_val_from_str(const char *str, unsigned int len, void *buffer, ir_mode *m
 
                case '9':
                case '8':
-                       if (base[0] > SC_7 || base[1] > SC_0) { /* (base > 8) */
+                       if (base[0] > SC_8 || base[1] > SC_0) { /* (base > 8) */
                                val[0] = _digit((*str)-'0');
                        }
                        else
@@ -1372,7 +1372,7 @@ const char *sc_print(const void *value, unsigned bits, enum base_t base, int sig
 
                /* last nibble must be masked */
                if (bits & 3) {
-                       mask = zex_digit[bits & 3];
+                       mask = zex_digit[(bits & 3) - 1];
                        x = and_table[_val(val[counter++])][mask];
                        *(--pos) = digits[_val(x)];
                }
@@ -1399,7 +1399,7 @@ const char *sc_print(const void *value, unsigned bits, enum base_t base, int sig
 
                /* last nibble must be masked */
                if (bits & 3) {
-                       mask = zex_digit[bits & 3];
+                       mask = zex_digit[(bits & 3) - 1];
                        x = and_table[_val(val[counter++])][mask];
 
                        pos -= 4;
@@ -1439,7 +1439,7 @@ const char *sc_print(const void *value, unsigned bits, enum base_t base, int sig
 
                /* last nibble must be masked */
                if (bits & 3) {
-                       mask = zex_digit[bits & 3];
+                       mask = zex_digit[(bits & 3) - 1];
                        div1_res[counter] = and_table[_val(p[counter])][mask];
                        ++counter;
                }
index 41442e6..49ec584 100644 (file)
@@ -1451,8 +1451,9 @@ int tarval_snprintf(char *buf, size_t len, tarval *tv) {
                        str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_OCT, 0);
                        break;
 
-               case TVO_HEX:
                case TVO_NATIVE:
+                       prefix = "0x";
+               case TVO_HEX:
                default:
                        str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_HEX, 0);
                        break;