shithub: scc

Download patch

ref: 8ab588d0ba2eaa191b6b93fdb4053db29fdcf8fa
parent: c4db51782e98cba3cd7b4203447db47dca8fa398
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon Feb 16 10:29:42 EST 2015

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.

--- a/cc2/code.c
+++ b/cc2/code.c
@@ -8,7 +8,24 @@
 #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",
 	[RET]  = "RET" , [ADDI]= "ADD", [LDI] = "LD", [ADDX] = "ADD",
@@ -35,6 +52,24 @@
 	[LDFX] = "\to\tr,(r+i)",
 	[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, ...)