shithub: scc

Download patch

ref: 6ef69d3ee0b835e5aad1532e946977035de9c405
parent: 3d2ccb36333113f1c1e71191926f2b5f5e3a64f6
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu May 7 04:36:16 EDT 2015

Remove emitternary()

This function can be implemented with emitbin()

--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -173,7 +173,7 @@
 
 /* operations */
 enum {
-	OPTR = 1,
+	OPTR,
 	OADD,
 	OSIZE,
 	OMUL,
@@ -205,6 +205,7 @@
 	OCAST,
 	OSYM,
 	OASK,
+	OCOLON,
 	OFIELD,
 	OTYP,
 	OLABEL,
@@ -286,5 +287,3 @@
             *longtype,    *ulongtype,
             *ullongtype,  *llongtype,
             *floattype,   *doubletype,  *ldoubletype;
-
-/* TODO: remove node(0 calls */
\ No newline at end of file
--- a/cc1/code.c
+++ b/cc1/code.c
@@ -8,13 +8,12 @@
 #include "cc1.h"
 
 static void emitbin(uint8_t, void *), emitunary(uint8_t, void *),
-            emitternary(uint8_t, void *), emitcast(uint8_t, void *),
+            emitcast(uint8_t, void *), emitswitch(uint8_t, void *),
             emitsym(uint8_t, void *), emitfield(uint8_t, void *),
             emitsizeof(uint8_t, void *), emitexp(uint8_t, void *),
             emitsymid(uint8_t, void *), emittext(uint8_t, void *),
             emitprint(uint8_t, void *), emitfun(uint8_t, void *),
-            emitret(uint8_t, void *), emitdcl(uint8_t, void *),
-            emitswitch(uint8_t, void *);
+            emitret(uint8_t, void *), emitdcl(uint8_t, void *);
 
 char *optxt[] = {
 	[OADD] = "+",
@@ -53,6 +52,7 @@
 	[OCPL] = "~",
 	[OAND] = "y",
 	[OOR] = "o",
+	[OASK] = "?",
 	[OCOMMA] = ",",
 	[OLABEL] = "L%d\n",
 	[ODEFAULT] = "\tf\tL%d\n",
@@ -106,7 +106,8 @@
 	[OCOMMA] = emitbin,
 	[OCAST] = emitcast,
 	[OSYM] = emitsym,
-	[OASK] = emitternary,
+	[OASK] = emitbin,
+	[OCOLON] = emitbin,
 	[OFIELD]= emitfield,
 	[OEXPR] = emitexp,
 	[OLABEL] = emitsymid,
@@ -228,24 +229,12 @@
 emitbin(uint8_t op, void *arg)
 {
 	Node *np = arg;
+	char *s;
 
 	emitnode(np->left);
 	emitnode(np->right);
-	printf("\t%s%c", optxt[op], np->type->letter);
-}
-
-static void
-emitternary(uint8_t op, void *arg)
-{
-	Node *cond, *ifyes, *ifno, *np = arg;
-
-	cond = np->left;
-	ifyes = np->right->left;
-	ifno = np->right->right;
-	emitnode(cond);
-	emitnode(ifyes);
-	emitnode(ifno);
-	printf("\t?%c", np->type->letter);
+	if ((s = optxt[op]) != NULL)
+		printf("\t%s%c", s, np->type->letter);
 }
 
 static void
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -72,7 +72,7 @@
 		return NULL;
 	if (np->op != OAND && np->op != OOR)
 		return np;
-	p = node(0, inttype, symbol(one), symbol(zero));
+	p = node(OCOLON, inttype, symbol(one), symbol(zero));
 	return node(OASK, inttype, np, p);
 }
 
@@ -791,7 +791,7 @@
 		expect(':');
 		ifno = promote(ternary());
 		typeconv(&ifyes, &ifno);
-		np = node(0, ifyes->type, ifyes, ifno);
+		np = node(OCOLON, ifyes->type, ifyes, ifno);
 		cond = node(OASK, np->type, cond, np);
 	}
 	return cond;