shithub: scc

Download patch

ref: 8c89b0304d6dc5652ccbd9249b1bf0b1e9271d03
parent: 3f821970c3b3572a47db68500f6081db65358298
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Feb 15 10:23:45 EST 2017

[cc1-cc2] Mark vararg function definitions

Qbe needs a special syntax for the declaration of vararg
functions, but we lacked of that information in our IR.
This patch reuses the old format for elipsis type
(which wasn't used anymore) for function with some
vararg parameter.

--- a/cc1/code.c
+++ b/cc1/code.c
@@ -251,7 +251,10 @@
 static void
 emitletter(Type *tp)
 {
-	putc(tp->letter, outfp);
+	int letter;
+
+	letter = (tp->prop&TELLIPSIS) ? 'E' : tp->letter;
+	putc(letter, outfp);
 	switch (tp->op) {
 	case ARY:
 	case STRUCT:
--- a/cc2/arch/amd64-sysv/types.c
+++ b/cc2/arch/amd64-sysv/types.c
@@ -88,11 +88,6 @@
 	.align = 0
 };
 
-Type elipsistype = {
-	.size = 0,
-	.align = 0
-};
-
 Type arg_type = {
 	.size = 24,
 	.align = 8
--- a/cc2/arch/i386-sysv/types.c
+++ b/cc2/arch/i386-sysv/types.c
@@ -88,11 +88,6 @@
 	.align = 0
 };
 
-Type elipsistype = {
-	.size = 0,
-	.align = 0
-};
-
 /* this type is not used in this architecture */
 Type arg_type = {
         .size = 0,
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
@@ -353,7 +353,7 @@
 			break;
 		printf("%s%s %s.val", sep, size2stack(&p->type), symname(p));
 	}
-	puts(")\n{");
+	printf("%s)\n{\n", (curfun->type.flags&ELLIPS) ? ", ..." : "");
 
 	/* emit assembler instructions */
 	for (pc = prog; pc; pc = pc->next) {
--- a/cc2/arch/qbe/types.c
+++ b/cc2/arch/qbe/types.c
@@ -88,11 +88,6 @@
 	.align = 0
 };
 
-Type elipsistype = {
-	.size = 0,
-	.align = 0
-};
-
 Type arg_type = {
 	.size = 24,
 	.align = 8
--- a/cc2/arch/z80/types.c
+++ b/cc2/arch/z80/types.c
@@ -88,11 +88,6 @@
 	.align = 0
 };
 
-Type elipsistype = {
-	.size = 0,
-	.align = 0
-};
-
 /* this types is not going to be used in this arch */
 Type arg_type = {
         .size = 0,
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -13,6 +13,7 @@
 	FUNF    =     1 << 5,  /* function */
 	PARF    =     1 << 6,  /* parameter */
 	INITF   =     1 << 7,  /* initializer flag */
+	ELLIPS  =     1 << 8,  /* vararg function */
 };
 
 enum sclass {
@@ -150,7 +151,7 @@
 struct type {
 	unsigned long size;
 	unsigned long align;
-	char flags;
+	short flags;
 };
 
 struct symbol {
--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -19,9 +19,12 @@
             booltype,
             ptrtype,
             voidtype,
-            elipsistype,
             arg_type;
 
+Type funetype = {
+	.flags = FUNF | ELLIPS
+};
+
 Type funtype = {
 	.flags = FUNF
 };
@@ -78,7 +81,7 @@
 	['0']   = {     NULL,    type, .u.arg =    &voidtype},
 	['B']   = {     NULL,    type, .u.arg =    &booltype},
 	['P']   = {     NULL,    type, .u.arg =     &ptrtype},
-	['E']   = {     NULL,    type, .u.arg = &elipsistype},
+	['E']   = {     NULL,    type, .u.arg =    &funetype},
 	['1']	= {     NULL,    type, .u.arg =    &arg_type},
 
 	['F']   = {     NULL,    type, .u.arg =     &funtype},