commit 6e1706f9eb1bc7e9fd6669ed256da1233d44c554
Author: Pekka Jylhä-Ollila <pekka.jylha.ollila_AT_gmail.com>
AuthorDate: Fri Apr 15 13:54:42 2016 +0300
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Fri Apr 15 13:51:43 2016 +0200
[cc1 - cc2] Output function return type in cc1 and cc2
Print function return type in cc1 and cc2.
In cc1 the return type is printed before the symbol type 'F', so that in cc2
we can first pop 'F' from the stack and see if we need to pop the return type.
The return type needs to be stored somewhere in cc2, so I added it
to Symbol as Symbol.rtype.
diff --git a/cc1/code.c b/cc1/code.c
index ff7f27e..e9f1698 100644
--- a/cc1/code.c
+++ b/cc1/code.c
_AT_@ -226,6 +226,11 @@ emitsym(unsigned op, void *arg)
static void
emitletter(Type *tp)
{
+ if (tp->op == FTN) {
+ emitletter(tp->type);
+ putchar('\t');
+ }
+
putchar(tp->letter);
switch (tp->op) {
case ARY:
diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c
index a993c29..e8840ce 100644
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
_AT_@ -167,7 +167,7 @@ writeout(void)
if (curfun->kind == GLOB)
fputs("export ", stdout);
- printf("function w %s(", symname(curfun));
+ printf("function %s $%s(", size2asm(&curfun->rtype), symname(curfun));
for (p = locals; p && p->type.flags & PARF; p = p->next)
printf("%s %s,", size2asm(&p->type), symname(p));
diff --git a/cc2/cc2.h b/cc2/cc2.h
index eb63665..ba7d3d6 100644
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
_AT_@ -131,6 +131,7 @@ struct type {
struct symbol {
Type type;
+ Type rtype;
unsigned short id;
unsigned short numid;
char *name;
diff --git a/cc2/parser.c b/cc2/parser.c
index b036fbd..c542d88 100644
--- a/cc2/parser.c
+++ b/cc2/parser.c
_AT_@ -524,13 +524,15 @@ decl(Symbol *sym)
static void
vardecl(void)
{
- Type *tp;
+ Type *tp, *rp;
Node *np;
Symbol *sym;
char *name;
name = pop();
tp = pop();
+ if (tp->flags & FUNF)
+ rp = pop();
np = pop();
sym = np->u.sym;
_AT_@ -542,6 +544,8 @@ vardecl(void)
free(sym->name);
sym->name = name;
sym->type = *tp;
+ if (tp->flags & FUNF)
+ sym->rtype = *rp;
sym->kind = sclass;
if (ininit)
Received on Fri Apr 15 2016 - 13:52:13 CEST
This archive was generated by hypermail 2.3.0
: Fri Apr 15 2016 - 14:00:21 CEST