target values */
#define N_CONSTANTS 2048
-/* XXX hack until theres's a proper interface */
-#define BAD 1
-#define SATURATE 2
-#define WRAP 3
-#define GET_OVERFLOW_MODE() BAD
+/* get the integer overflow mode */
+#define GET_OVERFLOW_MODE() int_overflow_mode
/* unused, float to int doesn't work yet */
#define TRUNCATE 1
****************************************************************************/
static struct set *tarvals; /* container for tarval structs */
static struct set *values; /* container for values */
+static tarval_int_overflow_mode_t int_overflow_mode = TV_OVERFLOW_WRAP;
/****************************************************************************
* private functions
return (tarval *)INSERT_TARVAL(&tv);
}
+/**
+ * handle overflow
+ */
static tarval *get_tarval_overflow(const void *value, int length, ir_mode *mode)
{
switch (get_mode_sort(mode))
case irms_int_number:
if (sc_comp(value, get_mode_max(mode)->value) == 1) {
switch (GET_OVERFLOW_MODE()) {
- case SATURATE:
+ case TV_OVERFLOW_SATURATE:
return get_mode_max(mode);
- case WRAP:
+ case TV_OVERFLOW_WRAP:
{
char *temp = alloca(sc_get_buffer_length());
char *diff = alloca(sc_get_buffer_length());
sc_sub(temp, diff, temp);
return get_tarval(temp, length, mode);
}
- case BAD:
+ case TV_OVERFLOW_BAD:
return tarval_bad;
default:
return get_tarval(value, length, mode);
}
if (sc_comp(value, get_mode_min(mode)->value) == -1) {
switch (GET_OVERFLOW_MODE()) {
- case SATURATE:
+ case TV_OVERFLOW_SATURATE:
return get_mode_min(mode);
- case WRAP:
+ case TV_OVERFLOW_WRAP:
{
char *temp = alloca(sc_get_buffer_length());
char *diff = alloca(sc_get_buffer_length());
sc_add(temp, diff, temp);
return get_tarval(temp, length, mode);
}
- case BAD:
+ case TV_OVERFLOW_BAD:
return tarval_bad;
default:
return get_tarval(value, length, mode);
ANNOUNCE();
assert(tarval_is_long(tv) && "tarval too big to fit in long");
- return sc_val_to_long(tv->value);
+ return sc_val_to_long(tv->value, get_mode_size_bits(tv->mode), mode_is_signed(tv->mode));
}
tarval *new_tarval_from_double(long double d, ir_mode *mode)
/* cast float to something */
case irms_float_number:
switch (get_mode_sort(m)) {
- case irms_float_number:
+ case irms_float_number:
switch (get_mode_size_bits(m))
{
case 32:
break;
}
return get_tarval(fc_get_buffer(), fc_get_buffer_length(), m);
- break;
case irms_int_number:
switch (GET_FLOAT_TO_INT_MODE())
* an intermediate representation is needed here first. */
/* return get_tarval(); */
return tarval_bad;
- break;
default:
/* the rest can't be converted */
ANNOUNCE();
assert(a);
assert(mode_is_num(a->mode)); /* negation only for numerical values */
- assert(mode_is_signed(a->mode)); /* negation is difficult without negative numbers, isn't it */
+
+ /* note: negation is allowed even for unsigned modes. */
if (get_mode_n_vector_elems(a->mode) > 1) {
/* vector arithmetic not implemented yet */
ANNOUNCE();
assert(a);
assert(b);
- assert((a->mode == b->mode) || (get_mode_sort(a->mode) == irms_character && mode_is_int(b->mode)));
+ assert(a->mode == b->mode);
if (get_mode_n_vector_elems(a->mode) > 1 || get_mode_n_vector_elems(b->mode) > 1) {
/* vector arithmetic not implemented yet */
ANNOUNCE();
assert(a);
assert(b);
- assert((a->mode == b->mode) || (get_mode_sort(a->mode) == irms_character && mode_is_int(b->mode)));
+ assert(a->mode == b->mode);
if (get_mode_n_vector_elems(a->mode) > 1 || get_mode_n_vector_elems(b->mode) > 1) {
/* vector arithmetic not implemented yet */
ANNOUNCE();
assert(a);
assert(b);
- assert((a->mode == b->mode) && mode_is_num(a->mode));
+ assert(a->mode == b->mode);
if (get_mode_n_vector_elems(a->mode) > 1) {
/* vector arithmetic not implemented yet */
return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
}
+/*
+ * carry flag of the last operation
+ */
+int tarval_carry(void)
+{
+ return sc_had_carry();
+}
/*
* Output of tarvals
case irms_control_flow:
case irms_memory:
case irms_auxiliary:
- return snprintf(buf, len, "<BAD>");
+ return snprintf(buf, len, "<TV_OVERFLOW_BAD>");
}
return 0;
char *get_tarval_bitpattern(tarval *tv)
{
- return NULL;
+ int i, j, pos = 0;
+ int n = get_mode_size_bits(tv->mode);
+ int bytes = (n + 7) / 8;
+ char *res = malloc((n + 1) * sizeof(char));
+ unsigned char byte;
+
+ for(i = 0; i < bytes; i++) {
+ byte = get_tarval_sub_bits(tv, i);
+ for(j = 1; j < 256; j <<= 1)
+ if(pos < n)
+ res[pos++] = j & byte ? '1' : '0';
+ }
+
+ res[n] = '\0';
+
+ return res;
}
/*
return TV_CLASSIFY_OTHER;
}
+/**
+ * Sets the overflow mode for integer operations.
+ */
+void tarval_set_integer_overflow_mode(tarval_int_overflow_mode_t ov_mode) {
+ int_overflow_mode = ov_mode;
+}
+
+/**
+ * Get the overflow mode for integer operations.
+ */
+tarval_int_overflow_mode_t tarval_get_integer_overflow_mode(void) {
+ return int_overflow_mode;
+}
+
/**
* default mode_info for output as HEX
*/