]> git.sur5r.net Git - cc65/blob - src/ca65/expr.h
2edff0e1d117a4b1a1f24ee497e11bea53b7ab53
[cc65] / src / ca65 / expr.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                  expr.h                                   */
4 /*                                                                           */
5 /*             Expression evaluation for the ca65 macroassembler             */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998-2003 Ullrich von Bassewitz                                       */
10 /*               Römerstraße 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 "exprdefs.h"
43
44
45
46 /*****************************************************************************/
47 /*                                   Code                                    */
48 /*****************************************************************************/
49
50
51
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.
55  */
56
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
60  * not constant.
61  */
62
63 void FreeExpr (ExprNode* Root);
64 /* Free the expression tree, Root is pointing to. */
65
66 ExprNode* GenLiteralExpr (long Val);
67 /* Return an expression tree that encodes the given literal value */
68
69 ExprNode* GenSymExpr (struct SymEntry* Sym);
70 /* Return an expression node that encodes the given symbol */
71
72 ExprNode* GenCurrentPC (void);
73 /* Return the current program counter as expression */
74
75 ExprNode* GenSwapExpr (ExprNode* Expr);
76 /* Return an extended expression with lo and hi bytes swapped */
77
78 ExprNode* GenBranchExpr (unsigned Offs);
79 /* Return an expression that encodes the difference between current PC plus
80  * offset and the target expression (that is, Expression() - (*+Offs) ).
81  */
82
83 ExprNode* GenULabelExpr (unsigned Num);
84 /* Return an expression for an unnamed label with the given index */
85
86 ExprNode* GenByteExpr (ExprNode* Expr);
87 /* Force the given expression into a byte and return the result */
88
89 ExprNode* GenWordExpr (ExprNode* Expr);
90 /* Force the given expression into a word and return the result. */
91
92 ExprNode* GenNE (ExprNode* Expr, long Val);
93 /* Generate an expression that compares Expr and Val for inequality */
94
95 int IsConstExpr (ExprNode* Expr, long* Val);
96 /* Return true if the given expression is a constant expression, that is, one
97  * with no references to external symbols. If Val is not NULL and the
98  * expression is constant, the constant value is stored here.
99  */
100
101 int IsByteExpr (ExprNode* Root);
102 /* Return true if this is a byte expression */
103
104 int IsByteRange (long Val);
105 /* Return true if this is a byte value */
106
107 int IsWordRange (long Val);
108 /* Return true if this is a word value */
109
110 ExprNode* CloneExpr (ExprNode* Expr);
111 /* Clone the given expression tree. The function will simply clone symbol
112  * nodes, it will not resolve them.
113  */
114
115 void WriteExpr (ExprNode* Expr);
116 /* Write the given expression to the object file */
117
118
119
120 /* End of expr.h */
121
122 #endif
123
124
125