scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit 38bb7f83ccf922f9dcbd59f70c83b50ae201730b
parent d5023fa3c97d9609e3e69b70b96bfb2efaf4263d
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 20 Feb 2018 13:30:50 +0000

[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.

Diffstat:
Mcc2/target/z80-scc/arch.h | 1+
Mcc2/target/z80-scc/cgen.c | 26++++++++++++++++++++++++++
2 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/cc2/target/z80-scc/arch.h b/cc2/target/z80-scc/arch.h @@ -1,4 +1,5 @@ enum asmop { ASJMP = 0, ASRET, + ASBRANCH, }; diff --git a/cc2/target/z80-scc/cgen.c b/cc2/target/z80-scc/cgen.c @@ -22,6 +22,32 @@ rhs(Node *np, Node *ret) 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 *