1 /* expr.h -> header file for expr.c
2 Copyright (C) 1987, 92-98, 1999 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. */
44 /* An illegal expression. */
46 /* A nonexistent expression. */
48 /* X_add_number (a constant expression). */
50 /* X_add_symbol + X_add_number. */
52 /* X_add_symbol + X_add_number - the base address of the image. */
54 /* A register (X_add_number is register number). */
56 /* A big value. If X_add_number is negative or 0, the value is in
57 generic_floating_point_number. Otherwise the value is in
58 generic_bignum, and X_add_number is the number of LITTLENUMs in
61 /* (- X_add_symbol) + X_add_number. */
63 /* (~ X_add_symbol) + X_add_number. */
65 /* (! X_add_symbol) + X_add_number. */
67 /* (X_add_symbol * X_op_symbol) + X_add_number. */
69 /* (X_add_symbol / X_op_symbol) + X_add_number. */
71 /* X_add_symbol % X_op_symbol) + X_add_number. */
73 /* X_add_symbol << X_op_symbol) + X_add_number. */
75 /* X_add_symbol >> X_op_symbol) + X_add_number. */
77 /* X_add_symbol | X_op_symbol) + X_add_number. */
79 /* X_add_symbol |~ X_op_symbol) + X_add_number. */
81 /* X_add_symbol ^ X_op_symbol) + X_add_number. */
83 /* X_add_symbol & X_op_symbol) + X_add_number. */
85 /* X_add_symbol + X_op_symbol) + X_add_number. */
87 /* X_add_symbol - X_op_symbol) + X_add_number. */
89 /* (X_add_symbol == X_op_symbol) + X_add_number. */
91 /* (X_add_symbol != X_op_symbol) + X_add_number. */
93 /* (X_add_symbol < X_op_symbol) + X_add_number. */
95 /* (X_add_symbol <= X_op_symbol) + X_add_number. */
97 /* (X_add_symbol >= X_op_symbol) + X_add_number. */
99 /* (X_add_symbol > X_op_symbol) + X_add_number. */
101 /* (X_add_symbol && X_op_symbol) + X_add_number. */
103 /* (X_add_symbol || X_op_symbol) + X_add_number. */
105 /* X_op_symbol [ X_add_symbol ] */
107 /* this must be the largest value */
111 typedef struct expressionS
113 /* The main symbol. */
114 symbolS
*X_add_symbol
;
115 /* The second symbol, if needed. */
116 symbolS
*X_op_symbol
;
117 /* A number to add. */
118 offsetT X_add_number
;
119 /* The type of the expression. */
121 /* Non-zero if X_add_number should be regarded as unsigned. This is
122 only valid for O_constant expressions. It is only used when an
123 O_constant must be extended into a bignum (i.e., it is not used
124 when performing arithmetic on these values).
125 FIXME: This field is not set very reliably. */
126 unsigned int X_unsigned
: 1;
129 /* "result" should be type (expressionS *). */
130 #define expression(result) expr (0, result)
132 /* If an expression is O_big, look here for its value. These common
133 data may be clobbered whenever expr() is called. */
134 /* Flonums returned here. Big enough to hold most precise flonum. */
135 extern FLONUM_TYPE generic_floating_point_number
;
136 /* Bignums returned here. */
137 extern LITTLENUM_TYPE generic_bignum
[];
138 /* Number of littlenums in above. */
139 #define SIZE_OF_LARGE_NUMBER (20)
141 typedef char operator_rankT
;
143 extern char get_symbol_end
PARAMS ((void));
144 extern void expr_begin
PARAMS ((void));
145 extern void expr_set_precedence
PARAMS ((void));
146 extern segT expr
PARAMS ((int rank
, expressionS
* resultP
));
147 extern unsigned int get_single_number
PARAMS ((void));
148 extern symbolS
*make_expr_symbol
PARAMS ((expressionS
* expressionP
));
149 extern int expr_symbol_where
150 PARAMS ((symbolS
*, char **, unsigned int *));
152 extern symbolS
*expr_build_uconstant
PARAMS ((offsetT
));
153 extern symbolS
*expr_build_unary
PARAMS ((operatorT
, symbolS
*));
154 extern symbolS
*expr_build_binary
PARAMS ((operatorT
, symbolS
*, symbolS
*));
155 extern symbolS
*expr_build_dot
PARAMS ((void));