1 /* expr.h -> header file for expr.c
2 Copyright (C) 1987, 92-99, 2000 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 * By popular demand, we define a struct to represent an expression.
23 * This will no doubt mutate as expressions become baroque.
25 * Currently, we support expressions like "foo OP bar + 42". In other
26 * words we permit a (possibly undefined) symbol, a (possibly
27 * undefined) symbol and the operation used to combine the symbols,
28 * and an (absolute) augend. RMS says this is so we can have 1-pass
29 * assembly for any compiler emissions, and a 'case' statement might
30 * emit 'undefined1 - undefined2'.
32 * The type of an expression used to be stored as a segment. That got
33 * confusing because it overloaded the concept of a segment. I added
34 * an operator field, instead.
37 /* This is the type of an expression. The operator types are also
38 used while parsing an expression.
40 NOTE: This enumeration must match the op_rank array in expr.c. */
43 /* An illegal expression. */
45 /* A nonexistent expression. */
47 /* X_add_number (a constant expression). */
49 /* X_add_symbol + X_add_number. */
51 /* X_add_symbol + X_add_number - the base address of the image. */
53 /* A register (X_add_number is register number). */
55 /* A big value. If X_add_number is negative or 0, the value is in
56 generic_floating_point_number. Otherwise the value is in
57 generic_bignum, and X_add_number is the number of LITTLENUMs in
60 /* (- X_add_symbol) + X_add_number. */
62 /* (~ X_add_symbol) + X_add_number. */
64 /* (! X_add_symbol) + X_add_number. */
66 /* (X_add_symbol * X_op_symbol) + X_add_number. */
68 /* (X_add_symbol / X_op_symbol) + X_add_number. */
70 /* X_add_symbol % X_op_symbol) + X_add_number. */
72 /* X_add_symbol << X_op_symbol) + X_add_number. */
74 /* X_add_symbol >> X_op_symbol) + X_add_number. */
76 /* X_add_symbol | X_op_symbol) + X_add_number. */
78 /* X_add_symbol |~ X_op_symbol) + X_add_number. */
80 /* X_add_symbol ^ X_op_symbol) + X_add_number. */
82 /* X_add_symbol & X_op_symbol) + X_add_number. */
84 /* X_add_symbol + X_op_symbol) + X_add_number. */
86 /* X_add_symbol - X_op_symbol) + X_add_number. */
88 /* (X_add_symbol == X_op_symbol) + X_add_number. */
90 /* (X_add_symbol != X_op_symbol) + X_add_number. */
92 /* (X_add_symbol < X_op_symbol) + X_add_number. */
94 /* (X_add_symbol <= X_op_symbol) + X_add_number. */
96 /* (X_add_symbol >= X_op_symbol) + X_add_number. */
98 /* (X_add_symbol > X_op_symbol) + X_add_number. */
100 /* (X_add_symbol && X_op_symbol) + X_add_number. */
102 /* (X_add_symbol || X_op_symbol) + X_add_number. */
104 /* X_op_symbol [ X_add_symbol ] */
106 /* machine dependent operators */
107 O_md1
, O_md2
, O_md3
, O_md4
, O_md5
, O_md6
, O_md7
, O_md8
,
108 O_md9
, O_md10
, O_md11
, O_md12
, O_md13
, O_md14
, O_md15
, O_md16
,
109 /* this must be the largest value */
113 typedef struct expressionS
{
114 /* The main symbol. */
115 symbolS
*X_add_symbol
;
116 /* The second symbol, if needed. */
117 symbolS
*X_op_symbol
;
118 /* A number to add. */
119 offsetT X_add_number
;
121 /* The type of the expression. We can't assume that an arbitrary
122 compiler can handle a bitfield of enum type. FIXME: We could
123 check this using autoconf. */
130 /* Non-zero if X_add_number should be regarded as unsigned. This is
131 only valid for O_constant expressions. It is only used when an
132 O_constant must be extended into a bignum (i.e., it is not used
133 when performing arithmetic on these values).
134 FIXME: This field is not set very reliably. */
135 unsigned int X_unsigned
: 1;
137 /* 7 additional bits can be defined if needed. */
139 /* Machine dependent field */
143 /* "result" should be type (expressionS *). */
144 #define expression(result) expr (0, result)
146 /* If an expression is O_big, look here for its value. These common
147 data may be clobbered whenever expr() is called. */
148 /* Flonums returned here. Big enough to hold most precise flonum. */
149 extern FLONUM_TYPE generic_floating_point_number
;
150 /* Bignums returned here. */
151 extern LITTLENUM_TYPE generic_bignum
[];
152 /* Number of littlenums in above. */
153 #define SIZE_OF_LARGE_NUMBER (20)
155 typedef char operator_rankT
;
157 extern char get_symbol_end
PARAMS ((void));
158 extern void expr_begin
PARAMS ((void));
159 extern void expr_set_precedence
PARAMS ((void));
160 extern segT expr
PARAMS ((int rank
, expressionS
* resultP
));
161 extern unsigned int get_single_number
PARAMS ((void));
162 extern symbolS
*make_expr_symbol
PARAMS ((expressionS
* expressionP
));
163 extern int expr_symbol_where
164 PARAMS ((symbolS
*, char **, unsigned int *));
166 extern symbolS
*expr_build_uconstant
PARAMS ((offsetT
));
167 extern symbolS
*expr_build_unary
PARAMS ((operatorT
, symbolS
*));
168 extern symbolS
*expr_build_binary
PARAMS ((operatorT
, symbolS
*, symbolS
*));
169 extern symbolS
*expr_build_dot
PARAMS ((void));