shithub: scc

Download patch

ref: fee4eeac3d4259a138bf98212c72faf394fcd379
parent: a580dd7611be537814383676fd4fb33cad7f6bb3
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Jul 21 13:53:47 EDT 2015

Fix emitcons()

Before of this commit the function was assuming that all the integer
constant were of type inttype, and the rest were strings, generating
a segfault with a long variable for example. This patch adds a skeleton
of what have to be done and a bit of checking.

--- a/cc1/TODO
+++ b/cc1/TODO
@@ -16,3 +16,4 @@
 * Implement enum type in eqtype()
 * Parse correctly all integer and float constants
 * Add C99 features (almost all the new features of C99 are missed)
+* Add correct emit for any kind of constant
--- a/cc1/code.c
+++ b/cc1/code.c
@@ -177,12 +177,22 @@
 	char *bp, c;
 	Symbol *sym = np->sym;
 
-	if (np->type == inttype) {
+	switch (np->type->op) {
+	case INT:
 		printf("#%c%x", np->type->letter, sym->u.i);
-	} else {
+		break;
+	case ARY:
+		/*
+		 * FIX: At this point we are going to assume
+		 * that all the arrays are strings
+		 */
 		putchar('"');
 		for (bp = sym->u.s; c = *bp; ++bp)
-			printf("%02X", (unsigned) c);
+			printf("%02X", c & 0xFF);
+		break;
+	default:
+		/* TODO: Handle other kind of constants */
+		abort;
 	}
 }