# include "xprintf.h"
#include <assert.h>
#include <limits.h>
+#include <errno.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
}
+tarval *
+tarval_f_from_str (const char *s, size_t len)
+{
+ tarval *tv;
+ char *buf;
+ char *eptr;
+
+ assert (!BUILDING);
+
+ buf = alloca (len+1);
+ stripcpy (buf, s, len);
+
+ tv = (tarval *)obstack_alloc (&tv_obst, sizeof (tarval));
+ tv->mode = mode_f;
+ tv->u.f = (float)strtod (buf, &eptr);
+ assert (eptr == buf+strlen(buf));
+
+ return tarval_identify (tv);
+}
+
+
tarval *
tarval_d_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
{
tarval *val = XP_GETARG (tarval *, 0);
int printed;
+ char buf[40];
TARVAL_VRFY (val);
break;
case irm_f: /* float */
- printed = XPF1R ("%g", (double)(val->u.f));
+ sprintf (buf, "%1.9e", (float)(val->u.f));
+ printed = XPF1R ("%s", buf);
break;
case irm_d: /* double */
- printed = XPF1R ("%g", (double)(val->u.d));
+ printed = XPF1R ("%1.30g", (double)(val->u.d));
break;
case irm_c: /* signed char */
if (isprint (val->u.chil)) {
printed = XPF1R ("'%c'", val->u.chil);
} else {
- printed = XPF1R ("'\\%03o'", val->u.chil);
+ printed = XPF1R ("0x%x", (unsigned long)val->u.chil);
}
break;
if (val->u.p.xname) {
printed = XPR (val->u.p.xname);
} else if (val->u.p.ent) {
- printed = XPF1R ("(%I)", val->u.p.ent->name);
+ if (get_entity_peculiarity(val->u.p.ent) == existent)
+ printed = XPF1R ("&(%I)", get_entity_ld_ident(val->u.p.ent));
+ else
+ printed = XPSR ("(NULL)");
} else {
assert (val == tarval_p_void);
printed = XPSR ("(void)");
{
return tv->mode;
}
+
+/* Returns the entity if the tv is a pointer to an entity, else
+ returns NULL; */
+entity *get_tv_entity(tarval *tv) {
+ entity *ent = NULL;
+
+ if (tv->mode == mode_p) {
+ if (tv->u.p.xname) {
+ assert(0);
+ /* not an entity */
+ } else if (tv->u.p.ent) {
+ ent = tv->u.p.ent;
+ } else {
+ /* not an entity */
+ }
+ }
+ return ent;
+}