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