133965Sjdp/* expr.h -> header file for expr.c
2218822Sdim   Copyright 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3218822Sdim   2002, 2003 Free Software Foundation, Inc.
433965Sjdp
533965Sjdp   This file is part of GAS, the GNU Assembler.
633965Sjdp
733965Sjdp   GAS is free software; you can redistribute it and/or modify
833965Sjdp   it under the terms of the GNU General Public License as published by
933965Sjdp   the Free Software Foundation; either version 2, or (at your option)
1033965Sjdp   any later version.
1133965Sjdp
1233965Sjdp   GAS is distributed in the hope that it will be useful,
1333965Sjdp   but WITHOUT ANY WARRANTY; without even the implied warranty of
1433965Sjdp   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1533965Sjdp   GNU General Public License for more details.
1633965Sjdp
1733965Sjdp   You should have received a copy of the GNU General Public License
1833965Sjdp   along with GAS; see the file COPYING.  If not, write to the Free
19218822Sdim   Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
20218822Sdim   02110-1301, USA.  */
2133965Sjdp
2233965Sjdp/*
2333965Sjdp * By popular demand, we define a struct to represent an expression.
2433965Sjdp * This will no doubt mutate as expressions become baroque.
2533965Sjdp *
2633965Sjdp * Currently, we support expressions like "foo OP bar + 42".  In other
2733965Sjdp * words we permit a (possibly undefined) symbol, a (possibly
2833965Sjdp * undefined) symbol and the operation used to combine the symbols,
2933965Sjdp * and an (absolute) augend.  RMS says this is so we can have 1-pass
3033965Sjdp * assembly for any compiler emissions, and a 'case' statement might
3133965Sjdp * emit 'undefined1 - undefined2'.
3233965Sjdp *
3333965Sjdp * The type of an expression used to be stored as a segment.  That got
3433965Sjdp * confusing because it overloaded the concept of a segment.  I added
3533965Sjdp * an operator field, instead.
3633965Sjdp */
3733965Sjdp
3833965Sjdp/* This is the type of an expression.  The operator types are also
3933965Sjdp   used while parsing an expression.
4033965Sjdp
4133965Sjdp   NOTE: This enumeration must match the op_rank array in expr.c.  */
4233965Sjdp
4377298Sobrientypedef enum {
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,
71130561Sobrien  /* (X_add_symbol % X_op_symbol) + X_add_number.  */
7233965Sjdp  O_modulus,
73130561Sobrien  /* (X_add_symbol << X_op_symbol) + X_add_number.  */
7433965Sjdp  O_left_shift,
75130561Sobrien  /* (X_add_symbol >> X_op_symbol) + X_add_number.  */
7633965Sjdp  O_right_shift,
77130561Sobrien  /* (X_add_symbol | X_op_symbol) + X_add_number.  */
7833965Sjdp  O_bit_inclusive_or,
79130561Sobrien  /* (X_add_symbol |~ X_op_symbol) + X_add_number.  */
8033965Sjdp  O_bit_or_not,
81130561Sobrien  /* (X_add_symbol ^ X_op_symbol) + X_add_number.  */
8233965Sjdp  O_bit_exclusive_or,
83130561Sobrien  /* (X_add_symbol & X_op_symbol) + X_add_number.  */
8433965Sjdp  O_bit_and,
85130561Sobrien  /* (X_add_symbol + X_op_symbol) + X_add_number.  */
8633965Sjdp  O_add,
87130561Sobrien  /* (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,
10560484Sobrien  /* X_op_symbol [ X_add_symbol ] */
10660484Sobrien  O_index,
10760484Sobrien  /* machine dependent operators */
10860484Sobrien  O_md1,  O_md2,  O_md3,  O_md4,  O_md5,  O_md6,  O_md7,  O_md8,
10960484Sobrien  O_md9,  O_md10, O_md11, O_md12, O_md13, O_md14, O_md15, O_md16,
110104834Sobrien  O_md17, O_md18, O_md19, O_md20, O_md21, O_md22, O_md23, O_md24,
111104834Sobrien  O_md25, O_md26, O_md27, O_md28, O_md29, O_md30, O_md31, O_md32,
11233965Sjdp  /* this must be the largest value */
11333965Sjdp  O_max
11433965Sjdp} operatorT;
11533965Sjdp
11677298Sobrientypedef struct expressionS {
11733965Sjdp  /* The main symbol.  */
11860484Sobrien  symbolS *X_add_symbol;
11933965Sjdp  /* The second symbol, if needed.  */
12060484Sobrien  symbolS *X_op_symbol;
12133965Sjdp  /* A number to add.  */
12233965Sjdp  offsetT X_add_number;
12360484Sobrien
12433965Sjdp  /* The type of the expression.  We can't assume that an arbitrary
12533965Sjdp     compiler can handle a bitfield of enum type.  FIXME: We could
12633965Sjdp     check this using autoconf.  */
12733965Sjdp#ifdef __GNUC__
12860484Sobrien  operatorT X_op : 8;
12933965Sjdp#else
13060484Sobrien  unsigned char X_op;
13133965Sjdp#endif
13260484Sobrien
13333965Sjdp  /* Non-zero if X_add_number should be regarded as unsigned.  This is
13433965Sjdp     only valid for O_constant expressions.  It is only used when an
13533965Sjdp     O_constant must be extended into a bignum (i.e., it is not used
13633965Sjdp     when performing arithmetic on these values).
13733965Sjdp     FIXME: This field is not set very reliably.  */
13833965Sjdp  unsigned int X_unsigned : 1;
13960484Sobrien
14060484Sobrien  /* 7 additional bits can be defined if needed.  */
14160484Sobrien
14260484Sobrien  /* Machine dependent field */
14360484Sobrien  unsigned short X_md;
14433965Sjdp} expressionS;
14533965Sjdp
146218822Sdimenum expr_mode
147218822Sdim{
148218822Sdim  expr_evaluate,
149218822Sdim  expr_normal,
150218822Sdim  expr_defer
151218822Sdim};
152218822Sdim
15377298Sobrien/* "result" should be type (expressionS *).  */
154218822Sdim#define expression(result) expr (0, result, expr_normal)
155218822Sdim#define expression_and_evaluate(result) expr (0, result, expr_evaluate)
156218822Sdim#define deferred_expression(result) expr (0, result, expr_defer)
15733965Sjdp
15833965Sjdp/* If an expression is O_big, look here for its value. These common
15977298Sobrien   data may be clobbered whenever expr() is called.  */
16077298Sobrien/* Flonums returned here.  Big enough to hold most precise flonum.  */
16133965Sjdpextern FLONUM_TYPE generic_floating_point_number;
16277298Sobrien/* Bignums returned here.  */
16333965Sjdpextern LITTLENUM_TYPE generic_bignum[];
16477298Sobrien/* Number of littlenums in above.  */
16533965Sjdp#define SIZE_OF_LARGE_NUMBER (20)
16633965Sjdp
16733965Sjdptypedef char operator_rankT;
16833965Sjdp
169130561Sobrienextern char get_symbol_end (void);
170130561Sobrienextern void expr_begin (void);
171130561Sobrienextern void expr_set_precedence (void);
172218822Sdimextern segT expr (int, expressionS *, enum expr_mode);
173130561Sobrienextern unsigned int get_single_number (void);
174130561Sobrienextern symbolS *make_expr_symbol (expressionS * expressionP);
175130561Sobrienextern int expr_symbol_where (symbolS *, char **, unsigned int *);
17633965Sjdp
177130561Sobrienextern symbolS *expr_build_uconstant (offsetT);
178130561Sobrienextern symbolS *expr_build_dot (void);
179218822Sdim
180218822Sdimint resolve_expression (expressionS *);
181