scc

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

commit d87648e6d3b8b6d2f6f430a7ef1c4f378feeae09
parent 7b4df93c6808bb73a3bfc1389f9f2a15dde30796
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 26 Jan 2016 14:19:12 +0100

[cc2-z80] Small format improvement

Diffstat:
Mcc2/arch/z80/code.c | 33+++++++++++----------------------
1 file changed, 11 insertions(+), 22 deletions(-)

diff --git a/cc2/arch/z80/code.c b/cc2/arch/z80/code.c @@ -35,23 +35,20 @@ symname(Symbol *sym) { static char name[IDENTSIZ+1]; static unsigned short id; - int k = sym->kind; if (sym->name) { switch (sym->kind) { case GLOB: case EXTRN: snprintf(name, sizeof(name), "_%s", sym->name); - return name;; + return name; case PRIVAT: return sym->name; } } - if (sym->numid == 0) { - if ((sym->numid = ++id) == 0) - error(EIDOVER); - } + if (sym->numid == 0 && (sym->numid = ++id) == 0) + error(EIDOVER); sprintf(name, ".%d", sym->numid); return name; @@ -79,10 +76,10 @@ label(Symbol *sym) switch (sym->kind) { case EXTRN: - printf("\tEXTRN %s\n", name); + printf("\tEXTRN\t%s\n", name); return; case GLOB: - printf("\tPUBLIC %s\n", name); + printf("\tPUBLIC\t%s\n", name); break; } @@ -90,26 +87,17 @@ label(Symbol *sym) } static void -emitstring(Node *np) -{ - /*In z80 we can ignore the aligment */ - printf("\"%s\"", np->u.s); - free(np->u.s); - np->u.s = NULL; -} - -static void emitconst(Node *np) { switch (np->type.size) { case 1: - printf("%02X", (int) np->u.i & 0xFF); + printf("%d", (int) np->u.i & 0xFF); break; case 2: - printf("%04X", (int) np->u.i & 0xFFFF); + printf("%d", (int) np->u.i & 0xFFFF); break; case 4: - printf("%08X", (long) np->u.i & 0xFFFFFFFF); + printf("%ld", (long) np->u.i & 0xFFFFFFFF); break; default: abort(); @@ -124,7 +112,9 @@ emittree(Node *np) switch (np->op) { case OSTRING: - emitstring(np); + printf("\"%s\"", np->u.s); + free(np->u.s); + np->u.s = NULL; break; case OCONST: emitconst(np); @@ -143,7 +133,6 @@ emittree(Node *np) } } - static void size2asm(Type *tp) {