expr.h revision 33965
133965Sjdp/* expr.h -> header file for expr.c
233965Sjdp   Copyright (C) 1987, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
333965Sjdp
433965Sjdp   This file is part of GAS, the GNU Assembler.
533965Sjdp
633965Sjdp   GAS is free software; you can redistribute it and/or modify
733965Sjdp   it under the terms of the GNU General Public License as published by
833965Sjdp   the Free Software Foundation; either version 2, or (at your option)
933965Sjdp   any later version.
1033965Sjdp
1133965Sjdp   GAS is distributed in the hope that it will be useful,
1233965Sjdp   but WITHOUT ANY WARRANTY; without even the implied warranty of
1333965Sjdp   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1433965Sjdp   GNU General Public License for more details.
1533965Sjdp
1633965Sjdp   You should have received a copy of the GNU General Public License
1733965Sjdp   along with GAS; see the file COPYING.  If not, write to the Free
1833965Sjdp   Software Foundation, 59 Temple Place - Suite 330, Boston, MA
1933965Sjdp   02111-1307, USA.  */
2033965Sjdp
2133965Sjdp/*
2233965Sjdp * By popular demand, we define a struct to represent an expression.
2333965Sjdp * This will no doubt mutate as expressions become baroque.
2433965Sjdp *
2533965Sjdp * Currently, we support expressions like "foo OP bar + 42".  In other
2633965Sjdp * words we permit a (possibly undefined) symbol, a (possibly
2733965Sjdp * undefined) symbol and the operation used to combine the symbols,
2833965Sjdp * and an (absolute) augend.  RMS says this is so we can have 1-pass
2933965Sjdp * assembly for any compiler emissions, and a 'case' statement might
3033965Sjdp * emit 'undefined1 - undefined2'.
3133965Sjdp *
3233965Sjdp * The type of an expression used to be stored as a segment.  That got
3333965Sjdp * confusing because it overloaded the concept of a segment.  I added
3433965Sjdp * an operator field, instead.
3533965Sjdp */
3633965Sjdp
3733965Sjdp/* This is the type of an expression.  The operator types are also
3833965Sjdp   used while parsing an expression.
3933965Sjdp
4033965Sjdp   NOTE: This enumeration must match the op_rank array in expr.c.  */
4133965Sjdp
4233965Sjdptypedef enum
4333965Sjdp{
4433965Sjdp  /* An illegal expression.  */
4533965Sjdp  O_illegal,
4633965Sjdp  /* A nonexistent expression.  */
4733965Sjdp  O_absent,
4833965Sjdp  /* X_add_number (a constant expression).  */
4933965Sjdp  O_constant,
5033965Sjdp  /* X_add_symbol + X_add_number.  */
5133965Sjdp  O_symbol,
5233965Sjdp  /* X_add_symbol + X_add_number - the base address of the image.  */
5333965Sjdp  O_symbol_rva,
5433965Sjdp  /* A register (X_add_number is register number).  */
5533965Sjdp  O_register,
5633965Sjdp  /* A big value.  If X_add_number is negative or 0, the value is in
5733965Sjdp     generic_floating_point_number.  Otherwise the value is in
5833965Sjdp     generic_bignum, and X_add_number is the number of LITTLENUMs in
5933965Sjdp     the value.  */
6033965Sjdp  O_big,
6133965Sjdp  /* (- X_add_symbol) + X_add_number.  */
6233965Sjdp  O_uminus,
6333965Sjdp  /* (~ X_add_symbol) + X_add_number.  */
6433965Sjdp  O_bit_not,
6533965Sjdp  /* (! X_add_symbol) + X_add_number.  */
6633965Sjdp  O_logical_not,
6733965Sjdp  /* (X_add_symbol * X_op_symbol) + X_add_number.  */
6833965Sjdp  O_multiply,
6933965Sjdp  /* (X_add_symbol / X_op_symbol) + X_add_number.  */
7033965Sjdp  O_divide,
7133965Sjdp  /* X_add_symbol % X_op_symbol) + X_add_number.  */
7233965Sjdp  O_modulus,
7333965Sjdp  /* X_add_symbol << X_op_symbol) + X_add_number.  */
7433965Sjdp  O_left_shift,
7533965Sjdp  /* X_add_symbol >> X_op_symbol) + X_add_number.  */
7633965Sjdp  O_right_shift,
7733965Sjdp  /* X_add_symbol | X_op_symbol) + X_add_number.  */
7833965Sjdp  O_bit_inclusive_or,
7933965Sjdp  /* X_add_symbol |~ X_op_symbol) + X_add_number.  */
8033965Sjdp  O_bit_or_not,
8133965Sjdp  /* X_add_symbol ^ X_op_symbol) + X_add_number.  */
8233965Sjdp  O_bit_exclusive_or,
8333965Sjdp  /* X_add_symbol & X_op_symbol) + X_add_number.  */
8433965Sjdp  O_bit_and,
8533965Sjdp  /* X_add_symbol + X_op_symbol) + X_add_number.  */
8633965Sjdp  O_add,
8733965Sjdp  /* X_add_symbol - X_op_symbol) + X_add_number.  */
8833965Sjdp  O_subtract,
8933965Sjdp  /* (X_add_symbol == X_op_symbol) + X_add_number.  */
9033965Sjdp  O_eq,
9133965Sjdp  /* (X_add_symbol != X_op_symbol) + X_add_number.  */
9233965Sjdp  O_ne,
9333965Sjdp  /* (X_add_symbol < X_op_symbol) + X_add_number.  */
9433965Sjdp  O_lt,
9533965Sjdp  /* (X_add_symbol <= X_op_symbol) + X_add_number.  */
9633965Sjdp  O_le,
9733965Sjdp  /* (X_add_symbol >= X_op_symbol) + X_add_number.  */
9833965Sjdp  O_ge,
9933965Sjdp  /* (X_add_symbol > X_op_symbol) + X_add_number.  */
10033965Sjdp  O_gt,
10133965Sjdp  /* (X_add_symbol && X_op_symbol) + X_add_number.  */
10233965Sjdp  O_logical_and,
10333965Sjdp  /* (X_add_symbol || X_op_symbol) + X_add_number.  */
10433965Sjdp  O_logical_or,
10533965Sjdp  /* this must be the largest value */
10633965Sjdp  O_max
10733965Sjdp} operatorT;
10833965Sjdp
10933965Sjdptypedef struct expressionS
11033965Sjdp{
11133965Sjdp  /* The main symbol.  */
11233965Sjdp  struct symbol *X_add_symbol;
11333965Sjdp  /* The second symbol, if needed.  */
11433965Sjdp  struct symbol *X_op_symbol;
11533965Sjdp  /* A number to add.  */
11633965Sjdp  offsetT X_add_number;
11733965Sjdp  /* The type of the expression.  We can't assume that an arbitrary
11833965Sjdp     compiler can handle a bitfield of enum type.  FIXME: We could
11933965Sjdp     check this using autoconf.  */
12033965Sjdp#ifdef __GNUC__
12133965Sjdp  operatorT X_op : 5;
12233965Sjdp#else
12333965Sjdp  unsigned X_op : 5;
12433965Sjdp#endif
12533965Sjdp  /* Non-zero if X_add_number should be regarded as unsigned.  This is
12633965Sjdp     only valid for O_constant expressions.  It is only used when an
12733965Sjdp     O_constant must be extended into a bignum (i.e., it is not used
12833965Sjdp     when performing arithmetic on these values).
12933965Sjdp     FIXME: This field is not set very reliably.  */
13033965Sjdp  unsigned int X_unsigned : 1;
13133965Sjdp} expressionS;
13233965Sjdp
13333965Sjdp/* "result" should be type (expressionS *). */
13433965Sjdp#define expression(result) expr (0, result)
13533965Sjdp
13633965Sjdp/* If an expression is O_big, look here for its value. These common
13733965Sjdp   data may be clobbered whenever expr() is called. */
13833965Sjdp/* Flonums returned here.  Big enough to hold most precise flonum. */
13933965Sjdpextern FLONUM_TYPE generic_floating_point_number;
14033965Sjdp/* Bignums returned here. */
14133965Sjdpextern LITTLENUM_TYPE generic_bignum[];
14233965Sjdp/* Number of littlenums in above. */
14333965Sjdp#define SIZE_OF_LARGE_NUMBER (20)
14433965Sjdp
14533965Sjdptypedef char operator_rankT;
14633965Sjdp
14733965Sjdpextern char get_symbol_end PARAMS ((void));
14833965Sjdpextern void expr_begin PARAMS ((void));
14933965Sjdpextern segT expr PARAMS ((int rank, expressionS * resultP));
15033965Sjdpextern unsigned int get_single_number PARAMS ((void));
15133965Sjdpextern struct symbol *make_expr_symbol PARAMS ((expressionS * expressionP));
15233965Sjdpextern int expr_symbol_where
15333965Sjdp  PARAMS ((struct symbol *, char **, unsigned int *));
15433965Sjdp
15533965Sjdp/* end of expr.h */
156