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