shithub: scc

Download patch

ref: ecd4d6b2a8336c5afbfaf469ada838d850755234
parent: 97f296d2d458fd1a887b903aec6b6dd72c64efa2
author: Roberto E. Vargas Caballero <[email protected]>
date: Wed May 6 15:19:19 EDT 2015

Remove emiteloop, emitbloop, emitestruct, emitefun

These functions can be unified.

--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -154,7 +154,7 @@
 	OA_AND, OA_XOR, OA_OR, OADDR,ONEG, OCPL, OEXC,
 	OCOMMA, OCAST, OSYM, OASK, OFIELD, OTYP,
 	OLABEL, ODEFAULT, OCASE, OSTRUCT, OJUMP, OBRANCH,
-	OEXPR,
+	OEXPR, OEFUN, OESTRUCT, OELOOP, OBLOOP,
 	/* TODO: This order is important, but must be changed */
 	OAND, OOR,
 	/*
@@ -166,14 +166,12 @@
 
 /*TODO: clean these declarations */
 extern void
-	emitdcl(Symbol *), emitefun(void),
+	emitdcl(Symbol *),
 	emit(uint8_t, void *),
 	emitprint(Node *),
-	emitbloop(void), emiteloop(void),
 	emitswitch(short),
 	emitret(Type *tp),
-	emitfun(Symbol *sym),
-	emitestruct(void);
+	emitfun(Symbol *sym);
 
 extern Node *node(uint8_t op, Type *tp, Node *left, Node *rigth);
 extern Node *symbol(Symbol *sym);
--- a/cc1/code.c
+++ b/cc1/code.c
@@ -10,8 +10,8 @@
 static void emitbin(uint8_t, void *), emitunary(uint8_t, void *),
             emitternary(uint8_t, void *), emitcast(uint8_t, void *),
             emitsym(uint8_t, void *), emitfield(uint8_t, void *),
-            emitsizeof(uint8_t, void *), emitexp(uint8_t op, void *arg),
-            emitsymid(uint8_t op, void *arg);
+            emitsizeof(uint8_t, void *), emitexp(uint8_t, void *),
+            emitsymid(uint8_t, void *), emittext(uint8_t, void *);
 
 char *optxt[] = {
 	[OADD] = "+",
@@ -57,6 +57,10 @@
 	[OSTRUCT] = "S%d\t(\n",
 	[OJUMP] = "\tj\tL%d\n",
 	[OBRANCH] = "\tj\tL%d",
+	[OEFUN] = "}",
+	[OESTRUCT] = ")",
+	[OELOOP] = "\tb",
+	[OBLOOP] = "\td"
 };
 
 void (*opcode[])(uint8_t, void *) = {
@@ -108,6 +112,10 @@
 	[OSTRUCT] = emitsymid,
 	[OJUMP] = emitsymid,
 	[OBRANCH] = emitsymid,
+	[OEFUN] = emittext,
+	[OESTRUCT] = emittext,
+	[OELOOP] = emittext,
+	[OBLOOP] = emittext
 };
 
 void
@@ -175,12 +183,6 @@
 }
 
 void
-emitestruct(void)
-{
-	puts(")");
-}
-
-void
 emitsym(uint8_t op, void *arg)
 {
 	Node *np = arg;
@@ -268,12 +270,6 @@
 }
 
 void
-emitefun(void)
-{
-	puts("}");
-}
-
-void
 emitret(Type *tp)
 {
 	fputs("\ty", stdout);
@@ -280,16 +276,10 @@
 	emittype(tp);
 }
 
-void
-emitbloop(void)
+static void
+emittext(uint8_t op, void *arg)
 {
-	puts("\td");
-}
-
-void
-emiteloop(void)
-{
-	puts("\tb");
+	puts(optxt[op]);
 }
 
 static void
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -351,7 +351,7 @@
 		expect(';');
 	}
 
-	emitestruct();
+	emit(OESTRUCT, NULL);
 	if ((n = bp - buff) != 0) {
 		siz = sizeof(Type *) * n;
 		tagtype->n.elem = n;
@@ -538,7 +538,7 @@
 				curfun = sym;
 				emitfun(sym);
 				compound(NULL, NULL, NULL);
-				emitefun();
+				emit(OEFUN, NULL);
 				popctx();
 				return;
 			}
--- a/cc1/stmt.c
+++ b/cc1/stmt.c
@@ -88,13 +88,13 @@
 	expect(WHILE);
 	np = condition();
 	emit(OJUMP, cond);
-	emitbloop();
+	emit(OBLOOP, NULL);
 	emit(OLABEL, begin);
 	stmt(end, begin, lswitch);
 	emit(OLABEL, cond);
 	emit(OBRANCH, begin);
 	emit(OEXPR, np);
-	emiteloop();
+	emit(OELOOP, NULL);
 	emit(OLABEL, end);
 	freetree(np);
 }
@@ -120,7 +120,7 @@
 
 	emit(OEXPR, einit);
 	emit(OJUMP, cond);
-	emitbloop();
+	emit(OBLOOP, NULL);
 	emit(OLABEL, begin);
 	stmt(end, begin, lswitch);
 	emit(OEXPR, einc);
@@ -127,7 +127,7 @@
 	emit(OLABEL, cond);
 	emit(OBRANCH, begin);
 	emit(OEXPR, econd);
-	emiteloop();
+	emit(OELOOP, NULL);
 	emit(OLABEL, end);
 	freetree(einit);
 	freetree(econd);
@@ -143,7 +143,7 @@
 	begin = install("", NS_LABEL);
 	end = install("", NS_LABEL);
 	expect(DO);
-	emitbloop();
+	emit(OBLOOP, NULL);
 	emit(OLABEL, begin);
 	stmt(end, begin, lswitch);
 	expect(WHILE);
@@ -150,7 +150,7 @@
 	np = condition();
 	emit(OBRANCH, begin);
 	emit(OEXPR, np);
-	emiteloop();
+	emit(OELOOP, NULL);
 	emit(OLABEL, end);
 	freetree(np);
 }