Home | History | Annotate | Download | only in gas
      1 /* expr.c -operands, expressions-
      2    Copyright (C) 1987-2016 Free Software Foundation, Inc.
      3 
      4    This file is part of GAS, the GNU Assembler.
      5 
      6    GAS is free software; you can redistribute it and/or modify
      7    it under the terms of the GNU General Public License as published by
      8    the Free Software Foundation; either version 3, or (at your option)
      9    any later version.
     10 
     11    GAS is distributed in the hope that it will be useful,
     12    but WITHOUT ANY WARRANTY; without even the implied warranty of
     13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14    GNU General Public License for more details.
     15 
     16    You should have received a copy of the GNU General Public License
     17    along with GAS; see the file COPYING.  If not, write to the Free
     18    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
     19    02110-1301, USA.  */
     20 
     21 /* 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   if (small)
    523     {
    524       /* Here with number, in correct radix. c is the next char.
    525 	 Note that unlike un*x, we allow "011f" "0x9f" to both mean
    526 	 the same as the (conventional) "9f".
    527 	 This is simply easier than checking for strict canonical
    528 	 form.  Syntax sux!  */
    529 
    530       if (LOCAL_LABELS_FB && c == 'b')
    531 	{
    532 	  /* Backward ref to local label.
    533 	     Because it is backward, expect it to be defined.  */
    534 	  /* Construct a local label.  */
    535 	  name = fb_label_name ((int) number, 0);
    536 
    537 	  /* Seen before, or symbol is defined: OK.  */
    538 	  symbolP = symbol_find (name);
    539 	  if ((symbolP != NULL) && (S_IS_DEFINED (symbolP)))
    540 	    {
    541 	      /* Local labels are never absolute.  Don't waste time
    542 		 checking absoluteness.  */
    543 	      know (SEG_NORMAL (S_GET_SEGMENT (symbolP)));
    544 
    545 	      expressionP->X_op = O_symbol;
    546 	      expressionP->X_add_symbol = symbolP;
    547 	    }
    548 	  else
    549 	    {
    550 	      /* Either not seen or not defined.  */
    551 	      /* @@ Should print out the original string instead of
    552 		 the parsed number.  */
    553 	      as_bad (_("backward ref to unknown label \"%d:\""),
    554 		      (int) number);
    555 	      expressionP->X_op = O_constant;
    556 	    }
    557 
    558 	  expressionP->X_add_number = 0;
    559 	}			/* case 'b' */
    560       else if (LOCAL_LABELS_FB && c == 'f')
    561 	{
    562 	  /* Forward reference.  Expect symbol to be undefined or
    563 	     unknown.  undefined: seen it before.  unknown: never seen
    564 	     it before.
    565 
    566 	     Construct a local label name, then an undefined symbol.
    567 	     Don't create a xseg frag for it: caller may do that.
    568 	     Just return it as never seen before.  */
    569 	  name = fb_label_name ((int) number, 1);
    570 	  symbolP = symbol_find_or_make (name);
    571 	  /* We have no need to check symbol properties.  */
    572 #ifndef many_segments
    573 	  /* Since "know" puts its arg into a "string", we
    574 	     can't have newlines in the argument.  */
    575 	  know (S_GET_SEGMENT (symbolP) == undefined_section || S_GET_SEGMENT (symbolP) == text_section || S_GET_SEGMENT (symbolP) == data_section);
    576 #endif
    577 	  expressionP->X_op = O_symbol;
    578 	  expressionP->X_add_symbol = symbolP;
    579 	  expressionP->X_add_number = 0;
    580 	}			/* case 'f' */
    581       else if (LOCAL_LABELS_DOLLAR && c == '$')
    582 	{
    583 	  /* If the dollar label is *currently* defined, then this is just
    584 	     another reference to it.  If it is not *currently* defined,
    585 	     then this is a fresh instantiation of that number, so create
    586 	     it.  */
    587 
    588 	  if (dollar_label_defined ((long) number))
    589 	    {
    590 	      name = dollar_label_name ((long) number, 0);
    591 	      symbolP = symbol_find (name);
    592 	      know (symbolP != NULL);
    593 	    }
    594 	  else
    595 	    {
    596 	      name = dollar_label_name ((long) number, 1);
    597 	      symbolP = symbol_find_or_make (name);
    598 	    }
    599 
    600 	  expressionP->X_op = O_symbol;
    601 	  expressionP->X_add_symbol = symbolP;
    602 	  expressionP->X_add_number = 0;
    603 	}			/* case '$' */
    604       else
    605 	{
    606 	  expressionP->X_op = O_constant;
    607 	  expressionP->X_add_number = number;
    608 	  input_line_pointer--;	/* Restore following character.  */
    609 	}			/* Really just a number.  */
    610     }
    611   else
    612     {
    613       /* Not a small number.  */
    614       expressionP->X_op = O_big;
    615       expressionP->X_add_number = number;	/* Number of littlenums.  */
    616       input_line_pointer--;	/* -> char following number.  */
    617     }
    618 }
    619 
    620 /* Parse an MRI multi character constant.  */
    621 
    622 static void
    623 mri_char_constant (expressionS *expressionP)
    624 {
    625   int i;
    626 
    627   if (*input_line_pointer == '\''
    628       && input_line_pointer[1] != '\'')
    629     {
    630       expressionP->X_op = O_constant;
    631       expressionP->X_add_number = 0;
    632       return;
    633     }
    634 
    635   /* In order to get the correct byte ordering, we must build the
    636      number in reverse.  */
    637   for (i = SIZE_OF_LARGE_NUMBER - 1; i >= 0; i--)
    638     {
    639       int j;
    640 
    641       generic_bignum[i] = 0;
    642       for (j = 0; j < CHARS_PER_LITTLENUM; j++)
    643 	{
    644 	  if (*input_line_pointer == '\'')
    645 	    {
    646 	      if (input_line_pointer[1] != '\'')
    647 		break;
    648 	      ++input_line_pointer;
    649 	    }
    650 	  generic_bignum[i] <<= 8;
    651 	  generic_bignum[i] += *input_line_pointer;
    652 	  ++input_line_pointer;
    653 	}
    654 
    655       if (i < SIZE_OF_LARGE_NUMBER - 1)
    656 	{
    657 	  /* If there is more than one littlenum, left justify the
    658 	     last one to make it match the earlier ones.  If there is
    659 	     only one, we can just use the value directly.  */
    660 	  for (; j < CHARS_PER_LITTLENUM; j++)
    661 	    generic_bignum[i] <<= 8;
    662 	}
    663 
    664       if (*input_line_pointer == '\''
    665 	  && input_line_pointer[1] != '\'')
    666 	break;
    667     }
    668 
    669   if (i < 0)
    670     {
    671       as_bad (_("character constant too large"));
    672       i = 0;
    673     }
    674 
    675   if (i > 0)
    676     {
    677       int c;
    678       int j;
    679 
    680       c = SIZE_OF_LARGE_NUMBER - i;
    681       for (j = 0; j < c; j++)
    682 	generic_bignum[j] = generic_bignum[i + j];
    683       i = c;
    684     }
    685 
    686   know (LITTLENUM_NUMBER_OF_BITS == 16);
    687   if (i > 2)
    688     {
    689       expressionP->X_op = O_big;
    690       expressionP->X_add_number = i;
    691     }
    692   else
    693     {
    694       expressionP->X_op = O_constant;
    695       if (i < 2)
    696 	expressionP->X_add_number = generic_bignum[0] & LITTLENUM_MASK;
    697       else
    698 	expressionP->X_add_number =
    699 	  (((generic_bignum[1] & LITTLENUM_MASK)
    700 	    << LITTLENUM_NUMBER_OF_BITS)
    701 	   | (generic_bignum[0] & LITTLENUM_MASK));
    702     }
    703 
    704   /* Skip the final closing quote.  */
    705   ++input_line_pointer;
    706 }
    707 
    708 /* Return an expression representing the current location.  This
    709    handles the magic symbol `.'.  */
    710 
    711 void
    712 current_location (expressionS *expressionp)
    713 {
    714   if (now_seg == absolute_section)
    715     {
    716       expressionp->X_op = O_constant;
    717       expressionp->X_add_number = abs_section_offset;
    718     }
    719   else
    720     {
    721       expressionp->X_op = O_symbol;
    722       expressionp->X_add_symbol = &dot_symbol;
    723       expressionp->X_add_number = 0;
    724     }
    725 }
    726 
    727 /* In:	Input_line_pointer points to 1st char of operand, which may
    728 	be a space.
    729 
    730    Out:	An expressionS.
    731 	The operand may have been empty: in this case X_op == O_absent.
    732 	Input_line_pointer->(next non-blank) char after operand.  */
    733 
    734 static segT
    735 operand (expressionS *expressionP, enum expr_mode mode)
    736 {
    737   char c;
    738   symbolS *symbolP;	/* Points to symbol.  */
    739   char *name;		/* Points to name of symbol.  */
    740   segT segment;
    741 
    742   /* All integers are regarded as unsigned unless they are negated.
    743      This is because the only thing which cares whether a number is
    744      unsigned is the code in emit_expr which extends constants into
    745      bignums.  It should only sign extend negative numbers, so that
    746      something like ``.quad 0x80000000'' is not sign extended even
    747      though it appears negative if valueT is 32 bits.  */
    748   expressionP->X_unsigned = 1;
    749   expressionP->X_extrabit = 0;
    750 
    751   /* Digits, assume it is a bignum.  */
    752 
    753   SKIP_WHITESPACE ();		/* Leading whitespace is part of operand.  */
    754   c = *input_line_pointer++;	/* input_line_pointer -> past char in c.  */
    755 
    756   if (is_end_of_line[(unsigned char) c])
    757     goto eol;
    758 
    759   switch (c)
    760     {
    761     case '1':
    762     case '2':
    763     case '3':
    764     case '4':
    765     case '5':
    766     case '6':
    767     case '7':
    768     case '8':
    769     case '9':
    770       input_line_pointer--;
    771 
    772       integer_constant ((NUMBERS_WITH_SUFFIX || flag_m68k_mri)
    773 			? 0 : 10,
    774 			expressionP);
    775       break;
    776 
    777 #ifdef LITERAL_PREFIXDOLLAR_HEX
    778     case '$':
    779       /* $L is the start of a local label, not a hex constant.  */
    780       if (* input_line_pointer == 'L')
    781       goto isname;
    782       integer_constant (16, expressionP);
    783       break;
    784 #endif
    785 
    786 #ifdef LITERAL_PREFIXPERCENT_BIN
    787     case '%':
    788       integer_constant (2, expressionP);
    789       break;
    790 #endif
    791 
    792     case '0':
    793       /* Non-decimal radix.  */
    794 
    795       if (NUMBERS_WITH_SUFFIX || flag_m68k_mri)
    796 	{
    797 	  char *s;
    798 
    799 	  /* Check for a hex or float constant.  */
    800 	  for (s = input_line_pointer; hex_p (*s); s++)
    801 	    ;
    802 	  if (*s == 'h' || *s == 'H' || *input_line_pointer == '.')
    803 	    {
    804 	      --input_line_pointer;
    805 	      integer_constant (0, expressionP);
    806 	      break;
    807 	    }
    808 	}
    809       c = *input_line_pointer;
    810       switch (c)
    811 	{
    812 	case 'o':
    813 	case 'O':
    814 	case 'q':
    815 	case 'Q':
    816 	case '8':
    817 	case '9':
    818 	  if (NUMBERS_WITH_SUFFIX || flag_m68k_mri)
    819 	    {
    820 	      integer_constant (0, expressionP);
    821 	      break;
    822 	    }
    823 	  /* Fall through.  */
    824 	default:
    825 	default_case:
    826 	  if (c && strchr (FLT_CHARS, c))
    827 	    {
    828 	      input_line_pointer++;
    829 	      floating_constant (expressionP);
    830 	      expressionP->X_add_number = - TOLOWER (c);
    831 	    }
    832 	  else
    833 	    {
    834 	      /* The string was only zero.  */
    835 	      expressionP->X_op = O_constant;
    836 	      expressionP->X_add_number = 0;
    837 	    }
    838 
    839 	  break;
    840 
    841 	case 'x':
    842 	case 'X':
    843 	  if (flag_m68k_mri)
    844 	    goto default_case;
    845 	  input_line_pointer++;
    846 	  integer_constant (16, expressionP);
    847 	  break;
    848 
    849 	case 'b':
    850 	  if (LOCAL_LABELS_FB && !flag_m68k_mri
    851 	      && input_line_pointer[1] != '0'
    852 	      && input_line_pointer[1] != '1')
    853 	    {
    854 	      /* Parse this as a back reference to label 0.  */
    855 	      input_line_pointer--;
    856 	      integer_constant (10, expressionP);
    857 	      break;
    858 	    }
    859 	  /* Otherwise, parse this as a binary number.  */
    860 	  /* Fall through.  */
    861 	case 'B':
    862 	  if (input_line_pointer[1] == '0'
    863 	      || input_line_pointer[1] == '1')
    864 	    {
    865 	      input_line_pointer++;
    866 	      integer_constant (2, expressionP);
    867 	      break;
    868 	    }
    869 	  if (flag_m68k_mri || NUMBERS_WITH_SUFFIX)
    870 	    input_line_pointer++;
    871 	  goto default_case;
    872 
    873 	case '0':
    874 	case '1':
    875 	case '2':
    876 	case '3':
    877 	case '4':
    878 	case '5':
    879 	case '6':
    880 	case '7':
    881 	  integer_constant ((flag_m68k_mri || NUMBERS_WITH_SUFFIX)
    882 			    ? 0 : 8,
    883 			    expressionP);
    884 	  break;
    885 
    886 	case 'f':
    887 	  if (LOCAL_LABELS_FB)
    888 	    {
    889 	      int is_label = 1;
    890 
    891 	      /* If it says "0f" and it could possibly be a floating point
    892 		 number, make it one.  Otherwise, make it a local label,
    893 		 and try to deal with parsing the rest later.  */
    894 	      if (!is_end_of_line[(unsigned char) input_line_pointer[1]]
    895 		  && strchr (FLT_CHARS, 'f') != NULL)
    896 		{
    897 		  char *cp = input_line_pointer + 1;
    898 
    899 		  atof_generic (&cp, ".", EXP_CHARS,
    900 				&generic_floating_point_number);
    901 
    902 		  /* Was nothing parsed, or does it look like an
    903 		     expression?  */
    904 		  is_label = (cp == input_line_pointer + 1
    905 			      || (cp == input_line_pointer + 2
    906 				  && (cp[-1] == '-' || cp[-1] == '+'))
    907 			      || *cp == 'f'
    908 			      || *cp == 'b');
    909 		}
    910 	      if (is_label)
    911 		{
    912 		  input_line_pointer--;
    913 		  integer_constant (10, expressionP);
    914 		  break;
    915 		}
    916 	    }
    917 	  /* Fall through.  */
    918 
    919 	case 'd':
    920 	case 'D':
    921 	  if (flag_m68k_mri || NUMBERS_WITH_SUFFIX)
    922 	    {
    923 	      integer_constant (0, expressionP);
    924 	      break;
    925 	    }
    926 	  /* Fall through.  */
    927 	case 'F':
    928 	case 'r':
    929 	case 'e':
    930 	case 'E':
    931 	case 'g':
    932 	case 'G':
    933 	  input_line_pointer++;
    934 	  floating_constant (expressionP);
    935 	  expressionP->X_add_number = - TOLOWER (c);
    936 	  break;
    937 
    938 	case '$':
    939 	  if (LOCAL_LABELS_DOLLAR)
    940 	    {
    941 	      integer_constant (10, expressionP);
    942 	      break;
    943 	    }
    944 	  else
    945 	    goto default_case;
    946 	}
    947 
    948       break;
    949 
    950 #ifndef NEED_INDEX_OPERATOR
    951     case '[':
    952 # ifdef md_need_index_operator
    953       if (md_need_index_operator())
    954 	goto de_fault;
    955 # endif
    956       /* FALLTHROUGH */
    957 #endif
    958     case '(':
    959       /* Didn't begin with digit & not a name.  */
    960       segment = expr (0, expressionP, mode);
    961       /* expression () will pass trailing whitespace.  */
    962       if ((c == '(' && *input_line_pointer != ')')
    963 	  || (c == '[' && *input_line_pointer != ']'))
    964 	{
    965 	  if (* input_line_pointer)
    966 	    as_bad (_("found '%c', expected: '%c'"),
    967 		    * input_line_pointer, c == '(' ? ')' : ']');
    968 	  else
    969 	    as_bad (_("missing '%c'"), c == '(' ? ')' : ']');
    970 	}
    971       else
    972 	input_line_pointer++;
    973       SKIP_WHITESPACE ();
    974       /* Here with input_line_pointer -> char after "(...)".  */
    975       return segment;
    976 
    977 #ifdef TC_M68K
    978     case 'E':
    979       if (! flag_m68k_mri || *input_line_pointer != '\'')
    980 	goto de_fault;
    981       as_bad (_("EBCDIC constants are not supported"));
    982       /* Fall through.  */
    983     case 'A':
    984       if (! flag_m68k_mri || *input_line_pointer != '\'')
    985 	goto de_fault;
    986       ++input_line_pointer;
    987       /* Fall through.  */
    988 #endif
    989     case '\'':
    990       if (! flag_m68k_mri)
    991 	{
    992 	  /* Warning: to conform to other people's assemblers NO
    993 	     ESCAPEMENT is permitted for a single quote.  The next
    994 	     character, parity errors and all, is taken as the value
    995 	     of the operand.  VERY KINKY.  */
    996 	  expressionP->X_op = O_constant;
    997 	  expressionP->X_add_number = *input_line_pointer++;
    998 	  break;
    999 	}
   1000 
   1001       mri_char_constant (expressionP);
   1002       break;
   1003 
   1004 #ifdef TC_M68K
   1005     case '"':
   1006       /* Double quote is the bitwise not operator in MRI mode.  */
   1007       if (! flag_m68k_mri)
   1008 	goto de_fault;
   1009       /* Fall through.  */
   1010 #endif
   1011     case '~':
   1012       /* '~' is permitted to start a label on the Delta.  */
   1013       if (is_name_beginner (c))
   1014 	goto isname;
   1015     case '!':
   1016     case '-':
   1017     case '+':
   1018       {
   1019 #ifdef md_operator
   1020       unary:
   1021 #endif
   1022 	operand (expressionP, mode);
   1023 	if (expressionP->X_op == O_constant)
   1024 	  {
   1025 	    /* input_line_pointer -> char after operand.  */
   1026 	    if (c == '-')
   1027 	      {
   1028 		expressionP->X_add_number
   1029 		  = - (addressT) expressionP->X_add_number;
   1030 		/* Notice: '-' may overflow: no warning is given.
   1031 		   This is compatible with other people's
   1032 		   assemblers.  Sigh.  */
   1033 		expressionP->X_unsigned = 0;
   1034 		if (expressionP->X_add_number)
   1035 		  expressionP->X_extrabit ^= 1;
   1036 	      }
   1037 	    else if (c == '~' || c == '"')
   1038 	      expressionP->X_add_number = ~ expressionP->X_add_number;
   1039 	    else if (c == '!')
   1040 	      expressionP->X_add_number = ! expressionP->X_add_number;
   1041 	  }
   1042 	else if (expressionP->X_op == O_big
   1043 		 && expressionP->X_add_number <= 0
   1044 		 && c == '-'
   1045 		 && (generic_floating_point_number.sign == '+'
   1046 		     || generic_floating_point_number.sign == 'P'))
   1047 	  {
   1048 	    /* Negative flonum (eg, -1.000e0).  */
   1049 	    if (generic_floating_point_number.sign == '+')
   1050 	      generic_floating_point_number.sign = '-';
   1051 	    else
   1052 	      generic_floating_point_number.sign = 'N';
   1053 	  }
   1054 	else if (expressionP->X_op == O_big
   1055 		 && expressionP->X_add_number > 0)
   1056 	  {
   1057 	    int i;
   1058 
   1059 	    if (c == '~' || c == '-')
   1060 	      {
   1061 		for (i = 0; i < expressionP->X_add_number; ++i)
   1062 		  generic_bignum[i] = ~generic_bignum[i];
   1063 
   1064 		/* Extend the bignum to at least the size of .octa.  */
   1065 		if (expressionP->X_add_number < SIZE_OF_LARGE_NUMBER)
   1066 		  {
   1067 		    expressionP->X_add_number = SIZE_OF_LARGE_NUMBER;
   1068 		    for (; i < expressionP->X_add_number; ++i)
   1069 		      generic_bignum[i] = ~(LITTLENUM_TYPE) 0;
   1070 		  }
   1071 
   1072 		if (c == '-')
   1073 		  for (i = 0; i < expressionP->X_add_number; ++i)
   1074 		    {
   1075 		      generic_bignum[i] += 1;
   1076 		      if (generic_bignum[i])
   1077 			break;
   1078 		    }
   1079 	      }
   1080 	    else if (c == '!')
   1081 	      {
   1082 		for (i = 0; i < expressionP->X_add_number; ++i)
   1083 		  if (generic_bignum[i] != 0)
   1084 		    break;
   1085 		expressionP->X_add_number = i >= expressionP->X_add_number;
   1086 		expressionP->X_op = O_constant;
   1087 		expressionP->X_unsigned = 1;
   1088 		expressionP->X_extrabit = 0;
   1089 	      }
   1090 	  }
   1091 	else if (expressionP->X_op != O_illegal
   1092 		 && expressionP->X_op != O_absent)
   1093 	  {
   1094 	    if (c != '+')
   1095 	      {
   1096 		expressionP->X_add_symbol = make_expr_symbol (expressionP);
   1097 		if (c == '-')
   1098 		  expressionP->X_op = O_uminus;
   1099 		else if (c == '~' || c == '"')
   1100 		  expressionP->X_op = O_bit_not;
   1101 		else
   1102 		  expressionP->X_op = O_logical_not;
   1103 		expressionP->X_add_number = 0;
   1104 	      }
   1105 	  }
   1106 	else
   1107 	  as_warn (_("Unary operator %c ignored because bad operand follows"),
   1108 		   c);
   1109       }
   1110       break;
   1111 
   1112 #if defined (DOLLAR_DOT) || defined (TC_M68K)
   1113     case '$':
   1114       /* '$' is the program counter when in MRI mode, or when
   1115 	 DOLLAR_DOT is defined.  */
   1116 #ifndef DOLLAR_DOT
   1117       if (! flag_m68k_mri)
   1118 	goto de_fault;
   1119 #endif
   1120       if (DOLLAR_AMBIGU && hex_p (*input_line_pointer))
   1121 	{
   1122 	  /* In MRI mode and on Z80, '$' is also used as the prefix
   1123 	     for a hexadecimal constant.  */
   1124 	  integer_constant (16, expressionP);
   1125 	  break;
   1126 	}
   1127 
   1128       if (is_part_of_name (*input_line_pointer))
   1129 	goto isname;
   1130 
   1131       current_location (expressionP);
   1132       break;
   1133 #endif
   1134 
   1135     case '.':
   1136       if (!is_part_of_name (*input_line_pointer))
   1137 	{
   1138 	  current_location (expressionP);
   1139 	  break;
   1140 	}
   1141       else if ((strncasecmp (input_line_pointer, "startof.", 8) == 0
   1142 		&& ! is_part_of_name (input_line_pointer[8]))
   1143 	       || (strncasecmp (input_line_pointer, "sizeof.", 7) == 0
   1144 		   && ! is_part_of_name (input_line_pointer[7])))
   1145 	{
   1146 	  int start;
   1147 
   1148 	  start = (input_line_pointer[1] == 't'
   1149 		   || input_line_pointer[1] == 'T');
   1150 	  input_line_pointer += start ? 8 : 7;
   1151 	  SKIP_WHITESPACE ();
   1152 	  if (*input_line_pointer != '(')
   1153 	    as_bad (_("syntax error in .startof. or .sizeof."));
   1154 	  else
   1155 	    {
   1156 	      char *buf;
   1157 
   1158 	      ++input_line_pointer;
   1159 	      SKIP_WHITESPACE ();
   1160 	      c = get_symbol_name (& name);
   1161 
   1162 	      buf = concat (start ? ".startof." : ".sizeof.", name,
   1163 			    (char *) NULL);
   1164 	      symbolP = symbol_make (buf);
   1165 	      free (buf);
   1166 
   1167 	      expressionP->X_op = O_symbol;
   1168 	      expressionP->X_add_symbol = symbolP;
   1169 	      expressionP->X_add_number = 0;
   1170 
   1171 	      *input_line_pointer = c;
   1172 	      SKIP_WHITESPACE_AFTER_NAME ();
   1173 	      if (*input_line_pointer != ')')
   1174 		as_bad (_("syntax error in .startof. or .sizeof."));
   1175 	      else
   1176 		++input_line_pointer;
   1177 	    }
   1178 	  break;
   1179 	}
   1180       else
   1181 	{
   1182 	  goto isname;
   1183 	}
   1184 
   1185     case ',':
   1186     eol:
   1187       /* Can't imagine any other kind of operand.  */
   1188       expressionP->X_op = O_absent;
   1189       input_line_pointer--;
   1190       break;
   1191 
   1192 #ifdef TC_M68K
   1193     case '%':
   1194       if (! flag_m68k_mri)
   1195 	goto de_fault;
   1196       integer_constant (2, expressionP);
   1197       break;
   1198 
   1199     case '@':
   1200       if (! flag_m68k_mri)
   1201 	goto de_fault;
   1202       integer_constant (8, expressionP);
   1203       break;
   1204 
   1205     case ':':
   1206       if (! flag_m68k_mri)
   1207 	goto de_fault;
   1208 
   1209       /* In MRI mode, this is a floating point constant represented
   1210 	 using hexadecimal digits.  */
   1211 
   1212       ++input_line_pointer;
   1213       integer_constant (16, expressionP);
   1214       break;
   1215 
   1216     case '*':
   1217       if (! flag_m68k_mri || is_part_of_name (*input_line_pointer))
   1218 	goto de_fault;
   1219 
   1220       current_location (expressionP);
   1221       break;
   1222 #endif
   1223 
   1224     default:
   1225 #if defined(md_need_index_operator) || defined(TC_M68K)
   1226     de_fault:
   1227 #endif
   1228       if (is_name_beginner (c) || c == '"')	/* Here if did not begin with a digit.  */
   1229 	{
   1230 	  /* Identifier begins here.
   1231 	     This is kludged for speed, so code is repeated.  */
   1232 	isname:
   1233 	  -- input_line_pointer;
   1234 	  c = get_symbol_name (&name);
   1235 
   1236 #ifdef md_operator
   1237 	  {
   1238 	    operatorT op = md_operator (name, 1, &c);
   1239 
   1240 	    switch (op)
   1241 	      {
   1242 	      case O_uminus:
   1243 		restore_line_pointer (c);
   1244 		c = '-';
   1245 		goto unary;
   1246 	      case O_bit_not:
   1247 		restore_line_pointer (c);
   1248 		c = '~';
   1249 		goto unary;
   1250 	      case O_logical_not:
   1251 		restore_line_pointer (c);
   1252 		c = '!';
   1253 		goto unary;
   1254 	      case O_illegal:
   1255 		as_bad (_("invalid use of operator \"%s\""), name);
   1256 		break;
   1257 	      default:
   1258 		break;
   1259 	      }
   1260 
   1261 	    if (op != O_absent && op != O_illegal)
   1262 	      {
   1263 		restore_line_pointer (c);
   1264 		expr (9, expressionP, mode);
   1265 		expressionP->X_add_symbol = make_expr_symbol (expressionP);
   1266 		expressionP->X_op_symbol = NULL;
   1267 		expressionP->X_add_number = 0;
   1268 		expressionP->X_op = op;
   1269 		break;
   1270 	      }
   1271 	  }
   1272 #endif
   1273 
   1274 #ifdef md_parse_name
   1275 	  /* This is a hook for the backend to parse certain names
   1276 	     specially in certain contexts.  If a name always has a
   1277 	     specific value, it can often be handled by simply
   1278 	     entering it in the symbol table.  */
   1279 	  if (md_parse_name (name, expressionP, mode, &c))
   1280 	    {
   1281 	      restore_line_pointer (c);
   1282 	      break;
   1283 	    }
   1284 #endif
   1285 
   1286 #ifdef TC_I960
   1287 	  /* The MRI i960 assembler permits
   1288 	         lda sizeof code,g13
   1289 	     FIXME: This should use md_parse_name.  */
   1290 	  if (flag_mri
   1291 	      && (strcasecmp (name, "sizeof") == 0
   1292 		  || strcasecmp (name, "startof") == 0))
   1293 	    {
   1294 	      int start;
   1295 	      char *buf;
   1296 
   1297 	      start = (name[1] == 't'
   1298 		       || name[1] == 'T');
   1299 
   1300 	      *input_line_pointer = c;
   1301 	      SKIP_WHITESPACE_AFTER_NAME ();
   1302 
   1303 	      c = get_symbol_name (& name);
   1304 
   1305 	      buf = concat (start ? ".startof." : ".sizeof.", name,
   1306 			    (char *) NULL);
   1307 	      symbolP = symbol_make (buf);
   1308 	      free (buf);
   1309 
   1310 	      expressionP->X_op = O_symbol;
   1311 	      expressionP->X_add_symbol = symbolP;
   1312 	      expressionP->X_add_number = 0;
   1313 
   1314 	      *input_line_pointer = c;
   1315 	      SKIP_WHITESPACE_AFTER_NAME ();
   1316 	      break;
   1317 	    }
   1318 #endif
   1319 
   1320 	  symbolP = symbol_find_or_make (name);
   1321 
   1322 	  /* If we have an absolute symbol or a reg, then we know its
   1323 	     value now.  */
   1324 	  segment = S_GET_SEGMENT (symbolP);
   1325 	  if (mode != expr_defer
   1326 	      && segment == absolute_section
   1327 	      && !S_FORCE_RELOC (symbolP, 0))
   1328 	    {
   1329 	      expressionP->X_op = O_constant;
   1330 	      expressionP->X_add_number = S_GET_VALUE (symbolP);
   1331 	    }
   1332 	  else if (mode != expr_defer && segment == reg_section)
   1333 	    {
   1334 	      expressionP->X_op = O_register;
   1335 	      expressionP->X_add_number = S_GET_VALUE (symbolP);
   1336 	    }
   1337 	  else
   1338 	    {
   1339 	      expressionP->X_op = O_symbol;
   1340 	      expressionP->X_add_symbol = symbolP;
   1341 	      expressionP->X_add_number = 0;
   1342 	    }
   1343 
   1344 	  restore_line_pointer (c);
   1345 	}
   1346       else
   1347 	{
   1348 	  /* Let the target try to parse it.  Success is indicated by changing
   1349 	     the X_op field to something other than O_absent and pointing
   1350 	     input_line_pointer past the expression.  If it can't parse the
   1351 	     expression, X_op and input_line_pointer should be unchanged.  */
   1352 	  expressionP->X_op = O_absent;
   1353 	  --input_line_pointer;
   1354 	  md_operand (expressionP);
   1355 	  if (expressionP->X_op == O_absent)
   1356 	    {
   1357 	      ++input_line_pointer;
   1358 	      as_bad (_("bad expression"));
   1359 	      expressionP->X_op = O_constant;
   1360 	      expressionP->X_add_number = 0;
   1361 	    }
   1362 	}
   1363       break;
   1364     }
   1365 
   1366   /* It is more 'efficient' to clean up the expressionS when they are
   1367      created.  Doing it here saves lines of code.  */
   1368   clean_up_expression (expressionP);
   1369   SKIP_WHITESPACE ();		/* -> 1st char after operand.  */
   1370   know (*input_line_pointer != ' ');
   1371 
   1372   /* The PA port needs this information.  */
   1373   if (expressionP->X_add_symbol)
   1374     symbol_mark_used (expressionP->X_add_symbol);
   1375 
   1376   if (mode != expr_defer)
   1377     {
   1378       expressionP->X_add_symbol
   1379 	= symbol_clone_if_forward_ref (expressionP->X_add_symbol);
   1380       expressionP->X_op_symbol
   1381 	= symbol_clone_if_forward_ref (expressionP->X_op_symbol);
   1382     }
   1383 
   1384   switch (expressionP->X_op)
   1385     {
   1386     default:
   1387       return absolute_section;
   1388     case O_symbol:
   1389       return S_GET_SEGMENT (expressionP->X_add_symbol);
   1390     case O_register:
   1391       return reg_section;
   1392     }
   1393 }
   1394 
   1395 /* Internal.  Simplify a struct expression for use by expr ().  */
   1397 
   1398 /* In:	address of an expressionS.
   1399 	The X_op field of the expressionS may only take certain values.
   1400 	Elsewise we waste time special-case testing. Sigh. Ditto SEG_ABSENT.
   1401 
   1402    Out:	expressionS may have been modified:
   1403 	Unused fields zeroed to help expr ().  */
   1404 
   1405 static void
   1406 clean_up_expression (expressionS *expressionP)
   1407 {
   1408   switch (expressionP->X_op)
   1409     {
   1410     case O_illegal:
   1411     case O_absent:
   1412       expressionP->X_add_number = 0;
   1413       /* Fall through.  */
   1414     case O_big:
   1415     case O_constant:
   1416     case O_register:
   1417       expressionP->X_add_symbol = NULL;
   1418       /* Fall through.  */
   1419     case O_symbol:
   1420     case O_uminus:
   1421     case O_bit_not:
   1422       expressionP->X_op_symbol = NULL;
   1423       break;
   1424     default:
   1425       break;
   1426     }
   1427 }
   1428 
   1429 /* Expression parser.  */
   1431 
   1432 /* We allow an empty expression, and just assume (absolute,0) silently.
   1433    Unary operators and parenthetical expressions are treated as operands.
   1434    As usual, Q==quantity==operand, O==operator, X==expression mnemonics.
   1435 
   1436    We used to do an aho/ullman shift-reduce parser, but the logic got so
   1437    warped that I flushed it and wrote a recursive-descent parser instead.
   1438    Now things are stable, would anybody like to write a fast parser?
   1439    Most expressions are either register (which does not even reach here)
   1440    or 1 symbol. Then "symbol+constant" and "symbol-symbol" are common.
   1441    So I guess it doesn't really matter how inefficient more complex expressions
   1442    are parsed.
   1443 
   1444    After expr(RANK,resultP) input_line_pointer->operator of rank <= RANK.
   1445    Also, we have consumed any leading or trailing spaces (operand does that)
   1446    and done all intervening operators.
   1447 
   1448    This returns the segment of the result, which will be
   1449    absolute_section or the segment of a symbol.  */
   1450 
   1451 #undef __
   1452 #define __ O_illegal
   1453 #ifndef O_SINGLE_EQ
   1454 #define O_SINGLE_EQ O_illegal
   1455 #endif
   1456 
   1457 /* Maps ASCII -> operators.  */
   1458 static const operatorT op_encoding[256] = {
   1459   __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
   1460   __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
   1461 
   1462   __, O_bit_or_not, __, __, __, O_modulus, O_bit_and, __,
   1463   __, __, O_multiply, O_add, __, O_subtract, __, O_divide,
   1464   __, __, __, __, __, __, __, __,
   1465   __, __, __, __, O_lt, O_SINGLE_EQ, O_gt, __,
   1466   __, __, __, __, __, __, __, __,
   1467   __, __, __, __, __, __, __, __,
   1468   __, __, __, __, __, __, __, __,
   1469   __, __, __,
   1470 #ifdef NEED_INDEX_OPERATOR
   1471   O_index,
   1472 #else
   1473   __,
   1474 #endif
   1475   __, __, O_bit_exclusive_or, __,
   1476   __, __, __, __, __, __, __, __,
   1477   __, __, __, __, __, __, __, __,
   1478   __, __, __, __, __, __, __, __,
   1479   __, __, __, __, O_bit_inclusive_or, __, __, __,
   1480 
   1481   __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
   1482   __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
   1483   __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
   1484   __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
   1485   __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
   1486   __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
   1487   __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
   1488   __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __
   1489 };
   1490 
   1491 /* Rank	Examples
   1492    0	operand, (expression)
   1493    1	||
   1494    2	&&
   1495    3	== <> < <= >= >
   1496    4	+ -
   1497    5	used for * / % in MRI mode
   1498    6	& ^ ! |
   1499    7	* / % << >>
   1500    8	unary - unary ~
   1501 */
   1502 static operator_rankT op_rank[O_max] = {
   1503   0,	/* O_illegal */
   1504   0,	/* O_absent */
   1505   0,	/* O_constant */
   1506   0,	/* O_symbol */
   1507   0,	/* O_symbol_rva */
   1508   0,	/* O_register */
   1509   0,	/* O_big */
   1510   9,	/* O_uminus */
   1511   9,	/* O_bit_not */
   1512   9,	/* O_logical_not */
   1513   8,	/* O_multiply */
   1514   8,	/* O_divide */
   1515   8,	/* O_modulus */
   1516   8,	/* O_left_shift */
   1517   8,	/* O_right_shift */
   1518   7,	/* O_bit_inclusive_or */
   1519   7,	/* O_bit_or_not */
   1520   7,	/* O_bit_exclusive_or */
   1521   7,	/* O_bit_and */
   1522   5,	/* O_add */
   1523   5,	/* O_subtract */
   1524   4,	/* O_eq */
   1525   4,	/* O_ne */
   1526   4,	/* O_lt */
   1527   4,	/* O_le */
   1528   4,	/* O_ge */
   1529   4,	/* O_gt */
   1530   3,	/* O_logical_and */
   1531   2,	/* O_logical_or */
   1532   1,	/* O_index */
   1533 };
   1534 
   1535 /* Unfortunately, in MRI mode for the m68k, multiplication and
   1536    division have lower precedence than the bit wise operators.  This
   1537    function sets the operator precedences correctly for the current
   1538    mode.  Also, MRI uses a different bit_not operator, and this fixes
   1539    that as well.  */
   1540 
   1541 #define STANDARD_MUL_PRECEDENCE 8
   1542 #define MRI_MUL_PRECEDENCE 6
   1543 
   1544 void
   1545 expr_set_precedence (void)
   1546 {
   1547   if (flag_m68k_mri)
   1548     {
   1549       op_rank[O_multiply] = MRI_MUL_PRECEDENCE;
   1550       op_rank[O_divide] = MRI_MUL_PRECEDENCE;
   1551       op_rank[O_modulus] = MRI_MUL_PRECEDENCE;
   1552     }
   1553   else
   1554     {
   1555       op_rank[O_multiply] = STANDARD_MUL_PRECEDENCE;
   1556       op_rank[O_divide] = STANDARD_MUL_PRECEDENCE;
   1557       op_rank[O_modulus] = STANDARD_MUL_PRECEDENCE;
   1558     }
   1559 }
   1560 
   1561 void
   1562 expr_set_rank (operatorT op, operator_rankT rank)
   1563 {
   1564   gas_assert (op >= O_md1 && op < ARRAY_SIZE (op_rank));
   1565   op_rank[op] = rank;
   1566 }
   1567 
   1568 /* Initialize the expression parser.  */
   1569 
   1570 void
   1571 expr_begin (void)
   1572 {
   1573   expr_set_precedence ();
   1574 
   1575   /* Verify that X_op field is wide enough.  */
   1576   {
   1577     expressionS e;
   1578     e.X_op = O_max;
   1579     gas_assert (e.X_op == O_max);
   1580   }
   1581 }
   1582 
   1583 /* Return the encoding for the operator at INPUT_LINE_POINTER, and
   1585    sets NUM_CHARS to the number of characters in the operator.
   1586    Does not advance INPUT_LINE_POINTER.  */
   1587 
   1588 static inline operatorT
   1589 operatorf (int *num_chars)
   1590 {
   1591   int c;
   1592   operatorT ret;
   1593 
   1594   c = *input_line_pointer & 0xff;
   1595   *num_chars = 1;
   1596 
   1597   if (is_end_of_line[c])
   1598     return O_illegal;
   1599 
   1600 #ifdef md_operator
   1601   if (is_name_beginner (c))
   1602     {
   1603       char *name;
   1604       char ec = get_symbol_name (& name);
   1605 
   1606       ret = md_operator (name, 2, &ec);
   1607       switch (ret)
   1608 	{
   1609 	case O_absent:
   1610 	  *input_line_pointer = ec;
   1611 	  input_line_pointer = name;
   1612 	  break;
   1613 	case O_uminus:
   1614 	case O_bit_not:
   1615 	case O_logical_not:
   1616 	  as_bad (_("invalid use of operator \"%s\""), name);
   1617 	  ret = O_illegal;
   1618 	  /* FALLTHROUGH */
   1619 	default:
   1620 	  *input_line_pointer = ec;
   1621 	  *num_chars = input_line_pointer - name;
   1622 	  input_line_pointer = name;
   1623 	  return ret;
   1624 	}
   1625     }
   1626 #endif
   1627 
   1628   switch (c)
   1629     {
   1630     default:
   1631       ret = op_encoding[c];
   1632 #ifdef md_operator
   1633       if (ret == O_illegal)
   1634 	{
   1635 	  char *start = input_line_pointer;
   1636 
   1637 	  ret = md_operator (NULL, 2, NULL);
   1638 	  if (ret != O_illegal)
   1639 	    *num_chars = input_line_pointer - start;
   1640 	  input_line_pointer = start;
   1641 	}
   1642 #endif
   1643       return ret;
   1644 
   1645     case '+':
   1646     case '-':
   1647       return op_encoding[c];
   1648 
   1649     case '<':
   1650       switch (input_line_pointer[1])
   1651 	{
   1652 	default:
   1653 	  return op_encoding[c];
   1654 	case '<':
   1655 	  ret = O_left_shift;
   1656 	  break;
   1657 	case '>':
   1658 	  ret = O_ne;
   1659 	  break;
   1660 	case '=':
   1661 	  ret = O_le;
   1662 	  break;
   1663 	}
   1664       *num_chars = 2;
   1665       return ret;
   1666 
   1667     case '=':
   1668       if (input_line_pointer[1] != '=')
   1669 	return op_encoding[c];
   1670 
   1671       *num_chars = 2;
   1672       return O_eq;
   1673 
   1674     case '>':
   1675       switch (input_line_pointer[1])
   1676 	{
   1677 	default:
   1678 	  return op_encoding[c];
   1679 	case '>':
   1680 	  ret = O_right_shift;
   1681 	  break;
   1682 	case '=':
   1683 	  ret = O_ge;
   1684 	  break;
   1685 	}
   1686       *num_chars = 2;
   1687       return ret;
   1688 
   1689     case '!':
   1690       switch (input_line_pointer[1])
   1691 	{
   1692 	case '!':
   1693 	  /* We accept !! as equivalent to ^ for MRI compatibility. */
   1694 	  *num_chars = 2;
   1695 	  return O_bit_exclusive_or;
   1696 	case '=':
   1697 	  /* We accept != as equivalent to <>.  */
   1698 	  *num_chars = 2;
   1699 	  return O_ne;
   1700 	default:
   1701 	  if (flag_m68k_mri)
   1702 	    return O_bit_inclusive_or;
   1703 	  return op_encoding[c];
   1704 	}
   1705 
   1706     case '|':
   1707       if (input_line_pointer[1] != '|')
   1708 	return op_encoding[c];
   1709 
   1710       *num_chars = 2;
   1711       return O_logical_or;
   1712 
   1713     case '&':
   1714       if (input_line_pointer[1] != '&')
   1715 	return op_encoding[c];
   1716 
   1717       *num_chars = 2;
   1718       return O_logical_and;
   1719     }
   1720 
   1721   /* NOTREACHED  */
   1722 }
   1723 
   1724 /* Implement "word-size + 1 bit" addition for
   1725    {resultP->X_extrabit:resultP->X_add_number} + {rhs_highbit:amount}.  This
   1726    is used so that the full range of unsigned word values and the full range of
   1727    signed word values can be represented in an O_constant expression, which is
   1728    useful e.g. for .sleb128 directives.  */
   1729 
   1730 void
   1731 add_to_result (expressionS *resultP, offsetT amount, int rhs_highbit)
   1732 {
   1733   valueT ures = resultP->X_add_number;
   1734   valueT uamount = amount;
   1735 
   1736   resultP->X_add_number += amount;
   1737 
   1738   resultP->X_extrabit ^= rhs_highbit;
   1739 
   1740   if (ures + uamount < ures)
   1741     resultP->X_extrabit ^= 1;
   1742 }
   1743 
   1744 /* Similarly, for subtraction.  */
   1745 
   1746 void
   1747 subtract_from_result (expressionS *resultP, offsetT amount, int rhs_highbit)
   1748 {
   1749   valueT ures = resultP->X_add_number;
   1750   valueT uamount = amount;
   1751 
   1752   resultP->X_add_number -= amount;
   1753 
   1754   resultP->X_extrabit ^= rhs_highbit;
   1755 
   1756   if (ures < uamount)
   1757     resultP->X_extrabit ^= 1;
   1758 }
   1759 
   1760 /* Parse an expression.  */
   1761 
   1762 segT
   1763 expr (int rankarg,		/* Larger # is higher rank.  */
   1764       expressionS *resultP,	/* Deliver result here.  */
   1765       enum expr_mode mode	/* Controls behavior.  */)
   1766 {
   1767   operator_rankT rank = (operator_rankT) rankarg;
   1768   segT retval;
   1769   expressionS right;
   1770   operatorT op_left;
   1771   operatorT op_right;
   1772   int op_chars;
   1773 
   1774   know (rankarg >= 0);
   1775 
   1776   /* Save the value of dot for the fixup code.  */
   1777   if (rank == 0)
   1778     {
   1779       dot_value = frag_now_fix ();
   1780       dot_frag = frag_now;
   1781     }
   1782 
   1783   retval = operand (resultP, mode);
   1784 
   1785   /* operand () gobbles spaces.  */
   1786   know (*input_line_pointer != ' ');
   1787 
   1788   op_left = operatorf (&op_chars);
   1789   while (op_left != O_illegal && op_rank[(int) op_left] > rank)
   1790     {
   1791       segT rightseg;
   1792       offsetT frag_off;
   1793 
   1794       input_line_pointer += op_chars;	/* -> after operator.  */
   1795 
   1796       right.X_md = 0;
   1797       rightseg = expr (op_rank[(int) op_left], &right, mode);
   1798       if (right.X_op == O_absent)
   1799 	{
   1800 	  as_warn (_("missing operand; zero assumed"));
   1801 	  right.X_op = O_constant;
   1802 	  right.X_add_number = 0;
   1803 	  right.X_add_symbol = NULL;
   1804 	  right.X_op_symbol = NULL;
   1805 	}
   1806 
   1807       know (*input_line_pointer != ' ');
   1808 
   1809       if (op_left == O_index)
   1810 	{
   1811 	  if (*input_line_pointer != ']')
   1812 	    as_bad ("missing right bracket");
   1813 	  else
   1814 	    {
   1815 	      ++input_line_pointer;
   1816 	      SKIP_WHITESPACE ();
   1817 	    }
   1818 	}
   1819 
   1820       op_right = operatorf (&op_chars);
   1821 
   1822       know (op_right == O_illegal || op_left == O_index
   1823 	    || op_rank[(int) op_right] <= op_rank[(int) op_left]);
   1824       know ((int) op_left >= (int) O_multiply);
   1825 #ifndef md_operator
   1826       know ((int) op_left <= (int) O_index);
   1827 #else
   1828       know ((int) op_left < (int) O_max);
   1829 #endif
   1830 
   1831       /* input_line_pointer->after right-hand quantity.  */
   1832       /* left-hand quantity in resultP.  */
   1833       /* right-hand quantity in right.  */
   1834       /* operator in op_left.  */
   1835 
   1836       if (resultP->X_op == O_big)
   1837 	{
   1838 	  if (resultP->X_add_number > 0)
   1839 	    as_warn (_("left operand is a bignum; integer 0 assumed"));
   1840 	  else
   1841 	    as_warn (_("left operand is a float; integer 0 assumed"));
   1842 	  resultP->X_op = O_constant;
   1843 	  resultP->X_add_number = 0;
   1844 	  resultP->X_add_symbol = NULL;
   1845 	  resultP->X_op_symbol = NULL;
   1846 	}
   1847       if (right.X_op == O_big)
   1848 	{
   1849 	  if (right.X_add_number > 0)
   1850 	    as_warn (_("right operand is a bignum; integer 0 assumed"));
   1851 	  else
   1852 	    as_warn (_("right operand is a float; integer 0 assumed"));
   1853 	  right.X_op = O_constant;
   1854 	  right.X_add_number = 0;
   1855 	  right.X_add_symbol = NULL;
   1856 	  right.X_op_symbol = NULL;
   1857 	}
   1858 
   1859       /* Optimize common cases.  */
   1860 #ifdef md_optimize_expr
   1861       if (md_optimize_expr (resultP, op_left, &right))
   1862 	{
   1863 	  /* Skip.  */
   1864 	  ;
   1865 	}
   1866       else
   1867 #endif
   1868 #ifndef md_register_arithmetic
   1869 # define md_register_arithmetic 1
   1870 #endif
   1871       if (op_left == O_add && right.X_op == O_constant
   1872 	  && (md_register_arithmetic || resultP->X_op != O_register))
   1873 	{
   1874 	  /* X + constant.  */
   1875 	  add_to_result (resultP, right.X_add_number, right.X_extrabit);
   1876 	}
   1877       /* This case comes up in PIC code.  */
   1878       else if (op_left == O_subtract
   1879 	       && right.X_op == O_symbol
   1880 	       && resultP->X_op == O_symbol
   1881 	       && retval == rightseg
   1882 #ifdef md_allow_local_subtract
   1883 	       && md_allow_local_subtract (resultP, & right, rightseg)
   1884 #endif
   1885 	       && ((SEG_NORMAL (rightseg)
   1886 		    && !S_FORCE_RELOC (resultP->X_add_symbol, 0)
   1887 		    && !S_FORCE_RELOC (right.X_add_symbol, 0))
   1888 		   || right.X_add_symbol == resultP->X_add_symbol)
   1889 	       && frag_offset_fixed_p (symbol_get_frag (resultP->X_add_symbol),
   1890 				       symbol_get_frag (right.X_add_symbol),
   1891 				       &frag_off))
   1892 	{
   1893 	  offsetT symval_diff = S_GET_VALUE (resultP->X_add_symbol)
   1894 				- S_GET_VALUE (right.X_add_symbol);
   1895 	  subtract_from_result (resultP, right.X_add_number, right.X_extrabit);
   1896 	  subtract_from_result (resultP, frag_off / OCTETS_PER_BYTE, 0);
   1897 	  add_to_result (resultP, symval_diff, symval_diff < 0);
   1898 	  resultP->X_op = O_constant;
   1899 	  resultP->X_add_symbol = 0;
   1900 	}
   1901       else if (op_left == O_subtract && right.X_op == O_constant
   1902 	       && (md_register_arithmetic || resultP->X_op != O_register))
   1903 	{
   1904 	  /* X - constant.  */
   1905 	  subtract_from_result (resultP, right.X_add_number, right.X_extrabit);
   1906 	}
   1907       else if (op_left == O_add && resultP->X_op == O_constant
   1908 	       && (md_register_arithmetic || right.X_op != O_register))
   1909 	{
   1910 	  /* Constant + X.  */
   1911 	  resultP->X_op = right.X_op;
   1912 	  resultP->X_add_symbol = right.X_add_symbol;
   1913 	  resultP->X_op_symbol = right.X_op_symbol;
   1914 	  add_to_result (resultP, right.X_add_number, right.X_extrabit);
   1915 	  retval = rightseg;
   1916 	}
   1917       else if (resultP->X_op == O_constant && right.X_op == O_constant)
   1918 	{
   1919 	  /* Constant OP constant.  */
   1920 	  offsetT v = right.X_add_number;
   1921 	  if (v == 0 && (op_left == O_divide || op_left == O_modulus))
   1922 	    {
   1923 	      as_warn (_("division by zero"));
   1924 	      v = 1;
   1925 	    }
   1926 	  if ((valueT) v >= sizeof(valueT) * CHAR_BIT
   1927 	      && (op_left == O_left_shift || op_left == O_right_shift))
   1928 	    {
   1929 	      as_warn_value_out_of_range (_("shift count"), v, 0,
   1930 					  sizeof(valueT) * CHAR_BIT - 1,
   1931 					  NULL, 0);
   1932 	      resultP->X_add_number = v = 0;
   1933 	    }
   1934 	  switch (op_left)
   1935 	    {
   1936 	    default:			goto general;
   1937 	    case O_multiply:		resultP->X_add_number *= v; break;
   1938 	    case O_divide:		resultP->X_add_number /= v; break;
   1939 	    case O_modulus:		resultP->X_add_number %= v; break;
   1940 	    case O_left_shift:		resultP->X_add_number <<= v; break;
   1941 	    case O_right_shift:
   1942 	      /* We always use unsigned shifts, to avoid relying on
   1943 		 characteristics of the compiler used to compile gas.  */
   1944 	      resultP->X_add_number =
   1945 		(offsetT) ((valueT) resultP->X_add_number >> (valueT) v);
   1946 	      break;
   1947 	    case O_bit_inclusive_or:	resultP->X_add_number |= v; break;
   1948 	    case O_bit_or_not:		resultP->X_add_number |= ~v; break;
   1949 	    case O_bit_exclusive_or:	resultP->X_add_number ^= v; break;
   1950 	    case O_bit_and:		resultP->X_add_number &= v; break;
   1951 	      /* Constant + constant (O_add) is handled by the
   1952 		 previous if statement for constant + X, so is omitted
   1953 		 here.  */
   1954 	    case O_subtract:
   1955 	      subtract_from_result (resultP, v, 0);
   1956 	      break;
   1957 	    case O_eq:
   1958 	      resultP->X_add_number =
   1959 		resultP->X_add_number == v ? ~ (offsetT) 0 : 0;
   1960 	      break;
   1961 	    case O_ne:
   1962 	      resultP->X_add_number =
   1963 		resultP->X_add_number != v ? ~ (offsetT) 0 : 0;
   1964 	      break;
   1965 	    case O_lt:
   1966 	      resultP->X_add_number =
   1967 		resultP->X_add_number <  v ? ~ (offsetT) 0 : 0;
   1968 	      break;
   1969 	    case O_le:
   1970 	      resultP->X_add_number =
   1971 		resultP->X_add_number <= v ? ~ (offsetT) 0 : 0;
   1972 	      break;
   1973 	    case O_ge:
   1974 	      resultP->X_add_number =
   1975 		resultP->X_add_number >= v ? ~ (offsetT) 0 : 0;
   1976 	      break;
   1977 	    case O_gt:
   1978 	      resultP->X_add_number =
   1979 		resultP->X_add_number >  v ? ~ (offsetT) 0 : 0;
   1980 	      break;
   1981 	    case O_logical_and:
   1982 	      resultP->X_add_number = resultP->X_add_number && v;
   1983 	      break;
   1984 	    case O_logical_or:
   1985 	      resultP->X_add_number = resultP->X_add_number || v;
   1986 	      break;
   1987 	    }
   1988 	}
   1989       else if (resultP->X_op == O_symbol
   1990 	       && right.X_op == O_symbol
   1991 	       && (op_left == O_add
   1992 		   || op_left == O_subtract
   1993 		   || (resultP->X_add_number == 0
   1994 		       && right.X_add_number == 0)))
   1995 	{
   1996 	  /* Symbol OP symbol.  */
   1997 	  resultP->X_op = op_left;
   1998 	  resultP->X_op_symbol = right.X_add_symbol;
   1999 	  if (op_left == O_add)
   2000 	    add_to_result (resultP, right.X_add_number, right.X_extrabit);
   2001 	  else if (op_left == O_subtract)
   2002 	    {
   2003 	      subtract_from_result (resultP, right.X_add_number,
   2004 				    right.X_extrabit);
   2005 	      if (retval == rightseg
   2006 		  && SEG_NORMAL (retval)
   2007 		  && !S_FORCE_RELOC (resultP->X_add_symbol, 0)
   2008 		  && !S_FORCE_RELOC (right.X_add_symbol, 0))
   2009 		{
   2010 		  retval = absolute_section;
   2011 		  rightseg = absolute_section;
   2012 		}
   2013 	    }
   2014 	}
   2015       else
   2016 	{
   2017         general:
   2018 	  /* The general case.  */
   2019 	  resultP->X_add_symbol = make_expr_symbol (resultP);
   2020 	  resultP->X_op_symbol = make_expr_symbol (&right);
   2021 	  resultP->X_op = op_left;
   2022 	  resultP->X_add_number = 0;
   2023 	  resultP->X_unsigned = 1;
   2024 	  resultP->X_extrabit = 0;
   2025 	}
   2026 
   2027       if (retval != rightseg)
   2028 	{
   2029 	  if (retval == undefined_section)
   2030 	    ;
   2031 	  else if (rightseg == undefined_section)
   2032 	    retval = rightseg;
   2033 	  else if (retval == expr_section)
   2034 	    ;
   2035 	  else if (rightseg == expr_section)
   2036 	    retval = rightseg;
   2037 	  else if (retval == reg_section)
   2038 	    ;
   2039 	  else if (rightseg == reg_section)
   2040 	    retval = rightseg;
   2041 	  else if (rightseg == absolute_section)
   2042 	    ;
   2043 	  else if (retval == absolute_section)
   2044 	    retval = rightseg;
   2045 #ifdef DIFF_EXPR_OK
   2046 	  else if (op_left == O_subtract)
   2047 	    ;
   2048 #endif
   2049 	  else
   2050 	    as_bad (_("operation combines symbols in different segments"));
   2051 	}
   2052 
   2053       op_left = op_right;
   2054     }				/* While next operator is >= this rank.  */
   2055 
   2056   /* The PA port needs this information.  */
   2057   if (resultP->X_add_symbol)
   2058     symbol_mark_used (resultP->X_add_symbol);
   2059 
   2060   if (rank == 0 && mode == expr_evaluate)
   2061     resolve_expression (resultP);
   2062 
   2063   return resultP->X_op == O_constant ? absolute_section : retval;
   2064 }
   2065 
   2066 /* Resolve an expression without changing any symbols/sub-expressions
   2067    used.  */
   2068 
   2069 int
   2070 resolve_expression (expressionS *expressionP)
   2071 {
   2072   /* Help out with CSE.  */
   2073   valueT final_val = expressionP->X_add_number;
   2074   symbolS *add_symbol = expressionP->X_add_symbol;
   2075   symbolS *orig_add_symbol = add_symbol;
   2076   symbolS *op_symbol = expressionP->X_op_symbol;
   2077   operatorT op = expressionP->X_op;
   2078   valueT left, right;
   2079   segT seg_left, seg_right;
   2080   fragS *frag_left, *frag_right;
   2081   offsetT frag_off;
   2082 
   2083   switch (op)
   2084     {
   2085     default:
   2086       return 0;
   2087 
   2088     case O_constant:
   2089     case O_register:
   2090       left = 0;
   2091       break;
   2092 
   2093     case O_symbol:
   2094     case O_symbol_rva:
   2095       if (!snapshot_symbol (&add_symbol, &left, &seg_left, &frag_left))
   2096 	return 0;
   2097 
   2098       break;
   2099 
   2100     case O_uminus:
   2101     case O_bit_not:
   2102     case O_logical_not:
   2103       if (!snapshot_symbol (&add_symbol, &left, &seg_left, &frag_left))
   2104 	return 0;
   2105 
   2106       if (seg_left != absolute_section)
   2107 	return 0;
   2108 
   2109       if (op == O_logical_not)
   2110 	left = !left;
   2111       else if (op == O_uminus)
   2112 	left = -left;
   2113       else
   2114 	left = ~left;
   2115       op = O_constant;
   2116       break;
   2117 
   2118     case O_multiply:
   2119     case O_divide:
   2120     case O_modulus:
   2121     case O_left_shift:
   2122     case O_right_shift:
   2123     case O_bit_inclusive_or:
   2124     case O_bit_or_not:
   2125     case O_bit_exclusive_or:
   2126     case O_bit_and:
   2127     case O_add:
   2128     case O_subtract:
   2129     case O_eq:
   2130     case O_ne:
   2131     case O_lt:
   2132     case O_le:
   2133     case O_ge:
   2134     case O_gt:
   2135     case O_logical_and:
   2136     case O_logical_or:
   2137       if (!snapshot_symbol (&add_symbol, &left, &seg_left, &frag_left)
   2138 	  || !snapshot_symbol (&op_symbol, &right, &seg_right, &frag_right))
   2139 	return 0;
   2140 
   2141       /* Simplify addition or subtraction of a constant by folding the
   2142 	 constant into X_add_number.  */
   2143       if (op == O_add)
   2144 	{
   2145 	  if (seg_right == absolute_section)
   2146 	    {
   2147 	      final_val += right;
   2148 	      op = O_symbol;
   2149 	      break;
   2150 	    }
   2151 	  else if (seg_left == absolute_section)
   2152 	    {
   2153 	      final_val += left;
   2154 	      left = right;
   2155 	      seg_left = seg_right;
   2156 	      add_symbol = op_symbol;
   2157 	      orig_add_symbol = expressionP->X_op_symbol;
   2158 	      op = O_symbol;
   2159 	      break;
   2160 	    }
   2161 	}
   2162       else if (op == O_subtract)
   2163 	{
   2164 	  if (seg_right == absolute_section)
   2165 	    {
   2166 	      final_val -= right;
   2167 	      op = O_symbol;
   2168 	      break;
   2169 	    }
   2170 	}
   2171 
   2172       /* Equality and non-equality tests are permitted on anything.
   2173 	 Subtraction, and other comparison operators are permitted if
   2174 	 both operands are in the same section.
   2175 	 Shifts by constant zero are permitted on anything.
   2176 	 Multiplies, bit-ors, and bit-ands with constant zero are
   2177 	 permitted on anything.
   2178 	 Multiplies and divides by constant one are permitted on
   2179 	 anything.
   2180 	 Binary operations with both operands being the same register
   2181 	 or undefined symbol are permitted if the result doesn't depend
   2182 	 on the input value.
   2183 	 Otherwise, both operands must be absolute.  We already handled
   2184 	 the case of addition or subtraction of a constant above.  */
   2185       frag_off = 0;
   2186       if (!(seg_left == absolute_section
   2187 	       && seg_right == absolute_section)
   2188 	  && !(op == O_eq || op == O_ne)
   2189 	  && !((op == O_subtract
   2190 		|| op == O_lt || op == O_le || op == O_ge || op == O_gt)
   2191 	       && seg_left == seg_right
   2192 	       && (finalize_syms
   2193 		   || frag_offset_fixed_p (frag_left, frag_right, &frag_off))
   2194 	       && (seg_left != reg_section || left == right)
   2195 	       && (seg_left != undefined_section || add_symbol == op_symbol)))
   2196 	{
   2197 	  if ((seg_left == absolute_section && left == 0)
   2198 	      || (seg_right == absolute_section && right == 0))
   2199 	    {
   2200 	      if (op == O_bit_exclusive_or || op == O_bit_inclusive_or)
   2201 		{
   2202 		  if (!(seg_right == absolute_section && right == 0))
   2203 		    {
   2204 		      seg_left = seg_right;
   2205 		      left = right;
   2206 		      add_symbol = op_symbol;
   2207 		      orig_add_symbol = expressionP->X_op_symbol;
   2208 		    }
   2209 		  op = O_symbol;
   2210 		  break;
   2211 		}
   2212 	      else if (op == O_left_shift || op == O_right_shift)
   2213 		{
   2214 		  if (!(seg_left == absolute_section && left == 0))
   2215 		    {
   2216 		      op = O_symbol;
   2217 		      break;
   2218 		    }
   2219 		}
   2220 	      else if (op != O_multiply
   2221 		       && op != O_bit_or_not && op != O_bit_and)
   2222 	        return 0;
   2223 	    }
   2224 	  else if (op == O_multiply
   2225 		   && seg_left == absolute_section && left == 1)
   2226 	    {
   2227 	      seg_left = seg_right;
   2228 	      left = right;
   2229 	      add_symbol = op_symbol;
   2230 	      orig_add_symbol = expressionP->X_op_symbol;
   2231 	      op = O_symbol;
   2232 	      break;
   2233 	    }
   2234 	  else if ((op == O_multiply || op == O_divide)
   2235 		   && seg_right == absolute_section && right == 1)
   2236 	    {
   2237 	      op = O_symbol;
   2238 	      break;
   2239 	    }
   2240 	  else if (!(left == right
   2241 		     && ((seg_left == reg_section && seg_right == reg_section)
   2242 			 || (seg_left == undefined_section
   2243 			     && seg_right == undefined_section
   2244 			     && add_symbol == op_symbol))))
   2245 	    return 0;
   2246 	  else if (op == O_bit_and || op == O_bit_inclusive_or)
   2247 	    {
   2248 	      op = O_symbol;
   2249 	      break;
   2250 	    }
   2251 	  else if (op != O_bit_exclusive_or && op != O_bit_or_not)
   2252 	    return 0;
   2253 	}
   2254 
   2255       right += frag_off / OCTETS_PER_BYTE;
   2256       switch (op)
   2257 	{
   2258 	case O_add:			left += right; break;
   2259 	case O_subtract:		left -= right; break;
   2260 	case O_multiply:		left *= right; break;
   2261 	case O_divide:
   2262 	  if (right == 0)
   2263 	    return 0;
   2264 	  left = (offsetT) left / (offsetT) right;
   2265 	  break;
   2266 	case O_modulus:
   2267 	  if (right == 0)
   2268 	    return 0;
   2269 	  left = (offsetT) left % (offsetT) right;
   2270 	  break;
   2271 	case O_left_shift:		left <<= right; break;
   2272 	case O_right_shift:		left >>= right; break;
   2273 	case O_bit_inclusive_or:	left |= right; break;
   2274 	case O_bit_or_not:		left |= ~right; break;
   2275 	case O_bit_exclusive_or:	left ^= right; break;
   2276 	case O_bit_and:			left &= right; break;
   2277 	case O_eq:
   2278 	case O_ne:
   2279 	  left = (left == right
   2280 		  && seg_left == seg_right
   2281 		  && (finalize_syms || frag_left == frag_right)
   2282 		  && (seg_left != undefined_section
   2283 		      || add_symbol == op_symbol)
   2284 		  ? ~ (valueT) 0 : 0);
   2285 	  if (op == O_ne)
   2286 	    left = ~left;
   2287 	  break;
   2288 	case O_lt:
   2289 	  left = (offsetT) left <  (offsetT) right ? ~ (valueT) 0 : 0;
   2290 	  break;
   2291 	case O_le:
   2292 	  left = (offsetT) left <= (offsetT) right ? ~ (valueT) 0 : 0;
   2293 	  break;
   2294 	case O_ge:
   2295 	  left = (offsetT) left >= (offsetT) right ? ~ (valueT) 0 : 0;
   2296 	  break;
   2297 	case O_gt:
   2298 	  left = (offsetT) left >  (offsetT) right ? ~ (valueT) 0 : 0;
   2299 	  break;
   2300 	case O_logical_and:	left = left && right; break;
   2301 	case O_logical_or:	left = left || right; break;
   2302 	default:		abort ();
   2303 	}
   2304 
   2305       op = O_constant;
   2306       break;
   2307     }
   2308 
   2309   if (op == O_symbol)
   2310     {
   2311       if (seg_left == absolute_section)
   2312 	op = O_constant;
   2313       else if (seg_left == reg_section && final_val == 0)
   2314 	op = O_register;
   2315       else if (!symbol_same_p (add_symbol, orig_add_symbol))
   2316 	final_val += left;
   2317       expressionP->X_add_symbol = add_symbol;
   2318     }
   2319   expressionP->X_op = op;
   2320 
   2321   if (op == O_constant || op == O_register)
   2322     final_val += left;
   2323   expressionP->X_add_number = final_val;
   2324 
   2325   return 1;
   2326 }
   2327 
   2328 /* This lives here because it belongs equally in expr.c & read.c.
   2330    expr.c is just a branch office read.c anyway, and putting it
   2331    here lessens the crowd at read.c.
   2332 
   2333    Assume input_line_pointer is at start of symbol name, or the
   2334     start of a double quote enclosed symbol name.
   2335    Advance input_line_pointer past symbol name.
   2336    Turn that character into a '\0', returning its former value,
   2337     which may be the closing double quote.
   2338    This allows a string compare (RMS wants symbol names to be strings)
   2339     of the symbol name.
   2340    There will always be a char following symbol name, because all good
   2341    lines end in end-of-line.  */
   2342 
   2343 char
   2344 get_symbol_name (char ** ilp_return)
   2345 {
   2346   char c;
   2347 
   2348   * ilp_return = input_line_pointer;
   2349   /* We accept \001 in a name in case this is being called with a
   2350      constructed string.  */
   2351   if (is_name_beginner (c = *input_line_pointer++) || c == '\001')
   2352     {
   2353       while (is_part_of_name (c = *input_line_pointer++)
   2354 	     || c == '\001')
   2355 	;
   2356       if (is_name_ender (c))
   2357 	c = *input_line_pointer++;
   2358     }
   2359   else if (c == '"')
   2360     {
   2361       bfd_boolean backslash_seen;
   2362 
   2363       * ilp_return = input_line_pointer;
   2364       do
   2365 	{
   2366 	  backslash_seen = c == '\\';
   2367 	  c = * input_line_pointer ++;
   2368 	}
   2369       while (c != 0 && (c != '"' || backslash_seen));
   2370 
   2371       if (c == 0)
   2372 	as_warn (_("missing closing '\"'"));
   2373     }
   2374   *--input_line_pointer = 0;
   2375   return c;
   2376 }
   2377 
   2378 /* Replace the NUL character pointed to by input_line_pointer
   2379    with C.  If C is \" then advance past it.  Return the character
   2380    now pointed to by input_line_pointer.  */
   2381 
   2382 char
   2383 restore_line_pointer (char c)
   2384 {
   2385   * input_line_pointer = c;
   2386   if (c == '"')
   2387     c = * ++ input_line_pointer;
   2388   return c;
   2389 }
   2390 
   2391 unsigned int
   2392 get_single_number (void)
   2393 {
   2394   expressionS exp;
   2395   operand (&exp, expr_normal);
   2396   return exp.X_add_number;
   2397 }
   2398