scc

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

commit b9a6331f4400d1372d2747c8dd371fefe6576a60
parent 401efa0d74d58e83b9f8754f738679c132742123
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri,  2 May 2014 20:10:14 +0200

Move type definition constant to a common header

These definitions maybe are going to be used in both programs,
so the best option is to remove hardcoded constant and put them
in a common place.

Diffstat:
Mcc1/cc1.h | 15+--------------
Mcc1/types.c | 46+++++++++++++++++++++++-----------------------
Minc/cc.h | 48++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 72 insertions(+), 37 deletions(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -2,6 +2,7 @@ #define CC1_H + struct user_opt { unsigned char implicit; unsigned char mixdcls; @@ -31,20 +32,6 @@ enum { struct funpars; struct symbol; -#define RANK_BOOL 0 -#define RANK_SCHAR 1 -#define RANK_UCHAR 2 -#define RANK_SHORT 3 -#define RANK_USHORT 4 -#define RANK_INT 5 -#define RANK_UINT 6 -#define RANK_LONG 7 -#define RANK_ULONG 8 -#define RANK_LLONG 9 -#define RANK_ULLONG 10 -#define RANK_FLOAT 11 -#define RANK_DOUBLE 12 -#define RANK_LDOUBLE 13 struct ctype { uint8_t op; /* type builder operator */ diff --git a/cc1/types.c b/cc1/types.c @@ -12,104 +12,104 @@ Type *voidtype = &(Type) { .op = VOID, - .letter = 'W' + .letter = L_VOID }, *pvoidtype = &(Type) { .op = PTR, - .letter = 'R' + .letter = L_POINTER }, *booltype = &(Type) { .op = INT, - .letter = 'B', + .letter = L_BOOL, .defined = 1, .u.rank = RANK_BOOL }, *schartype = &(Type) { .op = INT, - .letter = 'M', + .letter = L_SCHAR, .defined = 1, .u.rank = RANK_SCHAR }, *uchartype = &(Type) { .op = INT, - .letter = 'C', + .letter = L_UCHAR, .sign = 1, .defined = 1, .u.rank = RANK_UCHAR }, *chartype = &(Type) { .op = INT, - .letter = 'C', + .letter = L_CHAR, .sign = 1, .defined = 1, - .u.rank = RANK_UCHAR + .u.rank = RANK_CHAR }, *ushortype = &(Type) { .op = INT, - .letter = 'E', + .letter = L_USHORT, .defined = 1, .u.rank = RANK_USHORT }, *shortype = &(Type) { .op = INT, - .letter = 'K', + .letter = L_SHORT, .defined = 1, .u.rank = RANK_SHORT }, *uinttype = &(Type) { .op = INT, - .letter = 'U', + .letter = L_UINT, .sign = 1, .defined = 1, .u.rank = RANK_UINT }, *inttype = &(Type) { .op = INT, - .letter = 'I', + .letter = L_INT, .defined = 1, .u.rank = RANK_INT }, *longtype = &(Type) { .op = INT, - .letter = 'L', + .letter = L_LONG, .defined = 1, .u.rank = RANK_LONG }, *ulongtype = &(Type) { .op = INT, - .letter = 'Z', + .letter = L_ULONG, .sign = 1, .defined = 1, .u.rank = RANK_ULONG }, *ullongtype = &(Type) { .op = INT, - .letter = 'O', + .letter = L_ULLONG, .sign = 1, .defined = 1, .u.rank = RANK_ULLONG }, *llongtype = &(Type) { .op = INT, - .letter = 'J', + .letter = L_LLONG, .defined = 1, .u.rank = RANK_LLONG }, *floattype = &(Type) { .op = FLOAT, - .letter = 'F', + .letter = L_FLOAT, .defined = 1, .u.rank = RANK_FLOAT }, *doubletype = &(Type) { .op = FLOAT, - .letter = 'D', + .letter = L_DOUBLE, .defined = 1, .u.rank = RANK_DOUBLE }, *ldoubletype = &(Type) { .op = FLOAT, - .letter = 'H', + .letter = L_LDOUBLE, .defined = 1, .u.rank = RANK_LDOUBLE }; @@ -164,11 +164,11 @@ mktype(Type *tp, uint8_t op, } switch (op) { - case PTR: letter = 'R'; break; - case FTN: letter = 'F'; break; - case ARY: letter = 'V'; break; - case ENUM: letter = 'E'; break; - case STRUCT: letter = 'S'; break; + case PTR: letter = L_POINTER; break; + case FTN: letter = L_FUNCTION; break; + case ARY: letter = L_ARRAY; break; + case ENUM: letter = L_INT; break; + case STRUCT: letter = L_STRUCT; break; default: letter = tp->letter; } bp = xmalloc(sizeof(*bp)); diff --git a/inc/cc.h b/inc/cc.h @@ -6,6 +6,54 @@ #include <stdbool.h> #endif +#define RANK_BOOL 0 +#define RANK_SCHAR 1 +#define RANK_UCHAR 2 +#define RANK_CHAR 3 +#define RANK_SHORT 4 +#define RANK_USHORT 5 +#define RANK_INT 6 +#define RANK_UINT 7 +#define RANK_LONG 8 +#define RANK_ULONG 9 +#define RANK_LLONG 10 +#define RANK_ULLONG 11 +#define RANK_FLOAT 12 +#define RANK_DOUBLE 13 +#define RANK_LDOUBLE 15 + +#define L_INT8 'C' +#define L_INT16 'I' +#define L_INT32 'L' +#define L_INT64 'Q' +#define L_UINT8 'M' +#define L_UINT16 'N' +#define L_UINT32 'Z' +#define L_UINT64 'O' + +#define L_VOID '0' +#define L_POINTER 'P' +#define L_FUNCTION 'F' +#define L_ARRAY 'V' +#define L_UNION 'U' +#define L_STRUCT 'S' + +#define L_SCHAR L_INT8 +#define L_UCHAR L_UINT8 +#define L_CHAR L_UINT8 +#define L_SHORT L_INT16 +#define L_USHORT L_UINT16 +#define L_INT L_INT16 +#define L_UINT L_UINT16 +#define L_LONG L_INT32 +#define L_ULONG L_UINT32 +#define L_LLONG L_INT64 +#define L_ULLONG L_UINT64 +#define L_BOOL 'B' +#define L_FLOAT 'J' +#define L_DOUBLE 'D' +#define L_LDOUBLE 'H' + extern void die(const char *fmt, ...); extern void *xmalloc(size_t size); extern void *xcalloc(size_t nmemb, size_t size);