shithub: scc

Download patch

ref: 6b728d267fc34a0b1420eeb0f1ecb842baf35a48
parent: d13e4fe2e99ade7fffe53f72519ded2c1fb3665b
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Sep 16 10:53:08 EDT 2016

[cc2-qbe] Add basic support for struct assignment

At this moment there is no implementatin of struct assignment in
qbe, so this is only a skeleton to be filled later.

--- a/cc2/arch/qbe/arch.h
+++ b/cc2/arch/qbe/arch.h
@@ -9,6 +9,7 @@
 	ASSTH,
 	ASSTW,
 	ASSTL,
+	ASSTM,
 	ASSTS,
 	ASSTD,
 
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -113,6 +113,10 @@
 {
 	int op;
 
+	if (tp->flags & AGGRF) {
+		*new = *np;
+		return new;
+	}
 	switch (tp->size) {
 	case 1:
 		op = ASLDB;
@@ -127,8 +131,7 @@
 		op = (tp->flags & FLOATF) ? ASLDD : ASLDL;
 		break;
 	default:
-		*new = *np;
-		return new;
+		abort();
 	}
 	code(op, tmpnode(new, tp), np, NULL);
 
@@ -273,7 +276,8 @@
 		op = (tp->flags & FLOATF) ? ASSTD : ASSTL;
 		break;
 	default:
-		abort();
+		op = ASSTM;
+		break;
 	}
 	code(op, to, from, NULL);
 	return from;
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
@@ -11,7 +11,7 @@
 
 static void binary(void), unary(void), store(void), jmp(void), ret(void),
             branch(void), call(void), ecall(void), param(void),
-            alloc(void), form2local(void);
+            alloc(void), form2local(void), ldir(void);
 
 static struct opdata {
 	void (*fun)(void);
@@ -29,6 +29,7 @@
 	[ASSTH]   =  {.fun = store,  .txt = "store", .letter = 'h'},
 	[ASSTW]   =  {.fun = store,  .txt = "store", .letter = 'w'},
 	[ASSTL]   =  {.fun = store,  .txt = "store", .letter = 'l'},
+	[ASSTM]   =  {.fun = ldir},
 	[ASSTS]   =  {.fun = store,  .txt = "store", .letter = 's'},
 	[ASSTD]   =  {.fun = store,  .txt = "store", .letter = 'd'},
 
@@ -366,6 +367,16 @@
 	strcpy(from1, addr2txt(&pc->from1));
 	strcpy(from2, addr2txt(&pc->from2));
 	printf("\t%s =%c\t%s\t%s,%s\n", to, p->letter, p->txt, from1, from2);
+}
+
+static void
+ldir(void)
+{
+	struct opdata *p = &optbl[pc->op];
+	char to[ADDR_LEN], from[ADDR_LEN];
+	/* TODO: what type do we use for the size? */
+
+	/* TODO: it is pending */
 }
 
 static void
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -9,7 +9,7 @@
 	INTF    =     2,
 	FLOATF  =     4,
 	STRF    =     8,
-	UNIONF  =    16,
+	AGGRF   =    16,
 	FUNF    =    32,
 	PARF    =    64,
 };
--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -487,6 +487,7 @@
 
 	tp->size = size->u.i;
 	tp->align = align->u.i;
+	tp->flags = AGGRF;
 	/*
 	 * type is the first field of Symbol so we can obtain the
 	 * address of the symbol from the address of the type.