scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit 8c5632d62fb15b51382e21845995469d75cd96ab
parent c305b6f188a2d59e8ba7e87b6ee6761922d09447
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 16 Mar 2015 10:10:10 +0000

Fix generation of INDEX operands

In this operands we want the address not the content.

Diffstat:
cc2/cgen.c | 3++-
cc2/code.c | 21+++++++++++++--------
2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/cc2/cgen.c b/cc2/cgen.c @@ -193,7 +193,8 @@ index(Node *np) { if (reguse[H] || reguse[L]) push(&reg_HL); - code(MOV, &reg_HL, np); + code(LDI, &reg_HL, np); + reguse[H] = reguse[L] = np; np->op = INDEX; } diff --git a/cc2/code.c b/cc2/code.c @@ -133,9 +133,10 @@ writeout(void) } static void -addr2txt(Addr *a) +addr2txt(char op, Addr *a) { Symbol *sym; + char *fmt; switch (a->kind) { case REG: @@ -154,9 +155,9 @@ addr2txt(Addr *a) case MEM: sym = a->u.sym; if (sym->name) - printf("(%s)", sym); + printf((op == LDI) ? "%s" : "(%s)", sym); else - printf("(T%u)", sym->id); + printf((op == LDI) ? "T%u" : "(T%u)", sym->id); break; default: abort(); @@ -172,17 +173,21 @@ inst0(void) static void inst1(void) { - printf("\t%s\t", insttext[pc->op]); - addr2txt((pc->to.kind != NONE) ? &pc->to : &pc->from); + char op = pc->op; + + printf("\t%s\t", insttext[op]); + addr2txt(op, (pc->to.kind != NONE) ? &pc->to : &pc->from); putchar('\n'); } static void inst2(void) { - printf("\t%s\t", insttext[pc->op]); - addr2txt(&pc->to); + char op = pc->op; + + printf("\t%s\t", insttext[op]); + addr2txt(op, &pc->to); putchar(','); - addr2txt(&pc->from); + addr2txt(op, &pc->from); putchar('\n'); }