/*****************************************************************************/
/* */
-/* expr.h */
+/* expr.h */
/* */
-/* Expression evaluation for the ca65 macroassembler */
+/* Expression evaluation for the ca65 macroassembler */
/* */
/* */
/* */
-/* (C) 1998-2003 Ullrich von Bassewitz */
-/* Römerstrasse 52 */
-/* D-70794 Filderstadt */
-/* EMail: uz@cc65.org */
+/* (C) 1998-2012, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/* common */
+#include "coll.h"
#include "exprdefs.h"
/*****************************************************************************/
-/* Code */
+/* Forwards */
+/*****************************************************************************/
+
+
+
+struct ExprDesc;
+
+
+
+/*****************************************************************************/
+/* Code */
/*****************************************************************************/
void FreeExpr (ExprNode* Root);
/* Free the expression tree, Root is pointing to. */
-ExprNode* LiteralExpr (long Val);
+ExprNode* SimplifyExpr (ExprNode* Expr, const struct ExprDesc* D);
+/* Try to simplify the given expression tree */
+
+ExprNode* GenLiteralExpr (long Val);
/* Return an expression tree that encodes the given literal value */
-ExprNode* CurrentPC (void);
+ExprNode* GenLiteral0 (void);
+/* Return an expression tree that encodes the the number zero */
+
+ExprNode* GenSymExpr (struct SymEntry* Sym);
+/* Return an expression node that encodes the given symbol */
+
+ExprNode* GenAddExpr (ExprNode* Left, ExprNode* Right);
+/* Generate an addition from the two operands */
+
+ExprNode* GenCurrentPC (void);
/* Return the current program counter as expression */
-ExprNode* SwapExpr (ExprNode* Expr);
+ExprNode* GenSwapExpr (ExprNode* Expr);
/* Return an extended expression with lo and hi bytes swapped */
-ExprNode* BranchExpr (unsigned Offs);
+ExprNode* GenBranchExpr (unsigned Offs);
/* Return an expression that encodes the difference between current PC plus
* offset and the target expression (that is, Expression() - (*+Offs) ).
*/
-ExprNode* ULabelExpr (unsigned Num);
+ExprNode* GenULabelExpr (unsigned Num);
/* Return an expression for an unnamed label with the given index */
-ExprNode* ForceByteExpr (ExprNode* Expr);
+ExprNode* GenByteExpr (ExprNode* Expr);
/* Force the given expression into a byte and return the result */
-ExprNode* ForceWordExpr (ExprNode* Expr);
+ExprNode* GenWordExpr (ExprNode* Expr);
/* Force the given expression into a word and return the result. */
-ExprNode* CompareExpr (ExprNode* Expr, long Val);
-/* Generate an expression that compares Expr and Val for equality */
+ExprNode* GenFarAddrExpr (ExprNode* Expr);
+/* Force the given expression into a far address and return the result. */
-int IsConstExpr (ExprNode* Root);
+ExprNode* GenDWordExpr (ExprNode* Expr);
+/* Force the given expression into a dword and return the result. */
+
+ExprNode* GenNE (ExprNode* Expr, long Val);
+/* Generate an expression that compares Expr and Val for inequality */
+
+int IsConstExpr (ExprNode* Expr, long* Val);
/* Return true if the given expression is a constant expression, that is, one
- * with no references to external symbols.
+ * with no references to external symbols. If Val is not NULL and the
+ * expression is constant, the constant value is stored here.
*/
int IsByteExpr (ExprNode* Root);
/* Return true if this is a byte expression */
-long GetExprVal (ExprNode* Expr);
-/* Get the value of a constant expression */
-
int IsByteRange (long Val);
/* Return true if this is a byte value */
int IsWordRange (long Val);
/* Return true if this is a word value */
-ExprNode* FinalizeExpr (ExprNode* Expr);
-/* Resolve any symbols by cloning the symbol expression tree instead of the
- * symbol reference, then try to simplify the expression as much as possible.
- * This function must only be called if all symbols are resolved (no undefined
- * symbol errors).
+int IsFarRange (long Val);
+/* Return true if this is a far (24 bit) value */
+
+int IsEasyConst (const ExprNode* E, long* Val);
+/* Do some light checking if the given node is a constant. Don't care if E is
+ * a complex expression. If E is a constant, return true and place its value
+ * into Val, provided that Val is not NULL.
*/
ExprNode* CloneExpr (ExprNode* Expr);
void WriteExpr (ExprNode* Expr);
/* Write the given expression to the object file */
+void ExprGuessedAddrSize (const ExprNode* Expr, unsigned char AddrSize);
+/* Mark the address size of the given expression tree as guessed. The address
+ * size passed as argument is the one NOT used, because the actual address
+ * size wasn't known. Example: Zero page addressing was not used because symbol
+ * is undefined, and absolute addressing was available.
+ * This function will actually parse the expression tree for undefined symbols,
+ * and mark these symbols accordingly.
+ */
+ExprNode* FuncBankByte (void);
+/* Handle the .BANKBYTE builtin function */
-/* End of expr.h */
+ExprNode* FuncLoByte (void);
+/* Handle the .LOBYTE builtin function */
-#endif
+ExprNode* FuncHiByte (void);
+/* Handle the .HIBYTE builtin function */
+
+ExprNode* MakeBoundedExpr (ExprNode* Expr, unsigned Size);
+/* Force the given expression into a specific size of ForceRange is true */
+
+ExprNode* BoundedExpr (ExprNode* (*ExprFunc) (void), unsigned Size);
+/* Parse an expression and force it within a given size if ForceRange is true */
+/* End of expr.h */
+
+#endif