]> git.sur5r.net Git - cc65/blob - src/common/exprdefs.h
Removed (pretty inconsistently used) tab chars from source code base.
[cc65] / src / common / exprdefs.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                exprdefs.h                                 */
4 /*                                                                           */
5 /*                        Expression tree definitions                        */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998-2012, Ullrich von Bassewitz                                      */
10 /*                Roemerstrasse 52                                           */
11 /*                D-70794 Filderstadt                                        */
12 /* EMail:         uz@cc65.org                                                */
13 /*                                                                           */
14 /*                                                                           */
15 /* This software is provided 'as-is', without any expressed or implied       */
16 /* warranty.  In no event will the authors be held liable for any damages    */
17 /* arising from the use of this software.                                    */
18 /*                                                                           */
19 /* Permission is granted to anyone to use this software for any purpose,     */
20 /* including commercial applications, and to alter it and redistribute it    */
21 /* freely, subject to the following restrictions:                            */
22 /*                                                                           */
23 /* 1. The origin of this software must not be misrepresented; you must not   */
24 /*    claim that you wrote the original software. If you use this software   */
25 /*    in a product, an acknowledgment in the product documentation would be  */
26 /*    appreciated but is not required.                                       */
27 /* 2. Altered source versions must be plainly marked as such, and must not   */
28 /*    be misrepresented as being the original software.                      */
29 /* 3. This notice may not be removed or altered from any source              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #ifndef EXPRDEFS_H
37 #define EXPRDEFS_H
38
39
40
41 /*****************************************************************************/
42 /*                                   Data                                    */
43 /*****************************************************************************/
44
45
46
47 /* Expression type masks */
48 #define EXPR_TYPEMASK           0xC0
49 #define EXPR_BINARYNODE         0x00
50 #define EXPR_UNARYNODE          0x40
51 #define EXPR_LEAFNODE           0x80
52
53 /* Type of expression nodes */
54 #define EXPR_NULL               0x00    /* Internal error or NULL node */
55
56 /* Leaf node codes */
57 #define EXPR_LITERAL            (EXPR_LEAFNODE | 0x01)
58 #define EXPR_SYMBOL             (EXPR_LEAFNODE | 0x02)
59 #define EXPR_SECTION            (EXPR_LEAFNODE | 0x03)
60 #define EXPR_SEGMENT            (EXPR_LEAFNODE | 0x04)  /* Linker only */
61 #define EXPR_MEMAREA            (EXPR_LEAFNODE | 0x05)  /* Linker only */
62 #define EXPR_ULABEL             (EXPR_LEAFNODE | 0x06)  /* Assembler only */
63
64 /* Binary operations, left and right hand sides are valid */
65 #define EXPR_PLUS               (EXPR_BINARYNODE | 0x01)
66 #define EXPR_MINUS              (EXPR_BINARYNODE | 0x02)
67 #define EXPR_MUL                (EXPR_BINARYNODE | 0x03)
68 #define EXPR_DIV                (EXPR_BINARYNODE | 0x04)
69 #define EXPR_MOD                (EXPR_BINARYNODE | 0x05)
70 #define EXPR_OR                 (EXPR_BINARYNODE | 0x06)
71 #define EXPR_XOR                (EXPR_BINARYNODE | 0x07)
72 #define EXPR_AND                (EXPR_BINARYNODE | 0x08)
73 #define EXPR_SHL                (EXPR_BINARYNODE | 0x09)
74 #define EXPR_SHR                (EXPR_BINARYNODE | 0x0A)
75 #define EXPR_EQ                 (EXPR_BINARYNODE | 0x0B)
76 #define EXPR_NE                 (EXPR_BINARYNODE | 0x0C)
77 #define EXPR_LT                 (EXPR_BINARYNODE | 0x0D)
78 #define EXPR_GT                 (EXPR_BINARYNODE | 0x0E)
79 #define EXPR_LE                 (EXPR_BINARYNODE | 0x0F)
80 #define EXPR_GE                 (EXPR_BINARYNODE | 0x10)
81 #define EXPR_BOOLAND            (EXPR_BINARYNODE | 0x11)
82 #define EXPR_BOOLOR             (EXPR_BINARYNODE | 0x12)
83 #define EXPR_BOOLXOR            (EXPR_BINARYNODE | 0x13)
84 #define EXPR_MAX                (EXPR_BINARYNODE | 0x14)
85 #define EXPR_MIN                (EXPR_BINARYNODE | 0x15)
86
87 /* Unary operations, right hand side is empty */
88 #define EXPR_UNARY_MINUS        (EXPR_UNARYNODE | 0x01)
89 #define EXPR_NOT                (EXPR_UNARYNODE | 0x02)
90 #define EXPR_SWAP               (EXPR_UNARYNODE | 0x03)
91 #define EXPR_BOOLNOT            (EXPR_UNARYNODE | 0x04)
92 #define EXPR_BANK               (EXPR_UNARYNODE | 0x05)
93
94 #define EXPR_BYTE0              (EXPR_UNARYNODE | 0x08)
95 #define EXPR_BYTE1              (EXPR_UNARYNODE | 0x09)
96 #define EXPR_BYTE2              (EXPR_UNARYNODE | 0x0A)
97 #define EXPR_BYTE3              (EXPR_UNARYNODE | 0x0B)
98 #define EXPR_WORD0              (EXPR_UNARYNODE | 0x0C)
99 #define EXPR_WORD1              (EXPR_UNARYNODE | 0x0D)
100 #define EXPR_FARADDR            (EXPR_UNARYNODE | 0x0E)
101 #define EXPR_DWORD              (EXPR_UNARYNODE | 0x0F)
102
103
104
105 /* The expression node itself */
106 typedef struct ExprNode ExprNode;
107 struct ExprNode {
108     unsigned char           Op;         /* Operand/Type */
109     ExprNode*               Left;       /* Left leaf */
110     ExprNode*               Right;      /* Right leaf */
111     struct ObjData*         Obj;        /* Object file reference (linker) */
112     union {
113         long                IVal;       /* If this is a int value */
114         struct SymEntry*    Sym;        /* If this is a symbol */
115         unsigned            SecNum;     /* If this is a section and Obj != 0 */
116         unsigned            ImpNum;     /* If this is an import and Obj != 0 */
117         struct Import*      Imp;        /* If this is an import and Obj == 0 */
118         struct MemoryArea*  Mem;        /* If this is a memory area */
119         struct Segment*     Seg;        /* If this is a segment */
120         struct Section*     Sec;        /* If this is a section and Obj == 0 */
121     } V;
122 };
123
124
125
126 /* Macros to determine the expression type */
127 #define EXPR_NODETYPE(Op)       ((Op) & EXPR_TYPEMASK)
128 #define EXPR_IS_LEAF(Op)        (EXPR_NODETYPE (Op) == EXPR_LEAFNODE)
129 #define EXPR_IS_UNARY(Op)       (EXPR_NODETYPE (Op) == EXPR_UNARYNODE)
130 #define EXPR_IS_BINARY(OP)      (EXPR_NODETYPE (Op) == EXPR_BINARYNODE)
131
132
133
134 /*****************************************************************************/
135 /*                                   Code                                    */
136 /*****************************************************************************/
137
138
139
140 void DumpExpr (const ExprNode* Expr, const ExprNode* (*ResolveSym) (const struct SymEntry*));
141 /* Dump an expression tree to stdout */
142
143
144
145 /* End of exprdefs.h */
146
147 #endif
148
149
150