From: Götz Lindenmaier Date: Fri, 26 Apr 2002 12:15:43 +0000 (+0000) Subject: Added new constructor. X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=4b57a396e1728067d6f023d87c73c28d9f1423de;p=libfirm Added new constructor. [r385] --- diff --git a/ir/tv/tv.c b/ir/tv/tv.c index d5bcd9b3d..b5e03d18e 100644 --- a/ir/tv/tv.c +++ b/ir/tv/tv.c @@ -35,6 +35,7 @@ # include "xprintf.h" #include #include +#include #include #include #include @@ -609,6 +610,28 @@ tarval_S_from_str (const char *s, size_t len) return tarval_identify (tv); } +tarval *tarval_int_from_str (const char *s, size_t len, int base, ir_mode *m) { + long val; + char *eptr; + char *buf; + + assert (mode_is_int(m)); + assert (!BUILDING); + + buf = alloca (len+1); + stripcpy (buf, s, len); + + errno = 0; + val = strtol(buf, &eptr, base); /* strtoll */ + assert (eptr == buf+strlen(buf)); + if ((errno == ERANGE) && + ((m == mode_l) || (m == mode_L)) ) { + printf("WARNING: Constant %s not representable. Continuing with %ld.\n", + s, val); + } + + return tarval_from_long(m, val); +} /* Create a tarval with mode `m' and value `i' casted to the type that represents such tarvals on host. The resulting value must be legal