1 /*****************************************************************************/
5 /* Expression evaluation for the ca65 macroassembler */
9 /* (C) 1998 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@musoftware.de */
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. */
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: */
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 */
32 /*****************************************************************************/
46 /*****************************************************************************/
48 /*****************************************************************************/
52 ExprNode* Expression (void);
53 /* Evaluate an expression, build the expression tree on the heap and return
54 * a pointer to the root of the tree.
57 long ConstExpression (void);
58 /* Parse an expression. Check if the expression is const, and print an error
59 * message if not. Return the value of the expression, or a dummy, if it is
63 void FreeExpr (ExprNode* Root);
64 /* Free the expression tree, Root is pointing to. */
66 ExprNode* LiteralExpr (long Val);
67 /* Return an expression tree that encodes the given literal value */
69 ExprNode* CurrentPC (void);
70 /* Return the current program counter as expression */
72 ExprNode* SwapExpr (ExprNode* Expr);
73 /* Return an extended expression with lo and hi bytes swapped */
75 ExprNode* BranchExpr (unsigned Offs);
76 /* Return an expression that encodes the difference between current PC plus
77 * offset and the target expression (that is, Expression() - (*+Offs) ).
80 ExprNode* ULabelExpr (unsigned Num);
81 /* Return an expression for an unnamed label with the given index */
83 ExprNode* ForceWordExpr (ExprNode* Expr);
84 /* Force the given expression into a word and return the result. */
86 int IsConstExpr (ExprNode* Root);
87 /* Return true if the given expression is a constant expression, that is, one
88 * with no references to external symbols.
91 int IsByteExpr (ExprNode* Root);
92 /* Return true if this is a byte expression */
94 long GetExprVal (ExprNode* Expr);
95 /* Get the value of a constant expression */
97 int IsByteRange (long Val);
98 /* Return true if this is a byte value */
100 int IsWordRange (long Val);
101 /* Return true if this is a word value */
103 ExprNode* FinalizeExpr (ExprNode* Expr);
104 /* Resolve any symbols by cloning the symbol expression tree instead of the
105 * symbol reference, then try to simplify the expression as much as possible.
106 * This function must only be called if all symbols are resolved (no undefined
110 ExprNode* CloneExpr (ExprNode* Expr);
111 /* Clone the given expression tree. The function will simply clone symbol
112 * nodes, it will not resolve them.
115 void WriteExpr (ExprNode* Expr);
116 /* Write the given expression to the object file */