scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit ad3eeab0b264ec44bfc0d9370a458b1ce9279a6c
parent 9f519ebee29edca444e31fb8f01348f35252a754
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 15 Feb 2017 15:23:45 +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.

Diffstat:
Mcc1/code.c | 5++++-
Mcc2/arch/amd64-sysv/types.c | 5-----
Mcc2/arch/i386-sysv/types.c | 5-----
Mcc2/arch/qbe/code.c | 2+-
Mcc2/arch/qbe/types.c | 5-----
Mcc2/arch/z80/types.c | 5-----
Mcc2/cc2.h | 3++-
Mcc2/parser.c | 7+++++--
8 files changed, 12 insertions(+), 25 deletions(-)

diff --git a/cc1/code.c b/cc1/code.c @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 { @@ -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 @@ -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 }; @@ -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},