ref: b18a5a9dbc408cc4d30865dfc6d4a6f1329e142d
parent: 6c20179c7f7cc370d02d2be76bc60ccc5f448835
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Apr 19 23:44:11 EDT 2016
[cc2-qbe] Fix equality operators These operators have different form depending of the size of the operands, so we have to use different opcodes based in the size of the operands.
--- a/cc2/arch/qbe/arch.h
+++ b/cc2/arch/qbe/arch.h
@@ -18,7 +18,9 @@
ASLE,
ASGE,
ASEQ,
+ ASEQL,
ASNE,
+ ASNEL,
ASBAND,
ASBOR,
ASBXOR,
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -61,6 +61,7 @@
{Node *l, *r;
Symbol *sym;
+ Type *tp;
int op;
if (!np)
@@ -68,8 +69,9 @@
l = cgen(np->left);
r = cgen(np->right);
+ tp = &np->type;
- switch (op = np->op) {+ switch (np->op) {case OREG:
case OSTRING:
abort();
@@ -79,6 +81,10 @@
case OMEM:
case OAUTO:
return np;
+ case OEQ:
+ case ONE:
+ op = opasm[np->op] + (tp->size == 8);
+ goto binary;
case OADD:
case OSUB:
case OMUL:
@@ -90,18 +96,18 @@
case OGT:
case OLE:
case OGE:
- case OEQ:
- case ONE:
case OBAND:
case OBOR:
case OBXOR:
case OCPL:
+ op = opasm[np->op];
+ binary:
if ((l->flags & (ISTMP|ISCONS)) == 0)
l = np->left = load(l);
if ((r->flags & (ISTMP|ISCONS)) == 0)
r = np->right = load(r);
tmpnode(np);
- code(opasm[op], np, l, r);
+ code(op, np, l, r);
return np;
case ONOP:
case OBLOOP:
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
@@ -11,25 +11,28 @@
static struct opdata {void (*fun)(void);
char *txt;
+ char letter;
} optbl [] = {- [ASADD] = {.fun = binary, .txt = "add"},- [ASSUB] = {.fun = binary, .txt = "sub"},- [ASMUL] = {.fun = binary, .txt = "mul"},- [ASMOD] = {.fun = binary, .txt = "rem"},- [ASDIV] = {.fun = binary, .txt = "div"},- [ASSHL] = {.fun = binary, .txt = "shl"},- [ASSHR] = {.fun = binary, .txt = "shr"},- [ASLT] = {.fun = binary, .txt = "clt"},- [ASGT] = {.fun = binary, .txt = "cgt"},- [ASLE] = {.fun = binary, .txt = "cle"},- [ASGE] = {.fun = binary, .txt = "cge"},- [ASEQ] = {.fun = binary, .txt = "ceq"},- [ASNE] = {.fun = binary, .txt = "cne"},- [ASBAND] = {.fun = binary, .txt = "and"},- [ASBOR] = {.fun = binary, .txt = "or"},- [ASBXOR] = {.fun = binary, .txt = "xor"},- [ASLOAD] = {.fun = load, .txt = "load"},- [ASASSIG] = {.fun = store, .txt = "store"}+ [ASADD] = {.fun = binary, .txt = "add", .letter = 'w'},+ [ASSUB] = {.fun = binary, .txt = "sub", .letter = 'w'},+ [ASMUL] = {.fun = binary, .txt = "mul", .letter = 'w'},+ [ASMOD] = {.fun = binary, .txt = "rem", .letter = 'w'},+ [ASDIV] = {.fun = binary, .txt = "div", .letter = 'w'},+ [ASSHL] = {.fun = binary, .txt = "shl", .letter = 'w'},+ [ASSHR] = {.fun = binary, .txt = "shr", .letter = 'w'},+ [ASLT] = {.fun = binary, .txt = "clt", .letter = 'w'},+ [ASGT] = {.fun = binary, .txt = "cgt", .letter = 'w'},+ [ASLE] = {.fun = binary, .txt = "cle", .letter = 'w'},+ [ASGE] = {.fun = binary, .txt = "cge", .letter = 'w'},+ [ASEQ] = {.fun = binary, .txt = "ceqw", .letter = 'w'},+ [ASEQL] = {.fun = binary, .txt = "ceql", .letter = 'w'},+ [ASNE] = {.fun = binary, .txt = "cnew", .letter = 'w'},+ [ASNEL] = {.fun = binary, .txt = "cnel", .letter = 'w'},+ [ASBAND] = {.fun = binary, .txt = "and", .letter = 'w'},+ [ASBOR] = {.fun = binary, .txt = "or", .letter = 'w'},+ [ASBXOR] = {.fun = binary, .txt = "xor", .letter = 'w'},+ [ASLOAD] = {.fun = load, .txt = "load", .letter = 'w'},+ [ASASSIG] = {.fun = store, .txt = "store", .letter = 'w'}};
/*
@@ -241,8 +244,10 @@
static void
binary(void)
{+ struct opdata *p = &optbl[pc->op];
+
printf("\t%s %c=\t%s\t",- addr2txt(&pc->to), 'w', optbl[pc->op].txt);
+ addr2txt(&pc->to), p->letter, p->txt);
fputs(addr2txt(&pc->from1), stdout);
putchar(',');fputs(addr2txt(&pc->from2), stdout);
--
⑨