shithub: scc

Download patch

ref: a4fa945f60bc687372451bf44e75d4d11f9486b2
parent: 48fa7fb8560c55dda4fdb5446568a359aad6b892
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu Apr 14 04:01:55 EDT 2016

Revert "[cc2] Remove sigil function from qbe"

This reverts commit 669131252b1f35c13e32a47e22e84026ac69d1a8.

--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
@@ -6,11 +6,35 @@
 #include "../../cc2.h"
 #include "../../../inc/sizes.h"
 
+/*
+ * : is for user-defined Aggregate Types
+ * $ is for globals (represented by a pointer)
+ * % is for function-scope temporaries
+ * @ is for block labels
+ */
+static char
+sigil(Symbol *sym)
+{
+	switch (sym->kind) {
+	case EXTRN:
+	case GLOB:
+	case PRIVAT:
+	case LOCAL:
+		return '$';
+	case AUTO:
+	case REG:
+		return '%';
+	default:
+		abort();
+	}
+}
+
 static char *
 symname(Symbol *sym)
 {
-	static char name[IDENTSIZ+1];
+	static char name[IDENTSIZ+2];
 	static unsigned short id;
+	char c = sigil(sym);
 
 	if (sym->name) {
 		switch (sym->kind) {
@@ -17,6 +41,7 @@
 		case EXTRN:
 		case GLOB:
 		case PRIVAT:
+			sprintf(name, "%c%s", c, sym->name);
 			return sym->name;
 		}
 	}
@@ -23,7 +48,7 @@
 
 	if (sym->numid == 0 && (sym->numid = ++id) == 0)
 		error(EIDOVER);
-	sprintf(name, ".L%d", sym->numid);
+	sprintf(name, "%c.%d", c, sym->numid);
 
 	return name;
 }
@@ -115,7 +140,7 @@
 		return;
 	if (sym->kind == GLOB)
 		fputs("export ", stdout);
-	printf("data $%s = {\n", symname(sym));
+	printf("data %s = {\n", symname(sym));
 	if (sym->type.flags & INITF)
 		return;
 	printf("\tz\t%llu\n}\n", (unsigned long long) sym->type.size);
@@ -146,7 +171,7 @@
 {
 	if (curfun->kind == GLOB)
 		fputs("export ", stdout);
-	printf("function $%s(", symname(curfun));
+	printf("function %s(", symname(curfun));
 	puts("){");
 	puts("}");
 }