scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 2922dbe23dbf8ac30c6bed8ade83865abe0450a5
parent 9c68a8b2fe3756f5d9beed87ead96be63d0ab374
Author: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
Date:   Fri, 15 Apr 2016 14:45:44 +0200

[cc2-qbe] Add load() and store() to code.c

These functions emit the actual text needed in
QBE for loading and storing symbols.

Diffstat:
Mcc2/arch/qbe/code.c | 66+++++++++++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 43 insertions(+), 23 deletions(-)

diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c @@ -6,28 +6,30 @@ #include "../../cc2.h" #include "../../../inc/sizes.h" -static void inst3(void); +static void binary(void), load(void), store(void); static struct opdata { void (*fun)(void); char *txt; } optbl [] = { - [OADD] = {.fun = inst3, .txt = "add"}, - [OSUB] = {.fun = inst3, .txt = "sub"}, - [OMUL] = {.fun = inst3, .txt = "mul"}, - [OMOD] = {.fun = inst3, .txt = "rem"}, - [ODIV] = {.fun = inst3, .txt = "div"}, - [OSHL] = {.fun = inst3, .txt = "shl"}, - [OSHR] = {.fun = inst3, .txt = "shr"}, - [OLT] = {.fun = inst3, .txt = "clt"}, - [OGT] = {.fun = inst3, .txt = "cgt"}, - [OLE] = {.fun = inst3, .txt = "cle"}, - [OGE] = {.fun = inst3, .txt = "cge"}, - [OEQ] = {.fun = inst3, .txt = "ceq"}, - [ONE] = {.fun = inst3, .txt = "cne"}, - [OBAND] = {.fun = inst3, .txt = "and"}, - [OBOR] = {.fun = inst3, .txt = "or"}, - [OBXOR] = {.fun = inst3, .txt = "xor"} + [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"} }; /* @@ -231,13 +233,31 @@ addr2txt(Addr *a) } static void -inst3(void) +binary(void) { - printf("\t%s %c= %s\t%s,%s\n", - addr2txt(&pc->to), - 'w', /* FIXME */ - optbl[pc->op].txt, - addr2txt(&pc->from1), addr2txt(&pc->from2)); + printf("\t%s %c=\t%s\t", + addr2txt(&pc->to), 'w', optbl[pc->op].txt); + fputs(addr2txt(&pc->from1), stdout); + putchar(','); + fputs(addr2txt(&pc->from2), stdout); + putchar('\n'); +} + +static void +store(void) +{ + printf("\t\t%s%c\t", optbl[pc->op].txt, 'w'), + fputs(addr2txt(&pc->from1), stdout); + putchar(','); + fputs(addr2txt(&pc->to), stdout); + putchar('\n'); +} + +static void +load(void) +{ + printf("\t%s %c=\t", addr2txt(&pc->to), 'w'); + printf("%s\t%s\n", optbl[pc->op].txt, addr2txt(&pc->from1)); } void