shithub: scc

Download patch

ref: 0646fcf44045b03e1ac837d2f2333b8af85d9f54
parent: f78ae673a36b58d24c696c72e9e7867444f276c8
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Feb 20 08:30:50 EST 2018

[cc2/z80] Add code for bool()

This code is identical is almos identical in any architecture,
only the branch macro changes. More changes to this function
are expected in the future.

--- a/cc2/target/z80-scc/arch.h
+++ b/cc2/target/z80-scc/arch.h
@@ -1,4 +1,5 @@
 enum asmop {
 	ASJMP = 0,
 	ASRET,
+	ASBRANCH,
 };
--- a/cc2/target/z80-scc/cgen.c
+++ b/cc2/target/z80-scc/cgen.c
@@ -22,6 +22,32 @@
 static void
 bool(Node *np, Symbol *true, Symbol *false)
 {
+	Node *l = np->left, *r = np->right;
+	Node ret, ifyes, ifno;
+	Symbol *label;
+
+	switch (np->op) {
+	case ONEG:
+		bool(l, false, true);
+		break;
+	case OAND:
+		label = newlabel();
+		bool(l, label, false);
+		setlabel(label);
+		bool(r, true, false);
+		break;
+	case OOR:
+		label = newlabel();
+		bool(l, true, label);
+		setlabel(label);
+		bool(r, true, false);
+		break;
+	default:
+		label2node(&ifyes, true);
+		label2node(&ifno, false);
+		code(ASBRANCH, rhs(np, &ret), &ifyes, &ifno);
+		break;
+	}
 }
 
 Node *