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);
/* 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;
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
*/
*/
int tarval_is_double(tarval *tv);
-/**
- * Construct a tarval that represents the address of the entity.
- *
- * The address must be constant, the entity must have as owner the global type.
- * We no more support this function: Use the new SymConst instead.
-tarval *new_tarval_from_entity (entity *ent, ir_mode *mode);
- */
-
-/**
- * Returns the associated entity of a tarval. Asserts if tarval does not
- * contain an entity.
-entity *get_tarval_entity(tarval *tv);
- */
-
-/**
- * Returns non-zero if a the given tarval represents an entity.
-int tarval_is_entity(tarval *tv);
- */
/** ********** Access routines for tarval fields ********** **/
/* ******************** Arithmethic operations on tarvals ******************** */
+typedef enum _tarval_int_overflow_mode_t {
+ TV_OVERFLOW_BAD, /**< tarval module will return tarval_bad if a overflow occurs */
+ TV_OVERFLOW_WRAP, /**< tarval module will overflow will be ignored, wrap around occurs */
+ TV_OVERFLOW_SATURATE /**< tarval module will saturate the overflow */
+} tarval_int_overflow_mode_t;
+
+/**
+ * Sets the overflow mode for integer operations.
+ */
+void tarval_set_integer_overflow_mode(tarval_int_overflow_mode_t ov_mode);
+
+/**
+ * Get the overflow mode for integer operations.
+ */
+tarval_int_overflow_mode_t tarval_get_integer_overflow_mode(void);
+
/**
* Compares two tarvals
*
/** Rotation. */
tarval *tarval_rot(tarval *a, tarval *b);
+/** Carry flag of the last operation */
+int tarval_carry(void);
+
/* *********** Output of tarvals *********** */
/**