scc

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

commit 24572d7623dc7497d48c4e36f3250761377aba2f
parent bce2cfac7f576b3a9afe811fd9a6d71ae18d3cb0
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed,  6 May 2015 18:13:15 +0200

Unify emitbin() and emitunary()

Diffstat:
Mcc1/code.c | 32+++++++++++---------------------
1 file changed, 11 insertions(+), 21 deletions(-)

diff --git a/cc1/code.c b/cc1/code.c @@ -61,10 +61,10 @@ void (*opcode[])(void *) = { [OADD] = emitbin, [OSUB] = emitbin, [OMUL] = emitbin, - [OINC] = emitunary, - [ODEC] = emitunary, + [OINC] = emitbin, + [ODEC] = emitbin, [OSIZE] = emitsizeof, - [OPTR] = emitunary, + [OPTR] = emitbin, [OMOD] = emitbin, [ODIV] = emitbin, [OSHL] = emitbin, @@ -74,7 +74,7 @@ void (*opcode[])(void *) = { [OGE] = emitbin, [OLE] = emitbin, [OEQ] = emitbin, - [ONE] = emitunary, + [ONE] = emitbin, [OBAND] = emitbin, [OBXOR] = emitbin, [OBOR] = emitbin, @@ -89,9 +89,9 @@ void (*opcode[])(void *) = { [OA_AND] = emitbin, [OA_XOR] = emitbin, [OA_OR] = emitbin, - [OADDR] = emitunary, - [ONEG] = emitunary, - [OCPL] = emitunary, + [OADDR] = emitbin, + [ONEG] = emitbin, + [OCPL] = emitbin, [OAND] = emitbin, [OOR] = emitbin, [OCOMMA] = emitbin, @@ -189,26 +189,16 @@ emitcast(void *arg) } void -emitunary(void *arg) -{ - Node *lp, *np = arg; - char letter; - - letter = np->type->letter; - lp = np->left; - (*opcode[lp->op])(lp); - printf("\t%s%c", optxt[np->op], letter); -} - -void emitbin(void *arg) { Node *lp, *rp, *np = arg; lp = np->left; rp = np->rigth; - (*opcode[lp->op])(lp); - (*opcode[rp->op])(rp); + if (lp) + (*opcode[lp->op])(lp); + if (rp) + (*opcode[rp->op])(rp); printf("\t%s%c", optxt[np->op], np->type->letter); }