expr.h revision 130562
151974Smsmith/* expr.h -> header file for expr.c
265245Smsmith   Copyright 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000
365245Smsmith   Free Software Foundation, Inc.
4140687Sscottl
551974Smsmith   This file is part of GAS, the GNU Assembler.
651974Smsmith
751974Smsmith   GAS is free software; you can redistribute it and/or modify
851974Smsmith   it under the terms of the GNU General Public License as published by
951974Smsmith   the Free Software Foundation; either version 2, or (at your option)
1051974Smsmith   any later version.
1151974Smsmith
1251974Smsmith   GAS is distributed in the hope that it will be useful,
1351974Smsmith   but WITHOUT ANY WARRANTY; without even the implied warranty of
1451974Smsmith   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1551974Smsmith   GNU General Public License for more details.
1651974Smsmith
1751974Smsmith   You should have received a copy of the GNU General Public License
1851974Smsmith   along with GAS; see the file COPYING.  If not, write to the Free
1951974Smsmith   Software Foundation, 59 Temple Place - Suite 330, Boston, MA
2051974Smsmith   02111-1307, USA.  */
2151974Smsmith
2251974Smsmith/*
2351974Smsmith * By popular demand, we define a struct to represent an expression.
2451974Smsmith * This will no doubt mutate as expressions become baroque.
2551974Smsmith *
2651974Smsmith * Currently, we support expressions like "foo OP bar + 42".  In other
27119418Sobrien * words we permit a (possibly undefined) symbol, a (possibly
28139749Simp * undefined) symbol and the operation used to combine the symbols,
29106225Semoore * and an (absolute) augend.  RMS says this is so we can have 1-pass
30140688Sscottl * assembly for any compiler emissions, and a 'case' statement might
31106225Semoore * emit 'undefined1 - undefined2'.
32106225Semoore *
33106225Semoore * The type of an expression used to be stored as a segment.  That got
34106225Semoore * confusing because it overloaded the concept of a segment.  I added
35106225Semoore * an operator field, instead.
36106225Semoore */
37106225Semoore
38106225Semoore/* This is the type of an expression.  The operator types are also
39106225Semoore   used while parsing an expression.
40106225Semoore
41105419Semoore   NOTE: This enumeration must match the op_rank array in expr.c.  */
42106225Semoore
43105419Semooretypedef enum {
44105419Semoore  /* An illegal expression.  */
45106225Semoore  O_illegal,
46106225Semoore  /* A nonexistent expression.  */
47106225Semoore  O_absent,
48106225Semoore  /* X_add_number (a constant expression).  */
49106225Semoore  O_constant,
50106225Semoore  /* X_add_symbol + X_add_number.  */
51106225Semoore  O_symbol,
52106225Semoore  /* X_add_symbol + X_add_number - the base address of the image.  */
53106225Semoore  O_symbol_rva,
54106225Semoore  /* A register (X_add_number is register number).  */
55106225Semoore  O_register,
5651974Smsmith  /* A big value.  If X_add_number is negative or 0, the value is in
5751974Smsmith     generic_floating_point_number.  Otherwise the value is in
58119418Sobrien     generic_bignum, and X_add_number is the number of LITTLENUMs in
59119418Sobrien     the value.  */
60119418Sobrien  O_big,
6151974Smsmith  /* (- X_add_symbol) + X_add_number.  */
6265245Smsmith  O_uminus,
6351974Smsmith  /* (~ X_add_symbol) + X_add_number.  */
6451974Smsmith  O_bit_not,
6551974Smsmith  /* (! X_add_symbol) + X_add_number.  */
6651974Smsmith  O_logical_not,
6751974Smsmith  /* (X_add_symbol * X_op_symbol) + X_add_number.  */
6851974Smsmith  O_multiply,
69153409Sscottl  /* (X_add_symbol / X_op_symbol) + X_add_number.  */
70153409Sscottl  O_divide,
7151974Smsmith  /* (X_add_symbol % X_op_symbol) + X_add_number.  */
72148850Sscottl  O_modulus,
7351974Smsmith  /* (X_add_symbol << X_op_symbol) + X_add_number.  */
7451974Smsmith  O_left_shift,
7565245Smsmith  /* (X_add_symbol >> X_op_symbol) + X_add_number.  */
7651974Smsmith  O_right_shift,
7765245Smsmith  /* (X_add_symbol | X_op_symbol) + X_add_number.  */
78153409Sscottl  O_bit_inclusive_or,
7951974Smsmith  /* (X_add_symbol |~ X_op_symbol) + X_add_number.  */
8051974Smsmith  O_bit_or_not,
8151974Smsmith  /* (X_add_symbol ^ X_op_symbol) + X_add_number.  */
82119277Simp  O_bit_exclusive_or,
83119277Simp  /* (X_add_symbol & X_op_symbol) + X_add_number.  */
8465245Smsmith  O_bit_and,
8551974Smsmith  /* (X_add_symbol + X_op_symbol) + X_add_number.  */
8651974Smsmith  O_add,
8751974Smsmith  /* (X_add_symbol - X_op_symbol) + X_add_number.  */
8865245Smsmith  O_subtract,
8965245Smsmith  /* (X_add_symbol == X_op_symbol) + X_add_number.  */
9051974Smsmith  O_eq,
91152817Sscottl  /* (X_add_symbol != X_op_symbol) + X_add_number.  */
92152817Sscottl  O_ne,
93152817Sscottl  /* (X_add_symbol < X_op_symbol) + X_add_number.  */
94152817Sscottl  O_lt,
95152817Sscottl  /* (X_add_symbol <= X_op_symbol) + X_add_number.  */
96152817Sscottl  O_le,
97152817Sscottl  /* (X_add_symbol >= X_op_symbol) + X_add_number.  */
98153409Sscottl  O_ge,
99153409Sscottl  /* (X_add_symbol > X_op_symbol) + X_add_number.  */
10065245Smsmith  O_gt,
10165245Smsmith  /* (X_add_symbol && X_op_symbol) + X_add_number.  */
10265245Smsmith  O_logical_and,
10365245Smsmith  /* (X_add_symbol || X_op_symbol) + X_add_number.  */
10451974Smsmith  O_logical_or,
105126080Sphk  /* X_op_symbol [ X_add_symbol ] */
106126080Sphk  O_index,
107111815Sphk  /* machine dependent operators */
108111815Sphk  O_md1,  O_md2,  O_md3,  O_md4,  O_md5,  O_md6,  O_md7,  O_md8,
109111815Sphk  O_md9,  O_md10, O_md11, O_md12, O_md13, O_md14, O_md15, O_md16,
110111815Sphk  O_md17, O_md18, O_md19, O_md20, O_md21, O_md22, O_md23, O_md24,
11151974Smsmith  O_md25, O_md26, O_md27, O_md28, O_md29, O_md30, O_md31, O_md32,
11251974Smsmith  /* this must be the largest value */
113158267Sambrisko  O_max
11465245Smsmith} operatorT;
11565245Smsmith
11665245Smsmithtypedef struct expressionS {
11765245Smsmith  /* The main symbol.  */
11851974Smsmith  symbolS *X_add_symbol;
11951974Smsmith  /* The second symbol, if needed.  */
12051974Smsmith  symbolS *X_op_symbol;
12151974Smsmith  /* A number to add.  */
12265245Smsmith  offsetT X_add_number;
12365245Smsmith
124153409Sscottl  /* The type of the expression.  We can't assume that an arbitrary
12565245Smsmith     compiler can handle a bitfield of enum type.  FIXME: We could
126106225Semoore     check this using autoconf.  */
12751974Smsmith#ifdef __GNUC__
12851974Smsmith  operatorT X_op : 8;
12965245Smsmith#else
13051974Smsmith  unsigned char X_op;
13165245Smsmith#endif
13265245Smsmith
13351974Smsmith  /* Non-zero if X_add_number should be regarded as unsigned.  This is
13451974Smsmith     only valid for O_constant expressions.  It is only used when an
13565245Smsmith     O_constant must be extended into a bignum (i.e., it is not used
13651974Smsmith     when performing arithmetic on these values).
13765245Smsmith     FIXME: This field is not set very reliably.  */
138138422Sscottl  unsigned int X_unsigned : 1;
139138422Sscottl
14065245Smsmith  /* 7 additional bits can be defined if needed.  */
14165245Smsmith
14265245Smsmith  /* Machine dependent field */
143138422Sscottl  unsigned short X_md;
144153409Sscottl} expressionS;
145138422Sscottl
14651974Smsmith/* "result" should be type (expressionS *).  */
14751974Smsmith#define expression(result) expr (0, result)
14858883Smsmith
14958883Smsmith/* If an expression is O_big, look here for its value. These common
15065245Smsmith   data may be clobbered whenever expr() is called.  */
15158883Smsmith/* Flonums returned here.  Big enough to hold most precise flonum.  */
15258883Smsmithextern FLONUM_TYPE generic_floating_point_number;
15351974Smsmith/* Bignums returned here.  */
15451974Smsmithextern LITTLENUM_TYPE generic_bignum[];
155155222Sps/* Number of littlenums in above.  */
15665245Smsmith#define SIZE_OF_LARGE_NUMBER (20)
157107756Semoore
158138422Sscottltypedef char operator_rankT;
15951974Smsmith
160155222Spsextern char get_symbol_end (void);
16165245Smsmithextern void expr_begin (void);
162107756Semooreextern void expr_set_precedence (void);
16365245Smsmithextern segT expr (int rank, expressionS * resultP);
16451974Smsmithextern unsigned int get_single_number (void);
16565245Smsmithextern symbolS *make_expr_symbol (expressionS * expressionP);
16665245Smsmithextern int expr_symbol_where (symbolS *, char **, unsigned int *);
16765245Smsmith
16865245Smsmithextern symbolS *expr_build_uconstant (offsetT);
16965245Smsmithextern symbolS *expr_build_unary (operatorT, symbolS *);
17051974Smsmithextern symbolS *expr_build_binary (operatorT, symbolS *, symbolS *);
17151974Smsmithextern symbolS *expr_build_dot (void);
17251974Smsmith