shithub: scc

Download patch

ref: 1c3ae449cdff510ea0a8d628f60f8749442abe10
parent: 60f62db06595ad07503f3a587607d466c0d460a0
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Sep 10 13:14:27 EDT 2014

Use different symbols for function and global statics

They are basically different, because function static are local names,
while global static are global (of course). In both cases we have to
reserve static memory for them, but they use different tables in cc2.

--- a/cc1/code.c
+++ b/cc1/code.c
@@ -69,10 +69,12 @@
 {
 	char c;
 
-	if (sym->s.isglobal)
-		c = 'G';
-	else if (sym->s.isstatic)
+	if (sym->s.isstatic && !sym->s.isglobal)
 		c = 'T';
+	else if (sym->s.isstatic && sym->s.isglobal)
+		c = 'Y';
+	else if (sym->s.isglobal)
+		c = 'G';
 	else if (sym->s.isregister)
 		c = 'Q';
 	else
@@ -189,7 +191,7 @@
 emitfun(Symbol *sym)
 {
 	printf("%c%d\tF\t%s\t{\n",
-	       sym->s.isglobal ? 'G' : 'T', sym->id, sym->name);
+	       sym->s.isglobal ? 'G' : 'Y', sym->id, sym->name);
 }
 
 void
--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -165,8 +165,6 @@
 
 	switch (token[0]) {
 	case 'T':
-		if (!curfun)
-			goto global;
 		op = MEM;
 		goto local;
 	case 'P':
@@ -182,6 +180,7 @@
 		break;
 	case 'X':
 		/* TODO */
+	case 'Y':
 	case 'G':
 	global:
 		sym = global(token);
@@ -293,6 +292,7 @@
 	['^'] = operator,
 	[':'] = assignment,
 	[';'] = increment,
+	['Y'] = variable,
 	['A'] = variable,
 	['T'] = variable,
 	['G'] = variable,
@@ -352,10 +352,10 @@
 		curfun->u.f.pars = sym;
 		break;
 	case 'T':
-		if (!curfun) {
-			sym = global(token);
-			break;
-		}
+		if (!curfun)
+			error(ESYNTAX);
+		sym = local(token);
+		break;
 	case 'R': case 'A':
 		if (!curfun)
 			error(ESYNTAX);
@@ -367,6 +367,9 @@
 		sym = global(token);
 		sym->extrn = 1;
 		break;
+	case 'Y':
+		sym = global(token);
+		break;
 	case 'G':
 		sym = global(token);
 		sym->public = 1;
@@ -435,7 +438,7 @@
 		case 'S':
 			/* struct */
 			break;
-		case 'T': case 'G': case 'A': case 'R': case 'P':
+		case 'Y': case 'T': case 'G': case 'A': case 'R': case 'P':
 			fun = declaration;
 			break;
 		case '}':
--