shithub: scc

Download patch

ref: 3a8c3903f0d17cb87f1f14c575ade0b19c843bf1
parent: 36d8df36bca374c3c875fd30a69db60f9398de9a
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed May 25 12:56:52 EDT 2016

[cc2] Add architecture independent optimizer

We need this phase because it is not a good idea to transform
switches in the parser. Some of the code that is at this moment
in QBE optm_dep must come here.

--- a/cc2/Makefile
+++ b/cc2/Makefile
@@ -3,7 +3,7 @@
 
 include ../config.mk
 
-OBJS = main.o parser.o peep.o symbol.o node.o code.o\
+OBJS = main.o parser.o peep.o symbol.o node.o code.o optm.o\
        arch/$(ARCH)/code.o arch/$(ARCH)/cgen.o \
        arch/$(ARCH)/types.o arch/$(ARCH)/optm.o
 
--- a/cc2/arch/amd64-sysv/optm.c
+++ b/cc2/arch/amd64-sysv/optm.c
@@ -3,7 +3,7 @@
 #include "../../cc2.h"
 
 Node *
-optm(Node *np)
+optm_dep(Node *np)
 {
 	return np;
 }
--- a/cc2/arch/i386-sysv/optm.c
+++ b/cc2/arch/i386-sysv/optm.c
@@ -3,7 +3,7 @@
 #include "../../cc2.h"
 
 Node *
-optm(Node *np)
+optm_dep(Node *np)
 {
 	return np;
 }
--- a/cc2/arch/qbe/optm.c
+++ b/cc2/arch/qbe/optm.c
@@ -5,7 +5,7 @@
 #include "../../cc2.h"
 
 Node *
-optm(Node *np)
+optm_dep(Node *np)
 {
 	int op = np->op;
 	Node *p, *dst, *next = np->next;
--- a/cc2/arch/z80/optm.c
+++ b/cc2/arch/z80/optm.c
@@ -3,7 +3,7 @@
 #include "../../cc2.h"
 
 Node *
-optm(Node *np)
+optm_dep(Node *np)
 {
 	return np;
 }
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -191,7 +191,7 @@
 extern void parse(void);
 
 /* optm.c */
-extern Node *optm(Node *np);
+extern Node *optm_dep(Node *np), *optm_ind(Node *np);
 
 /* cgen.c */
 extern Node *sethi(Node *np);
--- a/cc2/main.c
+++ b/cc2/main.c
@@ -38,7 +38,8 @@
 
 	while (moreinput()) {
 		parse();
-		apply(optm);
+		apply(optm_ind);
+		apply(optm_dep);
 		apply(sethi);
 		apply(cgen);
 		peephole();