Subversion Repositories Kolibri OS

Rev

Rev 5222 | Blame | Compare with Previous | Last modification | View Log | RSS feed

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