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
53struct ExprDesc;
54
55
56
57/*****************************************************************************/
58/* Code */
59/*****************************************************************************/
60
61
62
63ExprNode* 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
68long 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
74void FreeExpr (ExprNode* Root);
75/* Free the expression tree, Root is pointing to. */
76
77ExprNode* SimplifyExpr (ExprNode* Expr, const struct ExprDesc* D);
78/* Try to simplify the given expression tree */
79
80ExprNode* GenLiteralExpr (long Val);
81/* Return an expression tree that encodes the given literal value */
82
83ExprNode* GenLiteral0 (void);
84/* Return an expression tree that encodes the the number zero */
85
86ExprNode* GenSymExpr (struct SymEntry* Sym);
87/* Return an expression node that encodes the given symbol */
88
89ExprNode* GenAddExpr (ExprNode* Left, ExprNode* Right);
90/* Generate an addition from the two operands */
91
92ExprNode* GenCurrentPC (void);
93/* Return the current program counter as expression */
94
95ExprNode* GenSwapExpr (ExprNode* Expr);
96/* Return an extended expression with lo and hi bytes swapped */
97
98ExprNode* 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
103ExprNode* GenULabelExpr (unsigned Num);
104/* Return an expression for an unnamed label with the given index */
105
106ExprNode* GenByteExpr (ExprNode* Expr);
107/* Force the given expression into a byte and return the result */
108
109ExprNode* GenWordExpr (ExprNode* Expr);
110/* Force the given expression into a word and return the result. */
111
112ExprNode* GenNearAddrExpr (ExprNode* Expr);
113/* A word sized expression that will error if given a far expression at assemble time. */
114
115ExprNode* GenFarAddrExpr (ExprNode* Expr);
116/* Force the given expression into a far address and return the result. */
117
118ExprNode* GenDWordExpr (ExprNode* Expr);
119/* Force the given expression into a dword and return the result. */
120
121ExprNode* GenNE (ExprNode* Expr, long Val);
122/* Generate an expression that compares Expr and Val for inequality */
123
124int IsConstExpr (ExprNode* Expr, long* Val);
125/* Return true if the given expression is a constant expression, that is, one
126** with no references to external symbols. If Val is not NULL and the
127** expression is constant, the constant value is stored here.
128*/
129
130int IsByteExpr (ExprNode* Root);
131/* Return true if this is a byte expression */
132
133int IsByteRange (long Val);
134/* Return true if this is a byte value */
135
136int IsWordRange (long Val);
137/* Return true if this is a word value */
138
139int IsFarRange (long Val);
140/* Return true if this is a far (24 bit) value */
141
142int IsEasyConst (const ExprNode* E, long* Val);
143/* Do some light checking if the given node is a constant. Don't care if E is
144** a complex expression. If E is a constant, return true and place its value
145** into Val, provided that Val is not NULL.
146*/
147
148ExprNode* CloneExpr (ExprNode* Expr);
149/* Clone the given expression tree. The function will simply clone symbol
150** nodes, it will not resolve them.
151*/
152
153void WriteExpr (ExprNode* Expr);
154/* Write the given expression to the object file */
155
156void ExprGuessedAddrSize (const ExprNode* Expr, unsigned char AddrSize);
157/* Mark the address size of the given expression tree as guessed. The address
158** size passed as argument is the one NOT used, because the actual address
159** size wasn't known. Example: Zero page addressing was not used because symbol
160** is undefined, and absolute addressing was available.
161** This function will actually parse the expression tree for undefined symbols,
162** and mark these symbols accordingly.
163*/
164
165ExprNode* FuncBankByte (void);
166/* Handle the .BANKBYTE builtin function */
167
168ExprNode* FuncLoByte (void);
169/* Handle the .LOBYTE builtin function */
170
171ExprNode* FuncHiByte (void);
172/* Handle the .HIBYTE builtin function */
173
174ExprNode* MakeBoundedExpr (ExprNode* Expr, unsigned Size);
175/* Force the given expression into a specific size of ForceRange is true */
176
177ExprNode* BoundedExpr (ExprNode* (*ExprFunc) (void), unsigned Size);
178/* Parse an expression and force it within a given size if ForceRange is true */
179
180
181
182/* End of expr.h */
183
184#endif
185