| 1 | /* expr.c -operands, expressions- | 
|---|
| 2 | Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, | 
|---|
| 3 | 1999, 2000, 2001, 2002 | 
|---|
| 4 | Free Software Foundation, Inc. | 
|---|
| 5 |  | 
|---|
| 6 | This file is part of GAS, the GNU Assembler. | 
|---|
| 7 |  | 
|---|
| 8 | GAS is free software; you can redistribute it and/or modify | 
|---|
| 9 | it under the terms of the GNU General Public License as published by | 
|---|
| 10 | the Free Software Foundation; either version 2, or (at your option) | 
|---|
| 11 | any later version. | 
|---|
| 12 |  | 
|---|
| 13 | GAS is distributed in the hope that it will be useful, | 
|---|
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 16 | GNU General Public License for more details. | 
|---|
| 17 |  | 
|---|
| 18 | You should have received a copy of the GNU General Public License | 
|---|
| 19 | along with GAS; see the file COPYING.  If not, write to the Free | 
|---|
| 20 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | 
|---|
| 21 | 02111-1307, USA.  */ | 
|---|
| 22 |  | 
|---|
| 23 | /* This is really a branch office of as-read.c. I split it out to clearly | 
|---|
| 24 | distinguish the world of expressions from the world of statements. | 
|---|
| 25 | (It also gives smaller files to re-compile.) | 
|---|
| 26 | Here, "operand"s are of expressions, not instructions.  */ | 
|---|
| 27 |  | 
|---|
| 28 | #include <string.h> | 
|---|
| 29 | #define min(a, b)       ((a) < (b) ? (a) : (b)) | 
|---|
| 30 |  | 
|---|
| 31 | #include "as.h" | 
|---|
| 32 | #include "safe-ctype.h" | 
|---|
| 33 | #include "obstack.h" | 
|---|
| 34 |  | 
|---|
| 35 | static void floating_constant PARAMS ((expressionS * expressionP)); | 
|---|
| 36 | static valueT generic_bignum_to_int32 PARAMS ((void)); | 
|---|
| 37 | #ifdef BFD64 | 
|---|
| 38 | static valueT generic_bignum_to_int64 PARAMS ((void)); | 
|---|
| 39 | #endif | 
|---|
| 40 | static void integer_constant PARAMS ((int radix, expressionS * expressionP)); | 
|---|
| 41 | static void mri_char_constant PARAMS ((expressionS *)); | 
|---|
| 42 | static void current_location PARAMS ((expressionS *)); | 
|---|
| 43 | static void clean_up_expression PARAMS ((expressionS * expressionP)); | 
|---|
| 44 | static segT operand PARAMS ((expressionS *)); | 
|---|
| 45 | static operatorT operator PARAMS ((int *)); | 
|---|
| 46 |  | 
|---|
| 47 | extern const char EXP_CHARS[], FLT_CHARS[]; | 
|---|
| 48 |  | 
|---|
| 49 | /* We keep a mapping of expression symbols to file positions, so that | 
|---|
| 50 | we can provide better error messages.  */ | 
|---|
| 51 |  | 
|---|
| 52 | struct expr_symbol_line { | 
|---|
| 53 | struct expr_symbol_line *next; | 
|---|
| 54 | symbolS *sym; | 
|---|
| 55 | char *file; | 
|---|
| 56 | unsigned int line; | 
|---|
| 57 | }; | 
|---|
| 58 |  | 
|---|
| 59 | static struct expr_symbol_line *expr_symbol_lines; | 
|---|
| 60 |  | 
|---|
| 61 |  | 
|---|
| 62 | /* Build a dummy symbol to hold a complex expression.  This is how we | 
|---|
| 63 | build expressions up out of other expressions.  The symbol is put | 
|---|
| 64 | into the fake section expr_section.  */ | 
|---|
| 65 |  | 
|---|
| 66 | symbolS * | 
|---|
| 67 | make_expr_symbol (expressionP) | 
|---|
| 68 | expressionS *expressionP; | 
|---|
| 69 | { | 
|---|
| 70 | expressionS zero; | 
|---|
| 71 | const char *fake; | 
|---|
| 72 | symbolS *symbolP; | 
|---|
| 73 | struct expr_symbol_line *n; | 
|---|
| 74 |  | 
|---|
| 75 | if (expressionP->X_op == O_symbol | 
|---|
| 76 | && expressionP->X_add_number == 0) | 
|---|
| 77 | return expressionP->X_add_symbol; | 
|---|
| 78 |  | 
|---|
| 79 | if (expressionP->X_op == O_big) | 
|---|
| 80 | { | 
|---|
| 81 | /* This won't work, because the actual value is stored in | 
|---|
| 82 | generic_floating_point_number or generic_bignum, and we are | 
|---|
| 83 | going to lose it if we haven't already.  */ | 
|---|
| 84 | if (expressionP->X_add_number > 0) | 
|---|
| 85 | as_bad (_("bignum invalid")); | 
|---|
| 86 | else | 
|---|
| 87 | as_bad (_("floating point number invalid")); | 
|---|
| 88 | zero.X_op = O_constant; | 
|---|
| 89 | zero.X_add_number = 0; | 
|---|
| 90 | zero.X_unsigned = 0; | 
|---|
| 91 | clean_up_expression (&zero); | 
|---|
| 92 | expressionP = &zero; | 
|---|
| 93 | } | 
|---|
| 94 |  | 
|---|
| 95 | fake = FAKE_LABEL_NAME; | 
|---|
| 96 |  | 
|---|
| 97 | /* Putting constant symbols in absolute_section rather than | 
|---|
| 98 | expr_section is convenient for the old a.out code, for which | 
|---|
| 99 | S_GET_SEGMENT does not always retrieve the value put in by | 
|---|
| 100 | S_SET_SEGMENT.  */ | 
|---|
| 101 | symbolP = symbol_create (fake, | 
|---|
| 102 | (expressionP->X_op == O_constant | 
|---|
| 103 | ? absolute_section | 
|---|
| 104 | : expr_section), | 
|---|
| 105 | 0, &zero_address_frag); | 
|---|
| 106 | symbol_set_value_expression (symbolP, expressionP); | 
|---|
| 107 |  | 
|---|
| 108 | if (expressionP->X_op == O_constant) | 
|---|
| 109 | resolve_symbol_value (symbolP); | 
|---|
| 110 |  | 
|---|
| 111 | n = (struct expr_symbol_line *) xmalloc (sizeof *n); | 
|---|
| 112 | n->sym = symbolP; | 
|---|
| 113 | as_where (&n->file, &n->line); | 
|---|
| 114 | n->next = expr_symbol_lines; | 
|---|
| 115 | expr_symbol_lines = n; | 
|---|
| 116 |  | 
|---|
| 117 | return symbolP; | 
|---|
| 118 | } | 
|---|
| 119 |  | 
|---|
| 120 | /* Return the file and line number for an expr symbol.  Return | 
|---|
| 121 | non-zero if something was found, 0 if no information is known for | 
|---|
| 122 | the symbol.  */ | 
|---|
| 123 |  | 
|---|
| 124 | int | 
|---|
| 125 | expr_symbol_where (sym, pfile, pline) | 
|---|
| 126 | symbolS *sym; | 
|---|
| 127 | char **pfile; | 
|---|
| 128 | unsigned int *pline; | 
|---|
| 129 | { | 
|---|
| 130 | register struct expr_symbol_line *l; | 
|---|
| 131 |  | 
|---|
| 132 | for (l = expr_symbol_lines; l != NULL; l = l->next) | 
|---|
| 133 | { | 
|---|
| 134 | if (l->sym == sym) | 
|---|
| 135 | { | 
|---|
| 136 | *pfile = l->file; | 
|---|
| 137 | *pline = l->line; | 
|---|
| 138 | return 1; | 
|---|
| 139 | } | 
|---|
| 140 | } | 
|---|
| 141 |  | 
|---|
| 142 | return 0; | 
|---|
| 143 | } | 
|---|
| 144 |  | 
|---|
| 145 |  | 
|---|
| 146 | /* Utilities for building expressions. | 
|---|
| 147 | Since complex expressions are recorded as symbols for use in other | 
|---|
| 148 | expressions these return a symbolS * and not an expressionS *. | 
|---|
| 149 | These explicitly do not take an "add_number" argument.  */ | 
|---|
| 150 | /* ??? For completeness' sake one might want expr_build_symbol. | 
|---|
| 151 | It would just return its argument.  */ | 
|---|
| 152 |  | 
|---|
| 153 | /* Build an expression for an unsigned constant. | 
|---|
| 154 | The corresponding one for signed constants is missing because | 
|---|
| 155 | there's currently no need for it.  One could add an unsigned_p flag | 
|---|
| 156 | but that seems more clumsy.  */ | 
|---|
| 157 |  | 
|---|
| 158 | symbolS * | 
|---|
| 159 | expr_build_uconstant (value) | 
|---|
| 160 | offsetT value; | 
|---|
| 161 | { | 
|---|
| 162 | expressionS e; | 
|---|
| 163 |  | 
|---|
| 164 | e.X_op = O_constant; | 
|---|
| 165 | e.X_add_number = value; | 
|---|
| 166 | e.X_unsigned = 1; | 
|---|
| 167 | return make_expr_symbol (&e); | 
|---|
| 168 | } | 
|---|
| 169 |  | 
|---|
| 170 | /* Build an expression for OP s1.  */ | 
|---|
| 171 |  | 
|---|
| 172 | symbolS * | 
|---|
| 173 | expr_build_unary (op, s1) | 
|---|
| 174 | operatorT op; | 
|---|
| 175 | symbolS *s1; | 
|---|
| 176 | { | 
|---|
| 177 | expressionS e; | 
|---|
| 178 |  | 
|---|
| 179 | e.X_op = op; | 
|---|
| 180 | e.X_add_symbol = s1; | 
|---|
| 181 | e.X_add_number = 0; | 
|---|
| 182 | return make_expr_symbol (&e); | 
|---|
| 183 | } | 
|---|
| 184 |  | 
|---|
| 185 | /* Build an expression for s1 OP s2.  */ | 
|---|
| 186 |  | 
|---|
| 187 | symbolS * | 
|---|
| 188 | expr_build_binary (op, s1, s2) | 
|---|
| 189 | operatorT op; | 
|---|
| 190 | symbolS *s1; | 
|---|
| 191 | symbolS *s2; | 
|---|
| 192 | { | 
|---|
| 193 | expressionS e; | 
|---|
| 194 |  | 
|---|
| 195 | e.X_op = op; | 
|---|
| 196 | e.X_add_symbol = s1; | 
|---|
| 197 | e.X_op_symbol = s2; | 
|---|
| 198 | e.X_add_number = 0; | 
|---|
| 199 | return make_expr_symbol (&e); | 
|---|
| 200 | } | 
|---|
| 201 |  | 
|---|
| 202 | /* Build an expression for the current location ('.').  */ | 
|---|
| 203 |  | 
|---|
| 204 | symbolS * | 
|---|
| 205 | expr_build_dot () | 
|---|
| 206 | { | 
|---|
| 207 | expressionS e; | 
|---|
| 208 |  | 
|---|
| 209 | current_location (&e); | 
|---|
| 210 | return make_expr_symbol (&e); | 
|---|
| 211 | } | 
|---|
| 212 |  | 
|---|
| 213 |  | 
|---|
| 214 | /* Build any floating-point literal here. | 
|---|
| 215 | Also build any bignum literal here.  */ | 
|---|
| 216 |  | 
|---|
| 217 | /* Seems atof_machine can backscan through generic_bignum and hit whatever | 
|---|
| 218 | happens to be loaded before it in memory.  And its way too complicated | 
|---|
| 219 | for me to fix right.  Thus a hack.  JF:  Just make generic_bignum bigger, | 
|---|
| 220 | and never write into the early words, thus they'll always be zero. | 
|---|
| 221 | I hate Dean's floating-point code.  Bleh.  */ | 
|---|
| 222 | LITTLENUM_TYPE generic_bignum[SIZE_OF_LARGE_NUMBER + 6]; | 
|---|
| 223 |  | 
|---|
| 224 | FLONUM_TYPE generic_floating_point_number = { | 
|---|
| 225 | &generic_bignum[6],           /* low.  (JF: Was 0)  */ | 
|---|
| 226 | &generic_bignum[SIZE_OF_LARGE_NUMBER + 6 - 1], /* high.  JF: (added +6)  */ | 
|---|
| 227 | 0,                            /* leader.  */ | 
|---|
| 228 | 0,                            /* exponent.  */ | 
|---|
| 229 | 0                             /* sign.  */ | 
|---|
| 230 | }; | 
|---|
| 231 |  | 
|---|
| 232 | /* If nonzero, we've been asked to assemble nan, +inf or -inf.  */ | 
|---|
| 233 | int generic_floating_point_magic; | 
|---|
| 234 |  | 
|---|
| 235 |  | 
|---|
| 236 | static void | 
|---|
| 237 | floating_constant (expressionP) | 
|---|
| 238 | expressionS *expressionP; | 
|---|
| 239 | { | 
|---|
| 240 | /* input_line_pointer -> floating-point constant.  */ | 
|---|
| 241 | int error_code; | 
|---|
| 242 |  | 
|---|
| 243 | error_code = atof_generic (&input_line_pointer, ".", EXP_CHARS, | 
|---|
| 244 | &generic_floating_point_number); | 
|---|
| 245 |  | 
|---|
| 246 | if (error_code) | 
|---|
| 247 | { | 
|---|
| 248 | if (error_code == ERROR_EXPONENT_OVERFLOW) | 
|---|
| 249 | { | 
|---|
| 250 | as_bad (_("bad floating-point constant: exponent overflow")); | 
|---|
| 251 | } | 
|---|
| 252 | else | 
|---|
| 253 | { | 
|---|
| 254 | as_bad (_("bad floating-point constant: unknown error code=%d"), | 
|---|
| 255 | error_code); | 
|---|
| 256 | } | 
|---|
| 257 | } | 
|---|
| 258 | expressionP->X_op = O_big; | 
|---|
| 259 | /* input_line_pointer -> just after constant, which may point to | 
|---|
| 260 | whitespace.  */ | 
|---|
| 261 | expressionP->X_add_number = -1; | 
|---|
| 262 | } | 
|---|
| 263 |  | 
|---|
| 264 | static valueT | 
|---|
| 265 | generic_bignum_to_int32 () | 
|---|
| 266 | { | 
|---|
| 267 | valueT number = | 
|---|
| 268 | ((generic_bignum[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS) | 
|---|
| 269 | | (generic_bignum[0] & LITTLENUM_MASK); | 
|---|
| 270 | number &= 0xffffffff; | 
|---|
| 271 | return number; | 
|---|
| 272 | } | 
|---|
| 273 |  | 
|---|
| 274 | #ifdef BFD64 | 
|---|
| 275 | static valueT | 
|---|
| 276 | generic_bignum_to_int64 () | 
|---|
| 277 | { | 
|---|
| 278 | valueT number = | 
|---|
| 279 | ((((((((valueT) generic_bignum[3] & LITTLENUM_MASK) | 
|---|
| 280 | << LITTLENUM_NUMBER_OF_BITS) | 
|---|
| 281 | | ((valueT) generic_bignum[2] & LITTLENUM_MASK)) | 
|---|
| 282 | << LITTLENUM_NUMBER_OF_BITS) | 
|---|
| 283 | | ((valueT) generic_bignum[1] & LITTLENUM_MASK)) | 
|---|
| 284 | << LITTLENUM_NUMBER_OF_BITS) | 
|---|
| 285 | | ((valueT) generic_bignum[0] & LITTLENUM_MASK)); | 
|---|
| 286 | return number; | 
|---|
| 287 | } | 
|---|
| 288 | #endif | 
|---|
| 289 |  | 
|---|
| 290 | static void | 
|---|
| 291 | integer_constant (radix, expressionP) | 
|---|
| 292 | int radix; | 
|---|
| 293 | expressionS *expressionP; | 
|---|
| 294 | { | 
|---|
| 295 | char *start;          /* Start of number.  */ | 
|---|
| 296 | char *suffix = NULL; | 
|---|
| 297 | char c; | 
|---|
| 298 | valueT number;        /* Offset or (absolute) value.  */ | 
|---|
| 299 | short int digit;      /* Value of next digit in current radix.  */ | 
|---|
| 300 | short int maxdig = 0; /* Highest permitted digit value.  */ | 
|---|
| 301 | int too_many_digits = 0;      /* If we see >= this number of.  */ | 
|---|
| 302 | char *name;           /* Points to name of symbol.  */ | 
|---|
| 303 | symbolS *symbolP;     /* Points to symbol.  */ | 
|---|
| 304 |  | 
|---|
| 305 | int small;                    /* True if fits in 32 bits.  */ | 
|---|
| 306 |  | 
|---|
| 307 | /* May be bignum, or may fit in 32 bits.  */ | 
|---|
| 308 | /* Most numbers fit into 32 bits, and we want this case to be fast. | 
|---|
| 309 | so we pretend it will fit into 32 bits.  If, after making up a 32 | 
|---|
| 310 | bit number, we realise that we have scanned more digits than | 
|---|
| 311 | comfortably fit into 32 bits, we re-scan the digits coding them | 
|---|
| 312 | into a bignum.  For decimal and octal numbers we are | 
|---|
| 313 | conservative: Some numbers may be assumed bignums when in fact | 
|---|
| 314 | they do fit into 32 bits.  Numbers of any radix can have excess | 
|---|
| 315 | leading zeros: We strive to recognise this and cast them back | 
|---|
| 316 | into 32 bits.  We must check that the bignum really is more than | 
|---|
| 317 | 32 bits, and change it back to a 32-bit number if it fits.  The | 
|---|
| 318 | number we are looking for is expected to be positive, but if it | 
|---|
| 319 | fits into 32 bits as an unsigned number, we let it be a 32-bit | 
|---|
| 320 | number.  The cavalier approach is for speed in ordinary cases.  */ | 
|---|
| 321 | /* This has been extended for 64 bits.  We blindly assume that if | 
|---|
| 322 | you're compiling in 64-bit mode, the target is a 64-bit machine. | 
|---|
| 323 | This should be cleaned up.  */ | 
|---|
| 324 |  | 
|---|
| 325 | #ifdef BFD64 | 
|---|
| 326 | #define valuesize 64 | 
|---|
| 327 | #else /* includes non-bfd case, mostly */ | 
|---|
| 328 | #define valuesize 32 | 
|---|
| 329 | #endif | 
|---|
| 330 |  | 
|---|
| 331 | if ((NUMBERS_WITH_SUFFIX || flag_m68k_mri) && radix == 0) | 
|---|
| 332 | { | 
|---|
| 333 | int flt = 0; | 
|---|
| 334 |  | 
|---|
| 335 | /* In MRI mode, the number may have a suffix indicating the | 
|---|
| 336 | radix.  For that matter, it might actually be a floating | 
|---|
| 337 | point constant.  */ | 
|---|
| 338 | for (suffix = input_line_pointer; ISALNUM (*suffix); suffix++) | 
|---|
| 339 | { | 
|---|
| 340 | if (*suffix == 'e' || *suffix == 'E') | 
|---|
| 341 | flt = 1; | 
|---|
| 342 | } | 
|---|
| 343 |  | 
|---|
| 344 | if (suffix == input_line_pointer) | 
|---|
| 345 | { | 
|---|
| 346 | radix = 10; | 
|---|
| 347 | suffix = NULL; | 
|---|
| 348 | } | 
|---|
| 349 | else | 
|---|
| 350 | { | 
|---|
| 351 | c = *--suffix; | 
|---|
| 352 | c = TOUPPER (c); | 
|---|
| 353 | if (c == 'B') | 
|---|
| 354 | radix = 2; | 
|---|
| 355 | else if (c == 'D') | 
|---|
| 356 | radix = 10; | 
|---|
| 357 | else if (c == 'O' || c == 'Q') | 
|---|
| 358 | radix = 8; | 
|---|
| 359 | else if (c == 'H') | 
|---|
| 360 | radix = 16; | 
|---|
| 361 | else if (suffix[1] == '.' || c == 'E' || flt) | 
|---|
| 362 | { | 
|---|
| 363 | floating_constant (expressionP); | 
|---|
| 364 | return; | 
|---|
| 365 | } | 
|---|
| 366 | else | 
|---|
| 367 | { | 
|---|
| 368 | radix = 10; | 
|---|
| 369 | suffix = NULL; | 
|---|
| 370 | } | 
|---|
| 371 | } | 
|---|
| 372 | } | 
|---|
| 373 |  | 
|---|
| 374 | switch (radix) | 
|---|
| 375 | { | 
|---|
| 376 | case 2: | 
|---|
| 377 | maxdig = 2; | 
|---|
| 378 | too_many_digits = valuesize + 1; | 
|---|
| 379 | break; | 
|---|
| 380 | case 8: | 
|---|
| 381 | maxdig = radix = 8; | 
|---|
| 382 | too_many_digits = (valuesize + 2) / 3 + 1; | 
|---|
| 383 | break; | 
|---|
| 384 | case 16: | 
|---|
| 385 | maxdig = radix = 16; | 
|---|
| 386 | too_many_digits = (valuesize + 3) / 4 + 1; | 
|---|
| 387 | break; | 
|---|
| 388 | case 10: | 
|---|
| 389 | maxdig = radix = 10; | 
|---|
| 390 | too_many_digits = (valuesize + 11) / 4; /* Very rough.  */ | 
|---|
| 391 | } | 
|---|
| 392 | #undef valuesize | 
|---|
| 393 | start = input_line_pointer; | 
|---|
| 394 | c = *input_line_pointer++; | 
|---|
| 395 | for (number = 0; | 
|---|
| 396 | (digit = hex_value (c)) < maxdig; | 
|---|
| 397 | c = *input_line_pointer++) | 
|---|
| 398 | { | 
|---|
| 399 | number = number * radix + digit; | 
|---|
| 400 | } | 
|---|
| 401 | /* c contains character after number.  */ | 
|---|
| 402 | /* input_line_pointer->char after c.  */ | 
|---|
| 403 | small = (input_line_pointer - start - 1) < too_many_digits; | 
|---|
| 404 |  | 
|---|
| 405 | if (radix == 16 && c == '_') | 
|---|
| 406 | { | 
|---|
| 407 | /* This is literal of the form 0x333_0_12345678_1. | 
|---|
| 408 | This example is equivalent to 0x00000333000000001234567800000001.  */ | 
|---|
| 409 |  | 
|---|
| 410 | int num_little_digits = 0; | 
|---|
| 411 | int i; | 
|---|
| 412 | input_line_pointer = start;       /* -> 1st digit.  */ | 
|---|
| 413 |  | 
|---|
| 414 | know (LITTLENUM_NUMBER_OF_BITS == 16); | 
|---|
| 415 |  | 
|---|
| 416 | for (c = '_'; c == '_'; num_little_digits += 2) | 
|---|
| 417 | { | 
|---|
| 418 |  | 
|---|
| 419 | /* Convert one 64-bit word.  */ | 
|---|
| 420 | int ndigit = 0; | 
|---|
| 421 | number = 0; | 
|---|
| 422 | for (c = *input_line_pointer++; | 
|---|
| 423 | (digit = hex_value (c)) < maxdig; | 
|---|
| 424 | c = *(input_line_pointer++)) | 
|---|
| 425 | { | 
|---|
| 426 | number = number * radix + digit; | 
|---|
| 427 | ndigit++; | 
|---|
| 428 | } | 
|---|
| 429 |  | 
|---|
| 430 | /* Check for 8 digit per word max.  */ | 
|---|
| 431 | if (ndigit > 8) | 
|---|
| 432 | as_bad (_("a bignum with underscores may not have more than 8 hex digits in any word")); | 
|---|
| 433 |  | 
|---|
| 434 | /* Add this chunk to the bignum. | 
|---|
| 435 | Shift things down 2 little digits.  */ | 
|---|
| 436 | know (LITTLENUM_NUMBER_OF_BITS == 16); | 
|---|
| 437 | for (i = min (num_little_digits + 1, SIZE_OF_LARGE_NUMBER - 1); | 
|---|
| 438 | i >= 2; | 
|---|
| 439 | i--) | 
|---|
| 440 | generic_bignum[i] = generic_bignum[i - 2]; | 
|---|
| 441 |  | 
|---|
| 442 | /* Add the new digits as the least significant new ones.  */ | 
|---|
| 443 | generic_bignum[0] = number & 0xffffffff; | 
|---|
| 444 | generic_bignum[1] = number >> 16; | 
|---|
| 445 | } | 
|---|
| 446 |  | 
|---|
| 447 | /* Again, c is char after number, input_line_pointer->after c.  */ | 
|---|
| 448 |  | 
|---|
| 449 | if (num_little_digits > SIZE_OF_LARGE_NUMBER - 1) | 
|---|
| 450 | num_little_digits = SIZE_OF_LARGE_NUMBER - 1; | 
|---|
| 451 |  | 
|---|
| 452 | assert (num_little_digits >= 4); | 
|---|
| 453 |  | 
|---|
| 454 | if (num_little_digits != 8) | 
|---|
| 455 | as_bad (_("a bignum with underscores must have exactly 4 words")); | 
|---|
| 456 |  | 
|---|
| 457 | /* We might have some leading zeros.  These can be trimmed to give | 
|---|
| 458 | us a change to fit this constant into a small number.  */ | 
|---|
| 459 | while (generic_bignum[num_little_digits - 1] == 0 | 
|---|
| 460 | && num_little_digits > 1) | 
|---|
| 461 | num_little_digits--; | 
|---|
| 462 |  | 
|---|
| 463 | if (num_little_digits <= 2) | 
|---|
| 464 | { | 
|---|
| 465 | /* will fit into 32 bits.  */ | 
|---|
| 466 | number = generic_bignum_to_int32 (); | 
|---|
| 467 | small = 1; | 
|---|
| 468 | } | 
|---|
| 469 | #ifdef BFD64 | 
|---|
| 470 | else if (num_little_digits <= 4) | 
|---|
| 471 | { | 
|---|
| 472 | /* Will fit into 64 bits.  */ | 
|---|
| 473 | number = generic_bignum_to_int64 (); | 
|---|
| 474 | small = 1; | 
|---|
| 475 | } | 
|---|
| 476 | #endif | 
|---|
| 477 | else | 
|---|
| 478 | { | 
|---|
| 479 | small = 0; | 
|---|
| 480 |  | 
|---|
| 481 | /* Number of littlenums in the bignum.  */ | 
|---|
| 482 | number = num_little_digits; | 
|---|
| 483 | } | 
|---|
| 484 | } | 
|---|
| 485 | else if (!small) | 
|---|
| 486 | { | 
|---|
| 487 | /* We saw a lot of digits. manufacture a bignum the hard way.  */ | 
|---|
| 488 | LITTLENUM_TYPE *leader;   /* -> high order littlenum of the bignum.  */ | 
|---|
| 489 | LITTLENUM_TYPE *pointer;  /* -> littlenum we are frobbing now.  */ | 
|---|
| 490 | long carry; | 
|---|
| 491 |  | 
|---|
| 492 | leader = generic_bignum; | 
|---|
| 493 | generic_bignum[0] = 0; | 
|---|
| 494 | generic_bignum[1] = 0; | 
|---|
| 495 | generic_bignum[2] = 0; | 
|---|
| 496 | generic_bignum[3] = 0; | 
|---|
| 497 | input_line_pointer = start;       /* -> 1st digit.  */ | 
|---|
| 498 | c = *input_line_pointer++; | 
|---|
| 499 | for (; (carry = hex_value (c)) < maxdig; c = *input_line_pointer++) | 
|---|
| 500 | { | 
|---|
| 501 | for (pointer = generic_bignum; pointer <= leader; pointer++) | 
|---|
| 502 | { | 
|---|
| 503 | long work; | 
|---|
| 504 |  | 
|---|
| 505 | work = carry + radix * *pointer; | 
|---|
| 506 | *pointer = work & LITTLENUM_MASK; | 
|---|
| 507 | carry = work >> LITTLENUM_NUMBER_OF_BITS; | 
|---|
| 508 | } | 
|---|
| 509 | if (carry) | 
|---|
| 510 | { | 
|---|
| 511 | if (leader < generic_bignum + SIZE_OF_LARGE_NUMBER - 1) | 
|---|
| 512 | { | 
|---|
| 513 | /* Room to grow a longer bignum.  */ | 
|---|
| 514 | *++leader = carry; | 
|---|
| 515 | } | 
|---|
| 516 | } | 
|---|
| 517 | } | 
|---|
| 518 | /* Again, c is char after number.  */ | 
|---|
| 519 | /* input_line_pointer -> after c.  */ | 
|---|
| 520 | know (LITTLENUM_NUMBER_OF_BITS == 16); | 
|---|
| 521 | if (leader < generic_bignum + 2) | 
|---|
| 522 | { | 
|---|
| 523 | /* Will fit into 32 bits.  */ | 
|---|
| 524 | number = generic_bignum_to_int32 (); | 
|---|
| 525 | small = 1; | 
|---|
| 526 | } | 
|---|
| 527 | #ifdef BFD64 | 
|---|
| 528 | else if (leader < generic_bignum + 4) | 
|---|
| 529 | { | 
|---|
| 530 | /* Will fit into 64 bits.  */ | 
|---|
| 531 | number = generic_bignum_to_int64 (); | 
|---|
| 532 | small = 1; | 
|---|
| 533 | } | 
|---|
| 534 | #endif | 
|---|
| 535 | else | 
|---|
| 536 | { | 
|---|
| 537 | /* Number of littlenums in the bignum.  */ | 
|---|
| 538 | number = leader - generic_bignum + 1; | 
|---|
| 539 | } | 
|---|
| 540 | } | 
|---|
| 541 |  | 
|---|
| 542 | if ((NUMBERS_WITH_SUFFIX || flag_m68k_mri) | 
|---|
| 543 | && suffix != NULL | 
|---|
| 544 | && input_line_pointer - 1 == suffix) | 
|---|
| 545 | c = *input_line_pointer++; | 
|---|
| 546 |  | 
|---|
| 547 | if (small) | 
|---|
| 548 | { | 
|---|
| 549 | /* Here with number, in correct radix. c is the next char. | 
|---|
| 550 | Note that unlike un*x, we allow "011f" "0x9f" to both mean | 
|---|
| 551 | the same as the (conventional) "9f". | 
|---|
| 552 | This is simply easier than checking for strict canonical | 
|---|
| 553 | form.  Syntax sux!  */ | 
|---|
| 554 |  | 
|---|
| 555 | if (LOCAL_LABELS_FB && c == 'b') | 
|---|
| 556 | { | 
|---|
| 557 | /* Backward ref to local label. | 
|---|
| 558 | Because it is backward, expect it to be defined.  */ | 
|---|
| 559 | /* Construct a local label.  */ | 
|---|
| 560 | name = fb_label_name ((int) number, 0); | 
|---|
| 561 |  | 
|---|
| 562 | /* Seen before, or symbol is defined: OK.  */ | 
|---|
| 563 | symbolP = symbol_find (name); | 
|---|
| 564 | if ((symbolP != NULL) && (S_IS_DEFINED (symbolP))) | 
|---|
| 565 | { | 
|---|
| 566 | /* Local labels are never absolute.  Don't waste time | 
|---|
| 567 | checking absoluteness.  */ | 
|---|
| 568 | know (SEG_NORMAL (S_GET_SEGMENT (symbolP))); | 
|---|
| 569 |  | 
|---|
| 570 | expressionP->X_op = O_symbol; | 
|---|
| 571 | expressionP->X_add_symbol = symbolP; | 
|---|
| 572 | } | 
|---|
| 573 | else | 
|---|
| 574 | { | 
|---|
| 575 | /* Either not seen or not defined.  */ | 
|---|
| 576 | /* @@ Should print out the original string instead of | 
|---|
| 577 | the parsed number.  */ | 
|---|
| 578 | as_bad (_("backward ref to unknown label \"%d:\""), | 
|---|
| 579 | (int) number); | 
|---|
| 580 | expressionP->X_op = O_constant; | 
|---|
| 581 | } | 
|---|
| 582 |  | 
|---|
| 583 | expressionP->X_add_number = 0; | 
|---|
| 584 | }                       /* case 'b' */ | 
|---|
| 585 | else if (LOCAL_LABELS_FB && c == 'f') | 
|---|
| 586 | { | 
|---|
| 587 | /* Forward reference.  Expect symbol to be undefined or | 
|---|
| 588 | unknown.  undefined: seen it before.  unknown: never seen | 
|---|
| 589 | it before. | 
|---|
| 590 |  | 
|---|
| 591 | Construct a local label name, then an undefined symbol. | 
|---|
| 592 | Don't create a xseg frag for it: caller may do that. | 
|---|
| 593 | Just return it as never seen before.  */ | 
|---|
| 594 | name = fb_label_name ((int) number, 1); | 
|---|
| 595 | symbolP = symbol_find_or_make (name); | 
|---|
| 596 | /* We have no need to check symbol properties.  */ | 
|---|
| 597 | #ifndef many_segments | 
|---|
| 598 | /* Since "know" puts its arg into a "string", we | 
|---|
| 599 | can't have newlines in the argument.  */ | 
|---|
| 600 | know (S_GET_SEGMENT (symbolP) == undefined_section || S_GET_SEGMENT (symbolP) == text_section || S_GET_SEGMENT (symbolP) == data_section); | 
|---|
| 601 | #endif | 
|---|
| 602 | expressionP->X_op = O_symbol; | 
|---|
| 603 | expressionP->X_add_symbol = symbolP; | 
|---|
| 604 | expressionP->X_add_number = 0; | 
|---|
| 605 | }                       /* case 'f' */ | 
|---|
| 606 | else if (LOCAL_LABELS_DOLLAR && c == '$') | 
|---|
| 607 | { | 
|---|
| 608 | /* If the dollar label is *currently* defined, then this is just | 
|---|
| 609 | another reference to it.  If it is not *currently* defined, | 
|---|
| 610 | then this is a fresh instantiation of that number, so create | 
|---|
| 611 | it.  */ | 
|---|
| 612 |  | 
|---|
| 613 | if (dollar_label_defined ((long) number)) | 
|---|
| 614 | { | 
|---|
| 615 | name = dollar_label_name ((long) number, 0); | 
|---|
| 616 | symbolP = symbol_find (name); | 
|---|
| 617 | know (symbolP != NULL); | 
|---|
| 618 | } | 
|---|
| 619 | else | 
|---|
| 620 | { | 
|---|
| 621 | name = dollar_label_name ((long) number, 1); | 
|---|
| 622 | symbolP = symbol_find_or_make (name); | 
|---|
| 623 | } | 
|---|
| 624 |  | 
|---|
| 625 | expressionP->X_op = O_symbol; | 
|---|
| 626 | expressionP->X_add_symbol = symbolP; | 
|---|
| 627 | expressionP->X_add_number = 0; | 
|---|
| 628 | }                       /* case '$' */ | 
|---|
| 629 | else | 
|---|
| 630 | { | 
|---|
| 631 | expressionP->X_op = O_constant; | 
|---|
| 632 | #ifdef TARGET_WORD_SIZE | 
|---|
| 633 | /* Sign extend NUMBER.  */ | 
|---|
| 634 | number |= (-(number >> (TARGET_WORD_SIZE - 1))) << (TARGET_WORD_SIZE - 1); | 
|---|
| 635 | #endif | 
|---|
| 636 | expressionP->X_add_number = number; | 
|---|
| 637 | input_line_pointer--; /* Restore following character.  */ | 
|---|
| 638 | }                       /* Really just a number.  */ | 
|---|
| 639 | } | 
|---|
| 640 | else | 
|---|
| 641 | { | 
|---|
| 642 | /* Not a small number.  */ | 
|---|
| 643 | expressionP->X_op = O_big; | 
|---|
| 644 | expressionP->X_add_number = number;       /* Number of littlenums.  */ | 
|---|
| 645 | input_line_pointer--;     /* -> char following number.  */ | 
|---|
| 646 | } | 
|---|
| 647 | } | 
|---|
| 648 |  | 
|---|
| 649 | /* Parse an MRI multi character constant.  */ | 
|---|
| 650 |  | 
|---|
| 651 | static void | 
|---|
| 652 | mri_char_constant (expressionP) | 
|---|
| 653 | expressionS *expressionP; | 
|---|
| 654 | { | 
|---|
| 655 | int i; | 
|---|
| 656 |  | 
|---|
| 657 | if (*input_line_pointer == '\'' | 
|---|
| 658 | && input_line_pointer[1] != '\'') | 
|---|
| 659 | { | 
|---|
| 660 | expressionP->X_op = O_constant; | 
|---|
| 661 | expressionP->X_add_number = 0; | 
|---|
| 662 | return; | 
|---|
| 663 | } | 
|---|
| 664 |  | 
|---|
| 665 | /* In order to get the correct byte ordering, we must build the | 
|---|
| 666 | number in reverse.  */ | 
|---|
| 667 | for (i = SIZE_OF_LARGE_NUMBER - 1; i >= 0; i--) | 
|---|
| 668 | { | 
|---|
| 669 | int j; | 
|---|
| 670 |  | 
|---|
| 671 | generic_bignum[i] = 0; | 
|---|
| 672 | for (j = 0; j < CHARS_PER_LITTLENUM; j++) | 
|---|
| 673 | { | 
|---|
| 674 | if (*input_line_pointer == '\'') | 
|---|
| 675 | { | 
|---|
| 676 | if (input_line_pointer[1] != '\'') | 
|---|
| 677 | break; | 
|---|
| 678 | ++input_line_pointer; | 
|---|
| 679 | } | 
|---|
| 680 | generic_bignum[i] <<= 8; | 
|---|
| 681 | generic_bignum[i] += *input_line_pointer; | 
|---|
| 682 | ++input_line_pointer; | 
|---|
| 683 | } | 
|---|
| 684 |  | 
|---|
| 685 | if (i < SIZE_OF_LARGE_NUMBER - 1) | 
|---|
| 686 | { | 
|---|
| 687 | /* If there is more than one littlenum, left justify the | 
|---|
| 688 | last one to make it match the earlier ones.  If there is | 
|---|
| 689 | only one, we can just use the value directly.  */ | 
|---|
| 690 | for (; j < CHARS_PER_LITTLENUM; j++) | 
|---|
| 691 | generic_bignum[i] <<= 8; | 
|---|
| 692 | } | 
|---|
| 693 |  | 
|---|
| 694 | if (*input_line_pointer == '\'' | 
|---|
| 695 | && input_line_pointer[1] != '\'') | 
|---|
| 696 | break; | 
|---|
| 697 | } | 
|---|
| 698 |  | 
|---|
| 699 | if (i < 0) | 
|---|
| 700 | { | 
|---|
| 701 | as_bad (_("character constant too large")); | 
|---|
| 702 | i = 0; | 
|---|
| 703 | } | 
|---|
| 704 |  | 
|---|
| 705 | if (i > 0) | 
|---|
| 706 | { | 
|---|
| 707 | int c; | 
|---|
| 708 | int j; | 
|---|
| 709 |  | 
|---|
| 710 | c = SIZE_OF_LARGE_NUMBER - i; | 
|---|
| 711 | for (j = 0; j < c; j++) | 
|---|
| 712 | generic_bignum[j] = generic_bignum[i + j]; | 
|---|
| 713 | i = c; | 
|---|
| 714 | } | 
|---|
| 715 |  | 
|---|
| 716 | know (LITTLENUM_NUMBER_OF_BITS == 16); | 
|---|
| 717 | if (i > 2) | 
|---|
| 718 | { | 
|---|
| 719 | expressionP->X_op = O_big; | 
|---|
| 720 | expressionP->X_add_number = i; | 
|---|
| 721 | } | 
|---|
| 722 | else | 
|---|
| 723 | { | 
|---|
| 724 | expressionP->X_op = O_constant; | 
|---|
| 725 | if (i < 2) | 
|---|
| 726 | expressionP->X_add_number = generic_bignum[0] & LITTLENUM_MASK; | 
|---|
| 727 | else | 
|---|
| 728 | expressionP->X_add_number = | 
|---|
| 729 | (((generic_bignum[1] & LITTLENUM_MASK) | 
|---|
| 730 | << LITTLENUM_NUMBER_OF_BITS) | 
|---|
| 731 | | (generic_bignum[0] & LITTLENUM_MASK)); | 
|---|
| 732 | } | 
|---|
| 733 |  | 
|---|
| 734 | /* Skip the final closing quote.  */ | 
|---|
| 735 | ++input_line_pointer; | 
|---|
| 736 | } | 
|---|
| 737 |  | 
|---|
| 738 | /* Return an expression representing the current location.  This | 
|---|
| 739 | handles the magic symbol `.'.  */ | 
|---|
| 740 |  | 
|---|
| 741 | static void | 
|---|
| 742 | current_location (expressionp) | 
|---|
| 743 | expressionS *expressionp; | 
|---|
| 744 | { | 
|---|
| 745 | if (now_seg == absolute_section) | 
|---|
| 746 | { | 
|---|
| 747 | expressionp->X_op = O_constant; | 
|---|
| 748 | expressionp->X_add_number = abs_section_offset; | 
|---|
| 749 | } | 
|---|
| 750 | else | 
|---|
| 751 | { | 
|---|
| 752 | symbolS *symbolp; | 
|---|
| 753 |  | 
|---|
| 754 | symbolp = symbol_new (FAKE_LABEL_NAME, now_seg, | 
|---|
| 755 | (valueT) frag_now_fix (), | 
|---|
| 756 | frag_now); | 
|---|
| 757 | expressionp->X_op = O_symbol; | 
|---|
| 758 | expressionp->X_add_symbol = symbolp; | 
|---|
| 759 | expressionp->X_add_number = 0; | 
|---|
| 760 | } | 
|---|
| 761 | } | 
|---|
| 762 |  | 
|---|
| 763 | /* In:  Input_line_pointer points to 1st char of operand, which may | 
|---|
| 764 | be a space. | 
|---|
| 765 |  | 
|---|
| 766 | Out: An expressionS. | 
|---|
| 767 | The operand may have been empty: in this case X_op == O_absent. | 
|---|
| 768 | Input_line_pointer->(next non-blank) char after operand.  */ | 
|---|
| 769 |  | 
|---|
| 770 | static segT | 
|---|
| 771 | operand (expressionP) | 
|---|
| 772 | expressionS *expressionP; | 
|---|
| 773 | { | 
|---|
| 774 | char c; | 
|---|
| 775 | symbolS *symbolP;     /* Points to symbol.  */ | 
|---|
| 776 | char *name;           /* Points to name of symbol.  */ | 
|---|
| 777 | segT segment; | 
|---|
| 778 |  | 
|---|
| 779 | /* All integers are regarded as unsigned unless they are negated. | 
|---|
| 780 | This is because the only thing which cares whether a number is | 
|---|
| 781 | unsigned is the code in emit_expr which extends constants into | 
|---|
| 782 | bignums.  It should only sign extend negative numbers, so that | 
|---|
| 783 | something like ``.quad 0x80000000'' is not sign extended even | 
|---|
| 784 | though it appears negative if valueT is 32 bits.  */ | 
|---|
| 785 | expressionP->X_unsigned = 1; | 
|---|
| 786 |  | 
|---|
| 787 | /* Digits, assume it is a bignum.  */ | 
|---|
| 788 |  | 
|---|
| 789 | SKIP_WHITESPACE ();           /* Leading whitespace is part of operand.  */ | 
|---|
| 790 | c = *input_line_pointer++;    /* input_line_pointer -> past char in c.  */ | 
|---|
| 791 |  | 
|---|
| 792 | if (is_end_of_line[(unsigned char) c]) | 
|---|
| 793 | goto eol; | 
|---|
| 794 |  | 
|---|
| 795 | switch (c) | 
|---|
| 796 | { | 
|---|
| 797 | case '1': | 
|---|
| 798 | case '2': | 
|---|
| 799 | case '3': | 
|---|
| 800 | case '4': | 
|---|
| 801 | case '5': | 
|---|
| 802 | case '6': | 
|---|
| 803 | case '7': | 
|---|
| 804 | case '8': | 
|---|
| 805 | case '9': | 
|---|
| 806 | input_line_pointer--; | 
|---|
| 807 |  | 
|---|
| 808 | integer_constant ((NUMBERS_WITH_SUFFIX || flag_m68k_mri) | 
|---|
| 809 | ? 0 : 10, | 
|---|
| 810 | expressionP); | 
|---|
| 811 | break; | 
|---|
| 812 |  | 
|---|
| 813 | #ifdef LITERAL_PREFIXDOLLAR_HEX | 
|---|
| 814 | case '$': | 
|---|
| 815 | /* $L is the start of a local label, not a hex constant.  */ | 
|---|
| 816 | if (* input_line_pointer == 'L') | 
|---|
| 817 | goto isname; | 
|---|
| 818 | integer_constant (16, expressionP); | 
|---|
| 819 | break; | 
|---|
| 820 | #endif | 
|---|
| 821 |  | 
|---|
| 822 | #ifdef LITERAL_PREFIXPERCENT_BIN | 
|---|
| 823 | case '%': | 
|---|
| 824 | integer_constant (2, expressionP); | 
|---|
| 825 | break; | 
|---|
| 826 | #endif | 
|---|
| 827 |  | 
|---|
| 828 | case '0': | 
|---|
| 829 | /* Non-decimal radix.  */ | 
|---|
| 830 |  | 
|---|
| 831 | if (NUMBERS_WITH_SUFFIX || flag_m68k_mri) | 
|---|
| 832 | { | 
|---|
| 833 | char *s; | 
|---|
| 834 |  | 
|---|
| 835 | /* Check for a hex or float constant.  */ | 
|---|
| 836 | for (s = input_line_pointer; hex_p (*s); s++) | 
|---|
| 837 | ; | 
|---|
| 838 | if (*s == 'h' || *s == 'H' || *input_line_pointer == '.') | 
|---|
| 839 | { | 
|---|
| 840 | --input_line_pointer; | 
|---|
| 841 | integer_constant (0, expressionP); | 
|---|
| 842 | break; | 
|---|
| 843 | } | 
|---|
| 844 | } | 
|---|
| 845 | c = *input_line_pointer; | 
|---|
| 846 | switch (c) | 
|---|
| 847 | { | 
|---|
| 848 | case 'o': | 
|---|
| 849 | case 'O': | 
|---|
| 850 | case 'q': | 
|---|
| 851 | case 'Q': | 
|---|
| 852 | case '8': | 
|---|
| 853 | case '9': | 
|---|
| 854 | if (NUMBERS_WITH_SUFFIX || flag_m68k_mri) | 
|---|
| 855 | { | 
|---|
| 856 | integer_constant (0, expressionP); | 
|---|
| 857 | break; | 
|---|
| 858 | } | 
|---|
| 859 | /* Fall through.  */ | 
|---|
| 860 | default: | 
|---|
| 861 | default_case: | 
|---|
| 862 | if (c && strchr (FLT_CHARS, c)) | 
|---|
| 863 | { | 
|---|
| 864 | input_line_pointer++; | 
|---|
| 865 | floating_constant (expressionP); | 
|---|
| 866 | expressionP->X_add_number = - TOLOWER (c); | 
|---|
| 867 | } | 
|---|
| 868 | else | 
|---|
| 869 | { | 
|---|
| 870 | /* The string was only zero.  */ | 
|---|
| 871 | expressionP->X_op = O_constant; | 
|---|
| 872 | expressionP->X_add_number = 0; | 
|---|
| 873 | } | 
|---|
| 874 |  | 
|---|
| 875 | break; | 
|---|
| 876 |  | 
|---|
| 877 | case 'x': | 
|---|
| 878 | case 'X': | 
|---|
| 879 | if (flag_m68k_mri) | 
|---|
| 880 | goto default_case; | 
|---|
| 881 | input_line_pointer++; | 
|---|
| 882 | integer_constant (16, expressionP); | 
|---|
| 883 | break; | 
|---|
| 884 |  | 
|---|
| 885 | case 'b': | 
|---|
| 886 | if (LOCAL_LABELS_FB && ! (flag_m68k_mri || NUMBERS_WITH_SUFFIX)) | 
|---|
| 887 | { | 
|---|
| 888 | /* This code used to check for '+' and '-' here, and, in | 
|---|
| 889 | some conditions, fall through to call | 
|---|
| 890 | integer_constant.  However, that didn't make sense, | 
|---|
| 891 | as integer_constant only accepts digits.  */ | 
|---|
| 892 | /* Some of our code elsewhere does permit digits greater | 
|---|
| 893 | than the expected base; for consistency, do the same | 
|---|
| 894 | here.  */ | 
|---|
| 895 | if (input_line_pointer[1] < '0' | 
|---|
| 896 | || input_line_pointer[1] > '9') | 
|---|
| 897 | { | 
|---|
| 898 | /* Parse this as a back reference to label 0.  */ | 
|---|
| 899 | input_line_pointer--; | 
|---|
| 900 | integer_constant (10, expressionP); | 
|---|
| 901 | break; | 
|---|
| 902 | } | 
|---|
| 903 | /* Otherwise, parse this as a binary number.  */ | 
|---|
| 904 | } | 
|---|
| 905 | /* Fall through.  */ | 
|---|
| 906 | case 'B': | 
|---|
| 907 | input_line_pointer++; | 
|---|
| 908 | if (flag_m68k_mri || NUMBERS_WITH_SUFFIX) | 
|---|
| 909 | goto default_case; | 
|---|
| 910 | integer_constant (2, expressionP); | 
|---|
| 911 | break; | 
|---|
| 912 |  | 
|---|
| 913 | case '0': | 
|---|
| 914 | case '1': | 
|---|
| 915 | case '2': | 
|---|
| 916 | case '3': | 
|---|
| 917 | case '4': | 
|---|
| 918 | case '5': | 
|---|
| 919 | case '6': | 
|---|
| 920 | case '7': | 
|---|
| 921 | integer_constant ((flag_m68k_mri || NUMBERS_WITH_SUFFIX) | 
|---|
| 922 | ? 0 : 8, | 
|---|
| 923 | expressionP); | 
|---|
| 924 | break; | 
|---|
| 925 |  | 
|---|
| 926 | case 'f': | 
|---|
| 927 | if (LOCAL_LABELS_FB) | 
|---|
| 928 | { | 
|---|
| 929 | /* If it says "0f" and it could possibly be a floating point | 
|---|
| 930 | number, make it one.  Otherwise, make it a local label, | 
|---|
| 931 | and try to deal with parsing the rest later.  */ | 
|---|
| 932 | if (!input_line_pointer[1] | 
|---|
| 933 | || (is_end_of_line[0xff & input_line_pointer[1]]) | 
|---|
| 934 | || strchr (FLT_CHARS, 'f') == NULL) | 
|---|
| 935 | goto is_0f_label; | 
|---|
| 936 | { | 
|---|
| 937 | char *cp = input_line_pointer + 1; | 
|---|
| 938 | int r = atof_generic (&cp, ".", EXP_CHARS, | 
|---|
| 939 | &generic_floating_point_number); | 
|---|
| 940 | switch (r) | 
|---|
| 941 | { | 
|---|
| 942 | case 0: | 
|---|
| 943 | case ERROR_EXPONENT_OVERFLOW: | 
|---|
| 944 | if (*cp == 'f' || *cp == 'b') | 
|---|
| 945 | /* Looks like a difference expression.  */ | 
|---|
| 946 | goto is_0f_label; | 
|---|
| 947 | else if (cp == input_line_pointer + 1) | 
|---|
| 948 | /* No characters has been accepted -- looks like | 
|---|
| 949 | end of operand.  */ | 
|---|
| 950 | goto is_0f_label; | 
|---|
| 951 | else | 
|---|
| 952 | goto is_0f_float; | 
|---|
| 953 | default: | 
|---|
| 954 | as_fatal (_("expr.c(operand): bad atof_generic return val %d"), | 
|---|
| 955 | r); | 
|---|
| 956 | } | 
|---|
| 957 | } | 
|---|
| 958 |  | 
|---|
| 959 | /* Okay, now we've sorted it out.  We resume at one of these | 
|---|
| 960 | two labels, depending on what we've decided we're probably | 
|---|
| 961 | looking at.  */ | 
|---|
| 962 | is_0f_label: | 
|---|
| 963 | input_line_pointer--; | 
|---|
| 964 | integer_constant (10, expressionP); | 
|---|
| 965 | break; | 
|---|
| 966 |  | 
|---|
| 967 | is_0f_float: | 
|---|
| 968 | /* Fall through.  */ | 
|---|
| 969 | ; | 
|---|
| 970 | } | 
|---|
| 971 |  | 
|---|
| 972 | case 'd': | 
|---|
| 973 | case 'D': | 
|---|
| 974 | if (flag_m68k_mri || NUMBERS_WITH_SUFFIX) | 
|---|
| 975 | { | 
|---|
| 976 | integer_constant (0, expressionP); | 
|---|
| 977 | break; | 
|---|
| 978 | } | 
|---|
| 979 | /* Fall through.  */ | 
|---|
| 980 | case 'F': | 
|---|
| 981 | case 'r': | 
|---|
| 982 | case 'e': | 
|---|
| 983 | case 'E': | 
|---|
| 984 | case 'g': | 
|---|
| 985 | case 'G': | 
|---|
| 986 | input_line_pointer++; | 
|---|
| 987 | floating_constant (expressionP); | 
|---|
| 988 | expressionP->X_add_number = - TOLOWER (c); | 
|---|
| 989 | break; | 
|---|
| 990 |  | 
|---|
| 991 | case '$': | 
|---|
| 992 | if (LOCAL_LABELS_DOLLAR) | 
|---|
| 993 | { | 
|---|
| 994 | integer_constant (10, expressionP); | 
|---|
| 995 | break; | 
|---|
| 996 | } | 
|---|
| 997 | else | 
|---|
| 998 | goto default_case; | 
|---|
| 999 | } | 
|---|
| 1000 |  | 
|---|
| 1001 | break; | 
|---|
| 1002 |  | 
|---|
| 1003 | case '(': | 
|---|
| 1004 | #ifndef NEED_INDEX_OPERATOR | 
|---|
| 1005 | case '[': | 
|---|
| 1006 | #endif | 
|---|
| 1007 | /* Didn't begin with digit & not a name.  */ | 
|---|
| 1008 | segment = expression (expressionP); | 
|---|
| 1009 | /* expression () will pass trailing whitespace.  */ | 
|---|
| 1010 | if ((c == '(' && *input_line_pointer != ')') | 
|---|
| 1011 | || (c == '[' && *input_line_pointer != ']')) | 
|---|
| 1012 | { | 
|---|
| 1013 | #ifdef RELAX_PAREN_GROUPING | 
|---|
| 1014 | if (c != '(') | 
|---|
| 1015 | #endif | 
|---|
| 1016 | as_bad (_("missing '%c'"), c == '(' ? ')' : ']'); | 
|---|
| 1017 | } | 
|---|
| 1018 | else | 
|---|
| 1019 | input_line_pointer++; | 
|---|
| 1020 | SKIP_WHITESPACE (); | 
|---|
| 1021 | /* Here with input_line_pointer -> char after "(...)".  */ | 
|---|
| 1022 | return segment; | 
|---|
| 1023 |  | 
|---|
| 1024 | #ifdef TC_M68K | 
|---|
| 1025 | case 'E': | 
|---|
| 1026 | if (! flag_m68k_mri || *input_line_pointer != '\'') | 
|---|
| 1027 | goto de_fault; | 
|---|
| 1028 | as_bad (_("EBCDIC constants are not supported")); | 
|---|
| 1029 | /* Fall through.  */ | 
|---|
| 1030 | case 'A': | 
|---|
| 1031 | if (! flag_m68k_mri || *input_line_pointer != '\'') | 
|---|
| 1032 | goto de_fault; | 
|---|
| 1033 | ++input_line_pointer; | 
|---|
| 1034 | /* Fall through.  */ | 
|---|
| 1035 | #endif | 
|---|
| 1036 | case '\'': | 
|---|
| 1037 | if (! flag_m68k_mri) | 
|---|
| 1038 | { | 
|---|
| 1039 | /* Warning: to conform to other people's assemblers NO | 
|---|
| 1040 | ESCAPEMENT is permitted for a single quote.  The next | 
|---|
| 1041 | character, parity errors and all, is taken as the value | 
|---|
| 1042 | of the operand.  VERY KINKY.  */ | 
|---|
| 1043 | expressionP->X_op = O_constant; | 
|---|
| 1044 | expressionP->X_add_number = *input_line_pointer++; | 
|---|
| 1045 | break; | 
|---|
| 1046 | } | 
|---|
| 1047 |  | 
|---|
| 1048 | mri_char_constant (expressionP); | 
|---|
| 1049 | break; | 
|---|
| 1050 |  | 
|---|
| 1051 | case '+': | 
|---|
| 1052 | (void) operand (expressionP); | 
|---|
| 1053 | break; | 
|---|
| 1054 |  | 
|---|
| 1055 | #ifdef TC_M68K | 
|---|
| 1056 | case '"': | 
|---|
| 1057 | /* Double quote is the bitwise not operator in MRI mode.  */ | 
|---|
| 1058 | if (! flag_m68k_mri) | 
|---|
| 1059 | goto de_fault; | 
|---|
| 1060 | /* Fall through.  */ | 
|---|
| 1061 | #endif | 
|---|
| 1062 | case '~': | 
|---|
| 1063 | /* '~' is permitted to start a label on the Delta.  */ | 
|---|
| 1064 | if (is_name_beginner (c)) | 
|---|
| 1065 | goto isname; | 
|---|
| 1066 | case '!': | 
|---|
| 1067 | case '-': | 
|---|
| 1068 | { | 
|---|
| 1069 | operand (expressionP); | 
|---|
| 1070 | if (expressionP->X_op == O_constant) | 
|---|
| 1071 | { | 
|---|
| 1072 | /* input_line_pointer -> char after operand.  */ | 
|---|
| 1073 | if (c == '-') | 
|---|
| 1074 | { | 
|---|
| 1075 | expressionP->X_add_number = - expressionP->X_add_number; | 
|---|
| 1076 | /* Notice: '-' may overflow: no warning is given. | 
|---|
| 1077 | This is compatible with other people's | 
|---|
| 1078 | assemblers.  Sigh.  */ | 
|---|
| 1079 | expressionP->X_unsigned = 0; | 
|---|
| 1080 | } | 
|---|
| 1081 | else if (c == '~' || c == '"') | 
|---|
| 1082 | expressionP->X_add_number = ~ expressionP->X_add_number; | 
|---|
| 1083 | else | 
|---|
| 1084 | expressionP->X_add_number = ! expressionP->X_add_number; | 
|---|
| 1085 | } | 
|---|
| 1086 | else if (expressionP->X_op == O_big | 
|---|
| 1087 | && expressionP->X_add_number <= 0 | 
|---|
| 1088 | && c == '-' | 
|---|
| 1089 | && (generic_floating_point_number.sign == '+' | 
|---|
| 1090 | || generic_floating_point_number.sign == 'P')) | 
|---|
| 1091 | { | 
|---|
| 1092 | /* Negative flonum (eg, -1.000e0).  */ | 
|---|
| 1093 | if (generic_floating_point_number.sign == '+') | 
|---|
| 1094 | generic_floating_point_number.sign = '-'; | 
|---|
| 1095 | else | 
|---|
| 1096 | generic_floating_point_number.sign = 'N'; | 
|---|
| 1097 | } | 
|---|
| 1098 | else if (expressionP->X_op != O_illegal | 
|---|
| 1099 | && expressionP->X_op != O_absent) | 
|---|
| 1100 | { | 
|---|
| 1101 | expressionP->X_add_symbol = make_expr_symbol (expressionP); | 
|---|
| 1102 | if (c == '-') | 
|---|
| 1103 | expressionP->X_op = O_uminus; | 
|---|
| 1104 | else if (c == '~' || c == '"') | 
|---|
| 1105 | expressionP->X_op = O_bit_not; | 
|---|
| 1106 | else | 
|---|
| 1107 | expressionP->X_op = O_logical_not; | 
|---|
| 1108 | expressionP->X_add_number = 0; | 
|---|
| 1109 | } | 
|---|
| 1110 | else | 
|---|
| 1111 | as_warn (_("Unary operator %c ignored because bad operand follows"), | 
|---|
| 1112 | c); | 
|---|
| 1113 | } | 
|---|
| 1114 | break; | 
|---|
| 1115 |  | 
|---|
| 1116 | #if defined (DOLLAR_DOT) || defined (TC_M68K) | 
|---|
| 1117 | case '$': | 
|---|
| 1118 | /* '$' is the program counter when in MRI mode, or when | 
|---|
| 1119 | DOLLAR_DOT is defined.  */ | 
|---|
| 1120 | #ifndef DOLLAR_DOT | 
|---|
| 1121 | if (! flag_m68k_mri) | 
|---|
| 1122 | goto de_fault; | 
|---|
| 1123 | #endif | 
|---|
| 1124 | if (flag_m68k_mri && hex_p (*input_line_pointer)) | 
|---|
| 1125 | { | 
|---|
| 1126 | /* In MRI mode, '$' is also used as the prefix for a | 
|---|
| 1127 | hexadecimal constant.  */ | 
|---|
| 1128 | integer_constant (16, expressionP); | 
|---|
| 1129 | break; | 
|---|
| 1130 | } | 
|---|
| 1131 |  | 
|---|
| 1132 | if (is_part_of_name (*input_line_pointer)) | 
|---|
| 1133 | goto isname; | 
|---|
| 1134 |  | 
|---|
| 1135 | current_location (expressionP); | 
|---|
| 1136 | break; | 
|---|
| 1137 | #endif | 
|---|
| 1138 |  | 
|---|
| 1139 | case '.': | 
|---|
| 1140 | if (!is_part_of_name (*input_line_pointer)) | 
|---|
| 1141 | { | 
|---|
| 1142 | current_location (expressionP); | 
|---|
| 1143 | break; | 
|---|
| 1144 | } | 
|---|
| 1145 | else if ((strncasecmp (input_line_pointer, "startof.", 8) == 0 | 
|---|
| 1146 | && ! is_part_of_name (input_line_pointer[8])) | 
|---|
| 1147 | || (strncasecmp (input_line_pointer, "sizeof.", 7) == 0 | 
|---|
| 1148 | && ! is_part_of_name (input_line_pointer[7]))) | 
|---|
| 1149 | { | 
|---|
| 1150 | int start; | 
|---|
| 1151 |  | 
|---|
| 1152 | start = (input_line_pointer[1] == 't' | 
|---|
| 1153 | || input_line_pointer[1] == 'T'); | 
|---|
| 1154 | input_line_pointer += start ? 8 : 7; | 
|---|
| 1155 | SKIP_WHITESPACE (); | 
|---|
| 1156 | if (*input_line_pointer != '(') | 
|---|
| 1157 | as_bad (_("syntax error in .startof. or .sizeof.")); | 
|---|
| 1158 | else | 
|---|
| 1159 | { | 
|---|
| 1160 | char *buf; | 
|---|
| 1161 |  | 
|---|
| 1162 | ++input_line_pointer; | 
|---|
| 1163 | SKIP_WHITESPACE (); | 
|---|
| 1164 | name = input_line_pointer; | 
|---|
| 1165 | c = get_symbol_end (); | 
|---|
| 1166 |  | 
|---|
| 1167 | buf = (char *) xmalloc (strlen (name) + 10); | 
|---|
| 1168 | if (start) | 
|---|
| 1169 | sprintf (buf, ".startof.%s", name); | 
|---|
| 1170 | else | 
|---|
| 1171 | sprintf (buf, ".sizeof.%s", name); | 
|---|
| 1172 | symbolP = symbol_make (buf); | 
|---|
| 1173 | free (buf); | 
|---|
| 1174 |  | 
|---|
| 1175 | expressionP->X_op = O_symbol; | 
|---|
| 1176 | expressionP->X_add_symbol = symbolP; | 
|---|
| 1177 | expressionP->X_add_number = 0; | 
|---|
| 1178 |  | 
|---|
| 1179 | *input_line_pointer = c; | 
|---|
| 1180 | SKIP_WHITESPACE (); | 
|---|
| 1181 | if (*input_line_pointer != ')') | 
|---|
| 1182 | as_bad (_("syntax error in .startof. or .sizeof.")); | 
|---|
| 1183 | else | 
|---|
| 1184 | ++input_line_pointer; | 
|---|
| 1185 | } | 
|---|
| 1186 | break; | 
|---|
| 1187 | } | 
|---|
| 1188 | else | 
|---|
| 1189 | { | 
|---|
| 1190 | goto isname; | 
|---|
| 1191 | } | 
|---|
| 1192 |  | 
|---|
| 1193 | case ',': | 
|---|
| 1194 | eol: | 
|---|
| 1195 | /* Can't imagine any other kind of operand.  */ | 
|---|
| 1196 | expressionP->X_op = O_absent; | 
|---|
| 1197 | input_line_pointer--; | 
|---|
| 1198 | break; | 
|---|
| 1199 |  | 
|---|
| 1200 | #ifdef TC_M68K | 
|---|
| 1201 | case '%': | 
|---|
| 1202 | if (! flag_m68k_mri) | 
|---|
| 1203 | goto de_fault; | 
|---|
| 1204 | integer_constant (2, expressionP); | 
|---|
| 1205 | break; | 
|---|
| 1206 |  | 
|---|
| 1207 | case '@': | 
|---|
| 1208 | if (! flag_m68k_mri) | 
|---|
| 1209 | goto de_fault; | 
|---|
| 1210 | integer_constant (8, expressionP); | 
|---|
| 1211 | break; | 
|---|
| 1212 |  | 
|---|
| 1213 | case ':': | 
|---|
| 1214 | if (! flag_m68k_mri) | 
|---|
| 1215 | goto de_fault; | 
|---|
| 1216 |  | 
|---|
| 1217 | /* In MRI mode, this is a floating point constant represented | 
|---|
| 1218 | using hexadecimal digits.  */ | 
|---|
| 1219 |  | 
|---|
| 1220 | ++input_line_pointer; | 
|---|
| 1221 | integer_constant (16, expressionP); | 
|---|
| 1222 | break; | 
|---|
| 1223 |  | 
|---|
| 1224 | case '*': | 
|---|
| 1225 | if (! flag_m68k_mri || is_part_of_name (*input_line_pointer)) | 
|---|
| 1226 | goto de_fault; | 
|---|
| 1227 |  | 
|---|
| 1228 | current_location (expressionP); | 
|---|
| 1229 | break; | 
|---|
| 1230 | #endif | 
|---|
| 1231 |  | 
|---|
| 1232 | default: | 
|---|
| 1233 | #ifdef TC_M68K | 
|---|
| 1234 | de_fault: | 
|---|
| 1235 | #endif | 
|---|
| 1236 | if (is_name_beginner (c)) /* Here if did not begin with a digit.  */ | 
|---|
| 1237 | { | 
|---|
| 1238 | /* Identifier begins here. | 
|---|
| 1239 | This is kludged for speed, so code is repeated.  */ | 
|---|
| 1240 | isname: | 
|---|
| 1241 | name = --input_line_pointer; | 
|---|
| 1242 | c = get_symbol_end (); | 
|---|
| 1243 |  | 
|---|
| 1244 | #ifdef md_parse_name | 
|---|
| 1245 | /* This is a hook for the backend to parse certain names | 
|---|
| 1246 | specially in certain contexts.  If a name always has a | 
|---|
| 1247 | specific value, it can often be handled by simply | 
|---|
| 1248 | entering it in the symbol table.  */ | 
|---|
| 1249 | if (md_parse_name (name, expressionP, &c)) | 
|---|
| 1250 | { | 
|---|
| 1251 | *input_line_pointer = c; | 
|---|
| 1252 | break; | 
|---|
| 1253 | } | 
|---|
| 1254 | #endif | 
|---|
| 1255 |  | 
|---|
| 1256 | #ifdef TC_I960 | 
|---|
| 1257 | /* The MRI i960 assembler permits | 
|---|
| 1258 | lda sizeof code,g13 | 
|---|
| 1259 | FIXME: This should use md_parse_name.  */ | 
|---|
| 1260 | if (flag_mri | 
|---|
| 1261 | && (strcasecmp (name, "sizeof") == 0 | 
|---|
| 1262 | || strcasecmp (name, "startof") == 0)) | 
|---|
| 1263 | { | 
|---|
| 1264 | int start; | 
|---|
| 1265 | char *buf; | 
|---|
| 1266 |  | 
|---|
| 1267 | start = (name[1] == 't' | 
|---|
| 1268 | || name[1] == 'T'); | 
|---|
| 1269 |  | 
|---|
| 1270 | *input_line_pointer = c; | 
|---|
| 1271 | SKIP_WHITESPACE (); | 
|---|
| 1272 |  | 
|---|
| 1273 | name = input_line_pointer; | 
|---|
| 1274 | c = get_symbol_end (); | 
|---|
| 1275 |  | 
|---|
| 1276 | buf = (char *) xmalloc (strlen (name) + 10); | 
|---|
| 1277 | if (start) | 
|---|
| 1278 | sprintf (buf, ".startof.%s", name); | 
|---|
| 1279 | else | 
|---|
| 1280 | sprintf (buf, ".sizeof.%s", name); | 
|---|
| 1281 | symbolP = symbol_make (buf); | 
|---|
| 1282 | free (buf); | 
|---|
| 1283 |  | 
|---|
| 1284 | expressionP->X_op = O_symbol; | 
|---|
| 1285 | expressionP->X_add_symbol = symbolP; | 
|---|
| 1286 | expressionP->X_add_number = 0; | 
|---|
| 1287 |  | 
|---|
| 1288 | *input_line_pointer = c; | 
|---|
| 1289 | SKIP_WHITESPACE (); | 
|---|
| 1290 |  | 
|---|
| 1291 | break; | 
|---|
| 1292 | } | 
|---|
| 1293 | #endif | 
|---|
| 1294 |  | 
|---|
| 1295 | symbolP = symbol_find_or_make (name); | 
|---|
| 1296 |  | 
|---|
| 1297 | /* If we have an absolute symbol or a reg, then we know its | 
|---|
| 1298 | value now.  */ | 
|---|
| 1299 | segment = S_GET_SEGMENT (symbolP); | 
|---|
| 1300 | if (segment == absolute_section) | 
|---|
| 1301 | { | 
|---|
| 1302 | expressionP->X_op = O_constant; | 
|---|
| 1303 | expressionP->X_add_number = S_GET_VALUE (symbolP); | 
|---|
| 1304 | } | 
|---|
| 1305 | else if (segment == reg_section) | 
|---|
| 1306 | { | 
|---|
| 1307 | expressionP->X_op = O_register; | 
|---|
| 1308 | expressionP->X_add_number = S_GET_VALUE (symbolP); | 
|---|
| 1309 | } | 
|---|
| 1310 | else | 
|---|
| 1311 | { | 
|---|
| 1312 | expressionP->X_op = O_symbol; | 
|---|
| 1313 | expressionP->X_add_symbol = symbolP; | 
|---|
| 1314 | expressionP->X_add_number = 0; | 
|---|
| 1315 | } | 
|---|
| 1316 | *input_line_pointer = c; | 
|---|
| 1317 | } | 
|---|
| 1318 | else | 
|---|
| 1319 | { | 
|---|
| 1320 | /* Let the target try to parse it.  Success is indicated by changing | 
|---|
| 1321 | the X_op field to something other than O_absent and pointing | 
|---|
| 1322 | input_line_pointer past the expression.  If it can't parse the | 
|---|
| 1323 | expression, X_op and input_line_pointer should be unchanged.  */ | 
|---|
| 1324 | expressionP->X_op = O_absent; | 
|---|
| 1325 | --input_line_pointer; | 
|---|
| 1326 | md_operand (expressionP); | 
|---|
| 1327 | if (expressionP->X_op == O_absent) | 
|---|
| 1328 | { | 
|---|
| 1329 | ++input_line_pointer; | 
|---|
| 1330 | as_bad (_("bad expression")); | 
|---|
| 1331 | expressionP->X_op = O_constant; | 
|---|
| 1332 | expressionP->X_add_number = 0; | 
|---|
| 1333 | } | 
|---|
| 1334 | } | 
|---|
| 1335 | break; | 
|---|
| 1336 | } | 
|---|
| 1337 |  | 
|---|
| 1338 | /* It is more 'efficient' to clean up the expressionS when they are | 
|---|
| 1339 | created.  Doing it here saves lines of code.  */ | 
|---|
| 1340 | clean_up_expression (expressionP); | 
|---|
| 1341 | SKIP_WHITESPACE ();           /* -> 1st char after operand.  */ | 
|---|
| 1342 | know (*input_line_pointer != ' '); | 
|---|
| 1343 |  | 
|---|
| 1344 | /* The PA port needs this information.  */ | 
|---|
| 1345 | if (expressionP->X_add_symbol) | 
|---|
| 1346 | symbol_mark_used (expressionP->X_add_symbol); | 
|---|
| 1347 |  | 
|---|
| 1348 | switch (expressionP->X_op) | 
|---|
| 1349 | { | 
|---|
| 1350 | default: | 
|---|
| 1351 | return absolute_section; | 
|---|
| 1352 | case O_symbol: | 
|---|
| 1353 | return S_GET_SEGMENT (expressionP->X_add_symbol); | 
|---|
| 1354 | case O_register: | 
|---|
| 1355 | return reg_section; | 
|---|
| 1356 | } | 
|---|
| 1357 | } | 
|---|
| 1358 |  | 
|---|
| 1359 |  | 
|---|
| 1360 | /* Internal.  Simplify a struct expression for use by expr ().  */ | 
|---|
| 1361 |  | 
|---|
| 1362 | /* In:  address of an expressionS. | 
|---|
| 1363 | The X_op field of the expressionS may only take certain values. | 
|---|
| 1364 | Elsewise we waste time special-case testing. Sigh. Ditto SEG_ABSENT. | 
|---|
| 1365 |  | 
|---|
| 1366 | Out: expressionS may have been modified: | 
|---|
| 1367 | Unused fields zeroed to help expr ().  */ | 
|---|
| 1368 |  | 
|---|
| 1369 | static void | 
|---|
| 1370 | clean_up_expression (expressionP) | 
|---|
| 1371 | expressionS *expressionP; | 
|---|
| 1372 | { | 
|---|
| 1373 | switch (expressionP->X_op) | 
|---|
| 1374 | { | 
|---|
| 1375 | case O_illegal: | 
|---|
| 1376 | case O_absent: | 
|---|
| 1377 | expressionP->X_add_number = 0; | 
|---|
| 1378 | /* Fall through.  */ | 
|---|
| 1379 | case O_big: | 
|---|
| 1380 | case O_constant: | 
|---|
| 1381 | case O_register: | 
|---|
| 1382 | expressionP->X_add_symbol = NULL; | 
|---|
| 1383 | /* Fall through.  */ | 
|---|
| 1384 | case O_symbol: | 
|---|
| 1385 | case O_uminus: | 
|---|
| 1386 | case O_bit_not: | 
|---|
| 1387 | expressionP->X_op_symbol = NULL; | 
|---|
| 1388 | break; | 
|---|
| 1389 | default: | 
|---|
| 1390 | break; | 
|---|
| 1391 | } | 
|---|
| 1392 | } | 
|---|
| 1393 |  | 
|---|
| 1394 |  | 
|---|
| 1395 | /* Expression parser.  */ | 
|---|
| 1396 |  | 
|---|
| 1397 | /* We allow an empty expression, and just assume (absolute,0) silently. | 
|---|
| 1398 | Unary operators and parenthetical expressions are treated as operands. | 
|---|
| 1399 | As usual, Q==quantity==operand, O==operator, X==expression mnemonics. | 
|---|
| 1400 |  | 
|---|
| 1401 | We used to do an aho/ullman shift-reduce parser, but the logic got so | 
|---|
| 1402 | warped that I flushed it and wrote a recursive-descent parser instead. | 
|---|
| 1403 | Now things are stable, would anybody like to write a fast parser? | 
|---|
| 1404 | Most expressions are either register (which does not even reach here) | 
|---|
| 1405 | or 1 symbol. Then "symbol+constant" and "symbol-symbol" are common. | 
|---|
| 1406 | So I guess it doesn't really matter how inefficient more complex expressions | 
|---|
| 1407 | are parsed. | 
|---|
| 1408 |  | 
|---|
| 1409 | After expr(RANK,resultP) input_line_pointer->operator of rank <= RANK. | 
|---|
| 1410 | Also, we have consumed any leading or trailing spaces (operand does that) | 
|---|
| 1411 | and done all intervening operators. | 
|---|
| 1412 |  | 
|---|
| 1413 | This returns the segment of the result, which will be | 
|---|
| 1414 | absolute_section or the segment of a symbol.  */ | 
|---|
| 1415 |  | 
|---|
| 1416 | #undef __ | 
|---|
| 1417 | #define __ O_illegal | 
|---|
| 1418 |  | 
|---|
| 1419 | /* Maps ASCII -> operators.  */ | 
|---|
| 1420 | static const operatorT op_encoding[256] = { | 
|---|
| 1421 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, | 
|---|
| 1422 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, | 
|---|
| 1423 |  | 
|---|
| 1424 | __, O_bit_or_not, __, __, __, O_modulus, O_bit_and, __, | 
|---|
| 1425 | __, __, O_multiply, O_add, __, O_subtract, __, O_divide, | 
|---|
| 1426 | __, __, __, __, __, __, __, __, | 
|---|
| 1427 | __, __, __, __, O_lt, __, O_gt, __, | 
|---|
| 1428 | __, __, __, __, __, __, __, __, | 
|---|
| 1429 | __, __, __, __, __, __, __, __, | 
|---|
| 1430 | __, __, __, __, __, __, __, __, | 
|---|
| 1431 | __, __, __, | 
|---|
| 1432 | #ifdef NEED_INDEX_OPERATOR | 
|---|
| 1433 | O_index, | 
|---|
| 1434 | #else | 
|---|
| 1435 | __, | 
|---|
| 1436 | #endif | 
|---|
| 1437 | __, __, O_bit_exclusive_or, __, | 
|---|
| 1438 | __, __, __, __, __, __, __, __, | 
|---|
| 1439 | __, __, __, __, __, __, __, __, | 
|---|
| 1440 | __, __, __, __, __, __, __, __, | 
|---|
| 1441 | __, __, __, __, O_bit_inclusive_or, __, __, __, | 
|---|
| 1442 |  | 
|---|
| 1443 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, | 
|---|
| 1444 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, | 
|---|
| 1445 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, | 
|---|
| 1446 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, | 
|---|
| 1447 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, | 
|---|
| 1448 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, | 
|---|
| 1449 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, | 
|---|
| 1450 | __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __ | 
|---|
| 1451 | }; | 
|---|
| 1452 |  | 
|---|
| 1453 | /* Rank Examples | 
|---|
| 1454 | 0    operand, (expression) | 
|---|
| 1455 | 1    || | 
|---|
| 1456 | 2    && | 
|---|
| 1457 | 3    == <> < <= >= > | 
|---|
| 1458 | 4    + - | 
|---|
| 1459 | 5    used for * / % in MRI mode | 
|---|
| 1460 | 6    & ^ ! | | 
|---|
| 1461 | 7    * / % << >> | 
|---|
| 1462 | 8    unary - unary ~ | 
|---|
| 1463 | */ | 
|---|
| 1464 | static operator_rankT op_rank[] = { | 
|---|
| 1465 | 0,    /* O_illegal */ | 
|---|
| 1466 | 0,    /* O_absent */ | 
|---|
| 1467 | 0,    /* O_constant */ | 
|---|
| 1468 | 0,    /* O_symbol */ | 
|---|
| 1469 | 0,    /* O_symbol_rva */ | 
|---|
| 1470 | 0,    /* O_register */ | 
|---|
| 1471 | 0,    /* O_big */ | 
|---|
| 1472 | 9,    /* O_uminus */ | 
|---|
| 1473 | 9,    /* O_bit_not */ | 
|---|
| 1474 | 9,    /* O_logical_not */ | 
|---|
| 1475 | 8,    /* O_multiply */ | 
|---|
| 1476 | 8,    /* O_divide */ | 
|---|
| 1477 | 8,    /* O_modulus */ | 
|---|
| 1478 | 8,    /* O_left_shift */ | 
|---|
| 1479 | 8,    /* O_right_shift */ | 
|---|
| 1480 | 7,    /* O_bit_inclusive_or */ | 
|---|
| 1481 | 7,    /* O_bit_or_not */ | 
|---|
| 1482 | 7,    /* O_bit_exclusive_or */ | 
|---|
| 1483 | 7,    /* O_bit_and */ | 
|---|
| 1484 | 5,    /* O_add */ | 
|---|
| 1485 | 5,    /* O_subtract */ | 
|---|
| 1486 | 4,    /* O_eq */ | 
|---|
| 1487 | 4,    /* O_ne */ | 
|---|
| 1488 | 4,    /* O_lt */ | 
|---|
| 1489 | 4,    /* O_le */ | 
|---|
| 1490 | 4,    /* O_ge */ | 
|---|
| 1491 | 4,    /* O_gt */ | 
|---|
| 1492 | 3,    /* O_logical_and */ | 
|---|
| 1493 | 2,    /* O_logical_or */ | 
|---|
| 1494 | 1,    /* O_index */ | 
|---|
| 1495 | 0,    /* O_md1 */ | 
|---|
| 1496 | 0,    /* O_md2 */ | 
|---|
| 1497 | 0,    /* O_md3 */ | 
|---|
| 1498 | 0,    /* O_md4 */ | 
|---|
| 1499 | 0,    /* O_md5 */ | 
|---|
| 1500 | 0,    /* O_md6 */ | 
|---|
| 1501 | 0,    /* O_md7 */ | 
|---|
| 1502 | 0,    /* O_md8 */ | 
|---|
| 1503 | 0,    /* O_md9 */ | 
|---|
| 1504 | 0,    /* O_md10 */ | 
|---|
| 1505 | 0,    /* O_md11 */ | 
|---|
| 1506 | 0,    /* O_md12 */ | 
|---|
| 1507 | 0,    /* O_md13 */ | 
|---|
| 1508 | 0,    /* O_md14 */ | 
|---|
| 1509 | 0,    /* O_md15 */ | 
|---|
| 1510 | 0,    /* O_md16 */ | 
|---|
| 1511 | }; | 
|---|
| 1512 |  | 
|---|
| 1513 | /* Unfortunately, in MRI mode for the m68k, multiplication and | 
|---|
| 1514 | division have lower precedence than the bit wise operators.  This | 
|---|
| 1515 | function sets the operator precedences correctly for the current | 
|---|
| 1516 | mode.  Also, MRI uses a different bit_not operator, and this fixes | 
|---|
| 1517 | that as well.  */ | 
|---|
| 1518 |  | 
|---|
| 1519 | #define STANDARD_MUL_PRECEDENCE 8 | 
|---|
| 1520 | #define MRI_MUL_PRECEDENCE 6 | 
|---|
| 1521 |  | 
|---|
| 1522 | void | 
|---|
| 1523 | expr_set_precedence () | 
|---|
| 1524 | { | 
|---|
| 1525 | if (flag_m68k_mri) | 
|---|
| 1526 | { | 
|---|
| 1527 | op_rank[O_multiply] = MRI_MUL_PRECEDENCE; | 
|---|
| 1528 | op_rank[O_divide] = MRI_MUL_PRECEDENCE; | 
|---|
| 1529 | op_rank[O_modulus] = MRI_MUL_PRECEDENCE; | 
|---|
| 1530 | } | 
|---|
| 1531 | else | 
|---|
| 1532 | { | 
|---|
| 1533 | op_rank[O_multiply] = STANDARD_MUL_PRECEDENCE; | 
|---|
| 1534 | op_rank[O_divide] = STANDARD_MUL_PRECEDENCE; | 
|---|
| 1535 | op_rank[O_modulus] = STANDARD_MUL_PRECEDENCE; | 
|---|
| 1536 | } | 
|---|
| 1537 | } | 
|---|
| 1538 |  | 
|---|
| 1539 | /* Initialize the expression parser.  */ | 
|---|
| 1540 |  | 
|---|
| 1541 | void | 
|---|
| 1542 | expr_begin () | 
|---|
| 1543 | { | 
|---|
| 1544 | expr_set_precedence (); | 
|---|
| 1545 |  | 
|---|
| 1546 | /* Verify that X_op field is wide enough.  */ | 
|---|
| 1547 | { | 
|---|
| 1548 | expressionS e; | 
|---|
| 1549 | e.X_op = O_max; | 
|---|
| 1550 | assert (e.X_op == O_max); | 
|---|
| 1551 | } | 
|---|
| 1552 | } | 
|---|
| 1553 |  | 
|---|
| 1554 |  | 
|---|
| 1555 | /* Return the encoding for the operator at INPUT_LINE_POINTER, and | 
|---|
| 1556 | sets NUM_CHARS to the number of characters in the operator. | 
|---|
| 1557 | Does not advance INPUT_LINE_POINTER.  */ | 
|---|
| 1558 |  | 
|---|
| 1559 | static inline operatorT | 
|---|
| 1560 | operator (num_chars) | 
|---|
| 1561 | int *num_chars; | 
|---|
| 1562 | { | 
|---|
| 1563 | int c; | 
|---|
| 1564 | operatorT ret; | 
|---|
| 1565 |  | 
|---|
| 1566 | c = *input_line_pointer & 0xff; | 
|---|
| 1567 | *num_chars = 1; | 
|---|
| 1568 |  | 
|---|
| 1569 | if (is_end_of_line[c]) | 
|---|
| 1570 | return O_illegal; | 
|---|
| 1571 |  | 
|---|
| 1572 | switch (c) | 
|---|
| 1573 | { | 
|---|
| 1574 | default: | 
|---|
| 1575 | return op_encoding[c]; | 
|---|
| 1576 |  | 
|---|
| 1577 | case '<': | 
|---|
| 1578 | switch (input_line_pointer[1]) | 
|---|
| 1579 | { | 
|---|
| 1580 | default: | 
|---|
| 1581 | return op_encoding[c]; | 
|---|
| 1582 | case '<': | 
|---|
| 1583 | ret = O_left_shift; | 
|---|
| 1584 | break; | 
|---|
| 1585 | case '>': | 
|---|
| 1586 | ret = O_ne; | 
|---|
| 1587 | break; | 
|---|
| 1588 | case '=': | 
|---|
| 1589 | ret = O_le; | 
|---|
| 1590 | break; | 
|---|
| 1591 | } | 
|---|
| 1592 | *num_chars = 2; | 
|---|
| 1593 | return ret; | 
|---|
| 1594 |  | 
|---|
| 1595 | case '=': | 
|---|
| 1596 | if (input_line_pointer[1] != '=') | 
|---|
| 1597 | return op_encoding[c]; | 
|---|
| 1598 |  | 
|---|
| 1599 | *num_chars = 2; | 
|---|
| 1600 | return O_eq; | 
|---|
| 1601 |  | 
|---|
| 1602 | case '>': | 
|---|
| 1603 | switch (input_line_pointer[1]) | 
|---|
| 1604 | { | 
|---|
| 1605 | default: | 
|---|
| 1606 | return op_encoding[c]; | 
|---|
| 1607 | case '>': | 
|---|
| 1608 | ret = O_right_shift; | 
|---|
| 1609 | break; | 
|---|
| 1610 | case '=': | 
|---|
| 1611 | ret = O_ge; | 
|---|
| 1612 | break; | 
|---|
| 1613 | } | 
|---|
| 1614 | *num_chars = 2; | 
|---|
| 1615 | return ret; | 
|---|
| 1616 |  | 
|---|
| 1617 | case '!': | 
|---|
| 1618 | /* We accept !! as equivalent to ^ for MRI compatibility.  */ | 
|---|
| 1619 | if (input_line_pointer[1] != '!') | 
|---|
| 1620 | { | 
|---|
| 1621 | if (flag_m68k_mri) | 
|---|
| 1622 | return O_bit_inclusive_or; | 
|---|
| 1623 | return op_encoding[c]; | 
|---|
| 1624 | } | 
|---|
| 1625 | *num_chars = 2; | 
|---|
| 1626 | return O_bit_exclusive_or; | 
|---|
| 1627 |  | 
|---|
| 1628 | case '|': | 
|---|
| 1629 | if (input_line_pointer[1] != '|') | 
|---|
| 1630 | return op_encoding[c]; | 
|---|
| 1631 |  | 
|---|
| 1632 | *num_chars = 2; | 
|---|
| 1633 | return O_logical_or; | 
|---|
| 1634 |  | 
|---|
| 1635 | case '&': | 
|---|
| 1636 | if (input_line_pointer[1] != '&') | 
|---|
| 1637 | return op_encoding[c]; | 
|---|
| 1638 |  | 
|---|
| 1639 | *num_chars = 2; | 
|---|
| 1640 | return O_logical_and; | 
|---|
| 1641 | } | 
|---|
| 1642 |  | 
|---|
| 1643 | /* NOTREACHED  */ | 
|---|
| 1644 | } | 
|---|
| 1645 |  | 
|---|
| 1646 | /* Parse an expression.  */ | 
|---|
| 1647 |  | 
|---|
| 1648 | segT | 
|---|
| 1649 | expr (rankarg, resultP) | 
|---|
| 1650 | int rankarg;       /* Larger # is higher rank.  */ | 
|---|
| 1651 | expressionS *resultP;      /* Deliver result here.  */ | 
|---|
| 1652 | { | 
|---|
| 1653 | operator_rankT rank = (operator_rankT) rankarg; | 
|---|
| 1654 | segT retval; | 
|---|
| 1655 | expressionS right; | 
|---|
| 1656 | operatorT op_left; | 
|---|
| 1657 | operatorT op_right; | 
|---|
| 1658 | int op_chars; | 
|---|
| 1659 |  | 
|---|
| 1660 | know (rank >= 0); | 
|---|
| 1661 |  | 
|---|
| 1662 | /* Save the value of dot for the fixup code.  */ | 
|---|
| 1663 | if (rank == 0) | 
|---|
| 1664 | dot_value = frag_now_fix (); | 
|---|
| 1665 |  | 
|---|
| 1666 | retval = operand (resultP); | 
|---|
| 1667 |  | 
|---|
| 1668 | /* operand () gobbles spaces.  */ | 
|---|
| 1669 | know (*input_line_pointer != ' '); | 
|---|
| 1670 |  | 
|---|
| 1671 | op_left = operator (&op_chars); | 
|---|
| 1672 | while (op_left != O_illegal && op_rank[(int) op_left] > rank) | 
|---|
| 1673 | { | 
|---|
| 1674 | segT rightseg; | 
|---|
| 1675 |  | 
|---|
| 1676 | input_line_pointer += op_chars;   /* -> after operator.  */ | 
|---|
| 1677 |  | 
|---|
| 1678 | rightseg = expr (op_rank[(int) op_left], &right); | 
|---|
| 1679 | if (right.X_op == O_absent) | 
|---|
| 1680 | { | 
|---|
| 1681 | as_warn (_("missing operand; zero assumed")); | 
|---|
| 1682 | right.X_op = O_constant; | 
|---|
| 1683 | right.X_add_number = 0; | 
|---|
| 1684 | right.X_add_symbol = NULL; | 
|---|
| 1685 | right.X_op_symbol = NULL; | 
|---|
| 1686 | } | 
|---|
| 1687 |  | 
|---|
| 1688 | know (*input_line_pointer != ' '); | 
|---|
| 1689 |  | 
|---|
| 1690 | if (op_left == O_index) | 
|---|
| 1691 | { | 
|---|
| 1692 | if (*input_line_pointer != ']') | 
|---|
| 1693 | as_bad ("missing right bracket"); | 
|---|
| 1694 | else | 
|---|
| 1695 | { | 
|---|
| 1696 | ++input_line_pointer; | 
|---|
| 1697 | SKIP_WHITESPACE (); | 
|---|
| 1698 | } | 
|---|
| 1699 | } | 
|---|
| 1700 |  | 
|---|
| 1701 | op_right = operator (&op_chars); | 
|---|
| 1702 |  | 
|---|
| 1703 | know (op_right == O_illegal | 
|---|
| 1704 | || op_rank[(int) op_right] <= op_rank[(int) op_left]); | 
|---|
| 1705 | know ((int) op_left >= (int) O_multiply | 
|---|
| 1706 | && (int) op_left <= (int) O_logical_or); | 
|---|
| 1707 |  | 
|---|
| 1708 | /* input_line_pointer->after right-hand quantity.  */ | 
|---|
| 1709 | /* left-hand quantity in resultP.  */ | 
|---|
| 1710 | /* right-hand quantity in right.  */ | 
|---|
| 1711 | /* operator in op_left.  */ | 
|---|
| 1712 |  | 
|---|
| 1713 | if (resultP->X_op == O_big) | 
|---|
| 1714 | { | 
|---|
| 1715 | if (resultP->X_add_number > 0) | 
|---|
| 1716 | as_warn (_("left operand is a bignum; integer 0 assumed")); | 
|---|
| 1717 | else | 
|---|
| 1718 | as_warn (_("left operand is a float; integer 0 assumed")); | 
|---|
| 1719 | resultP->X_op = O_constant; | 
|---|
| 1720 | resultP->X_add_number = 0; | 
|---|
| 1721 | resultP->X_add_symbol = NULL; | 
|---|
| 1722 | resultP->X_op_symbol = NULL; | 
|---|
| 1723 | } | 
|---|
| 1724 | if (right.X_op == O_big) | 
|---|
| 1725 | { | 
|---|
| 1726 | if (right.X_add_number > 0) | 
|---|
| 1727 | as_warn (_("right operand is a bignum; integer 0 assumed")); | 
|---|
| 1728 | else | 
|---|
| 1729 | as_warn (_("right operand is a float; integer 0 assumed")); | 
|---|
| 1730 | right.X_op = O_constant; | 
|---|
| 1731 | right.X_add_number = 0; | 
|---|
| 1732 | right.X_add_symbol = NULL; | 
|---|
| 1733 | right.X_op_symbol = NULL; | 
|---|
| 1734 | } | 
|---|
| 1735 |  | 
|---|
| 1736 | /* Optimize common cases.  */ | 
|---|
| 1737 | #ifdef md_optimize_expr | 
|---|
| 1738 | if (md_optimize_expr (resultP, op_left, &right)) | 
|---|
| 1739 | { | 
|---|
| 1740 | /* Skip.  */ | 
|---|
| 1741 | ; | 
|---|
| 1742 | } | 
|---|
| 1743 | else | 
|---|
| 1744 | #endif | 
|---|
| 1745 | if (op_left == O_add && right.X_op == O_constant) | 
|---|
| 1746 | { | 
|---|
| 1747 | /* X + constant.  */ | 
|---|
| 1748 | resultP->X_add_number += right.X_add_number; | 
|---|
| 1749 | } | 
|---|
| 1750 | /* This case comes up in PIC code.  */ | 
|---|
| 1751 | else if (op_left == O_subtract | 
|---|
| 1752 | && right.X_op == O_symbol | 
|---|
| 1753 | && resultP->X_op == O_symbol | 
|---|
| 1754 | && (symbol_get_frag (right.X_add_symbol) | 
|---|
| 1755 | == symbol_get_frag (resultP->X_add_symbol)) | 
|---|
| 1756 | && (SEG_NORMAL (rightseg) | 
|---|
| 1757 | || right.X_add_symbol == resultP->X_add_symbol)) | 
|---|
| 1758 | { | 
|---|
| 1759 | resultP->X_add_number -= right.X_add_number; | 
|---|
| 1760 | resultP->X_add_number += (S_GET_VALUE (resultP->X_add_symbol) | 
|---|
| 1761 | - S_GET_VALUE (right.X_add_symbol)); | 
|---|
| 1762 | resultP->X_op = O_constant; | 
|---|
| 1763 | resultP->X_add_symbol = 0; | 
|---|
| 1764 | } | 
|---|
| 1765 | else if (op_left == O_subtract && right.X_op == O_constant) | 
|---|
| 1766 | { | 
|---|
| 1767 | /* X - constant.  */ | 
|---|
| 1768 | resultP->X_add_number -= right.X_add_number; | 
|---|
| 1769 | } | 
|---|
| 1770 | else if (op_left == O_add && resultP->X_op == O_constant) | 
|---|
| 1771 | { | 
|---|
| 1772 | /* Constant + X.  */ | 
|---|
| 1773 | resultP->X_op = right.X_op; | 
|---|
| 1774 | resultP->X_add_symbol = right.X_add_symbol; | 
|---|
| 1775 | resultP->X_op_symbol = right.X_op_symbol; | 
|---|
| 1776 | resultP->X_add_number += right.X_add_number; | 
|---|
| 1777 | retval = rightseg; | 
|---|
| 1778 | } | 
|---|
| 1779 | else if (resultP->X_op == O_constant && right.X_op == O_constant) | 
|---|
| 1780 | { | 
|---|
| 1781 | /* Constant OP constant.  */ | 
|---|
| 1782 | offsetT v = right.X_add_number; | 
|---|
| 1783 | if (v == 0 && (op_left == O_divide || op_left == O_modulus)) | 
|---|
| 1784 | { | 
|---|
| 1785 | as_warn (_("division by zero")); | 
|---|
| 1786 | v = 1; | 
|---|
| 1787 | } | 
|---|
| 1788 | switch (op_left) | 
|---|
| 1789 | { | 
|---|
| 1790 | default:                    abort (); | 
|---|
| 1791 | case O_multiply:            resultP->X_add_number *= v; break; | 
|---|
| 1792 | case O_divide:              resultP->X_add_number /= v; break; | 
|---|
| 1793 | case O_modulus:             resultP->X_add_number %= v; break; | 
|---|
| 1794 | case O_left_shift:          resultP->X_add_number <<= v; break; | 
|---|
| 1795 | case O_right_shift: | 
|---|
| 1796 | /* We always use unsigned shifts, to avoid relying on | 
|---|
| 1797 | characteristics of the compiler used to compile gas.  */ | 
|---|
| 1798 | resultP->X_add_number = | 
|---|
| 1799 | (offsetT) ((valueT) resultP->X_add_number >> (valueT) v); | 
|---|
| 1800 | break; | 
|---|
| 1801 | case O_bit_inclusive_or:    resultP->X_add_number |= v; break; | 
|---|
| 1802 | case O_bit_or_not:          resultP->X_add_number |= ~v; break; | 
|---|
| 1803 | case O_bit_exclusive_or:    resultP->X_add_number ^= v; break; | 
|---|
| 1804 | case O_bit_and:             resultP->X_add_number &= v; break; | 
|---|
| 1805 | case O_add:                 resultP->X_add_number += v; break; | 
|---|
| 1806 | case O_subtract:            resultP->X_add_number -= v; break; | 
|---|
| 1807 | case O_eq: | 
|---|
| 1808 | resultP->X_add_number = | 
|---|
| 1809 | resultP->X_add_number == v ? ~ (offsetT) 0 : 0; | 
|---|
| 1810 | break; | 
|---|
| 1811 | case O_ne: | 
|---|
| 1812 | resultP->X_add_number = | 
|---|
| 1813 | resultP->X_add_number != v ? ~ (offsetT) 0 : 0; | 
|---|
| 1814 | break; | 
|---|
| 1815 | case O_lt: | 
|---|
| 1816 | resultP->X_add_number = | 
|---|
| 1817 | resultP->X_add_number <  v ? ~ (offsetT) 0 : 0; | 
|---|
| 1818 | break; | 
|---|
| 1819 | case O_le: | 
|---|
| 1820 | resultP->X_add_number = | 
|---|
| 1821 | resultP->X_add_number <= v ? ~ (offsetT) 0 : 0; | 
|---|
| 1822 | break; | 
|---|
| 1823 | case O_ge: | 
|---|
| 1824 | resultP->X_add_number = | 
|---|
| 1825 | resultP->X_add_number >= v ? ~ (offsetT) 0 : 0; | 
|---|
| 1826 | break; | 
|---|
| 1827 | case O_gt: | 
|---|
| 1828 | resultP->X_add_number = | 
|---|
| 1829 | resultP->X_add_number >  v ? ~ (offsetT) 0 : 0; | 
|---|
| 1830 | break; | 
|---|
| 1831 | case O_logical_and: | 
|---|
| 1832 | resultP->X_add_number = resultP->X_add_number && v; | 
|---|
| 1833 | break; | 
|---|
| 1834 | case O_logical_or: | 
|---|
| 1835 | resultP->X_add_number = resultP->X_add_number || v; | 
|---|
| 1836 | break; | 
|---|
| 1837 | } | 
|---|
| 1838 | } | 
|---|
| 1839 | else if (resultP->X_op == O_symbol | 
|---|
| 1840 | && right.X_op == O_symbol | 
|---|
| 1841 | && (op_left == O_add | 
|---|
| 1842 | || op_left == O_subtract | 
|---|
| 1843 | || (resultP->X_add_number == 0 | 
|---|
| 1844 | && right.X_add_number == 0))) | 
|---|
| 1845 | { | 
|---|
| 1846 | /* Symbol OP symbol.  */ | 
|---|
| 1847 | resultP->X_op = op_left; | 
|---|
| 1848 | resultP->X_op_symbol = right.X_add_symbol; | 
|---|
| 1849 | if (op_left == O_add) | 
|---|
| 1850 | resultP->X_add_number += right.X_add_number; | 
|---|
| 1851 | else if (op_left == O_subtract) | 
|---|
| 1852 | { | 
|---|
| 1853 | resultP->X_add_number -= right.X_add_number; | 
|---|
| 1854 | if (retval == rightseg && SEG_NORMAL (retval)) | 
|---|
| 1855 | { | 
|---|
| 1856 | retval = absolute_section; | 
|---|
| 1857 | rightseg = absolute_section; | 
|---|
| 1858 | } | 
|---|
| 1859 | } | 
|---|
| 1860 | } | 
|---|
| 1861 | else | 
|---|
| 1862 | { | 
|---|
| 1863 | /* The general case.  */ | 
|---|
| 1864 | resultP->X_add_symbol = make_expr_symbol (resultP); | 
|---|
| 1865 | resultP->X_op_symbol = make_expr_symbol (&right); | 
|---|
| 1866 | resultP->X_op = op_left; | 
|---|
| 1867 | resultP->X_add_number = 0; | 
|---|
| 1868 | resultP->X_unsigned = 1; | 
|---|
| 1869 | } | 
|---|
| 1870 |  | 
|---|
| 1871 | if (retval != rightseg) | 
|---|
| 1872 | { | 
|---|
| 1873 | if (! SEG_NORMAL (retval)) | 
|---|
| 1874 | { | 
|---|
| 1875 | if (retval != undefined_section || SEG_NORMAL (rightseg)) | 
|---|
| 1876 | retval = rightseg; | 
|---|
| 1877 | } | 
|---|
| 1878 | else if (SEG_NORMAL (rightseg) | 
|---|
| 1879 | #ifdef DIFF_EXPR_OK | 
|---|
| 1880 | && op_left != O_subtract | 
|---|
| 1881 | #endif | 
|---|
| 1882 | ) | 
|---|
| 1883 | as_bad (_("operation combines symbols in different segments")); | 
|---|
| 1884 | } | 
|---|
| 1885 |  | 
|---|
| 1886 | op_left = op_right; | 
|---|
| 1887 | }                           /* While next operator is >= this rank.  */ | 
|---|
| 1888 |  | 
|---|
| 1889 | /* The PA port needs this information.  */ | 
|---|
| 1890 | if (resultP->X_add_symbol) | 
|---|
| 1891 | symbol_mark_used (resultP->X_add_symbol); | 
|---|
| 1892 |  | 
|---|
| 1893 | return resultP->X_op == O_constant ? absolute_section : retval; | 
|---|
| 1894 | } | 
|---|
| 1895 |  | 
|---|
| 1896 |  | 
|---|
| 1897 | /* This lives here because it belongs equally in expr.c & read.c. | 
|---|
| 1898 | expr.c is just a branch office read.c anyway, and putting it | 
|---|
| 1899 | here lessens the crowd at read.c. | 
|---|
| 1900 |  | 
|---|
| 1901 | Assume input_line_pointer is at start of symbol name. | 
|---|
| 1902 | Advance input_line_pointer past symbol name. | 
|---|
| 1903 | Turn that character into a '\0', returning its former value. | 
|---|
| 1904 | This allows a string compare (RMS wants symbol names to be strings) | 
|---|
| 1905 | of the symbol name. | 
|---|
| 1906 | There will always be a char following symbol name, because all good | 
|---|
| 1907 | lines end in end-of-line.  */ | 
|---|
| 1908 |  | 
|---|
| 1909 | char | 
|---|
| 1910 | get_symbol_end () | 
|---|
| 1911 | { | 
|---|
| 1912 | char c; | 
|---|
| 1913 |  | 
|---|
| 1914 | /* We accept \001 in a name in case this is being called with a | 
|---|
| 1915 | constructed string.  */ | 
|---|
| 1916 | if (is_name_beginner (c = *input_line_pointer++) || c == '\001') | 
|---|
| 1917 | { | 
|---|
| 1918 | while (is_part_of_name (c = *input_line_pointer++) | 
|---|
| 1919 | || c == '\001') | 
|---|
| 1920 | ; | 
|---|
| 1921 | if (is_name_ender (c)) | 
|---|
| 1922 | c = *input_line_pointer++; | 
|---|
| 1923 | } | 
|---|
| 1924 | *--input_line_pointer = 0; | 
|---|
| 1925 | return (c); | 
|---|
| 1926 | } | 
|---|
| 1927 |  | 
|---|
| 1928 | unsigned int | 
|---|
| 1929 | get_single_number () | 
|---|
| 1930 | { | 
|---|
| 1931 | expressionS exp; | 
|---|
| 1932 | operand (&exp); | 
|---|
| 1933 | return exp.X_add_number; | 
|---|
| 1934 | } | 
|---|