1 /* expr.h -> header file for expr.c
2 Copyright 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 * By popular demand, we define a struct to represent an expression.
24 * This will no doubt mutate as expressions become baroque.
26 * Currently, we support expressions like "foo OP bar + 42". In other
27 * words we permit a (possibly undefined) symbol, a (possibly
28 * undefined) symbol and the operation used to combine the symbols,
29 * and an (absolute) augend. RMS says this is so we can have 1-pass
30 * assembly for any compiler emissions, and a 'case' statement might
31 * emit 'undefined1 - undefined2'.
33 * The type of an expression used to be stored as a segment. That got
34 * confusing because it overloaded the concept of a segment. I added
35 * an operator field, instead.
38 /* This is the type of an expression. The operator types are also
39 used while parsing an expression.
41 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 /* machine dependent operators */
108 O_md1
, O_md2
, O_md3
, O_md4
, O_md5
, O_md6
, O_md7
, O_md8
,
109 O_md9
, O_md10
, O_md11
, O_md12
, O_md13
, O_md14
, O_md15
, O_md16
,
110 /* this must be the largest value */
114 typedef struct expressionS
{
115 /* The main symbol. */
116 symbolS
*X_add_symbol
;
117 /* The second symbol, if needed. */
118 symbolS
*X_op_symbol
;
119 /* A number to add. */
120 offsetT X_add_number
;
122 /* The type of the expression. We can't assume that an arbitrary
123 compiler can handle a bitfield of enum type. FIXME: We could
124 check this using autoconf. */
131 /* Non-zero if X_add_number should be regarded as unsigned. This is
132 only valid for O_constant expressions. It is only used when an
133 O_constant must be extended into a bignum (i.e., it is not used
134 when performing arithmetic on these values).
135 FIXME: This field is not set very reliably. */
136 unsigned int X_unsigned
: 1;
138 /* 7 additional bits can be defined if needed. */
140 /* Machine dependent field */
144 /* "result" should be type (expressionS *). */
145 #define expression(result) expr (0, result)
147 /* If an expression is O_big, look here for its value. These common
148 data may be clobbered whenever expr() is called. */
149 /* Flonums returned here. Big enough to hold most precise flonum. */
150 extern FLONUM_TYPE generic_floating_point_number
;
151 /* Bignums returned here. */
152 extern LITTLENUM_TYPE generic_bignum
[];
153 /* Number of littlenums in above. */
154 #define SIZE_OF_LARGE_NUMBER (20)
156 typedef char operator_rankT
;
158 extern char get_symbol_end
PARAMS ((void));
159 extern void expr_begin
PARAMS ((void));
160 extern void expr_set_precedence
PARAMS ((void));
161 extern segT expr
PARAMS ((int rank
, expressionS
* resultP
));
162 extern unsigned int get_single_number
PARAMS ((void));
163 extern symbolS
*make_expr_symbol
PARAMS ((expressionS
* expressionP
));
164 extern int expr_symbol_where
165 PARAMS ((symbolS
*, char **, unsigned int *));
167 extern symbolS
*expr_build_uconstant
PARAMS ((offsetT
));
168 extern symbolS
*expr_build_unary
PARAMS ((operatorT
, symbolS
*));
169 extern symbolS
*expr_build_binary
PARAMS ((operatorT
, symbolS
*, symbolS
*));
170 extern symbolS
*expr_build_dot
PARAMS ((void));