scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit e062187973bf14214d5917be3ec9b70fa0f68d9f
parent db8cf76a3a055a1bc065c842516d7193147ba6e3
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 14 Sep 2016 14:58:43 +0200

[cc2-qbe] Add OINC and ODEC

These are special cases of abbreviatures and they need special dealing.

Diffstat:
Mcc2/arch/qbe/cgen.c | 49++++++++++++++++++++++++++++++-------------------
Mcc2/parser.c | 2++
2 files changed, 32 insertions(+), 19 deletions(-)

diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c @@ -254,17 +254,6 @@ call(Node *np, Node *ret) } static Node * -abbrev(Node *np, Node *ret) -{ - Node aux; - - tmpnode(&aux, &np->type); - aux.right = np->right; - aux.left = np->left; - return rhs(&aux, ret); -} - -static Node * assign(Type *tp, Node *to, Node *from) { int op; @@ -403,6 +392,7 @@ rhs(Node *np, Node *ret) case OELOOP: case OEFUN: return NULL; + case OTMP: case OCONST: *ret = *np; return np; @@ -480,12 +470,35 @@ rhs(Node *np, Node *ret) case OCAST: return cast(tp, rhs(l, &aux1), ret); case OASSIG: - /* TODO: see what is the more difficult */ - if (np->u.subop != 0) - r = abbrev(np, &aux1); - lhs(l, &aux2); - rhs(r, ret); - return assign(&np->type, &aux2, ret); + /* TODO: Do this transformations in sethi */ + switch (np->u.subop) { + case OINC: + op = OADD; + goto post_oper; + case ODEC: + op = OSUB; + post_oper: + aux1.op = op; + aux1.left = rhs(l, ret); + aux1.right = r; + aux1.type = np->type; + rhs(&aux1, &aux2); + lhs(l, &aux1); + assign(tp, &aux1, &aux2); + break; + default: + aux2.type = np->type; + aux2.op = np->u.subop; + aux2.right = np->right; + aux2.left = np->left; + r = rhs(&aux2, &aux1); + case 0: + /* TODO: see what is the most difficult */ + lhs(l, &aux2); + rhs(r, ret); + return assign(tp, &aux2, ret); + } + return ret; case OASK: return ternary(np, ret); case OCOMMA: @@ -495,8 +508,6 @@ rhs(Node *np, Node *ret) case OADDR: return lhs(l, ret); case OFIELD: - case OINC: - case ODEC: case OCASE: case ODEFAULT: case OESWITCH: diff --git a/cc2/parser.c b/cc2/parser.c @@ -129,6 +129,8 @@ static struct decoc { ['j'] = { NULL, jump, .u.op = OJMP}, ['y'] = { NULL, jump, .u.op = OBRANCH}, ['h'] = { NULL, oreturn, .u.op = ORET}, + ['i'] = { NULL, NULL, .u.op = OINC}, + ['d'] = { NULL, NULL, .u.op = ODEC}, ['b'] = { NULL, loop, .u.op = OBLOOP}, ['e'] = { NULL, loop, .u.op = OELOOP},