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