ref: 95d9b9e20994d6e7b7d99c4eedd7e444d04119f6
parent: 98535eb7cff01fafbf9d3110bf160d622fb461db
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Apr 19 01:10:05 EDT 2016
[cc2-qbe] Do not use node ops in Inst Until this moment we were using the same opcodes in nodes and in instructions, but in instructions we have a lose of semantic, so we need a different set of opcodes in instructions. This patch adds a new enumeration for the instruction opcodes, but it has direct relation with the node opcodes enumeration. It will be fixed soon.
--- a/cc2/arch/qbe/arch.h
+++ b/cc2/arch/qbe/arch.h
@@ -4,3 +4,24 @@
#define TFLOAT double
#define TSIZE unsigned long
+enum asmop {
+ ASLOAD,
+ ASADD,
+ ASSUB,
+ ASMUL,
+ ASMOD,
+ ASDIV,
+ ASSHL,
+ ASSHR,
+ ASLT,
+ ASGT,
+ ASLE,
+ ASGE,
+ ASEQ,
+ ASNE,
+ ASBAND,
+ ASBOR,
+ ASBXOR,
+ ASCPL,
+ ASASSIG
+};
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -9,6 +9,26 @@
ISCONS = 2
};
+static char opasm[] = {
+ [OADD] = ASADD,
+ [OSUB] = ASSUB,
+ [OMUL] = ASMUL,
+ [OMOD] = ASMOD,
+ [ODIV] = ASDIV,
+ [OSHL] = ASSHL,
+ [OSHR] = ASSHR,
+ [OLT] = ASLT,
+ [OGT] = ASGT,
+ [OLE] = ASLE,
+ [OGE] = ASGE,
+ [OEQ] = ASEQ,
+ [ONE] = ASNE,
+ [OBAND] = ASBAND,
+ [OBOR] = ASBOR,
+ [OBXOR] = ASBXOR,
+ [OCPL] = ASCPL
+};
+
static Node *
tmpnode(Node *np)
{
@@ -31,7 +51,7 @@
new = tmpnode(newnode());
new->left = np;
new->type = np->type;
- code(OLOAD, new, np, NULL);
+ code(ASLOAD, new, np, NULL);
return new;
}
@@ -81,7 +101,7 @@
if ((r->flags & (ISTMP|ISCONS)) == 0)
r = np->right = load(r);
tmpnode(np);
- code(op, np, l, r);
+ code(opasm[op], np, l, r);
return np;
case ONOP:
case OBLOOP:
@@ -96,7 +116,7 @@
case ODEC:
abort();
case OASSIG:
- code(op, l, r, NULL);
+ code(ASASSIG, l, r, NULL);
return r;
case OCALL:
case OFIELD:
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
@@ -12,24 +12,24 @@
void (*fun)(void);
char *txt;
} optbl [] = {
- [OADD] = {.fun = binary, .txt = "add"},
- [OSUB] = {.fun = binary, .txt = "sub"},
- [OMUL] = {.fun = binary, .txt = "mul"},
- [OMOD] = {.fun = binary, .txt = "rem"},
- [ODIV] = {.fun = binary, .txt = "div"},
- [OSHL] = {.fun = binary, .txt = "shl"},
- [OSHR] = {.fun = binary, .txt = "shr"},
- [OLT] = {.fun = binary, .txt = "clt"},
- [OGT] = {.fun = binary, .txt = "cgt"},
- [OLE] = {.fun = binary, .txt = "cle"},
- [OGE] = {.fun = binary, .txt = "cge"},
- [OEQ] = {.fun = binary, .txt = "ceq"},
- [ONE] = {.fun = binary, .txt = "cne"},
- [OBAND] = {.fun = binary, .txt = "and"},
- [OBOR] = {.fun = binary, .txt = "or"},
- [OBXOR] = {.fun = binary, .txt = "xor"},
- [OLOAD] = {.fun = load, .txt = "load"},
- [OASSIG] = {.fun = store, .txt = "store"}
+ [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"}
};
/*