scc

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

commit db5ea284e2d99a5aa3aa5fcb8242eda7c2bd9904
parent a914d8f2874b128360789b7c2e2511b0aa078978
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 22 Apr 2016 14:13:46 +0200

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

Diffstat:
Mcc2/arch/qbe/arch.h | 7++++++-
Mcc2/arch/qbe/cgen.c | 18+++++++++++++++++-
Mcc2/arch/qbe/code.c | 18++++++++++++------
3 files changed, 35 insertions(+), 8 deletions(-)

diff --git 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, diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c @@ -198,7 +198,23 @@ cgen(Node *np) 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: diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c @@ -17,7 +17,12 @@ static struct opdata { 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 @@ binary(void) 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