scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit fee4eeac3d4259a138bf98212c72faf394fcd379
parent a580dd7611be537814383676fd4fb33cad7f6bb3
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 21 Jul 2015 17:53:47 +0200

Fix emitcons()

Before of this commit the function was assuming that all the integer
constant were of type inttype, and the rest were strings, generating
a segfault with a long variable for example. This patch adds a skeleton
of what have to be done and a bit of checking.

Diffstat:
Mcc1/TODO | 1+
Mcc1/code.c | 16+++++++++++++---
2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/cc1/TODO b/cc1/TODO @@ -16,3 +16,4 @@ * Implement enum type in eqtype() * Parse correctly all integer and float constants * Add C99 features (almost all the new features of C99 are missed) +* Add correct emit for any kind of constant diff --git a/cc1/code.c b/cc1/code.c @@ -177,12 +177,22 @@ emitconst(Node *np) char *bp, c; Symbol *sym = np->sym; - if (np->type == inttype) { + switch (np->type->op) { + case INT: printf("#%c%x", np->type->letter, sym->u.i); - } else { + break; + case ARY: + /* + * FIX: At this point we are going to assume + * that all the arrays are strings + */ putchar('"'); for (bp = sym->u.s; c = *bp; ++bp) - printf("%02X", (unsigned) c); + printf("%02X", c & 0xFF); + break; + default: + /* TODO: Handle other kind of constants */ + abort; } }