scc

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

commit b90eb5f63f1264a37528244e8c2ce6a77a8da36a
parent 1361aa0b0a2a65bc002d6d6625416162fec0d3fd
Author: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
Date:   Sat, 23 Apr 2016 17:27:50 +0200

[cc2-qbe] Add jumps to qbe

Diffstat:
cc2/arch/qbe/arch.h | 4+++-
cc2/arch/qbe/cgen.c | 4+++-
cc2/arch/qbe/code.c | 13+++++++++++--
cc2/cc2.h | 1+
4 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/cc2/arch/qbe/arch.h b/cc2/arch/qbe/arch.h @@ -128,5 +128,7 @@ enum asmop { ASSLTOS, ASEXTS, - ASTRUNCD + ASTRUNCD, + + ASJMP }; diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c @@ -225,6 +225,7 @@ cgen(Node *np) if (!np) return NULL; + setlabel(np->label); l = cgen(np->left); r = cgen(np->right); tp = &np->type; @@ -327,8 +328,9 @@ cgen(Node *np) case OOR: abort(); case OBRANCH: + abort(); case OJMP: - code(op, NULL, l, r); + code(ASJMP, np, NULL, NULL); return NULL; case ORET: case OCASE: diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c @@ -9,7 +9,7 @@ #define ADDR_LEN (IDENTSIZ+64) -static void binary(void), unary(void), store(void); +static void binary(void), unary(void), store(void), jmp(void); static struct opdata { void (*fun)(void); @@ -121,6 +121,8 @@ static struct opdata { [ASEXTS] = {.fun = unary, .txt = "exts", .letter = 'd'}, [ASSLTOS]= {.fun = unary, .txt = "truncd", .letter = 's'}, + + [ASJMP] = {.fun = jmp}, }; static char buff[ADDR_LEN]; @@ -334,7 +336,8 @@ writeout(void) for (pc = prog; pc; pc = pc->next) { if (pc->label) printf("%s:\n", symname(pc->label)); - (*optbl[pc->op].fun)(); + if (pc->op) + (*optbl[pc->op].fun)(); } puts("}"); @@ -390,6 +393,12 @@ unary(void) printf("\t%s %c=\t%s\t%s\n", to, p->letter, p->txt, from); } +static void +jmp(void) +{ + printf("\t\tjmp\t%s\n", addr2txt(&pc->to)); +} + void endinit(void) { diff --git a/cc2/cc2.h b/cc2/cc2.h @@ -200,6 +200,7 @@ extern void data(Node *np); extern void writeout(void), endinit(void), newfun(void); extern void code(int op, Node *to, Node *from1, Node *from2); extern void defvar(Symbol *), defpar(Symbol *), defglobal(Symbol *); +extern void setlabel(Symbol *sym); /* node.c */ extern void apply(Node *(*fun)(Node *));