shithub: scc

Download patch

ref: c771b60a3dc764099b67879f8c9f529a121ba44a
parent: 80450c349f4ca1207c3dfcfbd4e7d91f90bb537e
author: FRIGN <[email protected]>
date: Tue May 17 13:06:13 EDT 2016

Re-add rtype-field to Symbol-type

The global rtype worked previously, but now we have not only one return
type. So we move that one back into the Symbol-type.

"Hay un cierto placer en la locura, que solo el loco conoce."
   - Pablo Neruda

--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
@@ -303,7 +303,7 @@
 
 	if (curfun->kind == SGLOB)
 		fputs("export ", stdout);
-	printf("function %s %s(", size2asm(&rtype), symname(curfun));
+	printf("function %s %s(", size2asm(&curfun->rtype), symname(curfun));
 
 	/* declare formal parameters */
 	for (sep = "", p = locals; p; p = p->next, sep = ",") {
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -133,6 +133,7 @@
 
 struct symbol {
 	Type type;
+	Type rtype;
 	unsigned short id;
 	unsigned short numid;
 	char *name;
@@ -223,7 +224,6 @@
 extern void freesym(Symbol *sym);
 
 /* globals */
-extern Type rtype;
 extern Symbol *curfun;
 extern Symbol *locals;
 extern Inst *pc, *prog;
--- a/cc2/node.c
+++ b/cc2/node.c
@@ -11,7 +11,6 @@
 
 Node *curstmt;
 Symbol *curfun;
-Type rtype;
 
 struct arena {
 	Node *mem;
--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -513,7 +513,7 @@
 	sym->name = name;
 	sym->type = *tp;
 	if (tp->flags & FUNF)
-		rtype = *rp;
+		sym->rtype = *rp;
 	sym->kind = sclass;
 
 	if (ininit)