shithub: scc

Download patch

ref: a7dba1661a8d960eac3e8f7f315a50b23673cc39
parent: 5dd0e7ed4619141a86023783b34c3e981025e003
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Sep 16 12:08:12 EDT 2014

Add INT type

This type is supposed to be the int type of the target architecture,
that in this case is short. This type should be used in a lot of
different places, but this is something that I will do only with
the time.

--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -35,7 +35,7 @@
 	uint8_t addable;
 	union {
 		Symbol *sym;
-		int imm;
+		TINT imm;
 	} u;
 	struct node *left, *right;
 } Node;
--- a/cc2/cgen.c
+++ b/cc2/cgen.c
@@ -36,8 +36,8 @@
 {
 	va_list va;
 	uint8_t reg1, reg2;
-	/* TODO: define a macro with the default integer type */
-	short imm, off;
+	TINT imm;
+	short off;
 	char *label;
 
 	va_start(va, op);
@@ -58,13 +58,13 @@
 	case ADDI: case LDI:
 		reg1 = va_arg(va, int);
 		imm = va_arg(va, int);
-		printf("\t%s\t%s,%hd\n", opnames[op], regnames[reg1], imm);
+		printf("\t%s\t%s,%d\n", opnames[op], regnames[reg1], imm);
 		break;
 	case LDX:
 		reg1 = va_arg(va, int);
 		off = va_arg(va, int);
 		reg2 = va_arg(va, int);
-		printf("\t%s\t(%s%+hd),%s\n",
+		printf("\t%s\t(%s%+d),%s\n",
 		       opnames[op], regnames[reg1], off, regnames[reg2]);
 		break;
 	case ADDX: case ADCX:
@@ -71,7 +71,7 @@
 		reg1 = va_arg(va, int);
 		reg2 = va_arg(va, int);
 		off = va_arg(va, int);
-		printf("\t%s\t%s,(%s%+hd)\n",
+		printf("\t%s\t%s,(%s%+d)\n",
 		       opnames[op], regnames[reg1], regnames[reg2], off);
 		break;
 	case ADDR:
@@ -87,7 +87,7 @@
 cgen(Node *np)
 {
 	Node *lp, *rp;
-	INT imm;
+	TINT imm;
 
 	if (!np || np->complex == 0)
 		return;
--- a/inc/cc.h
+++ b/inc/cc.h
@@ -6,6 +6,8 @@
 #include <stdbool.h>
 #endif
 
+#define TINT short
+
 #define RANK_BOOL    0
 #define RANK_SCHAR   1
 #define RANK_UCHAR   2