scc

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

commit 97ce08e631def638abe4aa08e45378e71bcdcf5a
parent 09da26144179fcba493815c2068f7df631cc9b54
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 22 Apr 2016 14:59:35 +0200

[cc2-qbe] Add different versions of load operations

Load depend of the type that is going to be loaded from
memory, so we need a different opcode for the different
sizes.

Diffstat:
Mcc2/arch/qbe/arch.h | 8+++++++-
Mcc2/arch/qbe/cgen.c | 23+++++++++++++++++++++--
Mcc2/arch/qbe/code.c | 16+++++++++++++---
3 files changed, 41 insertions(+), 6 deletions(-)

diff --git a/cc2/arch/qbe/arch.h b/cc2/arch/qbe/arch.h @@ -5,7 +5,6 @@ #define TSIZE unsigned long enum asmop { - ASLOAD, ASSTB, ASSTH, ASSTW, @@ -13,6 +12,13 @@ enum asmop { ASSTS, ASSTD, + ASLDB, + ASLDH, + ASLDW, + ASLDL, + ASLDS, + ASLDD, + ASADDW, ASSUBW, ASMULW, diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c @@ -107,11 +107,30 @@ static Node * load(Node *np) { Node *new; + int op; + Type *tp = &np->type; new = tmpnode(newnode()); new->left = np; - new->type = np->type; - code(ASLOAD, new, np, NULL); + new->type = *tp; + + switch (tp->size) { + case 1: + op = ASLDB; + break; + case 2: + op = ASLDH; + break; + case 4: + op = (tp->flags & INTF) ? ASLDW : ASLDS; + break; + case 8: + op = (tp->flags & INTF) ? ASLDL : ASLDD; + break; + default: + abort(); + } + code(op, new, np, NULL); return new; } diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c @@ -16,7 +16,13 @@ static struct opdata { char *txt; char letter; } optbl [] = { - [ASLOAD] = {.fun = load, .txt = "load", .letter = 'w'}, + [ASLDB] = {.fun = load, .txt = "load", .letter = 'b'}, + [ASLDH] = {.fun = load, .txt = "load", .letter = 'h'}, + [ASLDW] = {.fun = load, .txt = "load", .letter = 'w'}, + [ASLDL] = {.fun = load, .txt = "load", .letter = 'l'}, + [ASLDS] = {.fun = load, .txt = "load", .letter = 's'}, + [ASLDD] = {.fun = load, .txt = "load", .letter = 'd'}, + [ASSTB] = {.fun = store, .txt = "store", .letter = 'b'}, [ASSTH] = {.fun = store, .txt = "store", .letter = 'h'}, [ASSTW] = {.fun = store, .txt = "store", .letter = 'w'}, @@ -346,8 +352,12 @@ store(void) 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)); + 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%s %c=\t%s\t%s\n", to, p->letter, p->txt, from); } void