xref: /openbsd-src/gnu/usr.bin/binutils/gas/expr.h (revision 007c2a4539b8b8aaa95c5e73e77620090abe113b)
12159047fSniklas /* expr.h -> header file for expr.c
2b55d4692Sfgsch    Copyright 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000
3b55d4692Sfgsch    Free Software Foundation, Inc.
42159047fSniklas 
52159047fSniklas    This file is part of GAS, the GNU Assembler.
62159047fSniklas 
72159047fSniklas    GAS is free software; you can redistribute it and/or modify
82159047fSniklas    it under the terms of the GNU General Public License as published by
92159047fSniklas    the Free Software Foundation; either version 2, or (at your option)
102159047fSniklas    any later version.
112159047fSniklas 
122159047fSniklas    GAS is distributed in the hope that it will be useful,
132159047fSniklas    but WITHOUT ANY WARRANTY; without even the implied warranty of
142159047fSniklas    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
152159047fSniklas    GNU General Public License for more details.
162159047fSniklas 
172159047fSniklas    You should have received a copy of the GNU General Public License
18b305b0f1Sespie    along with GAS; see the file COPYING.  If not, write to the Free
19b305b0f1Sespie    Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20b305b0f1Sespie    02111-1307, USA.  */
212159047fSniklas 
222159047fSniklas /*
232159047fSniklas  * By popular demand, we define a struct to represent an expression.
242159047fSniklas  * This will no doubt mutate as expressions become baroque.
252159047fSniklas  *
262159047fSniklas  * Currently, we support expressions like "foo OP bar + 42".  In other
272159047fSniklas  * words we permit a (possibly undefined) symbol, a (possibly
282159047fSniklas  * undefined) symbol and the operation used to combine the symbols,
292159047fSniklas  * and an (absolute) augend.  RMS says this is so we can have 1-pass
302159047fSniklas  * assembly for any compiler emissions, and a 'case' statement might
312159047fSniklas  * emit 'undefined1 - undefined2'.
322159047fSniklas  *
332159047fSniklas  * The type of an expression used to be stored as a segment.  That got
342159047fSniklas  * confusing because it overloaded the concept of a segment.  I added
352159047fSniklas  * an operator field, instead.
362159047fSniklas  */
372159047fSniklas 
382159047fSniklas /* This is the type of an expression.  The operator types are also
392159047fSniklas    used while parsing an expression.
402159047fSniklas 
412159047fSniklas    NOTE: This enumeration must match the op_rank array in expr.c.  */
422159047fSniklas 
43b55d4692Sfgsch typedef enum {
442159047fSniklas   /* An illegal expression.  */
452159047fSniklas   O_illegal,
462159047fSniklas   /* A nonexistent expression.  */
472159047fSniklas   O_absent,
482159047fSniklas   /* X_add_number (a constant expression).  */
492159047fSniklas   O_constant,
502159047fSniklas   /* X_add_symbol + X_add_number.  */
512159047fSniklas   O_symbol,
522159047fSniklas   /* X_add_symbol + X_add_number - the base address of the image.  */
532159047fSniklas   O_symbol_rva,
542159047fSniklas   /* A register (X_add_number is register number).  */
552159047fSniklas   O_register,
562159047fSniklas   /* A big value.  If X_add_number is negative or 0, the value is in
572159047fSniklas      generic_floating_point_number.  Otherwise the value is in
582159047fSniklas      generic_bignum, and X_add_number is the number of LITTLENUMs in
592159047fSniklas      the value.  */
602159047fSniklas   O_big,
612159047fSniklas   /* (- X_add_symbol) + X_add_number.  */
622159047fSniklas   O_uminus,
632159047fSniklas   /* (~ X_add_symbol) + X_add_number.  */
642159047fSniklas   O_bit_not,
652159047fSniklas   /* (! X_add_symbol) + X_add_number.  */
662159047fSniklas   O_logical_not,
672159047fSniklas   /* (X_add_symbol * X_op_symbol) + X_add_number.  */
682159047fSniklas   O_multiply,
692159047fSniklas   /* (X_add_symbol / X_op_symbol) + X_add_number.  */
702159047fSniklas   O_divide,
71c074d1c9Sdrahn   /* (X_add_symbol % X_op_symbol) + X_add_number.  */
722159047fSniklas   O_modulus,
73c074d1c9Sdrahn   /* (X_add_symbol << X_op_symbol) + X_add_number.  */
742159047fSniklas   O_left_shift,
75c074d1c9Sdrahn   /* (X_add_symbol >> X_op_symbol) + X_add_number.  */
762159047fSniklas   O_right_shift,
77c074d1c9Sdrahn   /* (X_add_symbol | X_op_symbol) + X_add_number.  */
782159047fSniklas   O_bit_inclusive_or,
79c074d1c9Sdrahn   /* (X_add_symbol |~ X_op_symbol) + X_add_number.  */
802159047fSniklas   O_bit_or_not,
81c074d1c9Sdrahn   /* (X_add_symbol ^ X_op_symbol) + X_add_number.  */
822159047fSniklas   O_bit_exclusive_or,
83c074d1c9Sdrahn   /* (X_add_symbol & X_op_symbol) + X_add_number.  */
842159047fSniklas   O_bit_and,
85c074d1c9Sdrahn   /* (X_add_symbol + X_op_symbol) + X_add_number.  */
862159047fSniklas   O_add,
87c074d1c9Sdrahn   /* (X_add_symbol - X_op_symbol) + X_add_number.  */
882159047fSniklas   O_subtract,
892159047fSniklas   /* (X_add_symbol == X_op_symbol) + X_add_number.  */
902159047fSniklas   O_eq,
912159047fSniklas   /* (X_add_symbol != X_op_symbol) + X_add_number.  */
922159047fSniklas   O_ne,
932159047fSniklas   /* (X_add_symbol < X_op_symbol) + X_add_number.  */
942159047fSniklas   O_lt,
952159047fSniklas   /* (X_add_symbol <= X_op_symbol) + X_add_number.  */
962159047fSniklas   O_le,
972159047fSniklas   /* (X_add_symbol >= X_op_symbol) + X_add_number.  */
982159047fSniklas   O_ge,
992159047fSniklas   /* (X_add_symbol > X_op_symbol) + X_add_number.  */
1002159047fSniklas   O_gt,
1012159047fSniklas   /* (X_add_symbol && X_op_symbol) + X_add_number.  */
1022159047fSniklas   O_logical_and,
1032159047fSniklas   /* (X_add_symbol || X_op_symbol) + X_add_number.  */
104191aa565Sniklas   O_logical_or,
105b305b0f1Sespie   /* X_op_symbol [ X_add_symbol ] */
106b305b0f1Sespie   O_index,
107b305b0f1Sespie   /* machine dependent operators */
108b305b0f1Sespie   O_md1,  O_md2,  O_md3,  O_md4,  O_md5,  O_md6,  O_md7,  O_md8,
109b305b0f1Sespie   O_md9,  O_md10, O_md11, O_md12, O_md13, O_md14, O_md15, O_md16,
110c074d1c9Sdrahn   O_md17, O_md18, O_md19, O_md20, O_md21, O_md22, O_md23, O_md24,
111c074d1c9Sdrahn   O_md25, O_md26, O_md27, O_md28, O_md29, O_md30, O_md31, O_md32,
112191aa565Sniklas   /* this must be the largest value */
113191aa565Sniklas   O_max
1142159047fSniklas } operatorT;
1152159047fSniklas 
116b55d4692Sfgsch typedef struct expressionS {
1172159047fSniklas   /* The main symbol.  */
118b305b0f1Sespie   symbolS *X_add_symbol;
1192159047fSniklas   /* The second symbol, if needed.  */
120b305b0f1Sespie   symbolS *X_op_symbol;
1212159047fSniklas   /* A number to add.  */
1222159047fSniklas   offsetT X_add_number;
123b305b0f1Sespie 
124b305b0f1Sespie   /* The type of the expression.  We can't assume that an arbitrary
125b305b0f1Sespie      compiler can handle a bitfield of enum type.  FIXME: We could
126b305b0f1Sespie      check this using autoconf.  */
127b305b0f1Sespie #ifdef __GNUC__
128b305b0f1Sespie   operatorT X_op : 8;
129b305b0f1Sespie #else
130b305b0f1Sespie   unsigned char X_op;
131b305b0f1Sespie #endif
132b305b0f1Sespie 
1332159047fSniklas   /* Non-zero if X_add_number should be regarded as unsigned.  This is
1342159047fSniklas      only valid for O_constant expressions.  It is only used when an
1352159047fSniklas      O_constant must be extended into a bignum (i.e., it is not used
1362159047fSniklas      when performing arithmetic on these values).
137191aa565Sniklas      FIXME: This field is not set very reliably.  */
138191aa565Sniklas   unsigned int X_unsigned : 1;
139b305b0f1Sespie 
140b305b0f1Sespie   /* 7 additional bits can be defined if needed.  */
141b305b0f1Sespie 
142b305b0f1Sespie   /* Machine dependent field */
143b305b0f1Sespie   unsigned short X_md;
1442159047fSniklas } expressionS;
1452159047fSniklas 
1462159047fSniklas /* "result" should be type (expressionS *).  */
1472159047fSniklas #define expression(result) expr (0, result)
1482159047fSniklas 
1492159047fSniklas /* If an expression is O_big, look here for its value. These common
1502159047fSniklas    data may be clobbered whenever expr() is called.  */
1512159047fSniklas /* Flonums returned here.  Big enough to hold most precise flonum.  */
1522159047fSniklas extern FLONUM_TYPE generic_floating_point_number;
1532159047fSniklas /* Bignums returned here.  */
1542159047fSniklas extern LITTLENUM_TYPE generic_bignum[];
1552159047fSniklas /* Number of littlenums in above.  */
1562159047fSniklas #define SIZE_OF_LARGE_NUMBER (20)
1572159047fSniklas 
1582159047fSniklas typedef char operator_rankT;
1592159047fSniklas 
160*007c2a45Smiod extern char get_symbol_end (void);
161*007c2a45Smiod extern void expr_begin (void);
162*007c2a45Smiod extern void expr_set_precedence (void);
163*007c2a45Smiod extern segT expr (int rank, expressionS * resultP);
164*007c2a45Smiod extern unsigned int get_single_number (void);
165*007c2a45Smiod extern symbolS *make_expr_symbol (expressionS * expressionP);
166*007c2a45Smiod extern int expr_symbol_where (symbolS *, char **, unsigned int *);
167b305b0f1Sespie 
168*007c2a45Smiod extern symbolS *expr_build_uconstant (offsetT);
169*007c2a45Smiod extern symbolS *expr_build_unary (operatorT, symbolS *);
170*007c2a45Smiod extern symbolS *expr_build_binary (operatorT, symbolS *, symbolS *);
171*007c2a45Smiod extern symbolS *expr_build_dot (void);
172