expr.h revision 38889
1/* expr.h -> header file for expr.c 2 Copyright (C) 1987, 92-97, 1998 Free Software Foundation, Inc. 3 4 This file is part of GAS, the GNU Assembler. 5 6 GAS is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 GAS is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with GAS; see the file COPYING. If not, write to the Free 18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 19 02111-1307, USA. */ 20 21/* 22 * By popular demand, we define a struct to represent an expression. 23 * This will no doubt mutate as expressions become baroque. 24 * 25 * Currently, we support expressions like "foo OP bar + 42". In other 26 * words we permit a (possibly undefined) symbol, a (possibly 27 * undefined) symbol and the operation used to combine the symbols, 28 * and an (absolute) augend. RMS says this is so we can have 1-pass 29 * assembly for any compiler emissions, and a 'case' statement might 30 * emit 'undefined1 - undefined2'. 31 * 32 * The type of an expression used to be stored as a segment. That got 33 * confusing because it overloaded the concept of a segment. I added 34 * an operator field, instead. 35 */ 36 37/* This is the type of an expression. The operator types are also 38 used while parsing an expression. 39 40 NOTE: This enumeration must match the op_rank array in expr.c. */ 41 42typedef enum 43{ 44 /* An illegal expression. */ 45 O_illegal, 46 /* A nonexistent expression. */ 47 O_absent, 48 /* X_add_number (a constant expression). */ 49 O_constant, 50 /* X_add_symbol + X_add_number. */ 51 O_symbol, 52 /* X_add_symbol + X_add_number - the base address of the image. */ 53 O_symbol_rva, 54 /* A register (X_add_number is register number). */ 55 O_register, 56 /* A big value. If X_add_number is negative or 0, the value is in 57 generic_floating_point_number. Otherwise the value is in 58 generic_bignum, and X_add_number is the number of LITTLENUMs in 59 the value. */ 60 O_big, 61 /* (- X_add_symbol) + X_add_number. */ 62 O_uminus, 63 /* (~ X_add_symbol) + X_add_number. */ 64 O_bit_not, 65 /* (! X_add_symbol) + X_add_number. */ 66 O_logical_not, 67 /* (X_add_symbol * X_op_symbol) + X_add_number. */ 68 O_multiply, 69 /* (X_add_symbol / X_op_symbol) + X_add_number. */ 70 O_divide, 71 /* X_add_symbol % X_op_symbol) + X_add_number. */ 72 O_modulus, 73 /* X_add_symbol << X_op_symbol) + X_add_number. */ 74 O_left_shift, 75 /* X_add_symbol >> X_op_symbol) + X_add_number. */ 76 O_right_shift, 77 /* X_add_symbol | X_op_symbol) + X_add_number. */ 78 O_bit_inclusive_or, 79 /* X_add_symbol |~ X_op_symbol) + X_add_number. */ 80 O_bit_or_not, 81 /* X_add_symbol ^ X_op_symbol) + X_add_number. */ 82 O_bit_exclusive_or, 83 /* X_add_symbol & X_op_symbol) + X_add_number. */ 84 O_bit_and, 85 /* X_add_symbol + X_op_symbol) + X_add_number. */ 86 O_add, 87 /* X_add_symbol - X_op_symbol) + X_add_number. */ 88 O_subtract, 89 /* (X_add_symbol == X_op_symbol) + X_add_number. */ 90 O_eq, 91 /* (X_add_symbol != X_op_symbol) + X_add_number. */ 92 O_ne, 93 /* (X_add_symbol < X_op_symbol) + X_add_number. */ 94 O_lt, 95 /* (X_add_symbol <= X_op_symbol) + X_add_number. */ 96 O_le, 97 /* (X_add_symbol >= X_op_symbol) + X_add_number. */ 98 O_ge, 99 /* (X_add_symbol > X_op_symbol) + X_add_number. */ 100 O_gt, 101 /* (X_add_symbol && X_op_symbol) + X_add_number. */ 102 O_logical_and, 103 /* (X_add_symbol || X_op_symbol) + X_add_number. */ 104 O_logical_or, 105 /* this must be the largest value */ 106 O_max 107} operatorT; 108 109typedef struct expressionS 110{ 111 /* The main symbol. */ 112 struct symbol *X_add_symbol; 113 /* The second symbol, if needed. */ 114 struct symbol *X_op_symbol; 115 /* A number to add. */ 116 offsetT X_add_number; 117 /* The type of the expression. We can't assume that an arbitrary 118 compiler can handle a bitfield of enum type. FIXME: We could 119 check this using autoconf. */ 120#ifdef __GNUC__ 121 operatorT X_op : 5; 122#else 123 unsigned X_op : 5; 124#endif 125 /* Non-zero if X_add_number should be regarded as unsigned. This is 126 only valid for O_constant expressions. It is only used when an 127 O_constant must be extended into a bignum (i.e., it is not used 128 when performing arithmetic on these values). 129 FIXME: This field is not set very reliably. */ 130 unsigned int X_unsigned : 1; 131} expressionS; 132 133/* "result" should be type (expressionS *). */ 134#define expression(result) expr (0, result) 135 136/* If an expression is O_big, look here for its value. These common 137 data may be clobbered whenever expr() is called. */ 138/* Flonums returned here. Big enough to hold most precise flonum. */ 139extern FLONUM_TYPE generic_floating_point_number; 140/* Bignums returned here. */ 141extern LITTLENUM_TYPE generic_bignum[]; 142/* Number of littlenums in above. */ 143#define SIZE_OF_LARGE_NUMBER (20) 144 145typedef char operator_rankT; 146 147extern char get_symbol_end PARAMS ((void)); 148extern void expr_begin PARAMS ((void)); 149extern segT expr PARAMS ((int rank, expressionS * resultP)); 150extern unsigned int get_single_number PARAMS ((void)); 151extern struct symbol *make_expr_symbol PARAMS ((expressionS * expressionP)); 152extern int expr_symbol_where 153 PARAMS ((struct symbol *, char **, unsigned int *)); 154 155extern struct symbol * expr_build_uconstant PARAMS ((offsetT)); 156extern struct symbol * expr_build_unary PARAMS ((operatorT, struct symbol *)); 157extern struct symbol * expr_build_binary 158 PARAMS ((operatorT, struct symbol *, struct symbol *)); 159 160/* end of expr.h */ 161