1 /* expr.h -> header file for expr.c 2 Copyright (C) 1987-2016 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 3, 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, 51 Franklin Street - Fifth Floor, Boston, MA 19 02110-1301, 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 42 typedef enum { 43 /* An illegal expression. */ 44 O_illegal, 45 /* A nonexistent expression. */ 46 O_absent, 47 /* X_add_number (a constant expression). */ 48 O_constant, 49 /* X_add_symbol + X_add_number. */ 50 O_symbol, 51 /* X_add_symbol + X_add_number - the base address of the image. */ 52 O_symbol_rva, 53 /* A register (X_add_number is register number). */ 54 O_register, 55 /* A big value. If X_add_number is negative or 0, the value is in 56 generic_floating_point_number. Otherwise the value is in 57 generic_bignum, and X_add_number is the number of LITTLENUMs in 58 the value. */ 59 O_big, 60 /* (- X_add_symbol) + X_add_number. */ 61 O_uminus, 62 /* (~ X_add_symbol) + X_add_number. */ 63 O_bit_not, 64 /* (! X_add_symbol) + X_add_number. */ 65 O_logical_not, 66 /* (X_add_symbol * X_op_symbol) + X_add_number. */ 67 O_multiply, 68 /* (X_add_symbol / X_op_symbol) + X_add_number. */ 69 O_divide, 70 /* (X_add_symbol % X_op_symbol) + X_add_number. */ 71 O_modulus, 72 /* (X_add_symbol << X_op_symbol) + X_add_number. */ 73 O_left_shift, 74 /* (X_add_symbol >> X_op_symbol) + X_add_number. */ 75 O_right_shift, 76 /* (X_add_symbol | X_op_symbol) + X_add_number. */ 77 O_bit_inclusive_or, 78 /* (X_add_symbol |~ X_op_symbol) + X_add_number. */ 79 O_bit_or_not, 80 /* (X_add_symbol ^ X_op_symbol) + X_add_number. */ 81 O_bit_exclusive_or, 82 /* (X_add_symbol & X_op_symbol) + X_add_number. */ 83 O_bit_and, 84 /* (X_add_symbol + X_op_symbol) + X_add_number. */ 85 O_add, 86 /* (X_add_symbol - X_op_symbol) + X_add_number. */ 87 O_subtract, 88 /* (X_add_symbol == X_op_symbol) + X_add_number. */ 89 O_eq, 90 /* (X_add_symbol != X_op_symbol) + X_add_number. */ 91 O_ne, 92 /* (X_add_symbol < X_op_symbol) + X_add_number. */ 93 O_lt, 94 /* (X_add_symbol <= X_op_symbol) + X_add_number. */ 95 O_le, 96 /* (X_add_symbol >= X_op_symbol) + X_add_number. */ 97 O_ge, 98 /* (X_add_symbol > X_op_symbol) + X_add_number. */ 99 O_gt, 100 /* (X_add_symbol && X_op_symbol) + X_add_number. */ 101 O_logical_and, 102 /* (X_add_symbol || X_op_symbol) + X_add_number. */ 103 O_logical_or, 104 /* X_op_symbol [ X_add_symbol ] */ 105 O_index, 106 /* machine dependent operators */ 107 O_md1, O_md2, O_md3, O_md4, O_md5, O_md6, O_md7, O_md8, 108 O_md9, O_md10, O_md11, O_md12, O_md13, O_md14, O_md15, O_md16, 109 O_md17, O_md18, O_md19, O_md20, O_md21, O_md22, O_md23, O_md24, 110 O_md25, O_md26, O_md27, O_md28, O_md29, O_md30, O_md31, O_md32, 111 /* this must be the largest value */ 112 O_max 113 } operatorT; 114 115 typedef struct expressionS { 116 /* The main symbol. */ 117 symbolS *X_add_symbol; 118 /* The second symbol, if needed. */ 119 symbolS *X_op_symbol; 120 /* A number to add. */ 121 offsetT X_add_number; 122 123 /* The type of the expression. We can't assume that an arbitrary 124 compiler can handle a bitfield of enum type. FIXME: We could 125 check this using autoconf. */ 126 #ifdef __GNUC__ 127 operatorT X_op : 8; 128 #else 129 unsigned char X_op; 130 #endif 131 132 /* Non-zero if X_add_number should be regarded as unsigned. This is 133 only valid for O_constant expressions. It is only used when an 134 O_constant must be extended into a bignum (i.e., it is not used 135 when performing arithmetic on these values). 136 FIXME: This field is not set very reliably. */ 137 unsigned int X_unsigned : 1; 138 /* This is used to implement "word size + 1 bit" arithmetic, so that e.g. 139 expressions used with .sleb128 directives can use the full range available 140 for an unsigned word, but can also properly represent all values of a 141 signed word. */ 142 unsigned int X_extrabit : 1; 143 144 /* 7 additional bits can be defined if needed. */ 145 146 /* Machine dependent field */ 147 unsigned short X_md; 148 } expressionS; 149 150 enum expr_mode 151 { 152 expr_evaluate, 153 expr_normal, 154 expr_defer 155 }; 156 157 /* "result" should be type (expressionS *). */ 158 #define expression(result) expr (0, result, expr_normal) 159 #define expression_and_evaluate(result) expr (0, result, expr_evaluate) 160 #define deferred_expression(result) expr (0, result, expr_defer) 161 162 /* If an expression is O_big, look here for its value. These common 163 data may be clobbered whenever expr() is called. */ 164 /* Flonums returned here. Big enough to hold most precise flonum. */ 165 extern FLONUM_TYPE generic_floating_point_number; 166 /* Bignums returned here. */ 167 extern LITTLENUM_TYPE generic_bignum[]; 168 /* Number of littlenums in above. */ 169 #define SIZE_OF_LARGE_NUMBER (20) 170 171 typedef char operator_rankT; 172 173 extern char get_symbol_name (char **); 174 extern char restore_line_pointer (char); 175 extern void expr_begin (void); 176 extern void expr_set_precedence (void); 177 extern void expr_set_rank (operatorT, operator_rankT); 178 extern void add_to_result (expressionS *, offsetT, int); 179 extern void subtract_from_result (expressionS *, offsetT, int); 180 extern segT expr (int, expressionS *, enum expr_mode); 181 extern unsigned int get_single_number (void); 182 extern symbolS *make_expr_symbol (expressionS * expressionP); 183 extern int expr_symbol_where (symbolS *, const char **, unsigned int *); 184 extern void current_location (expressionS *); 185 186 extern symbolS *expr_build_uconstant (offsetT); 187 extern symbolS *expr_build_dot (void); 188 189 int resolve_expression (expressionS *); 190