]> git.sur5r.net Git - cc65/blob - src/ca65/expr.h
This commit was generated by cvs2svn to compensate for changes in r2,
[cc65] / src / ca65 / expr.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                  expr.h                                   */
4 /*                                                                           */
5 /*             Expression evaluation for the ca65 macroassembler             */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998     Ullrich von Bassewitz                                        */
10 /*              Wacholderweg 14                                              */
11 /*              D-70597 Stuttgart                                            */
12 /* EMail:       uz@musoftware.de                                             */
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 #include "../common/exprdefs.h"
42
43
44
45 /*****************************************************************************/
46 /*                                   Code                                    */
47 /*****************************************************************************/
48
49
50
51 ExprNode* Expression (void);
52 /* Evaluate an expression, build the expression tree on the heap and return
53  * a pointer to the root of the tree.
54  */
55
56 long ConstExpression (void);
57 /* Parse an expression. Check if the expression is const, and print an error
58  * message if not. Return the value of the expression, or a dummy, if it is
59  * not constant.
60  */
61
62 void FreeExpr (ExprNode* Root);
63 /* Free the expression tree, Root is pointing to. */
64
65 ExprNode* LiteralExpr (long Val);
66 /* Return an expression tree that encodes the given literal value */
67
68 ExprNode* CurrentPC (void);
69 /* Return the current program counter as expression */
70
71 ExprNode* SwapExpr (ExprNode* Expr);
72 /* Return an extended expression with lo and hi bytes swapped */
73
74 ExprNode* BranchExpr (unsigned Offs);
75 /* Return an expression that encodes the difference between current PC plus
76  * offset and the target expression (that is, Expression() - (*+Offs) ).
77  */
78
79 ExprNode* ULabelExpr (unsigned Num);
80 /* Return an expression for an unnamed label with the given index */
81
82 ExprNode* ForceWordExpr (ExprNode* Expr);
83 /* Force the given expression into a word and return the result. */
84
85 int IsConstExpr (ExprNode* Root);
86 /* Return true if the given expression is a constant expression, that is, one
87  * with no references to external symbols.
88  */
89
90 int IsByteExpr (ExprNode* Root);
91 /* Return true if this is a byte expression */
92
93 long GetExprVal (ExprNode* Expr);
94 /* Get the value of a constant expression */
95
96 int IsByteRange (long Val);
97 /* Return true if this is a byte value */
98
99 int IsWordRange (long Val);
100 /* Return true if this is a word value */
101
102 void DumpExpr (ExprNode* Expr);
103 /* Dump an expression tree to stdout */
104
105 ExprNode* FinalizeExpr (ExprNode* Expr);
106 /* Resolve any symbols by cloning the symbol expression tree instead of the
107  * symbol reference, then try to simplify the expression as much as possible.
108  * This function must only be called if all symbols are resolved (no undefined
109  * symbol errors).
110  */
111
112 ExprNode* CloneExpr (ExprNode* Expr);
113 /* Clone the given expression tree. The function will simply clone symbol
114  * nodes, it will not resolve them.
115  */
116
117 void WriteExpr (ExprNode* Expr);
118 /* Write the given expression to the object file */
119
120
121
122 /* End of expr.h */
123
124 #endif
125
126
127