scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit 8ab588d0ba2eaa191b6b93fdb4053db29fdcf8fa
parent c4db51782e98cba3cd7b4203447db47dca8fa398
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 16 Feb 2015 15:29:42 +0100

Add Inst data type in cc2

This type is the base for the instruction in the memory.
The idea is to have a list of these instructions, so we can
optimize them before of any operation.

Diffstat:
cc2/code.c | 35+++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+), 0 deletions(-)

diff --git a/cc2/code.c b/cc2/code.c @@ -8,6 +8,23 @@ #include "../inc/cc.h" #include "cc2.h" +typedef struct inst Inst; +typedef struct addr Addr; + +struct addr { + char kind; + union { + char reg; + Inst *pc; + Symbol *sym; + } u; +}; + +struct inst { + char op; + Addr from, to; + Inst *next; +}; static char *opnames[] = { [PUSH] = "PUSH", [POP] = "POP", [LD] = "LD", [ADD] = "ADD", @@ -36,6 +53,24 @@ static char *opfmt[] = { [LDX] = "\to\t(r+i),r", }; +Inst *prog, *pc; + +Inst * +inst(uint8_t op) +{ + Inst *new; + + new = xmalloc(sizeof(*new)); + if (!pc) + prog = new; + else + pc->next = new; + pc = new; + pc->op = op; + pc->next = NULL; + return pc; +} + void code(char op, ...) {