Commit 6e6733f9 authored by Matthias Braun's avatar Matthias Braun
Browse files

strcalc: use bool where possible

parent 13aa0f6d
...@@ -378,7 +378,7 @@ end: ...@@ -378,7 +378,7 @@ end:
* @todo Assertions seems to be wrong * @todo Assertions seems to be wrong
*/ */
static void do_shl(const char *val1, char *buffer, long shift_cnt, int bitsize, static void do_shl(const char *val1, char *buffer, long shift_cnt, int bitsize,
unsigned is_signed) bool is_signed)
{ {
assert((shift_cnt >= 0) || (0 && "negative leftshift")); assert((shift_cnt >= 0) || (0 && "negative leftshift"));
assert(((do_sign(val1) != -1) || is_signed) || (0 && "unsigned mode and negative value")); assert(((do_sign(val1) != -1) || is_signed) || (0 && "unsigned mode and negative value"));
...@@ -443,7 +443,7 @@ static void do_shl(const char *val1, char *buffer, long shift_cnt, int bitsize, ...@@ -443,7 +443,7 @@ static void do_shl(const char *val1, char *buffer, long shift_cnt, int bitsize,
* @todo Assertions seems to be wrong * @todo Assertions seems to be wrong
*/ */
static void do_shr(const char *val1, char *buffer, long shift_cnt, int bitsize, static void do_shr(const char *val1, char *buffer, long shift_cnt, int bitsize,
unsigned is_signed, int signed_shift) bool is_signed, int signed_shift)
{ {
assert((shift_cnt >= 0) || (0 && "negative rightshift")); assert((shift_cnt >= 0) || (0 && "negative rightshift"));
assert(((!_bitisset(val1[(bitsize-1)/4], (bitsize-1)%4)) || !is_signed || (do_sign(val1) == -1)) || (0 && "value is positive, should be negative")); assert(((!_bitisset(val1[(bitsize-1)/4], (bitsize-1)%4)) || !is_signed || (do_sign(val1) == -1)) || (0 && "value is positive, should be negative"));
...@@ -559,8 +559,8 @@ static inline void check_ascii(void) ...@@ -559,8 +559,8 @@ static inline void check_ascii(void)
|('5'-53) | ('6'-54) | ('7'-55) | ('8'- 56) | ('9'- 57)) == 0); |('5'-53) | ('6'-54) | ('7'-55) | ('8'- 56) | ('9'- 57)) == 0);
} }
int sc_val_from_str(char sign, unsigned base, const char *str, size_t len, bool sc_val_from_str(char sign, unsigned base, const char *str, size_t len,
void *buffer) void *buffer)
{ {
assert(sign == -1 || sign == 1); assert(sign == -1 || sign == 1);
assert(str != NULL); assert(str != NULL);
...@@ -589,10 +589,10 @@ int sc_val_from_str(char sign, unsigned base, const char *str, size_t len, ...@@ -589,10 +589,10 @@ int sc_val_from_str(char sign, unsigned base, const char *str, size_t len,
else if (c >= 'a' && c <= 'f') else if (c >= 'a' && c <= 'f')
v = c - 'a' + 10; v = c - 'a' + 10;
else else
return 0; return false;
if (v >= base) if (v >= base)
return 0; return false;
val[0] = v; val[0] = v;
/* Radix conversion from base b to base B: /* Radix conversion from base b to base B:
...@@ -610,7 +610,7 @@ int sc_val_from_str(char sign, unsigned base, const char *str, size_t len, ...@@ -610,7 +610,7 @@ int sc_val_from_str(char sign, unsigned base, const char *str, size_t len,
if (sign < 0) if (sign < 0)
do_negate((const char*) buffer, (char*) buffer); do_negate((const char*) buffer, (char*) buffer);
return 1; return true;
} }
void sc_val_from_long(long value, void *buffer) void sc_val_from_long(long value, void *buffer)
...@@ -675,7 +675,7 @@ uint64_t sc_val_to_uint64(const void *val) ...@@ -675,7 +675,7 @@ uint64_t sc_val_to_uint64(const void *val)
return res; return res;
} }
void sc_min_from_bits(unsigned int num_bits, unsigned int sign, void *buffer) void sc_min_from_bits(unsigned int num_bits, bool sign, void *buffer)
{ {
if (buffer == NULL) buffer = calc_buffer; if (buffer == NULL) buffer = calc_buffer;
CLEAR_BUFFER(buffer); CLEAR_BUFFER(buffer);
...@@ -695,7 +695,7 @@ void sc_min_from_bits(unsigned int num_bits, unsigned int sign, void *buffer) ...@@ -695,7 +695,7 @@ void sc_min_from_bits(unsigned int num_bits, unsigned int sign, void *buffer)
*pos++ = SC_F; *pos++ = SC_F;
} }
void sc_max_from_bits(unsigned int num_bits, unsigned int sign, void *buffer) void sc_max_from_bits(unsigned int num_bits, bool sign, void *buffer)
{ {
if (buffer == NULL) buffer = calc_buffer; if (buffer == NULL) buffer = calc_buffer;
CLEAR_BUFFER(buffer); CLEAR_BUFFER(buffer);
...@@ -820,22 +820,22 @@ void sc_set_bit_at(void *value, unsigned pos) ...@@ -820,22 +820,22 @@ void sc_set_bit_at(void *value, unsigned pos)
val[nibble] |= SHIFT(pos & 3); val[nibble] |= SHIFT(pos & 3);
} }
int sc_is_zero(const void *value) bool sc_is_zero(const void *value)
{ {
const char* val = (const char *)value; const char* val = (const char *)value;
for (int counter = 0; counter < calc_buffer_size; ++counter) { for (int counter = 0; counter < calc_buffer_size; ++counter) {
if (val[counter] != SC_0) if (val[counter] != SC_0)
return 0; return false;
} }
return 1; return true;
} }
int sc_is_negative(const void *value) bool sc_is_negative(const void *value)
{ {
return do_sign((const char*) value) == -1; return do_sign((const char*) value) == -1;
} }
int sc_had_carry(void) bool sc_had_carry(void)
{ {
return carry_flag; return carry_flag;
} }
...@@ -1256,7 +1256,7 @@ void sc_divmod(const void *value1, const void *value2, void *div_buffer, void *m ...@@ -1256,7 +1256,7 @@ void sc_divmod(const void *value1, const void *value2, void *div_buffer, void *m
} }
void sc_shlI(const void *val1, long shift_cnt, int bitsize, int sign, void *buffer) void sc_shlI(const void *val1, long shift_cnt, int bitsize, bool sign, void *buffer)
{ {
carry_flag = false; carry_flag = false;
...@@ -1267,14 +1267,14 @@ void sc_shlI(const void *val1, long shift_cnt, int bitsize, int sign, void *buff ...@@ -1267,14 +1267,14 @@ void sc_shlI(const void *val1, long shift_cnt, int bitsize, int sign, void *buff
} }
} }
void sc_shl(const void *val1, const void *val2, int bitsize, int sign, void *buffer) void sc_shl(const void *val1, const void *val2, int bitsize, bool sign, void *buffer)
{ {
long offset = sc_val_to_long(val2); long offset = sc_val_to_long(val2);
sc_shlI(val1, offset, bitsize, sign, buffer); sc_shlI(val1, offset, bitsize, sign, buffer);
} }
void sc_shrI(const void *val1, long shift_cnt, int bitsize, int sign, void *buffer) void sc_shrI(const void *val1, long shift_cnt, int bitsize, bool sign, void *buffer)
{ {
carry_flag = false; carry_flag = false;
...@@ -1285,14 +1285,14 @@ void sc_shrI(const void *val1, long shift_cnt, int bitsize, int sign, void *buff ...@@ -1285,14 +1285,14 @@ void sc_shrI(const void *val1, long shift_cnt, int bitsize, int sign, void *buff
} }
} }
void sc_shr(const void *val1, const void *val2, int bitsize, int sign, void *buffer) void sc_shr(const void *val1, const void *val2, int bitsize, bool sign, void *buffer)
{ {
long shift_cnt = sc_val_to_long(val2); long shift_cnt = sc_val_to_long(val2);
sc_shrI(val1, shift_cnt, bitsize, sign, buffer); sc_shrI(val1, shift_cnt, bitsize, sign, buffer);
} }
void sc_shrsI(const void *val1, long shift_cnt, int bitsize, int sign, void *buffer) void sc_shrsI(const void *val1, long shift_cnt, int bitsize, bool sign, void *buffer)
{ {
carry_flag = false; carry_flag = false;
...@@ -1303,7 +1303,7 @@ void sc_shrsI(const void *val1, long shift_cnt, int bitsize, int sign, void *buf ...@@ -1303,7 +1303,7 @@ void sc_shrsI(const void *val1, long shift_cnt, int bitsize, int sign, void *buf
} }
} }
void sc_shrs(const void *val1, const void *val2, int bitsize, int sign, void *buffer) void sc_shrs(const void *val1, const void *val2, int bitsize, bool sign, void *buffer)
{ {
long offset = sc_val_to_long(val2); long offset = sc_val_to_long(val2);
......
...@@ -138,32 +138,32 @@ void sc_divmod(const void *value1, const void *value2, void *div_buffer, void *m ...@@ -138,32 +138,32 @@ void sc_divmod(const void *value1, const void *value2, void *div_buffer, void *m
/** /**
* buffer = value1 << offset * buffer = value1 << offset
*/ */
void sc_shlI(const void *val1, long shift_cnt, int bitsize, int sign, void *buffer); void sc_shlI(const void *val1, long shift_cnt, int bitsize, bool sign, void *buffer);
/** /**
* buffer = value1 << value2 * buffer = value1 << value2
*/ */
void sc_shl(const void *value1, const void *value2, int bitsize, int sign, void *buffer); void sc_shl(const void *value1, const void *value2, int bitsize, bool sign, void *buffer);
/** /**
* buffer = value1 >>u offset * buffer = value1 >>u offset
*/ */
void sc_shrI(const void *val1, long shift_cnt, int bitsize, int sign, void *buffer); void sc_shrI(const void *val1, long shift_cnt, int bitsize, bool sign, void *buffer);
/** /**
* buffer = value1 >>u value2 * buffer = value1 >>u value2
*/ */
void sc_shr(const void *value1, const void *value2, int bitsize, int sign, void *buffer); void sc_shr(const void *value1, const void *value2, int bitsize, bool sign, void *buffer);
/** /**
* buffer = value1 >>s offset * buffer = value1 >>s offset
*/ */
void sc_shrsI(const void *val1, long shift_cnt, int bitsize, int sign, void *buffer); void sc_shrsI(const void *val1, long shift_cnt, int bitsize, bool sign, void *buffer);
/** /**
* buffer = value1 >>s value2 * buffer = value1 >>s value2
*/ */
void sc_shrs(const void *value1, const void *value2, int bitsize, int sign, void *buffer); void sc_shrs(const void *value1, const void *value2, int bitsize, bool sign, void *buffer);
/** /**
* buffer = 0 * buffer = 0
...@@ -180,10 +180,10 @@ void sign_extend(void *buffer, unsigned from_bits, bool is_signed); ...@@ -180,10 +180,10 @@ void sign_extend(void *buffer, unsigned from_bits, bool is_signed);
/** /**
* create an value form a string representation * create an value form a string representation
* @return 1 if ok, 0 in case of parse error * @return true if ok, false in case of parse error
*/ */
int sc_val_from_str(char sign, unsigned base, const char *str, bool sc_val_from_str(char sign, unsigned base, const char *str,
size_t len, void *buffer); size_t len, void *buffer);
/** create a value from a long */ /** create a value from a long */
void sc_val_from_long(long l, void *buffer); void sc_val_from_long(long l, void *buffer);
...@@ -214,8 +214,8 @@ void sc_val_from_bits(unsigned char const *const bytes, unsigned from, ...@@ -214,8 +214,8 @@ void sc_val_from_bits(unsigned char const *const bytes, unsigned from,
/** converts a value to a long */ /** converts a value to a long */
long sc_val_to_long(const void *val); long sc_val_to_long(const void *val);
uint64_t sc_val_to_uint64(const void *val); uint64_t sc_val_to_uint64(const void *val);
void sc_min_from_bits(unsigned int num_bits, unsigned int sign, void *buffer); void sc_min_from_bits(unsigned int num_bits, bool sign, void *buffer);
void sc_max_from_bits(unsigned int num_bits, unsigned int sign, void *buffer); void sc_max_from_bits(unsigned int num_bits, bool sign, void *buffer);
/** truncates a value to lowest @p num_bits bits */ /** truncates a value to lowest @p num_bits bits */
void sc_truncate(unsigned num_bits, void *buffer); void sc_truncate(unsigned num_bits, void *buffer);
...@@ -227,8 +227,8 @@ ir_relation sc_comp(void const *val1, void const *val2); ...@@ -227,8 +227,8 @@ ir_relation sc_comp(void const *val1, void const *val2);
int sc_get_highest_set_bit(const void *value); int sc_get_highest_set_bit(const void *value);
int sc_get_lowest_set_bit(const void *value); int sc_get_lowest_set_bit(const void *value);
int sc_is_zero(const void *value); bool sc_is_zero(const void *value);
int sc_is_negative(const void *value); bool sc_is_negative(const void *value);
/** /**
* Return the bits of a tarval at a given byte-offset. * Return the bits of a tarval at a given byte-offset.
...@@ -276,6 +276,6 @@ int sc_get_bit_at(const void *value, unsigned pos); ...@@ -276,6 +276,6 @@ int sc_get_bit_at(const void *value, unsigned pos);
void sc_set_bit_at(void *value, unsigned pos); void sc_set_bit_at(void *value, unsigned pos);
/* Strange semantics */ /* Strange semantics */
int sc_had_carry(void); bool sc_had_carry(void);
#endif /* FIRM_TV_STRCALC_H */ #endif /* FIRM_TV_STRCALC_H */
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