scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 5b7040998d5b60b95e827094a4412973fb7db862
parent 23f5f2a42ef1065d2c3eb91fe2161e4e570ba557
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 16 Jun 2016 11:41:22 +0200

[cc2] Add basic support for basic blocks

Basic blocks are going to be useful in the code generation of the
majority of the targets, and in the case of qbe it can help with
the label problem.

Diffstat:
Mcc2/arch/amd64-sysv/code.c | 5+++++
Mcc2/arch/i386-sysv/code.c | 5+++++
Mcc2/arch/qbe/code.c | 31+++++++++++++++++++++++++++++++
Mcc2/arch/z80/code.c | 5+++++
Mcc2/cc2.h | 10++++++++--
Mcc2/code.c | 1+
Mcc2/main.c | 1+
7 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/cc2/arch/amd64-sysv/code.c b/cc2/arch/amd64-sysv/code.c @@ -201,3 +201,8 @@ void endinit(void) { } + +void +getbblocks(void) +{ +} diff --git a/cc2/arch/i386-sysv/code.c b/cc2/arch/i386-sysv/code.c @@ -200,3 +200,8 @@ void endinit(void) { } + +void +getbblocks(void) +{ +} diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c @@ -466,3 +466,34 @@ endinit(void) { puts("}"); } + +void +getbblocks(void) +{ + Inst *i; + + if (!prog) + return; + + prog->flags |= BBENTRY; + for (pc = prog; pc; pc = pc->next) { + switch (pc->op) { + case ASBRANCH: + i = pc->from2.u.sym->u.inst; + i->flags |= BBENTRY; + case ASJMP: + i = pc->from1.u.sym->u.inst; + i->flags |= BBENTRY; + case ASRET: + case ASCALLB: + case ASCALLH: + case ASCALLW: + case ASCALLS: + case ASCALLL: + case ASCALLD: + case ASCALL: + pc->flags |= BBENTRY; + break; + } + } +} diff --git a/cc2/arch/z80/code.c b/cc2/arch/z80/code.c @@ -219,3 +219,8 @@ void endinit(void) { } + +void +getbblocks(void) +{ +} diff --git a/cc2/cc2.h b/cc2/cc2.h @@ -1,4 +1,9 @@ /* See LICENSE file for copyright and license details. */ + +enum iflags { + BBENTRY = 1, +}; + enum tflags { SIGNF = 1, INTF = 2, @@ -179,9 +184,10 @@ struct addr { struct inst { unsigned char op; + unsigned char flags; Symbol *label; - Addr from1, from2, to; Inst *next, *prev; + Addr from1, from2, to; }; /* main.c */ @@ -205,7 +211,7 @@ extern void data(Node *np); 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); +extern void setlabel(Symbol *sym), getbblocks(void); extern Node *label2node(Symbol *sym); extern Symbol *newlabel(void); diff --git a/cc2/code.c b/cc2/code.c @@ -22,6 +22,7 @@ nextpc(void) } new->prev = pc; + new->flags = 0; new->to.kind = new->from2.kind = new->from1.kind = SNONE; pc = new; } diff --git a/cc2/main.c b/cc2/main.c @@ -48,6 +48,7 @@ main(int argc, char *argv[]) apply(optm_dep); apply(sethi); apply(cgen); + getbblocks(); /* TODO: run apply over asm ins too */ peephole(); writeout(); }