expr.h revision 104834
133965Sjdp/* expr.h -> header file for expr.c 278836Sobrien Copyright 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000 3218822Sdim Free Software Foundation, Inc. 460514Sobrien 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 1933965Sjdp Software Foundation, 59 Temple Place - Suite 330, Boston, MA 20218822Sdim 02111-1307, USA. */ 21218822Sdim 2233965Sjdp/* 23218822Sdim * 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 31104836Sobrien * emit 'undefined1 - undefined2'. 32104836Sobrien * 33218822Sdim * 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. 40130570Sobrien 4133965Sjdp NOTE: This enumeration must match the op_rank array in expr.c. */ 4233965Sjdp 4333965Sjdptypedef 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). */ 55104836Sobrien O_register, 56104836Sobrien /* A big value. If X_add_number is negative or 0, the value is in 57104836Sobrien generic_floating_point_number. Otherwise the value is in 58104836Sobrien generic_bignum, and X_add_number is the number of LITTLENUMs in 59104836Sobrien the value. */ 60104836Sobrien O_big, 61104836Sobrien /* (- X_add_symbol) + X_add_number. */ 62104836Sobrien O_uminus, 63104836Sobrien /* (~ X_add_symbol) + X_add_number. */ 64104836Sobrien O_bit_not, 65104836Sobrien /* (! X_add_symbol) + X_add_number. */ 66104836Sobrien O_logical_not, 67104836Sobrien /* (X_add_symbol * X_op_symbol) + X_add_number. */ 68104836Sobrien O_multiply, 69104836Sobrien /* (X_add_symbol / X_op_symbol) + X_add_number. */ 7033965Sjdp O_divide, 7133965Sjdp /* X_add_symbol % X_op_symbol) + X_add_number. */ 72130570Sobrien O_modulus, 73130570Sobrien /* X_add_symbol << X_op_symbol) + X_add_number. */ 74130570Sobrien O_left_shift, 75130570Sobrien /* X_add_symbol >> X_op_symbol) + X_add_number. */ 76130570Sobrien O_right_shift, 77130570Sobrien /* X_add_symbol | X_op_symbol) + X_add_number. */ 78130570Sobrien O_bit_inclusive_or, 79130570Sobrien /* X_add_symbol |~ X_op_symbol) + X_add_number. */ 80130570Sobrien O_bit_or_not, 81130570Sobrien /* X_add_symbol ^ X_op_symbol) + X_add_number. */ 82130570Sobrien O_bit_exclusive_or, 83130570Sobrien /* X_add_symbol & X_op_symbol) + X_add_number. */ 84130570Sobrien O_bit_and, 85130570Sobrien /* X_add_symbol + X_op_symbol) + X_add_number. */ 86130570Sobrien O_add, 87130570Sobrien /* 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, 93130570Sobrien /* (X_add_symbol < X_op_symbol) + X_add_number. */ 9433965Sjdp O_lt, 9533965Sjdp /* (X_add_symbol <= X_op_symbol) + X_add_number. */ 96130570Sobrien O_le, 9733965Sjdp /* (X_add_symbol >= X_op_symbol) + X_add_number. */ 9833965Sjdp O_ge, 99130570Sobrien /* (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, 103130570Sobrien /* (X_add_symbol || X_op_symbol) + X_add_number. */ 10433965Sjdp O_logical_or, 10533965Sjdp /* X_op_symbol [ X_add_symbol ] */ 106130570Sobrien O_index, 10733965Sjdp /* machine dependent operators */ 108104836Sobrien O_md1, O_md2, O_md3, O_md4, O_md5, O_md6, O_md7, O_md8, 10933965Sjdp O_md9, O_md10, O_md11, O_md12, O_md13, O_md14, O_md15, O_md16, 11033965Sjdp O_md17, O_md18, O_md19, O_md20, O_md21, O_md22, O_md23, O_md24, 11133965Sjdp 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 11633965Sjdptypedef struct expressionS { 11733965Sjdp /* The main symbol. */ 11833965Sjdp symbolS *X_add_symbol; 11933965Sjdp /* The second symbol, if needed. */ 12033965Sjdp symbolS *X_op_symbol; 12133965Sjdp /* A number to add. */ 12233965Sjdp offsetT X_add_number; 12333965Sjdp 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__ 12833965Sjdp operatorT X_op : 8; 12933965Sjdp#else 13033965Sjdp unsigned char X_op; 13133965Sjdp#endif 13233965Sjdp 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; 13933965Sjdp 140104836Sobrien /* 7 additional bits can be defined if needed. */ 141104836Sobrien 142104836Sobrien /* Machine dependent field */ 143104836Sobrien unsigned short X_md; 144104836Sobrien} expressionS; 145104836Sobrien 146104836Sobrien/* "result" should be type (expressionS *). */ 147104836Sobrien#define expression(result) expr (0, result) 148104836Sobrien 149104836Sobrien/* If an expression is O_big, look here for its value. These common 150104836Sobrien data may be clobbered whenever expr() is called. */ 151104836Sobrien/* Flonums returned here. Big enough to hold most precise flonum. */ 152104836Sobrienextern FLONUM_TYPE generic_floating_point_number; 153218822Sdim/* Bignums returned here. */ 154104836Sobrienextern LITTLENUM_TYPE generic_bignum[]; 155218822Sdim/* Number of littlenums in above. */ 15633965Sjdp#define SIZE_OF_LARGE_NUMBER (20) 15733965Sjdp 15833965Sjdptypedef char operator_rankT; 15933965Sjdp 16033965Sjdpextern char get_symbol_end PARAMS ((void)); 16133965Sjdpextern void expr_begin PARAMS ((void)); 162218822Sdimextern void expr_set_precedence PARAMS ((void)); 163218822Sdimextern segT expr PARAMS ((int rank, expressionS * resultP)); 164218822Sdimextern unsigned int get_single_number PARAMS ((void)); 16533965Sjdpextern symbolS *make_expr_symbol PARAMS ((expressionS * expressionP)); 16633965Sjdpextern int expr_symbol_where 16733965Sjdp PARAMS ((symbolS *, char **, unsigned int *)); 16833965Sjdp 16933965Sjdpextern symbolS *expr_build_uconstant PARAMS ((offsetT)); 17038891Sjdpextern symbolS *expr_build_unary PARAMS ((operatorT, symbolS *)); 17133965Sjdpextern symbolS *expr_build_binary PARAMS ((operatorT, symbolS *, symbolS *)); 17238891Sjdpextern symbolS *expr_build_dot PARAMS ((void)); 17338891Sjdp