scc

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

commit 8b6cc7d0182df1ccb3dd60ad44abfad031234f25
parent c147c6119701d0534777b62521f36b4367967b66
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 21 Apr 2016 17:42:23 +0200

[cc2-qbe] Add support for sign in comparisions

Signed types and unsigned types have a different opcode in qbe, so
we have to look the signess of the types to see what is the opcode
we have to use.

Diffstat:
Mcc2/arch/qbe/arch.h | 8++++++++
Mcc2/arch/qbe/cgen.c | 21++++++++++++++-------
Mcc2/arch/qbe/code.c | 24++++++++++++++++--------
3 files changed, 38 insertions(+), 15 deletions(-)

diff --git a/cc2/arch/qbe/arch.h b/cc2/arch/qbe/arch.h @@ -16,9 +16,13 @@ enum asmop { ASSHLW, ASSHRW, ASLTW, + ASULTW, ASGTW, + ASUGTW, ASLEW, + ASULEW, ASGEW, + ASUGEW, ASEQW, ASNEW, ASBANDW, @@ -34,9 +38,13 @@ enum asmop { ASSHLL, ASSHRL, ASLTL, + ASULTL, ASGTL, + ASUGTL, ASLEL, + ASULEL, ASGEL, + ASUGEL, ASEQL, ASNEL, ASBANDL, diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c @@ -122,7 +122,7 @@ cgen(Node *np) Node *l, *r; Symbol *sym; Type *tp; - int op; + int op, off; char *tbl; if (!np) @@ -142,6 +142,16 @@ cgen(Node *np) case OMEM: case OAUTO: return np; + case OLT: + case OGT: + case OLE: + case OGE: + /* + * unsigned version of operations are always +1 the + * signed version + */ + off = (tp->flags & SIGNF) == 0; + goto binary; case OADD: case OSUB: case OMUL: @@ -149,16 +159,14 @@ cgen(Node *np) case ODIV: case OSHL: case OSHR: - case OLT: - case OGT: - case OLE: - case OGE: case OBAND: case OBOR: case OBXOR: case OCPL: case OEQ: case ONE: + off = 0; + binary: switch (tp->size) { case 4: tbl = (tp->flags & INTF) ? opasmw : opasms; @@ -169,8 +177,7 @@ cgen(Node *np) default: abort(); } - op = tbl[np->op]; - binary: + op = tbl[np->op] + off; if ((l->flags & (ISTMP|ISCONS)) == 0) l = np->left = load(l); if ((r->flags & (ISTMP|ISCONS)) == 0) diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c @@ -26,10 +26,14 @@ static struct opdata { [ASDIVW] = {.fun = binary, .txt = "div", .letter = 'w'}, [ASSHLW] = {.fun = binary, .txt = "shl", .letter = 'w'}, [ASSHRW] = {.fun = binary, .txt = "shr", .letter = 'w'}, - [ASLTW] = {.fun = binary, .txt = "cltw", .letter = 'w'}, - [ASGTW] = {.fun = binary, .txt = "cgtw", .letter = 'w'}, - [ASLEW] = {.fun = binary, .txt = "clew", .letter = 'w'}, - [ASGEW] = {.fun = binary, .txt = "cgew", .letter = 'w'}, + [ASLTW] = {.fun = binary, .txt = "csltw", .letter = 'w'}, + [ASULTW] = {.fun = binary, .txt = "cultw", .letter = 'w'}, + [ASGTW] = {.fun = binary, .txt = "csgtw", .letter = 'w'}, + [ASUGTW] = {.fun = binary, .txt = "cugtw", .letter = 'w'}, + [ASLEW] = {.fun = binary, .txt = "cslew", .letter = 'w'}, + [ASULEW] = {.fun = binary, .txt = "culew", .letter = 'w'}, + [ASGEW] = {.fun = binary, .txt = "csgew", .letter = 'w'}, + [ASUGEW] = {.fun = binary, .txt = "cugew", .letter = 'w'}, [ASEQW] = {.fun = binary, .txt = "ceqw", .letter = 'w'}, [ASNEW] = {.fun = binary, .txt = "cnew", .letter = 'w'}, [ASBANDW] = {.fun = binary, .txt = "and", .letter = 'w'}, @@ -43,10 +47,14 @@ static struct opdata { [ASDIVL] = {.fun = binary, .txt = "div", .letter = 'l'}, [ASSHLL] = {.fun = binary, .txt = "shl", .letter = 'l'}, [ASSHRL] = {.fun = binary, .txt = "shr", .letter = 'l'}, - [ASLTL] = {.fun = binary, .txt = "cltl", .letter = 'w'}, - [ASGTL] = {.fun = binary, .txt = "cgtl", .letter = 'w'}, - [ASLEL] = {.fun = binary, .txt = "clel", .letter = 'w'}, - [ASGEL] = {.fun = binary, .txt = "cgel", .letter = 'w'}, + [ASLTL] = {.fun = binary, .txt = "csltl", .letter = 'w'}, + [ASULTL] = {.fun = binary, .txt = "cultl", .letter = 'w'}, + [ASGTL] = {.fun = binary, .txt = "csgtl", .letter = 'w'}, + [ASUGTL] = {.fun = binary, .txt = "cugtl", .letter = 'w'}, + [ASLEL] = {.fun = binary, .txt = "cslel", .letter = 'w'}, + [ASULEL] = {.fun = binary, .txt = "culel", .letter = 'w'}, + [ASGEL] = {.fun = binary, .txt = "csgel", .letter = 'w'}, + [ASUGEL] = {.fun = binary, .txt = "cugel", .letter = 'w'}, [ASEQL] = {.fun = binary, .txt = "ceql", .letter = 'w'}, [ASNEL] = {.fun = binary, .txt = "cnel", .letter = 'w'}, [ASBANDL] = {.fun = binary, .txt = "and", .letter = 'l'},