shithub: scc

Download patch

ref: a17171c31cbee75461bd04eb7b406a7a73b31e76
parent: bf0048dd143ca9fcd3ba58b6e3c380e8a7e30726
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Apr 22 11:43:13 EDT 2016

[cc2] Remove rtype field from Type

We are going ot have only one rtype at the same time,
because it is the return type of the current function,
so it is a bit stupid to waste 2/4/8 bytes of every symbol
for this.

--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
@@ -276,7 +276,7 @@
 
 	if (curfun->kind == SGLOB)
 		fputs("export ", stdout);
-	printf("function %s %s(", size2asm(&curfun->rtype), symname(curfun));
+	printf("function %s %s(", size2asm(&rtype), symname(curfun));
 
 	/* declare formal parameters */
 	for (sep = "", p = locals; p; p = p->next, sep = ",") {
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -132,7 +132,6 @@
 
 struct symbol {
 	Type type;
-	Type rtype;
 	unsigned short id;
 	unsigned short numid;
 	char *name;
@@ -217,6 +216,7 @@
 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
@@ -10,6 +10,7 @@
 #define NNODES   32
 
 Symbol *curfun;
+Type rtype;
 
 struct arena {
 	Node *mem;
--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -537,7 +537,7 @@
 	sym->name = name;
 	sym->type = *tp;
 	if (tp->flags & FUNF)
-		sym->rtype = *rp;
+		rtype = *rp;
 	sym->kind = sclass;
 
 	if (ininit)
--