xref: /openbsd-src/gnu/usr.bin/binutils-2.17/gas/expr.h (revision 3d8817e467ea46cf4772788d6804dd293abfb01a)
1*3d8817e4Smiod /* expr.h -> header file for expr.c
2*3d8817e4Smiod    Copyright 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3*3d8817e4Smiod    2002, 2003 Free Software Foundation, Inc.
4*3d8817e4Smiod 
5*3d8817e4Smiod    This file is part of GAS, the GNU Assembler.
6*3d8817e4Smiod 
7*3d8817e4Smiod    GAS is free software; you can redistribute it and/or modify
8*3d8817e4Smiod    it under the terms of the GNU General Public License as published by
9*3d8817e4Smiod    the Free Software Foundation; either version 2, or (at your option)
10*3d8817e4Smiod    any later version.
11*3d8817e4Smiod 
12*3d8817e4Smiod    GAS is distributed in the hope that it will be useful,
13*3d8817e4Smiod    but WITHOUT ANY WARRANTY; without even the implied warranty of
14*3d8817e4Smiod    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*3d8817e4Smiod    GNU General Public License for more details.
16*3d8817e4Smiod 
17*3d8817e4Smiod    You should have received a copy of the GNU General Public License
18*3d8817e4Smiod    along with GAS; see the file COPYING.  If not, write to the Free
19*3d8817e4Smiod    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
20*3d8817e4Smiod    02110-1301, USA.  */
21*3d8817e4Smiod 
22*3d8817e4Smiod /*
23*3d8817e4Smiod  * By popular demand, we define a struct to represent an expression.
24*3d8817e4Smiod  * This will no doubt mutate as expressions become baroque.
25*3d8817e4Smiod  *
26*3d8817e4Smiod  * Currently, we support expressions like "foo OP bar + 42".  In other
27*3d8817e4Smiod  * words we permit a (possibly undefined) symbol, a (possibly
28*3d8817e4Smiod  * undefined) symbol and the operation used to combine the symbols,
29*3d8817e4Smiod  * and an (absolute) augend.  RMS says this is so we can have 1-pass
30*3d8817e4Smiod  * assembly for any compiler emissions, and a 'case' statement might
31*3d8817e4Smiod  * emit 'undefined1 - undefined2'.
32*3d8817e4Smiod  *
33*3d8817e4Smiod  * The type of an expression used to be stored as a segment.  That got
34*3d8817e4Smiod  * confusing because it overloaded the concept of a segment.  I added
35*3d8817e4Smiod  * an operator field, instead.
36*3d8817e4Smiod  */
37*3d8817e4Smiod 
38*3d8817e4Smiod /* This is the type of an expression.  The operator types are also
39*3d8817e4Smiod    used while parsing an expression.
40*3d8817e4Smiod 
41*3d8817e4Smiod    NOTE: This enumeration must match the op_rank array in expr.c.  */
42*3d8817e4Smiod 
43*3d8817e4Smiod typedef enum {
44*3d8817e4Smiod   /* An illegal expression.  */
45*3d8817e4Smiod   O_illegal,
46*3d8817e4Smiod   /* A nonexistent expression.  */
47*3d8817e4Smiod   O_absent,
48*3d8817e4Smiod   /* X_add_number (a constant expression).  */
49*3d8817e4Smiod   O_constant,
50*3d8817e4Smiod   /* X_add_symbol + X_add_number.  */
51*3d8817e4Smiod   O_symbol,
52*3d8817e4Smiod   /* X_add_symbol + X_add_number - the base address of the image.  */
53*3d8817e4Smiod   O_symbol_rva,
54*3d8817e4Smiod   /* A register (X_add_number is register number).  */
55*3d8817e4Smiod   O_register,
56*3d8817e4Smiod   /* A big value.  If X_add_number is negative or 0, the value is in
57*3d8817e4Smiod      generic_floating_point_number.  Otherwise the value is in
58*3d8817e4Smiod      generic_bignum, and X_add_number is the number of LITTLENUMs in
59*3d8817e4Smiod      the value.  */
60*3d8817e4Smiod   O_big,
61*3d8817e4Smiod   /* (- X_add_symbol) + X_add_number.  */
62*3d8817e4Smiod   O_uminus,
63*3d8817e4Smiod   /* (~ X_add_symbol) + X_add_number.  */
64*3d8817e4Smiod   O_bit_not,
65*3d8817e4Smiod   /* (! X_add_symbol) + X_add_number.  */
66*3d8817e4Smiod   O_logical_not,
67*3d8817e4Smiod   /* (X_add_symbol * X_op_symbol) + X_add_number.  */
68*3d8817e4Smiod   O_multiply,
69*3d8817e4Smiod   /* (X_add_symbol / X_op_symbol) + X_add_number.  */
70*3d8817e4Smiod   O_divide,
71*3d8817e4Smiod   /* (X_add_symbol % X_op_symbol) + X_add_number.  */
72*3d8817e4Smiod   O_modulus,
73*3d8817e4Smiod   /* (X_add_symbol << X_op_symbol) + X_add_number.  */
74*3d8817e4Smiod   O_left_shift,
75*3d8817e4Smiod   /* (X_add_symbol >> X_op_symbol) + X_add_number.  */
76*3d8817e4Smiod   O_right_shift,
77*3d8817e4Smiod   /* (X_add_symbol | X_op_symbol) + X_add_number.  */
78*3d8817e4Smiod   O_bit_inclusive_or,
79*3d8817e4Smiod   /* (X_add_symbol |~ X_op_symbol) + X_add_number.  */
80*3d8817e4Smiod   O_bit_or_not,
81*3d8817e4Smiod   /* (X_add_symbol ^ X_op_symbol) + X_add_number.  */
82*3d8817e4Smiod   O_bit_exclusive_or,
83*3d8817e4Smiod   /* (X_add_symbol & X_op_symbol) + X_add_number.  */
84*3d8817e4Smiod   O_bit_and,
85*3d8817e4Smiod   /* (X_add_symbol + X_op_symbol) + X_add_number.  */
86*3d8817e4Smiod   O_add,
87*3d8817e4Smiod   /* (X_add_symbol - X_op_symbol) + X_add_number.  */
88*3d8817e4Smiod   O_subtract,
89*3d8817e4Smiod   /* (X_add_symbol == X_op_symbol) + X_add_number.  */
90*3d8817e4Smiod   O_eq,
91*3d8817e4Smiod   /* (X_add_symbol != X_op_symbol) + X_add_number.  */
92*3d8817e4Smiod   O_ne,
93*3d8817e4Smiod   /* (X_add_symbol < X_op_symbol) + X_add_number.  */
94*3d8817e4Smiod   O_lt,
95*3d8817e4Smiod   /* (X_add_symbol <= X_op_symbol) + X_add_number.  */
96*3d8817e4Smiod   O_le,
97*3d8817e4Smiod   /* (X_add_symbol >= X_op_symbol) + X_add_number.  */
98*3d8817e4Smiod   O_ge,
99*3d8817e4Smiod   /* (X_add_symbol > X_op_symbol) + X_add_number.  */
100*3d8817e4Smiod   O_gt,
101*3d8817e4Smiod   /* (X_add_symbol && X_op_symbol) + X_add_number.  */
102*3d8817e4Smiod   O_logical_and,
103*3d8817e4Smiod   /* (X_add_symbol || X_op_symbol) + X_add_number.  */
104*3d8817e4Smiod   O_logical_or,
105*3d8817e4Smiod   /* X_op_symbol [ X_add_symbol ] */
106*3d8817e4Smiod   O_index,
107*3d8817e4Smiod   /* machine dependent operators */
108*3d8817e4Smiod   O_md1,  O_md2,  O_md3,  O_md4,  O_md5,  O_md6,  O_md7,  O_md8,
109*3d8817e4Smiod   O_md9,  O_md10, O_md11, O_md12, O_md13, O_md14, O_md15, O_md16,
110*3d8817e4Smiod   O_md17, O_md18, O_md19, O_md20, O_md21, O_md22, O_md23, O_md24,
111*3d8817e4Smiod   O_md25, O_md26, O_md27, O_md28, O_md29, O_md30, O_md31, O_md32,
112*3d8817e4Smiod   /* this must be the largest value */
113*3d8817e4Smiod   O_max
114*3d8817e4Smiod } operatorT;
115*3d8817e4Smiod 
116*3d8817e4Smiod typedef struct expressionS {
117*3d8817e4Smiod   /* The main symbol.  */
118*3d8817e4Smiod   symbolS *X_add_symbol;
119*3d8817e4Smiod   /* The second symbol, if needed.  */
120*3d8817e4Smiod   symbolS *X_op_symbol;
121*3d8817e4Smiod   /* A number to add.  */
122*3d8817e4Smiod   offsetT X_add_number;
123*3d8817e4Smiod 
124*3d8817e4Smiod   /* The type of the expression.  We can't assume that an arbitrary
125*3d8817e4Smiod      compiler can handle a bitfield of enum type.  FIXME: We could
126*3d8817e4Smiod      check this using autoconf.  */
127*3d8817e4Smiod #ifdef __GNUC__
128*3d8817e4Smiod   operatorT X_op : 8;
129*3d8817e4Smiod #else
130*3d8817e4Smiod   unsigned char X_op;
131*3d8817e4Smiod #endif
132*3d8817e4Smiod 
133*3d8817e4Smiod   /* Non-zero if X_add_number should be regarded as unsigned.  This is
134*3d8817e4Smiod      only valid for O_constant expressions.  It is only used when an
135*3d8817e4Smiod      O_constant must be extended into a bignum (i.e., it is not used
136*3d8817e4Smiod      when performing arithmetic on these values).
137*3d8817e4Smiod      FIXME: This field is not set very reliably.  */
138*3d8817e4Smiod   unsigned int X_unsigned : 1;
139*3d8817e4Smiod 
140*3d8817e4Smiod   /* 7 additional bits can be defined if needed.  */
141*3d8817e4Smiod 
142*3d8817e4Smiod   /* Machine dependent field */
143*3d8817e4Smiod   unsigned short X_md;
144*3d8817e4Smiod } expressionS;
145*3d8817e4Smiod 
146*3d8817e4Smiod enum expr_mode
147*3d8817e4Smiod {
148*3d8817e4Smiod   expr_evaluate,
149*3d8817e4Smiod   expr_normal,
150*3d8817e4Smiod   expr_defer
151*3d8817e4Smiod };
152*3d8817e4Smiod 
153*3d8817e4Smiod /* "result" should be type (expressionS *).  */
154*3d8817e4Smiod #define expression(result) expr (0, result, expr_normal)
155*3d8817e4Smiod #define expression_and_evaluate(result) expr (0, result, expr_evaluate)
156*3d8817e4Smiod #define deferred_expression(result) expr (0, result, expr_defer)
157*3d8817e4Smiod 
158*3d8817e4Smiod /* If an expression is O_big, look here for its value. These common
159*3d8817e4Smiod    data may be clobbered whenever expr() is called.  */
160*3d8817e4Smiod /* Flonums returned here.  Big enough to hold most precise flonum.  */
161*3d8817e4Smiod extern FLONUM_TYPE generic_floating_point_number;
162*3d8817e4Smiod /* Bignums returned here.  */
163*3d8817e4Smiod extern LITTLENUM_TYPE generic_bignum[];
164*3d8817e4Smiod /* Number of littlenums in above.  */
165*3d8817e4Smiod #define SIZE_OF_LARGE_NUMBER (20)
166*3d8817e4Smiod 
167*3d8817e4Smiod typedef char operator_rankT;
168*3d8817e4Smiod 
169*3d8817e4Smiod extern char get_symbol_end (void);
170*3d8817e4Smiod extern void expr_begin (void);
171*3d8817e4Smiod extern void expr_set_precedence (void);
172*3d8817e4Smiod extern segT expr (int, expressionS *, enum expr_mode);
173*3d8817e4Smiod extern unsigned int get_single_number (void);
174*3d8817e4Smiod extern symbolS *make_expr_symbol (expressionS * expressionP);
175*3d8817e4Smiod extern int expr_symbol_where (symbolS *, char **, unsigned int *);
176*3d8817e4Smiod 
177*3d8817e4Smiod extern symbolS *expr_build_uconstant (offsetT);
178*3d8817e4Smiod extern symbolS *expr_build_dot (void);
179*3d8817e4Smiod 
180*3d8817e4Smiod int resolve_expression (expressionS *);
181