diff --git a/src/cc65/datatype.c b/src/cc65/datatype.c index ba2fa33ff..ac86cfa49 100644 --- a/src/cc65/datatype.c +++ b/src/cc65/datatype.c @@ -57,6 +57,7 @@ /* Predefined type strings */ +type type_uchar [] = { T_UCHAR, T_END }; type type_int [] = { T_INT, T_END }; type type_uint [] = { T_UINT, T_END }; type type_long [] = { T_LONG, T_END }; diff --git a/src/cc65/datatype.h b/src/cc65/datatype.h index a710dc9e1..9224c78d8 100644 --- a/src/cc65/datatype.h +++ b/src/cc65/datatype.h @@ -138,6 +138,7 @@ typedef unsigned short type; #define DECODE_SIZE 5 /* Predefined type strings */ +extern type type_uchar []; extern type type_int []; extern type type_uint []; extern type type_long []; diff --git a/src/cc65/exprnode.c b/src/cc65/exprnode.c new file mode 100644 index 000000000..d8bc2eda0 --- /dev/null +++ b/src/cc65/exprnode.c @@ -0,0 +1,57 @@ +/*****************************************************************************/ +/* */ +/* exprnode.c */ +/* */ +/* Expression node structure for the cc65 C compiler */ +/* */ +/* */ +/* */ +/* (C) 2000 Ullrich von Bassewitz */ +/* Wacholderweg 14 */ +/* D-70597 Stuttgart */ +/* EMail: uz@musoftware.de */ +/* */ +/* */ +/* This software is provided 'as-is', without any expressed or implied */ +/* warranty. In no event will the authors be held liable for any damages */ +/* arising from the use of this software. */ +/* */ +/* Permission is granted to anyone to use this software for any purpose, */ +/* including commercial applications, and to alter it and redistribute it */ +/* freely, subject to the following restrictions: */ +/* */ +/* 1. The origin of this software must not be misrepresented; you must not */ +/* claim that you wrote the original software. If you use this software */ +/* in a product, an acknowledgment in the product documentation would be */ +/* appreciated but is not required. */ +/* 2. Altered source versions must be plainly marked as such, and must not */ +/* be misrepresented as being the original software. */ +/* 3. This notice may not be removed or altered from any source */ +/* distribution. */ +/* */ +/*****************************************************************************/ + + + +#include "exprnode.h" + + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +void InitExprNode (ExprNode* E) +/* Initialize a new expression node */ +{ + E->Left = 0; + E->Right = 0; + E->NT = NT_NONE; + E->Type = 0; + E->LValue = 0; +} + + + diff --git a/src/cc65/exprnode.h b/src/cc65/exprnode.h new file mode 100644 index 000000000..969ee7506 --- /dev/null +++ b/src/cc65/exprnode.h @@ -0,0 +1,169 @@ +/*****************************************************************************/ +/* */ +/* exprnode.h */ +/* */ +/* Expression node structure for the cc65 C compiler */ +/* */ +/* */ +/* */ +/* (C) 2000 Ullrich von Bassewitz */ +/* Wacholderweg 14 */ +/* D-70597 Stuttgart */ +/* EMail: uz@musoftware.de */ +/* */ +/* */ +/* This software is provided 'as-is', without any expressed or implied */ +/* warranty. In no event will the authors be held liable for any damages */ +/* arising from the use of this software. */ +/* */ +/* Permission is granted to anyone to use this software for any purpose, */ +/* including commercial applications, and to alter it and redistribute it */ +/* freely, subject to the following restrictions: */ +/* */ +/* 1. The origin of this software must not be misrepresented; you must not */ +/* claim that you wrote the original software. If you use this software */ +/* in a product, an acknowledgment in the product documentation would be */ +/* appreciated but is not required. */ +/* 2. Altered source versions must be plainly marked as such, and must not */ +/* be misrepresented as being the original software. */ +/* 3. This notice may not be removed or altered from any source */ +/* distribution. */ +/* */ +/*****************************************************************************/ + + + +#ifndef EXPRNODE_H +#define EXPRNODE_H + + + +#include "datatype.h" + + + +/*****************************************************************************/ +/* Forwards */ +/*****************************************************************************/ + + + +struct SymEntry; + + + +/*****************************************************************************/ +/* Data */ +/*****************************************************************************/ + + + +/* Node types */ +typedef enum { + NT_NONE, /* None (invalid) op */ + + NT_SYM, /* Symbol */ + NT_CONST, /* A constant of some sort */ + + NT_ICAST, /* Implicit type cast */ + NT_ECAST, /* Explicit type cast */ + + NT_REG_A, /* A register */ + NT_REG_X, /* X register */ + NT_REG_Y, /* Y register */ + NT_REG_AX, /* AX register */ + NT_REG_EAX, /* EAX register */ + + NT_CALLFUNC, /* Function call */ + NT_PUSH, /* Push the value onto the stack */ + NT_POP, /* Pop the value from the stack */ + + NT_NOT, /* ~ */ + NT_PLUS, /* + */ + NT_MINUS, /* - */ + NT_MUL, /* * */ + NT_DIV, /* / */ + NT_SHL, /* << */ + NT_SHR, /* >> */ + NT_AND, /* & */ + NT_OR, /* | */ + NT_XOR, /* ^ */ + + NT_ASSIGN, /* = */ + NT_PLUS_ASSIGN, /* += */ + NT_MINUS_ASSIGN, /* -= */ + NT_MUL_ASSIGN, /* *= */ + NT_DIV_ASSIGN, /* /= */ + NT_SHL_ASSIGN, /* <<= */ + NT_SHR_ASSIGN, /* >>= */ + NT_AND_ASSIGN, /* &= */ + NT_OR_ASSIGN, /* |= */ + NT_XOR_ASSIGN, /* ^= */ + + NT_PRE_DEC, /* -- */ + NT_POST_DEC, /* -- */ + NT_PRE_INC, /* ++ */ + NT_POST_INC, /* ++ */ + + NT_BOOL_NOT, /* ! */ + NT_BOOL_OR, /* || */ + NT_BOOL_AND, /* && */ + + NT_EQ, /* == */ + NT_NE, /* != */ + NT_LT, /* < */ + NT_LE, /* <= */ + NT_GT, /* > */ + NT_GE, /* >= */ + + NT_DEREF, /* * and others */ + + NT_COUNT /* Operation count */ +} nodetype_t; + + + +/* Struct describing one node in an expression tree */ +typedef struct ExprNode ExprNode; +struct ExprNode { + + ExprNode* Left; /* Left and right leaves */ + ExprNode* Right; + + nodetype_t NT; /* Node type */ + type* Type; /* Resulting type */ + int LValue; /* True if this is an lvalue */ + + union { + /* Branch data */ + ExprNode* Test; /* Third expr for ternary op */ + + /* Leave data */ + long I; /* Constant int value if any */ + double F; /* Constant float value if any */ + struct SymEntry* Sym; /* Symbol table entry if any */ + } V; + +}; + + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +void InitExprNode (ExprNode* E); +/* Initialize a new expression node */ + + + +/* End of exprnode.h */ + +#endif + + + + + diff --git a/src/cc65/make/gcc.mak b/src/cc65/make/gcc.mak index cc6f8b086..314d7415b 100644 --- a/src/cc65/make/gcc.mak +++ b/src/cc65/make/gcc.mak @@ -24,6 +24,8 @@ OBJS = anonname.o \ declare.o \ error.o \ expr.o \ + exprnode.o \ + exprtree.o \ funcdesc.o \ function.o \ global.o \ @@ -68,7 +70,7 @@ cc65: $(OBJS) clean: rm -f *~ core *.map - + zap: clean rm -f *.o $(EXECS) .depend diff --git a/src/cc65/make/watcom.mak b/src/cc65/make/watcom.mak index 000f33a4b..2e7b04179 100644 --- a/src/cc65/make/watcom.mak +++ b/src/cc65/make/watcom.mak @@ -79,6 +79,8 @@ OBJS = anonname.obj \ declare.obj \ error.obj \ expr.obj \ + exprnode.obj \ + exprtree.obj \ funcdesc.obj \ function.obj \ global.obj \ @@ -136,6 +138,8 @@ FILE datatype.obj FILE declare.obj FILE error.obj FILE expr.obj +FILE exprnode.obj +FILE exprtree.obj FILE funcdesc.obj FILE function.obj FILE global.obj diff --git a/src/cc65/scanner.c b/src/cc65/scanner.c index 95d01b39f..c981ad9f8 100644 --- a/src/cc65/scanner.c +++ b/src/cc65/scanner.c @@ -48,8 +48,11 @@ static const struct Keyword { unsigned char Tok; /* The token */ unsigned char Type; /* Token type */ } Keywords [] = { + { "__A__", TOK_A, TT_C }, { "__AX__", TOK_AX, TT_C }, { "__EAX__", TOK_EAX, TT_C }, + { "__X__", TOK_X, TT_C }, + { "__Y__", TOK_Y, TT_C }, { "__asm__", TOK_ASM, TT_C }, { "__attribute__", TOK_ATTRIBUTE, TT_C }, { "__far__", TOK_FAR, TT_C }, diff --git a/src/cc65/scanner.h b/src/cc65/scanner.h index a707e4d14..db10cb9b9 100644 --- a/src/cc65/scanner.h +++ b/src/cc65/scanner.h @@ -127,9 +127,12 @@ typedef enum token_t { TOK_ATTRIBUTE, TOK_FAR, TOK_FASTCALL, + TOK_A, + TOK_X, + TOK_Y, TOK_AX, TOK_EAX, - + TOK_PRAGMA } token_t;