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