scc

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

commit a7dba1661a8d960eac3e8f7f315a50b23673cc39
parent 5dd0e7ed4619141a86023783b34c3e981025e003
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 16 Sep 2014 16:08:12 +0200

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.

Diffstat:
Mcc2/cc2.h | 2+-
Mcc2/cgen.c | 12++++++------
Minc/cc.h | 2++
3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/cc2/cc2.h b/cc2/cc2.h @@ -35,7 +35,7 @@ typedef struct node { uint8_t addable; union { Symbol *sym; - int imm; + TINT imm; } u; struct node *left, *right; } Node; diff --git a/cc2/cgen.c b/cc2/cgen.c @@ -36,8 +36,8 @@ emit(char op, ...) { 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,20 +58,20 @@ emit(char op, ...) 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: 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 @@ void cgen(Node *np) { Node *lp, *rp; - INT imm; + TINT imm; if (!np || np->complex == 0) return; diff --git 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