expr.h revision 77298
133965Sjdp/* expr.h -> header file for expr.c 277298Sobrien Copyright (C) 1987, 92-99, 2000 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 4277298Sobrientypedef enum { 4333965Sjdp /* An illegal expression. */ 4433965Sjdp O_illegal, 4533965Sjdp /* A nonexistent expression. */ 4633965Sjdp O_absent, 4733965Sjdp /* X_add_number (a constant expression). */ 4833965Sjdp O_constant, 4933965Sjdp /* X_add_symbol + X_add_number. */ 5033965Sjdp O_symbol, 5133965Sjdp /* X_add_symbol + X_add_number - the base address of the image. */ 5233965Sjdp O_symbol_rva, 5333965Sjdp /* A register (X_add_number is register number). */ 5433965Sjdp O_register, 5533965Sjdp /* A big value. If X_add_number is negative or 0, the value is in 5633965Sjdp generic_floating_point_number. Otherwise the value is in 5733965Sjdp generic_bignum, and X_add_number is the number of LITTLENUMs in 5833965Sjdp the value. */ 5933965Sjdp O_big, 6033965Sjdp /* (- X_add_symbol) + X_add_number. */ 6133965Sjdp O_uminus, 6233965Sjdp /* (~ X_add_symbol) + X_add_number. */ 6333965Sjdp O_bit_not, 6433965Sjdp /* (! X_add_symbol) + X_add_number. */ 6533965Sjdp O_logical_not, 6633965Sjdp /* (X_add_symbol * X_op_symbol) + X_add_number. */ 6733965Sjdp O_multiply, 6833965Sjdp /* (X_add_symbol / X_op_symbol) + X_add_number. */ 6933965Sjdp O_divide, 7033965Sjdp /* X_add_symbol % X_op_symbol) + X_add_number. */ 7133965Sjdp O_modulus, 7233965Sjdp /* X_add_symbol << X_op_symbol) + X_add_number. */ 7333965Sjdp O_left_shift, 7433965Sjdp /* X_add_symbol >> X_op_symbol) + X_add_number. */ 7533965Sjdp O_right_shift, 7633965Sjdp /* X_add_symbol | X_op_symbol) + X_add_number. */ 7733965Sjdp O_bit_inclusive_or, 7833965Sjdp /* X_add_symbol |~ X_op_symbol) + X_add_number. */ 7933965Sjdp O_bit_or_not, 8033965Sjdp /* X_add_symbol ^ X_op_symbol) + X_add_number. */ 8133965Sjdp O_bit_exclusive_or, 8233965Sjdp /* X_add_symbol & X_op_symbol) + X_add_number. */ 8333965Sjdp O_bit_and, 8433965Sjdp /* X_add_symbol + X_op_symbol) + X_add_number. */ 8533965Sjdp O_add, 8633965Sjdp /* X_add_symbol - X_op_symbol) + X_add_number. */ 8733965Sjdp O_subtract, 8833965Sjdp /* (X_add_symbol == X_op_symbol) + X_add_number. */ 8933965Sjdp O_eq, 9033965Sjdp /* (X_add_symbol != X_op_symbol) + X_add_number. */ 9133965Sjdp O_ne, 9233965Sjdp /* (X_add_symbol < X_op_symbol) + X_add_number. */ 9333965Sjdp O_lt, 9433965Sjdp /* (X_add_symbol <= X_op_symbol) + X_add_number. */ 9533965Sjdp O_le, 9633965Sjdp /* (X_add_symbol >= X_op_symbol) + X_add_number. */ 9733965Sjdp O_ge, 9833965Sjdp /* (X_add_symbol > X_op_symbol) + X_add_number. */ 9933965Sjdp O_gt, 10033965Sjdp /* (X_add_symbol && X_op_symbol) + X_add_number. */ 10133965Sjdp O_logical_and, 10233965Sjdp /* (X_add_symbol || X_op_symbol) + X_add_number. */ 10333965Sjdp O_logical_or, 10460484Sobrien /* X_op_symbol [ X_add_symbol ] */ 10560484Sobrien O_index, 10660484Sobrien /* machine dependent operators */ 10760484Sobrien O_md1, O_md2, O_md3, O_md4, O_md5, O_md6, O_md7, O_md8, 10860484Sobrien O_md9, O_md10, O_md11, O_md12, O_md13, O_md14, O_md15, O_md16, 10933965Sjdp /* this must be the largest value */ 11033965Sjdp O_max 11133965Sjdp} operatorT; 11233965Sjdp 11377298Sobrientypedef struct expressionS { 11433965Sjdp /* The main symbol. */ 11560484Sobrien symbolS *X_add_symbol; 11633965Sjdp /* The second symbol, if needed. */ 11760484Sobrien symbolS *X_op_symbol; 11833965Sjdp /* A number to add. */ 11933965Sjdp offsetT X_add_number; 12060484Sobrien 12133965Sjdp /* The type of the expression. We can't assume that an arbitrary 12233965Sjdp compiler can handle a bitfield of enum type. FIXME: We could 12333965Sjdp check this using autoconf. */ 12433965Sjdp#ifdef __GNUC__ 12560484Sobrien operatorT X_op : 8; 12633965Sjdp#else 12760484Sobrien unsigned char X_op; 12833965Sjdp#endif 12960484Sobrien 13033965Sjdp /* Non-zero if X_add_number should be regarded as unsigned. This is 13133965Sjdp only valid for O_constant expressions. It is only used when an 13233965Sjdp O_constant must be extended into a bignum (i.e., it is not used 13333965Sjdp when performing arithmetic on these values). 13433965Sjdp FIXME: This field is not set very reliably. */ 13533965Sjdp unsigned int X_unsigned : 1; 13660484Sobrien 13760484Sobrien /* 7 additional bits can be defined if needed. */ 13860484Sobrien 13960484Sobrien /* Machine dependent field */ 14060484Sobrien unsigned short X_md; 14133965Sjdp} expressionS; 14233965Sjdp 14377298Sobrien/* "result" should be type (expressionS *). */ 14433965Sjdp#define expression(result) expr (0, result) 14533965Sjdp 14633965Sjdp/* If an expression is O_big, look here for its value. These common 14777298Sobrien data may be clobbered whenever expr() is called. */ 14877298Sobrien/* Flonums returned here. Big enough to hold most precise flonum. */ 14933965Sjdpextern FLONUM_TYPE generic_floating_point_number; 15077298Sobrien/* Bignums returned here. */ 15133965Sjdpextern LITTLENUM_TYPE generic_bignum[]; 15277298Sobrien/* Number of littlenums in above. */ 15333965Sjdp#define SIZE_OF_LARGE_NUMBER (20) 15433965Sjdp 15533965Sjdptypedef char operator_rankT; 15633965Sjdp 15733965Sjdpextern char get_symbol_end PARAMS ((void)); 15833965Sjdpextern void expr_begin PARAMS ((void)); 15960484Sobrienextern void expr_set_precedence PARAMS ((void)); 16033965Sjdpextern segT expr PARAMS ((int rank, expressionS * resultP)); 16133965Sjdpextern unsigned int get_single_number PARAMS ((void)); 16260484Sobrienextern symbolS *make_expr_symbol PARAMS ((expressionS * expressionP)); 16333965Sjdpextern int expr_symbol_where 16460484Sobrien PARAMS ((symbolS *, char **, unsigned int *)); 16533965Sjdp 16660484Sobrienextern symbolS *expr_build_uconstant PARAMS ((offsetT)); 16760484Sobrienextern symbolS *expr_build_unary PARAMS ((operatorT, symbolS *)); 16860484Sobrienextern symbolS *expr_build_binary PARAMS ((operatorT, symbolS *, symbolS *)); 16960484Sobrienextern symbolS *expr_build_dot PARAMS ((void)); 170