if (length > 0) {
/* if there already is such a value, it is returned, else value
* is copied into the set */
- char *temp = alloca(sc_get_buffer_length());
- memcpy(temp, value, sc_get_buffer_length());
- sign_extend(temp, mode);
+ char *temp = alloca(length);
+ memcpy(temp, value, length);
+ if (get_mode_arithmetic(mode) == irma_twos_complement) {
+ sign_extend(temp, mode);
+ }
tv.value = INSERT_VALUE(temp, length);
} else {
tv.value = value;
case irms_control_flow:
case irms_memory:
case irms_auxiliary:
- case irms_internal_boolean:
assert(0);
break;
case irms_float_number:
return new_tarval_from_double(0.0, mode);
+ case irms_internal_boolean:
case irms_int_number:
return new_tarval_from_long(0l, mode);
* test if null, 1 means 'yes'
*/
int tarval_is_null(tarval *a) {
- ir_mode *m = get_tarval_mode(a);
-
- return a == get_tarval_null(m);
+ return
+ a != tarval_bad &&
+ a == get_tarval_null(get_tarval_mode(a));
}
/*
* test if one, 1 means 'yes'
*/
int tarval_is_one(tarval *a) {
- ir_mode *m = get_tarval_mode(a);
+ return
+ a != tarval_bad &&
+ a == get_tarval_one(get_tarval_mode(a));
+}
- return a == get_tarval_one(m);
+int tarval_is_all_one(tarval *tv) {
+ return
+ tv != tarval_bad &&
+ tv == get_mode_all_one(get_tarval_mode(tv));
}
/*
return mode->tv_priv;
}
-/*
- * Identifying tarvals values for algebraic simplifications.
- *
- * Returns:
- * - TV_CLASSIFY_NULL for additive neutral or the NULL tarval for reference modes,
- * - TV_CLASSIFY_ONE for multiplicative neutral,
- * - TV_CLASSIFY_ALL_ONE for bitwise-and neutral
- * - TV_CLASSIFY_OTHER else
- */
-tarval_classification_t classify_tarval(tarval *tv) {
- if (!tv || tv == tarval_bad) return TV_CLASSIFY_OTHER;
-
- if (tv == get_mode_null(tv->mode))
- return TV_CLASSIFY_NULL;
- else if (tv == get_mode_one(tv->mode))
- return TV_CLASSIFY_ONE;
- else if (tv == get_mode_all_one(tv->mode))
- return TV_CLASSIFY_ALL_ONE;
-
- return TV_CLASSIFY_OTHER;
-}
-
/*
* Returns non-zero if a given (integer) tarval has only one single bit
* set.