ref: 89c576b05ec3efa7bfe0880be3002742fba88cd1
parent: c6c78143c4f439c038bfaf363b46352bd17d3430
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Apr 22 10:13:46 EDT 2016
[cc2-qbe] Add all the possibilities to store Store can store integer of 1,2,4 or 8 bytes, or floats of 4 or 8 bytes.
--- a/cc2/arch/qbe/arch.h
+++ b/cc2/arch/qbe/arch.h
@@ -6,7 +6,12 @@
enum asmop {ASLOAD,
- ASASSIG,
+ ASSTB,
+ ASSTH,
+ ASSTW,
+ ASSTL,
+ ASSTS,
+ ASSTD,
ASADDW,
ASSUBW,
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -198,7 +198,23 @@
case ODEC:
abort();
case OASSIG:
- code(ASASSIG, l, r, NULL);
+ switch (tp->size) {+ case 1:
+ op = ASSTB;
+ break;
+ case 2:
+ op = ASSTH;
+ break;
+ case 4:
+ op = (tp->flags & INTF) ? ASSTW : ASSTS;
+ break;
+ case 8:
+ op = (tp->flags & INTF) ? ASSTL : ASSTD;
+ break;
+ default:
+ abort();
+ }
+ code(op, l, r, NULL);
return r;
case OCALL:
case OFIELD:
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
@@ -17,7 +17,12 @@
char letter;
} optbl [] = { [ASLOAD] = {.fun = load, .txt = "load", .letter = 'w'},- [ASASSIG] = {.fun = store, .txt = "store", .letter = 'w'},+ [ASSTB] = {.fun = store, .txt = "store", .letter = 'b'},+ [ASSTH] = {.fun = store, .txt = "store", .letter = 'h'},+ [ASSTW] = {.fun = store, .txt = "store", .letter = 'w'},+ [ASSTL] = {.fun = store, .txt = "store", .letter = 'l'},+ [ASSTS] = {.fun = store, .txt = "store", .letter = 's'},+ [ASSTD] = {.fun = store, .txt = "store", .letter = 'd'}, [ASADDW] = {.fun = binary, .txt = "add", .letter = 'w'}, [ASSUBW] = {.fun = binary, .txt = "sub", .letter = 'w'},@@ -330,11 +335,12 @@
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');+ struct opdata *p = &optbl[pc->op];
+ char to[ADDR_LEN], from[ADDR_LEN];
+
+ strcpy(to, addr2txt(&pc->to));
+ strcpy(from, addr2txt(&pc->from1));
+ printf("\t\t%s%c\t%s,%s\n", p->txt, p->letter, from, to);}
static void
--
⑨