scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 2caa6847c311d53c4a3666659e9798cbd5d3bce2
parent 48c5ae1798901462bcc7dab2413384636171330e
Author: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
Date:   Tue, 19 Apr 2016 05:10:05 +0200

[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.

Diffstat:
Mcc2/arch/qbe/arch.h | 21+++++++++++++++++++++
Mcc2/arch/qbe/cgen.c | 26+++++++++++++++++++++++---
Mcc2/arch/qbe/code.c | 36++++++++++++++++++------------------
3 files changed, 62 insertions(+), 21 deletions(-)

diff --git 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 +}; diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c @@ -9,6 +9,26 @@ enum sflags { 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 @@ load(Node *np) 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 @@ cgen(Node *np) 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 @@ cgen(Node *np) case ODEC: abort(); case OASSIG: - code(op, l, r, NULL); + code(ASASSIG, l, r, NULL); return r; case OCALL: case OFIELD: diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c @@ -12,24 +12,24 @@ static struct opdata { 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"} }; /*