[hackers] [scc] [cc1-cc2] Mark vararg function definitions || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Wed, 15 Feb 2017 15:26:33 +0100 (CET)

commit 00160b91a0d11766923de60a9ee162c382aaf4f1
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Wed Feb 15 15:23:45 2017 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Wed Feb 15 15:25:53 2017 +0100

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

diff --git a/cc1/code.c b/cc1/code.c
index 7931c75..c4ce697 100644
--- a/cc1/code.c
+++ b/cc1/code.c
_AT_@ -251,7 +251,10 @@ emitsym(unsigned op, void *arg)
 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:
diff --git a/cc2/arch/amd64-sysv/types.c b/cc2/arch/amd64-sysv/types.c
index 1abef83..44ee603 100644
--- a/cc2/arch/amd64-sysv/types.c
+++ b/cc2/arch/amd64-sysv/types.c
_AT_@ -88,11 +88,6 @@ Type voidtype = {
         .align = 0
 };
 
-Type elipsistype = {
- .size = 0,
- .align = 0
-};
-
 Type arg_type = {
         .size = 24,
         .align = 8
diff --git a/cc2/arch/i386-sysv/types.c b/cc2/arch/i386-sysv/types.c
index 2a448e8..23ff8d4 100644
--- a/cc2/arch/i386-sysv/types.c
+++ b/cc2/arch/i386-sysv/types.c
_AT_@ -88,11 +88,6 @@ Type voidtype = {
         .align = 0
 };
 
-Type elipsistype = {
- .size = 0,
- .align = 0
-};
-
 /* this type is not used in this architecture */
 Type arg_type = {
         .size = 0,
diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c
index 0a62e24..d2cd66b 100644
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
_AT_@ -353,7 +353,7 @@ writeout(void)
                         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) {
diff --git a/cc2/arch/qbe/types.c b/cc2/arch/qbe/types.c
index dcd6f20..c256ab3 100644
--- a/cc2/arch/qbe/types.c
+++ b/cc2/arch/qbe/types.c
_AT_@ -88,11 +88,6 @@ Type voidtype = {
         .align = 0
 };
 
-Type elipsistype = {
- .size = 0,
- .align = 0
-};
-
 Type arg_type = {
         .size = 24,
         .align = 8
diff --git a/cc2/arch/z80/types.c b/cc2/arch/z80/types.c
index 06b8eb7..e53417b 100644
--- a/cc2/arch/z80/types.c
+++ b/cc2/arch/z80/types.c
_AT_@ -88,11 +88,6 @@ Type voidtype = {
         .align = 0
 };
 
-Type elipsistype = {
- .size = 0,
- .align = 0
-};
-
 /* this types is not going to be used in this arch */
 Type arg_type = {
         .size = 0,
diff --git a/cc2/cc2.h b/cc2/cc2.h
index 5b06260..d393ea2 100644
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
_AT_@ -13,6 +13,7 @@ enum tflags {
         FUNF = 1 << 5, /* function */
         PARF = 1 << 6, /* parameter */
         INITF = 1 << 7, /* initializer flag */
+ ELLIPS = 1 << 8, /* vararg function */
 };
 
 enum sclass {
_AT_@ -150,7 +151,7 @@ typedef struct inst Inst;
 struct type {
         unsigned long size;
         unsigned long align;
- char flags;
+ short flags;
 };
 
 struct symbol {
diff --git a/cc2/parser.c b/cc2/parser.c
index e8ea893..7a51941 100644
--- a/cc2/parser.c
+++ b/cc2/parser.c
_AT_@ -19,9 +19,12 @@ extern Type int8type, int16type, int32type, int64type,
             booltype,
             ptrtype,
             voidtype,
- elipsistype,
             arg_type;
 
+Type funetype = {
+ .flags = FUNF | ELLIPS
+};
+
 Type funtype = {
         .flags = FUNF
 };
_AT_@ -78,7 +81,7 @@ static struct decoc {
         ['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},
diff --git a/config.mk b/config.mk
index b1cc627..ab95416 100644
--- a/config.mk
+++ b/config.mk
_AT_@ -23,7 +23,6 @@ MANPREFIX = $(PREFIX)/share/man
 SCC_CFLAGS = -DARCH=\"$(ARCH)\" \
              $(CSTDINC) \
              -DPREFIX=\"$(PREFIX)\" \
- -DNDEBUG \
              $(CFLAGS)
 
 SCC_LDFLAGS = $(LDFLAGS)
Received on Wed Feb 15 2017 - 15:26:33 CET

This archive was generated by hypermail 2.3.0 : Wed Feb 15 2017 - 15:36:18 CET