2000-05-28 13:40:48 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* */
|
2013-05-09 11:56:54 +00:00
|
|
|
/* exprdefs.h */
|
2000-05-28 13:40:48 +00:00
|
|
|
/* */
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Expression tree definitions */
|
2000-05-28 13:40:48 +00:00
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* */
|
2012-01-03 21:41:34 +00:00
|
|
|
/* (C) 1998-2012, Ullrich von Bassewitz */
|
2010-02-11 18:54:08 +00:00
|
|
|
/* Roemerstrasse 52 */
|
|
|
|
/* D-70794 Filderstadt */
|
|
|
|
/* EMail: uz@cc65.org */
|
2000-05-28 13:40:48 +00:00
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* 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 EXPRDEFS_H
|
|
|
|
#define EXPRDEFS_H
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Data */
|
2000-05-28 13:40:48 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Expression type masks */
|
2013-05-09 11:56:54 +00:00
|
|
|
#define EXPR_TYPEMASK 0xC0
|
|
|
|
#define EXPR_BINARYNODE 0x00
|
|
|
|
#define EXPR_UNARYNODE 0x40
|
|
|
|
#define EXPR_LEAFNODE 0x80
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
/* Type of expression nodes */
|
2013-05-09 11:56:54 +00:00
|
|
|
#define EXPR_NULL 0x00 /* Internal error or NULL node */
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
/* Leaf node codes */
|
2013-05-09 11:56:54 +00:00
|
|
|
#define EXPR_LITERAL (EXPR_LEAFNODE | 0x01)
|
|
|
|
#define EXPR_SYMBOL (EXPR_LEAFNODE | 0x02)
|
2002-12-14 22:57:00 +00:00
|
|
|
#define EXPR_SECTION (EXPR_LEAFNODE | 0x03)
|
2013-05-09 11:56:54 +00:00
|
|
|
#define EXPR_SEGMENT (EXPR_LEAFNODE | 0x04) /* Linker only */
|
|
|
|
#define EXPR_MEMAREA (EXPR_LEAFNODE | 0x05) /* Linker only */
|
|
|
|
#define EXPR_ULABEL (EXPR_LEAFNODE | 0x06) /* Assembler only */
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
/* Binary operations, left and right hand sides are valid */
|
2013-05-09 11:56:54 +00:00
|
|
|
#define EXPR_PLUS (EXPR_BINARYNODE | 0x01)
|
|
|
|
#define EXPR_MINUS (EXPR_BINARYNODE | 0x02)
|
|
|
|
#define EXPR_MUL (EXPR_BINARYNODE | 0x03)
|
|
|
|
#define EXPR_DIV (EXPR_BINARYNODE | 0x04)
|
|
|
|
#define EXPR_MOD (EXPR_BINARYNODE | 0x05)
|
|
|
|
#define EXPR_OR (EXPR_BINARYNODE | 0x06)
|
|
|
|
#define EXPR_XOR (EXPR_BINARYNODE | 0x07)
|
|
|
|
#define EXPR_AND (EXPR_BINARYNODE | 0x08)
|
|
|
|
#define EXPR_SHL (EXPR_BINARYNODE | 0x09)
|
|
|
|
#define EXPR_SHR (EXPR_BINARYNODE | 0x0A)
|
|
|
|
#define EXPR_EQ (EXPR_BINARYNODE | 0x0B)
|
|
|
|
#define EXPR_NE (EXPR_BINARYNODE | 0x0C)
|
|
|
|
#define EXPR_LT (EXPR_BINARYNODE | 0x0D)
|
|
|
|
#define EXPR_GT (EXPR_BINARYNODE | 0x0E)
|
|
|
|
#define EXPR_LE (EXPR_BINARYNODE | 0x0F)
|
|
|
|
#define EXPR_GE (EXPR_BINARYNODE | 0x10)
|
|
|
|
#define EXPR_BOOLAND (EXPR_BINARYNODE | 0x11)
|
|
|
|
#define EXPR_BOOLOR (EXPR_BINARYNODE | 0x12)
|
|
|
|
#define EXPR_BOOLXOR (EXPR_BINARYNODE | 0x13)
|
2010-02-11 18:54:08 +00:00
|
|
|
#define EXPR_MAX (EXPR_BINARYNODE | 0x14)
|
|
|
|
#define EXPR_MIN (EXPR_BINARYNODE | 0x15)
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
/* Unary operations, right hand side is empty */
|
2013-05-09 11:56:54 +00:00
|
|
|
#define EXPR_UNARY_MINUS (EXPR_UNARYNODE | 0x01)
|
|
|
|
#define EXPR_NOT (EXPR_UNARYNODE | 0x02)
|
|
|
|
#define EXPR_SWAP (EXPR_UNARYNODE | 0x03)
|
|
|
|
#define EXPR_BOOLNOT (EXPR_UNARYNODE | 0x04)
|
2012-06-30 17:18:03 +00:00
|
|
|
#define EXPR_BANK (EXPR_UNARYNODE | 0x05)
|
2000-07-29 15:53:33 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
#define EXPR_BYTE0 (EXPR_UNARYNODE | 0x08)
|
|
|
|
#define EXPR_BYTE1 (EXPR_UNARYNODE | 0x09)
|
|
|
|
#define EXPR_BYTE2 (EXPR_UNARYNODE | 0x0A)
|
|
|
|
#define EXPR_BYTE3 (EXPR_UNARYNODE | 0x0B)
|
|
|
|
#define EXPR_WORD0 (EXPR_UNARYNODE | 0x0C)
|
|
|
|
#define EXPR_WORD1 (EXPR_UNARYNODE | 0x0D)
|
2019-05-01 06:50:16 +00:00
|
|
|
#define EXPR_FARADDR (EXPR_UNARYNODE | 0x0E)
|
|
|
|
#define EXPR_DWORD (EXPR_UNARYNODE | 0x0F)
|
|
|
|
#define EXPR_NEARADDR (EXPR_UNARYNODE | 0x10)
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* The expression node itself */
|
2000-11-02 22:11:48 +00:00
|
|
|
typedef struct ExprNode ExprNode;
|
2003-11-10 22:18:49 +00:00
|
|
|
struct ExprNode {
|
2013-05-09 11:56:54 +00:00
|
|
|
unsigned char Op; /* Operand/Type */
|
|
|
|
ExprNode* Left; /* Left leaf */
|
|
|
|
ExprNode* Right; /* Right leaf */
|
|
|
|
struct ObjData* Obj; /* Object file reference (linker) */
|
2000-05-28 13:40:48 +00:00
|
|
|
union {
|
2013-05-09 11:56:54 +00:00
|
|
|
long IVal; /* If this is a int value */
|
|
|
|
struct SymEntry* Sym; /* If this is a symbol */
|
|
|
|
unsigned SecNum; /* If this is a section and Obj != 0 */
|
2010-11-09 20:34:08 +00:00
|
|
|
unsigned ImpNum; /* If this is an import and Obj != 0 */
|
2013-05-09 11:56:54 +00:00
|
|
|
struct Import* Imp; /* If this is an import and Obj == 0 */
|
2010-11-08 21:52:24 +00:00
|
|
|
struct MemoryArea* Mem; /* If this is a memory area */
|
2013-05-09 11:56:54 +00:00
|
|
|
struct Segment* Seg; /* If this is a segment */
|
|
|
|
struct Section* Sec; /* If this is a section and Obj == 0 */
|
2000-05-28 13:40:48 +00:00
|
|
|
} V;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Macros to determine the expression type */
|
2012-01-03 21:41:34 +00:00
|
|
|
#define EXPR_NODETYPE(Op) ((Op) & EXPR_TYPEMASK)
|
2013-05-09 11:56:54 +00:00
|
|
|
#define EXPR_IS_LEAF(Op) (EXPR_NODETYPE (Op) == EXPR_LEAFNODE)
|
|
|
|
#define EXPR_IS_UNARY(Op) (EXPR_NODETYPE (Op) == EXPR_UNARYNODE)
|
|
|
|
#define EXPR_IS_BINARY(OP) (EXPR_NODETYPE (Op) == EXPR_BINARYNODE)
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2000-07-29 15:53:33 +00:00
|
|
|
/*****************************************************************************/
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Code */
|
2000-07-29 15:53:33 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-11-11 13:58:00 +00:00
|
|
|
void DumpExpr (const ExprNode* Expr, const ExprNode* (*ResolveSym) (const struct SymEntry*));
|
2000-07-29 15:53:33 +00:00
|
|
|
/* Dump an expression tree to stdout */
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
/* End of exprdefs.h */
|
|
|
|
|
|
|
|
#endif
|