shithub: scc

Download patch

ref: c305b6f188a2d59e8ba7e87b6ee6761922d09447
parent: 9d132dc59173787dd773ce0e82b55bc4e1c1dffc
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon Mar 16 05:56:34 EDT 2015

Add LDI instruction

This instruction is used for immediate loads.

--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -112,7 +112,17 @@
 
 
 enum {
-	LDW, LDL, LDH, MOV, ADD, PUSH, POP, RET, NOP, INC
+	LDW,
+	LDL,
+	LDH,
+	MOV,
+	LDI,
+	ADD,
+	PUSH,
+	POP,
+	RET,
+	NOP,
+	INC
 };
 
 enum {
--- a/cc2/cgen.c
+++ b/cc2/cgen.c
@@ -122,8 +122,17 @@
 	Symbol *sym;
 
 	switch (np->op) {
-	case AUTO:
 	case CONST:
+		switch (np->type.size) {
+		case 1:
+		case 2:
+			code(LDI, regs[reg], np);
+			break;
+		default:
+			abort();
+		}
+		break;
+	case AUTO:
 		sym = np->u.sym;
 		switch (np->type.size) {
 		case 1:
--- a/cc2/code.c
+++ b/cc2/code.c
@@ -24,6 +24,7 @@
 	[LDW] = inst2,
 	[LDL] = inst2,
 	[LDH] = inst2,
+	[LDI] = inst2,
 	[MOV] = inst2,
 	[ADD] = inst2,
 	[PUSH] = inst1,
@@ -37,6 +38,7 @@
 	[LDW] = "LD",
 	[LDL] = "LD",
 	[LDH] = "LD",
+	[LDI] = "LD",
 	[MOV] = "LD",
 	[ADD] = "ADD",
 	[PUSH] = "PUSH",