]> git.sur5r.net Git - cc65/blob - src/ca65/expr.h
Removed (pretty inconsistently used) tab chars from source code base.
[cc65] / src / ca65 / expr.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                  expr.h                                   */
4 /*                                                                           */
5 /*             Expression evaluation for the ca65 macroassembler             */
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 EXPR_H
37 #define EXPR_H
38
39
40
41 /* common */
42 #include "coll.h"
43 #include "exprdefs.h"
44
45
46
47 /*****************************************************************************/
48 /*                                 Forwards                                  */
49 /*****************************************************************************/
50
51
52
53 struct ExprDesc;
54
55
56
57 /*****************************************************************************/
58 /*                                   Code                                    */
59 /*****************************************************************************/
60
61
62
63 ExprNode* Expression (void);
64 /* Evaluate an expression, build the expression tree on the heap and return
65  * a pointer to the root of the tree.
66  */
67
68 long ConstExpression (void);
69 /* Parse an expression. Check if the expression is const, and print an error
70  * message if not. Return the value of the expression, or a dummy, if it is
71  * not constant.
72  */
73
74 void FreeExpr (ExprNode* Root);
75 /* Free the expression tree, Root is pointing to. */
76
77 ExprNode* SimplifyExpr (ExprNode* Expr, const struct ExprDesc* D);
78 /* Try to simplify the given expression tree */
79
80 ExprNode* GenLiteralExpr (long Val);
81 /* Return an expression tree that encodes the given literal value */
82
83 ExprNode* GenLiteral0 (void);
84 /* Return an expression tree that encodes the the number zero */
85
86 ExprNode* GenSymExpr (struct SymEntry* Sym);
87 /* Return an expression node that encodes the given symbol */
88
89 ExprNode* GenAddExpr (ExprNode* Left, ExprNode* Right);
90 /* Generate an addition from the two operands */
91
92 ExprNode* GenCurrentPC (void);
93 /* Return the current program counter as expression */
94
95 ExprNode* GenSwapExpr (ExprNode* Expr);
96 /* Return an extended expression with lo and hi bytes swapped */
97
98 ExprNode* GenBranchExpr (unsigned Offs);
99 /* Return an expression that encodes the difference between current PC plus
100  * offset and the target expression (that is, Expression() - (*+Offs) ).
101  */
102
103 ExprNode* GenULabelExpr (unsigned Num);
104 /* Return an expression for an unnamed label with the given index */
105
106 ExprNode* GenByteExpr (ExprNode* Expr);
107 /* Force the given expression into a byte and return the result */
108
109 ExprNode* GenWordExpr (ExprNode* Expr);
110 /* Force the given expression into a word and return the result. */
111
112 ExprNode* GenFarAddrExpr (ExprNode* Expr);
113 /* Force the given expression into a far address and return the result. */
114
115 ExprNode* GenDWordExpr (ExprNode* Expr);
116 /* Force the given expression into a dword and return the result. */
117
118 ExprNode* GenNE (ExprNode* Expr, long Val);
119 /* Generate an expression that compares Expr and Val for inequality */
120
121 int IsConstExpr (ExprNode* Expr, long* Val);
122 /* Return true if the given expression is a constant expression, that is, one
123  * with no references to external symbols. If Val is not NULL and the
124  * expression is constant, the constant value is stored here.
125  */
126
127 int IsByteExpr (ExprNode* Root);
128 /* Return true if this is a byte expression */
129
130 int IsByteRange (long Val);
131 /* Return true if this is a byte value */
132
133 int IsWordRange (long Val);
134 /* Return true if this is a word value */
135
136 int IsFarRange (long Val);
137 /* Return true if this is a far (24 bit) value */
138
139 int IsEasyConst (const ExprNode* E, long* Val);
140 /* Do some light checking if the given node is a constant. Don't care if E is
141  * a complex expression. If E is a constant, return true and place its value
142  * into Val, provided that Val is not NULL.
143  */
144
145 ExprNode* CloneExpr (ExprNode* Expr);
146 /* Clone the given expression tree. The function will simply clone symbol
147  * nodes, it will not resolve them.
148  */
149
150 void WriteExpr (ExprNode* Expr);
151 /* Write the given expression to the object file */
152
153 void ExprGuessedAddrSize (const ExprNode* Expr, unsigned char AddrSize);
154 /* Mark the address size of the given expression tree as guessed. The address
155  * size passed as argument is the one NOT used, because the actual address
156  * size wasn't known. Example: Zero page addressing was not used because symbol
157  * is undefined, and absolute addressing was available.
158  * This function will actually parse the expression tree for undefined symbols,
159  * and mark these symbols accordingly.
160  */
161
162 ExprNode* FuncBankByte (void);
163 /* Handle the .BANKBYTE builtin function */
164
165 ExprNode* FuncLoByte (void);
166 /* Handle the .LOBYTE builtin function */
167
168 ExprNode* FuncHiByte (void);
169 /* Handle the .HIBYTE builtin function */
170
171 ExprNode* MakeBoundedExpr (ExprNode* Expr, unsigned Size);
172 /* Force the given expression into a specific size of ForceRange is true */
173
174 ExprNode* BoundedExpr (ExprNode* (*ExprFunc) (void), unsigned Size);
175 /* Parse an expression and force it within a given size if ForceRange is true */
176
177
178
179 /* End of expr.h */
180
181 #endif
182
183
184