Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

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