expr.h revision 60484
150476Speter/* expr.h -> header file for expr.c
226419Sache   Copyright (C) 1987, 92-98, 1999 Free Software Foundation, Inc.
326419Sache
426419Sache   This file is part of GAS, the GNU Assembler.
526419Sache
626419Sache   GAS is free software; you can redistribute it and/or modify
726419Sache   it under the terms of the GNU General Public License as published by
836307Sphk   the Free Software Foundation; either version 2, or (at your option)
936307Sphk   any later version.
1036307Sphk
1136307Sphk   GAS is distributed in the hope that it will be useful,
1236307Sphk   but WITHOUT ANY WARRANTY; without even the implied warranty of
1336307Sphk   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1436307Sphk   GNU General Public License for more details.
1536307Sphk
1636307Sphk   You should have received a copy of the GNU General Public License
1736307Sphk   along with GAS; see the file COPYING.  If not, write to the Free
1836307Sphk   Software Foundation, 59 Temple Place - Suite 330, Boston, MA
1936307Sphk   02111-1307, USA.  */
2026419Sache
2126419Sache/*
2226419Sache * By popular demand, we define a struct to represent an expression.
2336307Sphk * This will no doubt mutate as expressions become baroque.
2436307Sphk *
2536307Sphk * Currently, we support expressions like "foo OP bar + 42".  In other
2636307Sphk * words we permit a (possibly undefined) symbol, a (possibly
2736307Sphk * undefined) symbol and the operation used to combine the symbols,
2836307Sphk * and an (absolute) augend.  RMS says this is so we can have 1-pass
2936307Sphk * assembly for any compiler emissions, and a 'case' statement might
3036307Sphk * emit 'undefined1 - undefined2'.
3136307Sphk *
3236307Sphk * The type of an expression used to be stored as a segment.  That got
3336307Sphk * confusing because it overloaded the concept of a segment.  I added
3436307Sphk * an operator field, instead.
3526419Sache */
3626419Sache
3726419Sache/* This is the type of an expression.  The operator types are also
3836307Sphk   used while parsing an expression.
3936307Sphk
4036307Sphk   NOTE: This enumeration must match the op_rank array in expr.c.  */
4136307Sphk
4236307Sphktypedef enum
4336307Sphk{
4436307Sphk  /* An illegal expression.  */
4526419Sache  O_illegal,
4626419Sache  /* A nonexistent expression.  */
4726419Sache  O_absent,
4836307Sphk  /* X_add_number (a constant expression).  */
4936307Sphk  O_constant,
5036307Sphk  /* X_add_symbol + X_add_number.  */
5136307Sphk  O_symbol,
5236307Sphk  /* X_add_symbol + X_add_number - the base address of the image.  */
5336307Sphk  O_symbol_rva,
5436307Sphk  /* A register (X_add_number is register number).  */
5526419Sache  O_register,
5626419Sache  /* A big value.  If X_add_number is negative or 0, the value is in
5726419Sache     generic_floating_point_number.  Otherwise the value is in
5826419Sache     generic_bignum, and X_add_number is the number of LITTLENUMs in
5926419Sache     the value.  */
6026419Sache  O_big,
6126419Sache  /* (- X_add_symbol) + X_add_number.  */
6226419Sache  O_uminus,
6326419Sache  /* (~ X_add_symbol) + X_add_number.  */
6426419Sache  O_bit_not,
6526419Sache  /* (! X_add_symbol) + X_add_number.  */
6653943Sache  O_logical_not,
6726419Sache  /* (X_add_symbol * X_op_symbol) + X_add_number.  */
6826419Sache  O_multiply,
6926419Sache  /* (X_add_symbol / X_op_symbol) + X_add_number.  */
7026419Sache  O_divide,
7126419Sache  /* X_add_symbol % X_op_symbol) + X_add_number.  */
7226419Sache  O_modulus,
7326419Sache  /* X_add_symbol << X_op_symbol) + X_add_number.  */
7426419Sache  O_left_shift,
7526419Sache  /* X_add_symbol >> X_op_symbol) + X_add_number.  */
7626419Sache  O_right_shift,
7726419Sache  /* X_add_symbol | X_op_symbol) + X_add_number.  */
7853943Sache  O_bit_inclusive_or,
7953943Sache  /* X_add_symbol |~ X_op_symbol) + X_add_number.  */
8053943Sache  O_bit_or_not,
8153943Sache  /* X_add_symbol ^ X_op_symbol) + X_add_number.  */
8253943Sache  O_bit_exclusive_or,
8353943Sache  /* X_add_symbol & X_op_symbol) + X_add_number.  */
8453943Sache  O_bit_and,
8553943Sache  /* X_add_symbol + X_op_symbol) + X_add_number.  */
8653943Sache  O_add,
8753943Sache  /* X_add_symbol - X_op_symbol) + X_add_number.  */
8853943Sache  O_subtract,
8953943Sache  /* (X_add_symbol == X_op_symbol) + X_add_number.  */
9053943Sache  O_eq,
9153943Sache  /* (X_add_symbol != X_op_symbol) + X_add_number.  */
9253943Sache  O_ne,
9353943Sache  /* (X_add_symbol < X_op_symbol) + X_add_number.  */
9453943Sache  O_lt,
9553943Sache  /* (X_add_symbol <= X_op_symbol) + X_add_number.  */
9653943Sache  O_le,
9753943Sache  /* (X_add_symbol >= X_op_symbol) + X_add_number.  */
98  O_ge,
99  /* (X_add_symbol > X_op_symbol) + X_add_number.  */
100  O_gt,
101  /* (X_add_symbol && X_op_symbol) + X_add_number.  */
102  O_logical_and,
103  /* (X_add_symbol || X_op_symbol) + X_add_number.  */
104  O_logical_or,
105  /* X_op_symbol [ X_add_symbol ] */
106  O_index,
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 */
111  O_max
112} operatorT;
113
114typedef struct expressionS
115{
116  /* The main symbol.  */
117  symbolS *X_add_symbol;
118  /* The second symbol, if needed.  */
119  symbolS *X_op_symbol;
120  /* A number to add.  */
121  offsetT X_add_number;
122
123  /* The type of the expression.  We can't assume that an arbitrary
124     compiler can handle a bitfield of enum type.  FIXME: We could
125     check this using autoconf.  */
126#ifdef __GNUC__
127  operatorT X_op : 8;
128#else
129  unsigned char X_op;
130#endif
131
132  /* Non-zero if X_add_number should be regarded as unsigned.  This is
133     only valid for O_constant expressions.  It is only used when an
134     O_constant must be extended into a bignum (i.e., it is not used
135     when performing arithmetic on these values).
136     FIXME: This field is not set very reliably.  */
137  unsigned int X_unsigned : 1;
138
139  /* 7 additional bits can be defined if needed.  */
140
141  /* Machine dependent field */
142  unsigned short X_md;
143} expressionS;
144
145/* "result" should be type (expressionS *). */
146#define expression(result) expr (0, result)
147
148/* If an expression is O_big, look here for its value. These common
149   data may be clobbered whenever expr() is called. */
150/* Flonums returned here.  Big enough to hold most precise flonum. */
151extern FLONUM_TYPE generic_floating_point_number;
152/* Bignums returned here. */
153extern LITTLENUM_TYPE generic_bignum[];
154/* Number of littlenums in above. */
155#define SIZE_OF_LARGE_NUMBER (20)
156
157typedef char operator_rankT;
158
159extern char get_symbol_end PARAMS ((void));
160extern void expr_begin PARAMS ((void));
161extern void expr_set_precedence PARAMS ((void));
162extern segT expr PARAMS ((int rank, expressionS * resultP));
163extern unsigned int get_single_number PARAMS ((void));
164extern symbolS *make_expr_symbol PARAMS ((expressionS * expressionP));
165extern int expr_symbol_where
166  PARAMS ((symbolS *, char **, unsigned int *));
167
168extern symbolS *expr_build_uconstant PARAMS ((offsetT));
169extern symbolS *expr_build_unary PARAMS ((operatorT, symbolS *));
170extern symbolS *expr_build_binary PARAMS ((operatorT, symbolS *, symbolS *));
171extern symbolS *expr_build_dot PARAMS ((void));
172
173/* end of expr.h */
174