]> git.sur5r.net Git - cc65/blob - src/ca65/expr.h
Replace tabs by spaces in file lists.
[cc65] / src / ca65 / expr.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                  expr.h                                   */
4 /*                                                                           */
5 /*             Expression evaluation for the ca65 macroassembler             */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998-2006 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 /*                                 Forwards                                  */
48 /*****************************************************************************/
49
50
51
52 struct ExprDesc;
53
54
55
56 /*****************************************************************************/
57 /*                                   Code                                    */
58 /*****************************************************************************/
59
60
61
62 ExprNode* Expression (void);
63 /* Evaluate an expression, build the expression tree on the heap and return
64  * a pointer to the root of the tree.
65  */
66
67 long ConstExpression (void);
68 /* Parse an expression. Check if the expression is const, and print an error
69  * message if not. Return the value of the expression, or a dummy, if it is
70  * not constant.
71  */
72
73 void FreeExpr (ExprNode* Root);
74 /* Free the expression tree, Root is pointing to. */
75
76 ExprNode* SimplifyExpr (ExprNode* Expr, const struct ExprDesc* D);
77 /* Try to simplify the given expression tree */
78
79 ExprNode* GenLiteralExpr (long Val);
80 /* Return an expression tree that encodes the given literal value */
81
82 ExprNode* GenLiteral0 (void);
83 /* Return an expression tree that encodes the the number zero */
84
85 ExprNode* GenSymExpr (struct SymEntry* Sym);
86 /* Return an expression node that encodes the given symbol */
87
88 ExprNode* GenAddExpr (ExprNode* Left, ExprNode* Right);
89 /* Generate an addition from the two operands */
90
91 ExprNode* GenCurrentPC (void);
92 /* Return the current program counter as expression */
93
94 ExprNode* GenSwapExpr (ExprNode* Expr);
95 /* Return an extended expression with lo and hi bytes swapped */
96
97 ExprNode* GenBranchExpr (unsigned Offs);
98 /* Return an expression that encodes the difference between current PC plus
99  * offset and the target expression (that is, Expression() - (*+Offs) ).
100  */
101
102 ExprNode* GenULabelExpr (unsigned Num);
103 /* Return an expression for an unnamed label with the given index */
104
105 ExprNode* GenByteExpr (ExprNode* Expr);
106 /* Force the given expression into a byte and return the result */
107
108 ExprNode* GenWordExpr (ExprNode* Expr);
109 /* Force the given expression into a word and return the result. */
110
111 ExprNode* GenNE (ExprNode* Expr, long Val);
112 /* Generate an expression that compares Expr and Val for inequality */
113
114 int IsConstExpr (ExprNode* Expr, long* Val);
115 /* Return true if the given expression is a constant expression, that is, one
116  * with no references to external symbols. If Val is not NULL and the
117  * expression is constant, the constant value is stored here.
118  */
119
120 int IsByteExpr (ExprNode* Root);
121 /* Return true if this is a byte expression */
122
123 int IsByteRange (long Val);
124 /* Return true if this is a byte value */
125
126 int IsWordRange (long Val);
127 /* Return true if this is a word value */
128
129 int IsFarRange (long Val);
130 /* Return true if this is a far (24 bit) value */
131
132 ExprNode* CloneExpr (ExprNode* Expr);
133 /* Clone the given expression tree. The function will simply clone symbol
134  * nodes, it will not resolve them.
135  */
136
137 void WriteExpr (ExprNode* Expr);
138 /* Write the given expression to the object file */
139
140 void ExprGuessedAddrSize (const ExprNode* Expr, unsigned char AddrSize);
141 /* Mark the address size of the given expression tree as guessed. The address
142  * size passed as argument is the one NOT used, because the actual address
143  * size wasn't known. Example: Zero page addressing was not used because symbol
144  * is undefined, and absolute addressing was available.
145  * This function will actually parse the expression tree for undefined symbols,
146  * and mark these symbols accordingly.
147  */
148
149 ExprNode* FuncBankByte (void);
150 /* Handle the .BANKBYTE builtin function */
151
152 ExprNode* FuncLoByte (void);
153 /* Handle the .LOBYTE builtin function */
154
155 ExprNode* FuncHiByte (void);
156 /* Handle the .HIBYTE builtin function */
157
158
159 /* End of expr.h */
160
161 #endif
162
163
164