Commit 360daec7 authored by Matthias Braun's avatar Matthias Braun
Browse files

add tarval_to_uint64(), tarval_is_uint64()

parent af6fbbfe
......@@ -664,6 +664,14 @@ long sc_val_to_long(const void *val)
return l;
}
uint64_t sc_val_to_uint64(const void *val)
{
uint64_t res = 0;
for (int i = calc_buffer_size - 1; i >= 0; i--) {
res = (res << 4) + _val(((char*)val)[i]);
}
}
void sc_min_from_bits(unsigned int num_bits, unsigned int sign, void *buffer)
{
if (buffer == NULL) buffer = calc_buffer;
......
......@@ -19,6 +19,7 @@
#ifndef FIRM_TV_STRCALC_H
#define FIRM_TV_STRCALC_H
#include <stdint.h>
#include "irmode.h"
#ifdef STRCALC_DEBUG_ALL /* switch on all debug options */
......@@ -191,6 +192,7 @@ void sc_val_from_ulong(unsigned long l, void *buffer);
/** converts a value to a long */
long sc_val_to_long(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_max_from_bits(unsigned int num_bits, unsigned int sign, void *buffer);
......
......@@ -393,11 +393,32 @@ int tarval_is_long(ir_tarval *tv)
long get_tarval_long(ir_tarval* tv)
{
assert(tarval_is_long(tv) && "tarval too big to fit in long");
assert(tarval_is_long(tv));
return sc_val_to_long(tv->value);
}
bool tarval_is_uint64(ir_tarval *tv)
{
if (!mode_is_int(tv->mode) && !mode_is_reference(tv->mode))
return false;
if (get_mode_size_bits(tv->mode) > (int) (sizeof(uint64_t) << 3)) {
/* the value might be too big to fit in a long */
sc_max_from_bits(sizeof(uint64_t) << 3, 0, NULL);
if (sc_comp(sc_get_buffer(), tv->value) == ir_relation_less) {
/* really doesn't fit */
return false;
}
}
return true;
}
uint64_t get_tarval_uint64(ir_tarval *tv)
{
assert(tarval_is_uint64(tv));
return sc_val_to_uint64(tv->value);
}
ir_tarval *new_tarval_from_long_double(long double d, ir_mode *mode)
{
const float_descriptor_t *desc;
......
......@@ -16,6 +16,8 @@
#include "firm_common.h"
#include "irmode.h"
#include "tv.h"
#include <stdint.h>
#include <stdbool.h>
#define get_tarval_mode(tv) _get_tarval_mode(tv)
#define get_tarval_bad() _get_tarval_bad()
......@@ -114,4 +116,8 @@ static inline int _is_tarval(const void *thing)
return get_kind(thing) == k_tarval;
}
uint64_t get_tarval_uint64(ir_tarval *tv);
bool tarval_is_uint64(ir_tarval *tv);
#endif /* FIRM_TV_TV_T_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