shithub: scc

Download patch

ref: c097639e7efa2061e1a1b6409f11da28096216e6
parent: a06ccd18deaeedf0f3cb0da8fa3531fa89e6f177
author: Roberto E. Vargas Caballero <[email protected]>
date: Sat Apr 23 13:27:50 EDT 2016

[cc2-qbe] Add jumps to qbe

--- a/cc2/arch/qbe/arch.h
+++ b/cc2/arch/qbe/arch.h
@@ -128,5 +128,7 @@
 	ASSLTOS,
 
 	ASEXTS,
-	ASTRUNCD
+	ASTRUNCD,
+
+	ASJMP
 };
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -225,6 +225,7 @@
 	if (!np)
 		return NULL;
 
+	setlabel(np->label);
 	l = cgen(np->left);
 	r = cgen(np->right);
 	tp = &np->type;
@@ -327,8 +328,9 @@
 	case OOR:
 		abort();
 	case OBRANCH:
+		abort();
 	case OJMP:
-		code(op, NULL, l, r);
+		code(ASJMP, np, NULL, NULL);
 		return NULL;
 	case ORET:
 	case OCASE:
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
@@ -9,7 +9,7 @@
 
 #define ADDR_LEN (IDENTSIZ+64)
 
-static void binary(void), unary(void), store(void);
+static void binary(void), unary(void), store(void), jmp(void);
 
 static struct opdata {
 	void (*fun)(void);
@@ -121,6 +121,8 @@
 
 	[ASEXTS] = {.fun = unary, .txt = "exts", .letter = 'd'},
 	[ASSLTOS]= {.fun = unary, .txt = "truncd", .letter = 's'},
+
+	[ASJMP]  = {.fun = jmp},
 };
 
 static char buff[ADDR_LEN];
@@ -334,7 +336,8 @@
 	for (pc = prog; pc; pc = pc->next) {
 		if (pc->label)
 			printf("%s:\n", symname(pc->label));
-		(*optbl[pc->op].fun)();
+		if (pc->op)
+			(*optbl[pc->op].fun)();
 	}
 
 	puts("}");
@@ -388,6 +391,12 @@
 	strcpy(to, addr2txt(&pc->to));
 	strcpy(from, addr2txt(&pc->from1));
 	printf("\t%s %c=\t%s\t%s\n", to, p->letter, p->txt, from);
+}
+
+static void
+jmp(void)
+{
+	printf("\t\tjmp\t%s\n", addr2txt(&pc->to));
 }
 
 void
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -200,6 +200,7 @@
 extern void writeout(void), endinit(void), newfun(void);
 extern void code(int op, Node *to, Node *from1, Node *from2);
 extern void defvar(Symbol *), defpar(Symbol *), defglobal(Symbol *);
+extern void setlabel(Symbol *sym);
 
 /* node.c */
 extern void apply(Node *(*fun)(Node *));