/****************************************************************************
* private variables
****************************************************************************/
-static struct set *tarvals; /* container for tarval structs */
-static struct set *values; /* container for values */
+static struct set *tarvals = NULL; /* container for tarval structs */
+static struct set *values = NULL; /* container for values */
static tarval_int_overflow_mode_t int_overflow_mode = TV_OVERFLOW_WRAP;
/****************************************************************************
}
#endif /* NDEBUG */
-static int hash_tv(tarval *tv)
-{
+/** Hash a tarval. */
+static int hash_tv(tarval *tv) {
return (PTR_TO_INT(tv->value) ^ PTR_TO_INT(tv->mode)) + tv->length;
}
-static int hash_val(const void *value, unsigned int length)
-{
+/** Hash a value. Treat it as a byte array. */
+static int hash_val(const void *value, unsigned int length) {
unsigned int i;
unsigned int hash = 0;
char *temp = alloca(sc_get_buffer_length());
sc_val_from_ulong(-1, temp);
sc_and(temp, value, temp);
+ /* the sc_ module expects that all bits are set ... */
+ sign_extend(temp, mode);
return get_tarval(temp, length, mode);
}
case TV_OVERFLOW_BAD:
switch (get_mode_sort(m)) {
case irms_int_number:
case irms_character:
- return get_tarval_overflow(src->value, src->length, m);
+ buffer = alloca(sc_get_buffer_length());
+ memcpy(buffer, src->value, sc_get_buffer_length());
+ sign_extend(buffer, src->mode);
+ return get_tarval_overflow(buffer, src->length, m);
case irms_internal_boolean:
/* XXX C semantics */
/* decimal string representation because hexadecimal output is
* interpreted unsigned by fc_val_from_str, so this is a HACK */
snprintf(buffer, 100, "%s",
- sc_print(src->value, get_mode_size_bits(src->mode), SC_DEC));
+ sc_print(src->value, get_mode_size_bits(src->mode), SC_DEC, mode_is_signed(src->mode)));
+ buffer[100 - 1] = '\0';
switch (get_mode_size_bits(m))
{
case 32:
switch (get_mode_sort(tv->mode))
{
+ case irms_reference:
+ if (tv == tv->mode->null) return snprintf(buf, len, "NULL");
+ /* fall through */
case irms_int_number:
case irms_character:
switch (mode_info->mode_output) {
case TVO_DECIMAL:
- str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_DEC);
- break;
+ str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_DEC, mode_is_signed(tv->mode));
+ break;
case TVO_OCTAL:
- str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_OCT);
- break;
+ str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_OCT, 0);
+ break;
case TVO_HEX:
case TVO_NATIVE:
default:
- str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_HEX);
- break;
+ str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_HEX, 0);
+ break;
}
return snprintf(buf, len, "%s%s%s", prefix, str, suffix);
}
break;
- case irms_reference:
- if (tv == tv->mode->null) return snprintf(buf, len, "NULL");
- if (tv->value != NULL) {
- if (len > tv->length) {
- memcpy(buf, tv->value, tv->length);
- buf[tv->length] = '\0';
- }
- else {
- /* truncated */
- memcpy(buf, tv->value, len-1);
- buf[len-1] = '\0';
- }
- return tv->length;
- }
- else
- return snprintf(buf, len, "void");
-
case irms_internal_boolean:
switch (mode_info->mode_output) {
NULL,
};
-/**
- * default mode_info for output as reference
- */
-static const tarval_mode_info reference_output = {
- TVO_NATIVE,
- "&(",
- ")",
-};
-
/*
* Initialization of the tarval module: called before init_mode()
*/
set_tarval_mode_output_option(mode_Iu, &hex_output);
set_tarval_mode_output_option(mode_Ls, &hex_output);
set_tarval_mode_output_option(mode_Lu, &hex_output);
- set_tarval_mode_output_option(mode_P, &reference_output);
+ set_tarval_mode_output_option(mode_P, &hex_output);
}
/* free all memory occupied by tarval. */