shithub: scc

Download patch

ref: c677d8a0ea50a1a005d88f82c17c30c345549642
parent: 606b97ad13fb4cd06ed620a08d9fcd362e16c882
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu Jun 2 10:50:07 EDT 2016

[cc2-qbe] Add type in function parameters

This was the last point missed in function calls, and after this point
we can generate beatiful programs that will do something interesting.

--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -266,7 +266,9 @@
 
 	for (q = pars; q < &pars[n]; ++q) {
 		op = (q == &pars[n-1]) ? ASPARE : ASPAR;
-		code(op, NULL, *q, NULL);
+		p = newnode(OTMP);
+		p->type = (*q)->type;
+		code(op, NULL, *q, tmpnode(p));
 	}
 	code(ASCALL, NULL, NULL, NULL);
 
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
@@ -133,8 +133,8 @@
 	[ASCALLL] = {.fun = call, .letter = 'l'},
 	[ASCALLD] = {.fun = call, .letter = 'd'},
 	[ASCALL] = {.fun = ecall},
-	[ASPAR] = {.fun = param, .txt = "\t\t%s,\n"},
-	[ASPARE] = {.fun = param, .txt = "\t\t%s\n"},
+	[ASPAR] = {.fun = param, .txt = "\t\t%s %s,\n"},
+	[ASPARE] = {.fun = param, .txt = "\t\t%s %s\n"},
 };
 
 static char buff[ADDR_LEN];
@@ -421,7 +421,10 @@
 static void
 param(void)
 {
-	printf(optbl[pc->op].txt, addr2txt(&pc->from1));
+	Symbol *sym = pc->from2.u.sym;
+
+	printf(optbl[pc->op].txt,
+	       size2asm(&sym->type), addr2txt(&pc->from1));
 }
 
 static void