diff options
Diffstat (limited to 'bootstrap/cgen.c')
| -rw-r--r-- | bootstrap/cgen.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/bootstrap/cgen.c b/bootstrap/cgen.c index 938e8f3..4bc6280 100644 --- a/bootstrap/cgen.c +++ b/bootstrap/cgen.c @@ -87,6 +87,9 @@ pri(const char *fmt, ...) { case 'U': fprintf(outfp, "%llu", (unsigned long long)va_arg(ap, u64)); break; + case 'I': + fprintf(outfp, "%lld", (long long)va_arg(ap, u64)); + break; case 'z': fprintf(outfp, "%zu", va_arg(ap, size_t)); break; @@ -124,13 +127,15 @@ static void genblock(struct blockstmt block); static void genexpr(struct expr *ex) { - const struct type *ty = ex->ty; + const struct type *ty = unconstify(ex->ty); switch (ex->t) { case Eintlit: if (ty == ty_int) - pri("%U", ex->i); + pri("%I", ex->i); + else if (ty == ty_u64) + pri("((uint64_t)%U)", ex->i); else - pri("((%t)%U)", ty, ex->i); + pri("((%t)%I)", ty, ex->i); break; case Eflolit: pri("%f%s", ex->f, ty->size == 4 ? "f" : ""); @@ -378,7 +383,8 @@ liftnested(struct stmt *stmt) { liftnested(blocktostmt(*stmt->iswitch.f)); break; case Sreturn: - liftnestedex(stmt->retex); + if (stmt->retex) + liftnestedex(stmt->retex); break; } } @@ -488,7 +494,10 @@ defctype(const struct type *ty, void *_) { static void prelude() { pri("#include <stdint.h>\n" - "#include <stddef.h>\n"); + "#include <stddef.h>\n" + "#define not !\n" + "#define and &&\n" + "#define or ||\n"); } void |