dbg_info *dbgi = get_dbg_info(&cnst->expression.source_position);
ir_mode *mode = get_ir_mode(cnst->expression.datatype);
- tarval *tv;
+ char buf[128];
+ tarval *tv;
+ size_t len;
if(mode_is_float(mode)) {
- tv = new_tarval_from_double(cnst->v.float_value, mode);
+ len = snprintf(buf, sizeof(buf), "%LF", cnst->v.float_value);
} else {
- tv = new_tarval_from_long(cnst->v.int_value, mode);
+ if(mode_is_signed(mode)) {
+ len = snprintf(buf, sizeof(buf), "%lld", cnst->v.int_value);
+ } else {
+ len = snprintf(buf, sizeof(buf), "%llu", cnst->v.int_value);
+ }
}
+ tv = new_tarval_from_str(buf, len, mode);
return new_d_Const(dbgi, mode, tv);
}
#include "adt/error.h"
#include "adt/strset.h"
#include "adt/util.h"
+#include "type_t.h"
#include <assert.h>
#include <errno.h>
static const char *bufpos;
static strset_t stringset;
+static type_t *type_int = NULL;
+static type_t *type_uint = NULL;
+static type_t *type_long = NULL;
+static type_t *type_ulong = NULL;
+static type_t *type_longlong = NULL;
+static type_t *type_ulonglong = NULL;
+static type_t *type_float = NULL;
+static type_t *type_double = NULL;
+static type_t *type_longdouble = NULL;
+
static void error_prefix_at(const char *input_name, unsigned linenr)
{
fprintf(stderr, "%s:%u: Error: ", input_name, linenr);
static void parse_integer_suffix(void)
{
if(c == 'U' || c == 'U') {
- /* TODO do something with the suffixes... */
next_char();
if(c == 'L' || c == 'l') {
next_char();
if(c == 'L' || c == 'l') {
next_char();
+ lexer_token.datatype = type_ulonglong;
+ } else {
+ lexer_token.datatype = type_ulong;
}
+ } else {
+ lexer_token.datatype = type_uint;
}
} else if(c == 'l' || c == 'L') {
next_char();
next_char();
if(c == 'u' || c == 'U') {
next_char();
+ lexer_token.datatype = type_ulonglong;
+ } else {
+ lexer_token.datatype = type_longlong;
}
} else if(c == 'u' || c == 'U') {
next_char();
+ lexer_token.datatype = type_ulong;
+ } else {
+ lexer_token.datatype = type_int;
}
+ } else {
+ lexer_token.datatype = type_int;
}
}
/* TODO: do something usefull with the suffixes... */
case 'f':
case 'F':
+ next_char();
+ lexer_token.datatype = type_float;
+ break;
case 'l':
case 'L':
next_char();
+ lexer_token.datatype = type_longdouble;
break;
default:
+ lexer_token.datatype = type_double;
break;
}
}
char *endptr;
lexer_token.type = T_INTEGER;
- lexer_token.v.intvalue = strtoll(string, &endptr, 16);
+ lexer_token.v.intvalue = strtoull(string, &endptr, 16);
if(*endptr != '\0') {
parse_error("hex number literal too long");
}
char *endptr;
lexer_token.type = T_INTEGER;
- lexer_token.v.intvalue = strtoll(string, &endptr, 8);
+ lexer_token.v.intvalue = strtoull(string, &endptr, 8);
if(*endptr != '\0') {
parse_error("octal number literal too long");
}
parse_floating_suffix();
} else {
lexer_token.type = T_INTEGER;
- lexer_token.v.intvalue = strtoll(string, &endptr, 10);
+ lexer_token.v.intvalue = strtoull(string, &endptr, 10);
if(*endptr != '\0') {
parse_error("invalid number literal");
void init_lexer(void)
{
strset_init(&stringset);
+
+ type_int = make_atomic_type(ATOMIC_TYPE_INT, TYPE_QUALIFIER_CONST);
+ type_uint = make_atomic_type(ATOMIC_TYPE_UINT, TYPE_QUALIFIER_CONST);
+ type_long = make_atomic_type(ATOMIC_TYPE_LONG, TYPE_QUALIFIER_CONST);
+ type_ulong = make_atomic_type(ATOMIC_TYPE_ULONG, TYPE_QUALIFIER_CONST);
+ type_longlong = make_atomic_type(ATOMIC_TYPE_LONGLONG,
+ TYPE_QUALIFIER_CONST);
+ type_ulonglong = make_atomic_type(ATOMIC_TYPE_ULONGLONG,
+ TYPE_QUALIFIER_CONST);
+
+ type_float = make_atomic_type(ATOMIC_TYPE_FLOAT, TYPE_QUALIFIER_CONST);
+ type_double = make_atomic_type(ATOMIC_TYPE_DOUBLE,
+ TYPE_QUALIFIER_CONST);
+ type_longdouble = make_atomic_type(ATOMIC_TYPE_LONG_DOUBLE,
+ TYPE_QUALIFIER_CONST);
}
void lexer_open_stream(FILE *stream, const char *input_name)