commit 442e6287627c9e3bfee8b6508e41063c3a555faa
parent 7b4b809f9c1352da0292da3ff3ffbb8f037792f4
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Sun, 10 Aug 2014 18:51:06 +0200
Add stub support for assignations in cc2
Diffstat:
3 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/cc2/cc2.h b/cc2/cc2.h
@@ -66,6 +66,7 @@ enum nerrors {
#define LABEL 'L'
#define OADD '+'
#define OSUB '-'
+#define OASSIG ':'
extern void error(unsigned nerror, ...);
extern void genaddable(Node *list[]);
diff --git a/cc2/cgen.c b/cc2/cgen.c
@@ -26,7 +26,7 @@ genstack(Symbol *fun)
}
enum {
- PUSH, POP, LD, ADD, RET, ADDI, LDI, ADDR, ADDX, ADCX
+ PUSH, POP, LD, ADD, RET, ADDI, LDI, ADDR, ADDX, ADCX, LDX
};
enum {
@@ -36,7 +36,7 @@ enum {
char *opnames[] = {
[PUSH] = "PUSH", [POP] = "POP", [LD] = "LD", [ADD] = "ADD",
[RET] = "RET" , [ADDI]= "ADD", [LDI] = "LD", [ADDX] = "ADD",
- [ADCX] = "ADC"
+ [ADCX] = "ADC" , [LDX] = "LD"
};
char *regnames[] = {
@@ -75,6 +75,13 @@ emit(char op, ...)
imm = va_arg(va, int);
printf("\t%s\t%s,%hd\n", opnames[op], regnames[reg1], imm);
break;
+ case LDX:
+ reg1 = va_arg(va, int);
+ off = va_arg(va, int);
+ reg2 = va_arg(va, int);
+ printf("\t%s\t(%s%+hd),%s\n",
+ opnames[op], regnames[reg1], off, regnames[reg2]);
+ break;
case ADDX: case ADCX:
reg1 = va_arg(va, int);
reg2 = va_arg(va, int);
@@ -128,8 +135,17 @@ xcgen(Node *np)
emit(LDI, A, imm >> 8);
emit(ADCX, A, IX, -off);
emit(LD, H, A);
+ } else {
+ abort();
}
break;
+ case OASSIG:
+ /* TODO: check that it is really in HL and AUTO */
+ assert(lp->op == AUTO);
+ off = lp->u.sym->u.v.off;
+ emit(LDX, IX, -(off+1), L);
+ emit(LDX, IX, off, H);
+ break;
default:
abort();
}
@@ -193,7 +209,7 @@ xaddable(Node *np)
case CONST:
np->addable = 20;
break;
- case OADD: case OSUB:
+ case OASSIG: case OADD: case OSUB:
xaddable(lp);
xaddable(rp);
switch (rp->addable) {
@@ -215,6 +231,8 @@ xaddable(Node *np)
default:
abort();
}
+ case 1:
+ break;
default:
abort();
}
diff --git a/cc2/parser.c b/cc2/parser.c
@@ -233,6 +233,7 @@ static void (*optbl[])(char *) = {
['-'] = operator,
['*'] = operator,
['/'] = operator,
+ [':'] = operator,
['A'] = variable,
['T'] = variable,
['G'] = variable,