Commit 54dfb24d authored by Matthias Braun's avatar Matthias Braun
Browse files

strcalc should not depend on ir_mode structure

parent c8b89d12
......@@ -522,13 +522,13 @@ int sc_get_buffer_length(void)
return calc_buffer_size;
}
void sign_extend(void *buffer, ir_mode *mode)
void sign_extend(void *buffer, unsigned from_bits, bool is_signed)
{
char *calc_buffer = (char*)buffer;
int bits = get_mode_size_bits(mode) - 1;
int bits = from_bits - 1;
int nibble = bits >> 2;
if (mode_is_signed(mode)) {
if (is_signed) {
int max = max_digit[bits & 3];
if (calc_buffer[nibble] > max) {
/* sign bit is set, we need sign expansion */
......
......@@ -21,7 +21,7 @@
#include <stdint.h>
#include <stdbool.h>
#include "irmode.h"
#include "firm_types.h"
#ifdef STRCALC_DEBUG_ALL /* switch on all debug options */
# ifndef STRCALC_DEBUG
......@@ -176,7 +176,7 @@ void sc_zero(void *buffer);
const void *sc_get_buffer(void);
int sc_get_buffer_length(void);
void sign_extend(void *buffer, ir_mode *mode);
void sign_extend(void *buffer, unsigned from_bits, bool is_signed);
/**
* create an value form a string representation
......
......@@ -111,7 +111,7 @@ static ir_tarval *get_tarval(const void *value, size_t length, ir_mode *mode)
char *temp = ALLOCAN(char, length);
memcpy(temp, value, length);
if (get_mode_arithmetic(mode) == irma_twos_complement) {
sign_extend(temp, mode);
sign_extend(temp, get_mode_size_bits(mode), mode_is_signed(mode));
}
tv.value = INSERT_VALUE(temp, length);
} else {
......@@ -133,7 +133,7 @@ static ir_tarval *get_tarval_overflow(const void *value, size_t length,
memcpy(temp, value, sc_get_buffer_length());
sc_truncate(get_mode_size_bits(mode), temp);
/* the sc_ module expects that all bits are set ... */
sign_extend(temp, mode);
sign_extend(temp, get_mode_size_bits(mode), mode_is_signed(mode));
return get_tarval(temp, length, mode);
}
......@@ -147,7 +147,7 @@ static ir_tarval *get_tarval_overflow(const void *value, size_t length,
memcpy(temp, value, sc_get_buffer_length());
sc_truncate(get_mode_size_bits(mode), temp);
/* the sc_ module expects that all bits are set ... */
sign_extend(temp, mode);
sign_extend(temp, get_mode_size_bits(mode), mode_is_signed(mode));
return get_tarval(temp, length, mode);
}
case TV_OVERFLOW_BAD:
......@@ -789,7 +789,8 @@ ir_tarval *tarval_convert_to(ir_tarval *src, ir_mode *dst_mode)
if (get_mode_sort(dst_mode) == irms_int_number) {
char *buffer = ALLOCAN(char, sc_get_buffer_length());
memcpy(buffer, src->value, sc_get_buffer_length());
sign_extend(buffer, src->mode);
sign_extend(buffer, get_mode_size_bits(src->mode),
mode_is_signed(src->mode));
return get_tarval_overflow(buffer, src->length, dst_mode);
}
break;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment