ref: f497555405330a595da88af8b145fa26d70d694e
parent: 5c514c971adaf928ffde1832f949db834f990dc6
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Feb 6 12:37:38 EST 2018
[cc2-z80] Add basic code for cgen()
--- a/cc2/target/z80-scc/arch.h
+++ b/cc2/target/z80-scc/arch.h
@@ -1,0 +1,4 @@
+enum asmop {
+ ASJMP = 0,
+ ASRET,
+};
--- a/cc2/target/z80-scc/cgen.c
+++ b/cc2/target/z80-scc/cgen.c
@@ -4,9 +4,57 @@
#include "../../../inc/scc.h"
#include "../../cc2.h"
+static void
+swtch(Node *idx)
+{
+}
+
+static Node *
+lhs(Node *np, Node *ret)
+{
+}
+
+static Node *
+rhs(Node *np, Node *ret)
+{
+}
+
+static void
+bool(Node *np, Symbol *true, Symbol *false)
+{
+}
+
Node *
cgen(Node *np)
{
+ Node aux, *p, *next;
+
+ setlabel(np->label);
+ switch (np->op) {
+ case OJMP:
+ label2node(&aux, np->u.sym);
+ code(ASJMP, NULL, &aux, NULL);
+ break;
+ case OBRANCH:
+ next = np->next;
+ if (!next->label)
+ next->label = newlabel();
+ bool(np->left, np->u.sym, next->label);
+ break;
+ case ORET:
+ p = np->left;
+ if (p)
+ p = rhs(np->left, &aux);
+ code(ASRET, NULL, p, NULL);
+ break;
+ case OBSWITCH:
+ swtch(rhs(np->left, &aux));
+ break;
+ default:
+ rhs(np, &aux);
+ break;
+ }
+ return NULL;
}
/*