[hackers] [scc] [cc1-cc2] Mark vararg function definitions || Roberto E. Vargas Caballero
commit ad3eeab0b264ec44bfc0d9370a458b1ce9279a6c
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:35:28 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},
Received on Wed Feb 15 2017 - 15:35:40 CET
This archive was generated by hypermail 2.3.0
: Wed Feb 15 2017 - 15:36:23 CET