shithub: scc

Download patch

ref: 61d8726cf90753d8e36ad03684becdd2420d0d40
parent: f83b3b72e8baead496893abecf170e118603689b
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Jun 17 09:55:27 EDT 2016

[cc2-qbe] Force to have a label in bb

Qbe needs a label at the beginning of every basic block
so we have to check this condition.

--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
@@ -304,6 +304,7 @@
 	Symbol *p;
 	Type *tp;
 	char *sep, *name;
+	int haslabel;
 
 	if (curfun->kind == SGLOB)
 		fputs("export ", stdout);
@@ -315,14 +316,21 @@
 			break;
 		printf("%s%s %s.val", sep, size2asm(&p->type), symname(p));
 	}
-	puts(")\n{\n@.start");
+	puts(")\n{");
 
 	/* emit assembler instructions */
 	for (pc = prog; pc; pc = pc->next) {
-		if (pc->label)
+		if (pc->label) {
+			haslabel = 1;
 			printf("%s\n", symname(pc->label));
-		if (pc->op)
-			(*optbl[pc->op].fun)();
+		}
+		if (!pc->op)
+			continue;
+		if (pc->flags&BBENTRY && !haslabel)
+			printf("%s\n", symname(newlabel()));
+		(*optbl[pc->op].fun)();
+		if (!pc->label)
+			haslabel = 0;
 	}
 
 	puts("}");
@@ -486,7 +494,8 @@
 		case ASCALLL:
 		case ASCALLD:
 		case ASCALL:
-			pc->flags |= BBENTRY;
+			if (pc->next)
+				pc->next->flags |= BBENTRY;
 			break;
 		}
 	}