shithub: scc

Download patch

ref: 507e3c823892f2f2bac6acd42bab1b079798fa05
parent: 9d1c91396f9fa249332adf91de26cb7f98a60f88
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed May 6 13:05:11 EDT 2015

Makes all emit*() only one parameter

We want to convert all the emit functions in only one function,
so the first step to become them more uniform, because in some
moment we will transform them into opcode[] elements.

--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -166,9 +166,10 @@
 extern void
 	emitdcl(Symbol *), emitefun(void),
 	emitexp(Node *),
-	emitprint(Node *), emitlabel(Symbol *), emitjump(Symbol *, Node *),
+	emitprint(Node *), emitlabel(Symbol *), emitjump(Symbol *),
+	emitbranch(Symbol *sym),
 	emitbloop(void), emiteloop(void),
-	emitswitch(short, Node *), emitcase(Symbol *, Node *),
+	emitswitch(short), emitcase(Symbol *),
 	emitret(Type *tp),
 	emitfun(Symbol *sym),
 	emitdefault(Symbol *),
--- a/cc1/code.c
+++ b/cc1/code.c
@@ -288,28 +288,28 @@
 }
 
 void
-emitjump(Symbol *sym, Node *np)
+emitjump(Symbol *sym)
 {
+	printf("\tj\tL%d\n", sym->id);
+}
+
+void
+emitbranch(Symbol *sym)
+{
 	printf("\tj\tL%d", sym->id);
-	if (!np)
-		putchar('\n');
-	else
-		emitexp(np);
 }
 
 void
-emitswitch(short nr, Node *np)
+emitswitch(short nr)
 {
 	printf("\teI\t#%0x", nr);
-	emitexp(np);
 }
 
 void
-emitcase(Symbol *sym, Node *np)
+emitcase(Symbol *sym)
 {
 	fputs("\tw\t", stdout);
 	printf("L%d", sym->id);
-	emitexp(np);
 }
 
 void
--- a/cc1/stmt.c
+++ b/cc1/stmt.c
@@ -87,12 +87,13 @@
 
 	expect(WHILE);
 	np = condition();
-	emitjump(cond, NULL);
+	emitjump(cond);
 	emitbloop();
 	emitlabel(begin);
 	stmt(end, begin, lswitch);
 	emitlabel(cond);
-	emitjump(begin, np);
+	emitbranch(begin);
+	emitexp(np);
 	emiteloop();
 	emitlabel(end);
 	freetree(np);
@@ -118,13 +119,14 @@
 	expect(')');
 
 	emitexp(einit);
-	emitjump(cond, NULL);
+	emitjump(cond);
 	emitbloop();
 	emitlabel(begin);
 	stmt(end, begin, lswitch);
 	emitexp(einc);
 	emitlabel(cond);
-	emitjump(begin, econd);
+	emitbranch(begin);
+	emitexp(econd);
 	emiteloop();
 	emitlabel(end);
 	freetree(einit);
@@ -146,7 +148,8 @@
 	stmt(end, begin, lswitch);
 	expect(WHILE);
 	np = condition();
-	emitjump(begin, np);
+	emitbranch(begin);
+	emitexp(np);
 	emiteloop();
 	emitlabel(end);
 	freetree(np);
@@ -182,7 +185,7 @@
 	expect(BREAK);
 	if (!lbreak)
 		error("break statement not within loop or switch");
-	emitjump(lbreak, NULL);
+	emitjump(lbreak);
 	expect(';');
 }
 
@@ -209,7 +212,7 @@
 	expect(CONTINUE);
 	if (!lcont)
 		error("continue statement not within loop");
-	emitjump(lcont, NULL);
+	emitjump(lcont);
 	expect(';');
 }
 
@@ -220,7 +223,7 @@
 
 	if (yytoken != IDEN)
 		unexpected();
-	emitjump(label(yytext, 0), NULL);
+	emitjump(label(yytext, 0));
 	next();
 	expect(';');
 }
@@ -243,12 +246,14 @@
 
 	lbreak = install("", NS_LABEL);
 	lcond = install("", NS_LABEL);
-	emitjump(lcond, NULL);
+	emitjump(lcond);
 	stmt(lbreak, lcont, &lcase);
 	emitlabel(lcond);
-	emitswitch(lcase.nr, cond);
+	emitswitch(lcase.nr);
+	emitexp(cond);
 	for (p = lcase.head; p; p = next) {
-		emitcase(p->label, p->expr);
+		emitcase(p->label);
+		emitexp(p->expr);
 		next = p->next;
 		freetree(p->expr);
 		free(p);
@@ -301,11 +306,12 @@
 	expect(IF);
 	np = condition();
 	NEGATE(np, 1);
-	emitjump(lelse, np);
+	emitbranch(lelse);
+	emitexp(np);
 	stmt(lbreak, lcont, lswitch);
 	if (accept(ELSE)) {
 		end = install("", NS_LABEL);
-		emitjump(end, NULL);
+		emitjump(end);
 		emitlabel(lelse);
 		stmt(lbreak, lcont, lswitch);
 		emitlabel(end);