shithub: scc

Download patch

ref: 9d1c91396f9fa249332adf91de26cb7f98a60f88
parent: 5d9e9d545a1ce2824d0e7ef0db7060194aff1164
author: Roberto E. Vargas Caballero <[email protected]>
date: Wed May 6 12:28:35 EDT 2015

Change type of opcode[] array in cc1

We want to use this array as the base for an unique emit() function.
We already know that this function must accept different pointers, so
the solution is to change the elements of opcode[] to accept a void
pointer.

--- a/cc1/code.c
+++ b/cc1/code.c
@@ -7,9 +7,9 @@
 #include "../inc/cc.h"
 #include "cc1.h"
 
-static void emitbin(Node *), emitunary(Node *), emitternary(Node *),
-     emitcast(Node *), emitsym(Node *), emitfield(Node *),
-     emitsizeof(Node *);
+static void emitbin(void *), emitunary(void *), emitternary(void *),
+     emitcast(void *), emitsym(void *), emitfield(void *),
+     emitsizeof(void *);
 
 char *optxt[] = {
 	[OADD] = "+",
@@ -51,7 +51,7 @@
 	[OCOMMA] = ","
 };
 
-void (*opcode[])(Node *) = {
+void (*opcode[])(void *) = {
 	[OADD] = emitbin,
 	[OSUB] = emitbin,
 	[OMUL] = emitbin,
@@ -157,8 +157,9 @@
 }
 
 void
-emitsym(Node *np)
+emitsym(void *arg)
 {
+	Node *np = arg;
 	putchar('\t');
 	(np->constant) ? emitconst(np) : emitvar(np->sym);
 }
@@ -179,9 +180,9 @@
 }
 
 void
-emitcast(Node *np)
+emitcast(void *arg)
 {
-	Node *lp = np->left;
+	Node *np = arg, *lp = np->left;
 
 	(*opcode[lp->op])(lp);
 	printf("\t%c%c", lp->type->letter, np->type->letter);
@@ -188,9 +189,9 @@
 }
 
 void
-emitunary(Node *np)
+emitunary(void *arg)
 {
-	Node *lp;
+	Node *lp, *np = arg;
 	char letter;
 
 	letter = np->type->letter;
@@ -200,9 +201,9 @@
 }
 
 void
-emitbin(Node *np)
+emitbin(void *arg)
 {
-	Node *lp, *rp;
+	Node *lp, *rp, *np = arg;
 
 	lp = np->left;
 	rp = np->rigth;
@@ -212,9 +213,9 @@
 }
 
 void
-emitternary(Node *np)
+emitternary(void *arg)
 {
-	Node *cond, *ifyes, *ifno;
+	Node *cond, *ifyes, *ifno, *np = arg;
 
 	cond = np->left;
 	ifyes = np->rigth->left;
@@ -226,8 +227,9 @@
 }
 
 void
-emitsizeof(Node *np)
+emitsizeof(void *arg)
 {
+	Node *np = arg;
 	printf("\t#%c", np->left->type->letter);
 }
 
@@ -318,9 +320,9 @@
 }
 
 void
-emitfield(Node *np)
+emitfield(void *arg)
 {
-	Node *lp = np->left;
+	Node *np = arg, *lp = np->left;
 
 	(*opcode[lp->op])(lp);
 	putchar('\t');