shithub: scc

Download patch

ref: 73db3c729687684d80a30f3edab1eecc55b8ae5f
parent: 915befc8a258da8337f7329437fe819d5ce18a22
author: Roberto E. Vargas Caballero <[email protected]>
date: Fri Apr 22 10:59:35 EDT 2016

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

--- 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,
@@ -12,6 +11,13 @@
 	ASSTL,
 	ASSTS,
 	ASSTD,
+
+	ASLDB,
+	ASLDH,
+	ASLDW,
+	ASLDL,
+	ASLDS,
+	ASLDD,
 
 	ASADDW,
 	ASSUBW,
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -107,11 +107,30 @@
 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;
 }
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
@@ -16,7 +16,13 @@
 	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 @@
 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