ref: 8cc7f57a951c9807a7d55cbb7ed1a9cb456930e2
parent: 8d0d2c097a87b8d96e107bab9b0c9176e75f89ef
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sat Mar 21 00:06:52 EDT 2015
Add BAND, BOR and BXOR operations These are exactly the same than add operation, so they were really easy.
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -136,7 +136,10 @@
INC,
SUB,
DEC,
- JP
+ JP,
+ AND,
+ OR,
+ XOR
};
enum {
--- a/cc2/cgen.c
+++ b/cc2/cgen.c
@@ -252,6 +252,9 @@
break;
case OADD:
case OSUB:
+ case OBAND:
+ case OBOR:
+ case OBXOR:
switch (np->op) {
case PAR:
case AUTO:
@@ -286,12 +289,13 @@
add(Node *np)
{
Node *lp = np->left, *rp = np->right, *a;
+ uint8_t op;
switch (np->type.size) {
case 1:
a = reguse[A];
if (a == lp)
- goto add1;
+ goto update_a;
if (a == rp)
goto conmute1;
if (lp->op == CONST) {
@@ -299,13 +303,32 @@
goto conmute1;
}
accum(lp);
- goto add1;
+ goto update_a;
conmute1:
conmute(np);
lp = np->left, rp = np->right;
- add1:
+ update_a:
move(rp, np);
- code((np->op == OADD) ? ADD : SUB, lp, rp);
+ switch (np->op) {
+ case OADD:
+ op = ADD;
+ break;
+ case OSUB:
+ op = SUB;
+ break;
+ case OBAND:
+ op = AND;
+ break;
+ case OBOR:
+ op = OR;
+ break;
+ case OBXOR:
+ op = XOR;
+ break;
+ default:
+ abort();
+ }
+ code(op, lp, rp);
lp->used = rp->used = 1;
np->op = REG;
np->reg = A;
@@ -380,7 +403,10 @@
[REG] = nop,
[AUTO] = nop,
[CONST] = nop,
- [PAR] = nop
+ [PAR] = nop,
+ [OBOR] = add,
+ [OBAND] = add,
+ [OBXOR] = add
};
static void
--- a/cc2/code.c
+++ b/cc2/code.c
@@ -34,7 +34,10 @@
[INC] = inst1,
[SUB] = inst2,
[DEC] = inst1,
- [JP] = inst1
+ [JP] = inst1,
+ [AND] = inst2,
+ [OR] = inst2,
+ [XOR] = inst2
};
static char *insttext[] = {
@@ -51,7 +54,10 @@
[INC] = "INC",
[SUB] = "SUB",
[DEC] = "DEC",
- [JP] = "JP"
+ [JP] = "JP",
+ [AND] = "AND",
+ [OR] = "OR",
+ [XOR] = "XOR"
};
Inst *pc, *prog;