expr.c revision 78828
1290001Sglebius/* expr.c -operands, expressions-
2132451Sroberto   Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
354359Sroberto   1999, 2000, 2001
4290001Sglebius   Free Software Foundation, Inc.
5290001Sglebius
654359Sroberto   This file is part of GAS, the GNU Assembler.
754359Sroberto
854359Sroberto   GAS is free software; you can redistribute it and/or modify
954359Sroberto   it under the terms of the GNU General Public License as published by
1054359Sroberto   the Free Software Foundation; either version 2, or (at your option)
1154359Sroberto   any later version.
1254359Sroberto
1354359Sroberto   GAS is distributed in the hope that it will be useful,
1454359Sroberto   but WITHOUT ANY WARRANTY; without even the implied warranty of
15106163Sroberto   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16106163Sroberto   GNU General Public License for more details.
1754359Sroberto
18290001Sglebius   You should have received a copy of the GNU General Public License
19290001Sglebius   along with GAS; see the file COPYING.  If not, write to the Free
20290001Sglebius   Software Foundation, 59 Temple Place - Suite 330, Boston, MA
21290001Sglebius   02111-1307, USA.  */
22290001Sglebius
23290001Sglebius/* This is really a branch office of as-read.c. I split it out to clearly
24290001Sglebius   distinguish the world of expressions from the world of statements.
25290001Sglebius   (It also gives smaller files to re-compile.)
26290001Sglebius   Here, "operand"s are of expressions, not instructions.  */
27290001Sglebius
28290001Sglebius#include <ctype.h>
29290001Sglebius#include <string.h>
30290001Sglebius#define min(a, b)       ((a) < (b) ? (a) : (b))
31290001Sglebius
32290001Sglebius#include "as.h"
33290001Sglebius#include "obstack.h"
34290001Sglebius
35290001Sglebiusstatic void floating_constant PARAMS ((expressionS * expressionP));
36290001Sglebiusstatic valueT generic_bignum_to_int32 PARAMS ((void));
37290001Sglebius#ifdef BFD64
38290001Sglebiusstatic valueT generic_bignum_to_int64 PARAMS ((void));
39290001Sglebius#endif
40290001Sglebiusstatic void integer_constant PARAMS ((int radix, expressionS * expressionP));
41290001Sglebiusstatic void mri_char_constant PARAMS ((expressionS *));
42290001Sglebiusstatic void current_location PARAMS ((expressionS *));
43290001Sglebiusstatic void clean_up_expression PARAMS ((expressionS * expressionP));
44290001Sglebiusstatic segT operand PARAMS ((expressionS *));
45290001Sglebiusstatic operatorT operator PARAMS ((int *));
46290001Sglebius
47290001Sglebiusextern const char EXP_CHARS[], FLT_CHARS[];
48290001Sglebius
49290001Sglebius/* We keep a mapping of expression symbols to file positions, so that
50290001Sglebius   we can provide better error messages.  */
51290001Sglebius
52290001Sglebiusstruct expr_symbol_line {
53290001Sglebius  struct expr_symbol_line *next;
54290001Sglebius  symbolS *sym;
55290001Sglebius  char *file;
56290001Sglebius  unsigned int line;
57290001Sglebius};
58290001Sglebius
59290001Sglebiusstatic struct expr_symbol_line *expr_symbol_lines;
60290001Sglebius
61290001Sglebius/* Build a dummy symbol to hold a complex expression.  This is how we
62290001Sglebius   build expressions up out of other expressions.  The symbol is put
63290001Sglebius   into the fake section expr_section.  */
64290001Sglebius
65290001SglebiussymbolS *
66290001Sglebiusmake_expr_symbol (expressionP)
67290001Sglebius     expressionS *expressionP;
68290001Sglebius{
69290001Sglebius  expressionS zero;
70290001Sglebius  const char *fake;
71290001Sglebius  symbolS *symbolP;
72290001Sglebius  struct expr_symbol_line *n;
7354359Sroberto
74200576Sroberto  if (expressionP->X_op == O_symbol
7554359Sroberto      && expressionP->X_add_number == 0)
76200576Sroberto    return expressionP->X_add_symbol;
77132451Sroberto
78132451Sroberto  if (expressionP->X_op == O_big)
79132451Sroberto    {
80132451Sroberto      /* This won't work, because the actual value is stored in
8182498Sroberto         generic_floating_point_number or generic_bignum, and we are
82132451Sroberto         going to lose it if we haven't already.  */
8354359Sroberto      if (expressionP->X_add_number > 0)
8454359Sroberto	as_bad (_("bignum invalid; zero assumed"));
8554359Sroberto      else
8654359Sroberto	as_bad (_("floating point number invalid; zero assumed"));
8754359Sroberto      zero.X_op = O_constant;
8854359Sroberto      zero.X_add_number = 0;
8954359Sroberto      zero.X_unsigned = 0;
9054359Sroberto      clean_up_expression (&zero);
91290001Sglebius      expressionP = &zero;
92182007Sroberto    }
93182007Sroberto
94290001Sglebius  fake = FAKE_LABEL_NAME;
95290001Sglebius
96290001Sglebius  /* Putting constant symbols in absolute_section rather than
97290001Sglebius     expr_section is convenient for the old a.out code, for which
98290001Sglebius     S_GET_SEGMENT does not always retrieve the value put in by
99290001Sglebius     S_SET_SEGMENT.  */
100290001Sglebius  symbolP = symbol_create (fake,
101290001Sglebius			   (expressionP->X_op == O_constant
102290001Sglebius			    ? absolute_section
103290001Sglebius			    : expr_section),
104290001Sglebius			   0, &zero_address_frag);
105290001Sglebius  symbol_set_value_expression (symbolP, expressionP);
106290001Sglebius
107290001Sglebius  if (expressionP->X_op == O_constant)
108290001Sglebius    resolve_symbol_value (symbolP, 1);
109290001Sglebius
110290001Sglebius  n = (struct expr_symbol_line *) xmalloc (sizeof *n);
111290001Sglebius  n->sym = symbolP;
112290001Sglebius  as_where (&n->file, &n->line);
113290001Sglebius  n->next = expr_symbol_lines;
114290001Sglebius  expr_symbol_lines = n;
115290001Sglebius
116290001Sglebius  return symbolP;
117290001Sglebius}
118290001Sglebius
119290001Sglebius/* Return the file and line number for an expr symbol.  Return
120290001Sglebius   non-zero if something was found, 0 if no information is known for
121290001Sglebius   the symbol.  */
122290001Sglebius
123290001Sglebiusint
124290001Sglebiusexpr_symbol_where (sym, pfile, pline)
125290001Sglebius     symbolS *sym;
126290001Sglebius     char **pfile;
127290001Sglebius     unsigned int *pline;
128290001Sglebius{
129290001Sglebius  register struct expr_symbol_line *l;
130290001Sglebius
131290001Sglebius  for (l = expr_symbol_lines; l != NULL; l = l->next)
132182007Sroberto    {
133182007Sroberto      if (l->sym == sym)
134290001Sglebius	{
135182007Sroberto	  *pfile = l->file;
136182007Sroberto	  *pline = l->line;
137182007Sroberto	  return 1;
138200576Sroberto	}
139182007Sroberto    }
140182007Sroberto
141290001Sglebius  return 0;
142290001Sglebius}
143290001Sglebius
144290001Sglebius/* Utilities for building expressions.
145290001Sglebius   Since complex expressions are recorded as symbols for use in other
146290001Sglebius   expressions these return a symbolS * and not an expressionS *.
147290001Sglebius   These explicitly do not take an "add_number" argument.  */
148290001Sglebius/* ??? For completeness' sake one might want expr_build_symbol.
149290001Sglebius   It would just return its argument.  */
150182007Sroberto
151290001Sglebius/* Build an expression for an unsigned constant.
152290001Sglebius   The corresponding one for signed constants is missing because
153290001Sglebius   there's currently no need for it.  One could add an unsigned_p flag
154290001Sglebius   but that seems more clumsy.  */
155290001Sglebius
156290001SglebiussymbolS *
157290001Sglebiusexpr_build_uconstant (value)
158290001Sglebius     offsetT value;
159290001Sglebius{
160290001Sglebius  expressionS e;
161290001Sglebius
162290001Sglebius  e.X_op = O_constant;
163290001Sglebius  e.X_add_number = value;
164290001Sglebius  e.X_unsigned = 1;
165290001Sglebius  return make_expr_symbol (&e);
166290001Sglebius}
167200576Sroberto
168290001Sglebius/* Build an expression for OP s1.  */
169182007Sroberto
170200576SrobertosymbolS *
171182007Srobertoexpr_build_unary (op, s1)
172182007Sroberto     operatorT op;
173290001Sglebius     symbolS *s1;
174290001Sglebius{
175290001Sglebius  expressionS e;
176290001Sglebius
177290001Sglebius  e.X_op = op;
178290001Sglebius  e.X_add_symbol = s1;
179290001Sglebius  e.X_add_number = 0;
180290001Sglebius  return make_expr_symbol (&e);
181182007Sroberto}
182290001Sglebius
183290001Sglebius/* Build an expression for s1 OP s2.  */
184290001Sglebius
185290001SglebiussymbolS *
186290001Sglebiusexpr_build_binary (op, s1, s2)
187290001Sglebius     operatorT op;
188290001Sglebius     symbolS *s1;
189290001Sglebius     symbolS *s2;
190290001Sglebius{
191290001Sglebius  expressionS e;
192290001Sglebius
193290001Sglebius  e.X_op = op;
194290001Sglebius  e.X_add_symbol = s1;
195290001Sglebius  e.X_op_symbol = s2;
196290001Sglebius  e.X_add_number = 0;
197290001Sglebius  return make_expr_symbol (&e);
198290001Sglebius}
199290001Sglebius
200290001Sglebius/* Build an expression for the current location ('.').  */
201290001Sglebius
202290001SglebiussymbolS *
203290001Sglebiusexpr_build_dot ()
204290001Sglebius{
205290001Sglebius  expressionS e;
206290001Sglebius
207290001Sglebius  current_location (&e);
208290001Sglebius  return make_expr_symbol (&e);
209290001Sglebius}
210290001Sglebius
211290001Sglebius/* Build any floating-point literal here.
212290001Sglebius   Also build any bignum literal here.  */
213182007Sroberto
214182007Sroberto/* Seems atof_machine can backscan through generic_bignum and hit whatever
215290001Sglebius   happens to be loaded before it in memory.  And its way too complicated
216290001Sglebius   for me to fix right.  Thus a hack.  JF:  Just make generic_bignum bigger,
217290001Sglebius   and never write into the early words, thus they'll always be zero.
218182007Sroberto   I hate Dean's floating-point code.  Bleh.  */
219132451SrobertoLITTLENUM_TYPE generic_bignum[SIZE_OF_LARGE_NUMBER + 6];
220290001Sglebius
22154359SrobertoFLONUM_TYPE generic_floating_point_number = {
222290001Sglebius  &generic_bignum[6],		/* low.  (JF: Was 0)  */
223182007Sroberto  &generic_bignum[SIZE_OF_LARGE_NUMBER + 6 - 1], /* high.  JF: (added +6)  */
224132451Sroberto  0,				/* leader.  */
225132451Sroberto  0,				/* exponent.  */
226132451Sroberto  0				/* sign.  */
22754359Sroberto};
228290001Sglebius
229290001Sglebius/* If nonzero, we've been asked to assemble nan, +inf or -inf.  */
230290001Sglebiusint generic_floating_point_magic;
231290001Sglebius
232290001Sglebiusstatic void
233290001Sglebiusfloating_constant (expressionP)
23454359Sroberto     expressionS *expressionP;
235132451Sroberto{
23654359Sroberto  /* input_line_pointer -> floating-point constant.  */
237290001Sglebius  int error_code;
238290001Sglebius
23954359Sroberto  error_code = atof_generic (&input_line_pointer, ".", EXP_CHARS,
240290001Sglebius			     &generic_floating_point_number);
24154359Sroberto
242132451Sroberto  if (error_code)
243290001Sglebius    {
244290001Sglebius      if (error_code == ERROR_EXPONENT_OVERFLOW)
245290001Sglebius	{
246290001Sglebius	  as_bad (_("bad floating-point constant: exponent overflow, probably assembling junk"));
247290001Sglebius	}
248290001Sglebius      else
249132451Sroberto	{
25054359Sroberto	  as_bad (_("bad floating-point constant: unknown error code=%d."), error_code);
251132451Sroberto	}
25256746Sroberto    }
253290001Sglebius  expressionP->X_op = O_big;
254290001Sglebius  /* input_line_pointer -> just after constant, which may point to
255290001Sglebius     whitespace.  */
256132451Sroberto  expressionP->X_add_number = -1;
257132451Sroberto}
258132451Sroberto
259290001Sglebiusstatic valueT
260132451Srobertogeneric_bignum_to_int32 ()
261106163Sroberto{
262290001Sglebius  valueT number =
263200576Sroberto	   ((generic_bignum[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
264290001Sglebius	   | (generic_bignum[0] & LITTLENUM_MASK);
265290001Sglebius  number &= 0xffffffff;
266290001Sglebius  return number;
267290001Sglebius}
268290001Sglebius
269200576Sroberto#ifdef BFD64
270290001Sglebiusstatic valueT
271290001Sglebiusgeneric_bignum_to_int64 ()
272290001Sglebius{
273200576Sroberto  valueT number =
274132451Sroberto    ((((((((valueT) generic_bignum[3] & LITTLENUM_MASK)
275132451Sroberto	  << LITTLENUM_NUMBER_OF_BITS)
276132451Sroberto	 | ((valueT) generic_bignum[2] & LITTLENUM_MASK))
27782498Sroberto	<< LITTLENUM_NUMBER_OF_BITS)
278290001Sglebius       | ((valueT) generic_bignum[1] & LITTLENUM_MASK))
279290001Sglebius      << LITTLENUM_NUMBER_OF_BITS)
280290001Sglebius     | ((valueT) generic_bignum[0] & LITTLENUM_MASK));
281290001Sglebius  return number;
282290001Sglebius}
283290001Sglebius#endif
28454359Sroberto
285290001Sglebiusstatic void
286290001Sglebiusinteger_constant (radix, expressionP)
287290001Sglebius     int radix;
288132451Sroberto     expressionS *expressionP;
289182007Sroberto{
290182007Sroberto  char *start;		/* Start of number.  */
291182007Sroberto  char *suffix = NULL;
29254359Sroberto  char c;
293132451Sroberto  valueT number;	/* Offset or (absolute) value.  */
294182007Sroberto  short int digit;	/* Value of next digit in current radix.  */
295290001Sglebius  short int maxdig = 0;	/* Highest permitted digit value.  */
296290001Sglebius  int too_many_digits = 0;	/* If we see >= this number of.  */
29754359Sroberto  char *name;		/* Points to name of symbol.  */
298200576Sroberto  symbolS *symbolP;	/* Points to symbol.  */
299290001Sglebius
300132451Sroberto  int small;			/* True if fits in 32 bits.  */
301132451Sroberto
30254359Sroberto  /* May be bignum, or may fit in 32 bits.  */
303182007Sroberto  /* Most numbers fit into 32 bits, and we want this case to be fast.
30454359Sroberto     so we pretend it will fit into 32 bits.  If, after making up a 32
305132451Sroberto     bit number, we realise that we have scanned more digits than
30654359Sroberto     comfortably fit into 32 bits, we re-scan the digits coding them
30754359Sroberto     into a bignum.  For decimal and octal numbers we are
308132451Sroberto     conservative: Some numbers may be assumed bignums when in fact
309290001Sglebius     they do fit into 32 bits.  Numbers of any radix can have excess
31054359Sroberto     leading zeros: We strive to recognise this and cast them back
31154359Sroberto     into 32 bits.  We must check that the bignum really is more than
31254359Sroberto     32 bits, and change it back to a 32-bit number if it fits.  The
31382498Sroberto     number we are looking for is expected to be positive, but if it
314290001Sglebius     fits into 32 bits as an unsigned number, we let it be a 32-bit
315290001Sglebius     number.  The cavalier approach is for speed in ordinary cases.  */
316200576Sroberto  /* This has been extended for 64 bits.  We blindly assume that if
317290001Sglebius     you're compiling in 64-bit mode, the target is a 64-bit machine.
318290001Sglebius     This should be cleaned up.  */
319290001Sglebius
320290001Sglebius#ifdef BFD64
321290001Sglebius#define valuesize 64
322290001Sglebius#else /* includes non-bfd case, mostly */
323290001Sglebius#define valuesize 32
324290001Sglebius#endif
325290001Sglebius
326290001Sglebius  if ((NUMBERS_WITH_SUFFIX || flag_m68k_mri) && radix == 0)
327290001Sglebius    {
328290001Sglebius      int flt = 0;
329290001Sglebius
330290001Sglebius      /* In MRI mode, the number may have a suffix indicating the
331290001Sglebius         radix.  For that matter, it might actually be a floating
332290001Sglebius         point constant.  */
333290001Sglebius      for (suffix = input_line_pointer;
334290001Sglebius	   isalnum ((unsigned char) *suffix);
335290001Sglebius	   suffix++)
336290001Sglebius	{
337290001Sglebius	  if (*suffix == 'e' || *suffix == 'E')
338290001Sglebius	    flt = 1;
339290001Sglebius	}
340290001Sglebius
341290001Sglebius      if (suffix == input_line_pointer)
342290001Sglebius	{
343290001Sglebius	  radix = 10;
344290001Sglebius	  suffix = NULL;
345290001Sglebius	}
346290001Sglebius      else
347290001Sglebius	{
348290001Sglebius	  c = *--suffix;
349290001Sglebius	  if (islower ((unsigned char) c))
350290001Sglebius	    c = toupper (c);
351290001Sglebius	  if (c == 'B')
352290001Sglebius	    radix = 2;
353290001Sglebius	  else if (c == 'D')
354290001Sglebius	    radix = 10;
355290001Sglebius	  else if (c == 'O' || c == 'Q')
356290001Sglebius	    radix = 8;
357290001Sglebius	  else if (c == 'H')
358290001Sglebius	    radix = 16;
359290001Sglebius	  else if (suffix[1] == '.' || c == 'E' || flt)
360290001Sglebius	    {
361290001Sglebius	      floating_constant (expressionP);
362290001Sglebius	      return;
363290001Sglebius	    }
364290001Sglebius	  else
365290001Sglebius	    {
366290001Sglebius	      radix = 10;
367290001Sglebius	      suffix = NULL;
368290001Sglebius	    }
369290001Sglebius	}
370290001Sglebius    }
371290001Sglebius
372290001Sglebius  switch (radix)
373290001Sglebius    {
374290001Sglebius    case 2:
375290001Sglebius      maxdig = 2;
376106163Sroberto      too_many_digits = valuesize + 1;
377290001Sglebius      break;
378290001Sglebius    case 8:
37954359Sroberto      maxdig = radix = 8;
380132451Sroberto      too_many_digits = (valuesize + 2) / 3 + 1;
381132451Sroberto      break;
382132451Sroberto    case 16:
383132451Sroberto      maxdig = radix = 16;
384200576Sroberto      too_many_digits = (valuesize + 3) / 4 + 1;
385132451Sroberto      break;
386290001Sglebius    case 10:
38782498Sroberto      maxdig = radix = 10;
388290001Sglebius      too_many_digits = (valuesize + 11) / 4; /* Very rough.  */
389132451Sroberto    }
390290001Sglebius#undef valuesize
391290001Sglebius  start = input_line_pointer;
392290001Sglebius  c = *input_line_pointer++;
393290001Sglebius  for (number = 0;
39454359Sroberto       (digit = hex_value (c)) < maxdig;
395290001Sglebius       c = *input_line_pointer++)
39654359Sroberto    {
397290001Sglebius      number = number * radix + digit;
398132451Sroberto    }
399132451Sroberto  /* c contains character after number.  */
400290001Sglebius  /* input_line_pointer->char after c.  */
401290001Sglebius  small = (input_line_pointer - start - 1) < too_many_digits;
402290001Sglebius
403290001Sglebius  if (radix == 16 && c == '_')
404290001Sglebius    {
405290001Sglebius      /* This is literal of the form 0x333_0_12345678_1.
406290001Sglebius         This example is equivalent to 0x00000333000000001234567800000001.  */
407290001Sglebius
408290001Sglebius      int num_little_digits = 0;
409290001Sglebius      int i;
410132451Sroberto      input_line_pointer = start;	/* -> 1st digit.  */
41154359Sroberto
412290001Sglebius      know (LITTLENUM_NUMBER_OF_BITS == 16);
413290001Sglebius
414290001Sglebius      for (c = '_'; c == '_'; num_little_digits += 2)
415290001Sglebius	{
416290001Sglebius
417290001Sglebius	  /* Convert one 64-bit word.  */
418290001Sglebius	  int ndigit = 0;
419290001Sglebius	  number = 0;
420290001Sglebius	  for (c = *input_line_pointer++;
421290001Sglebius	       (digit = hex_value (c)) < maxdig;
422290001Sglebius	       c = *(input_line_pointer++))
423290001Sglebius	    {
424290001Sglebius	      number = number * radix + digit;
425290001Sglebius	      ndigit++;
426290001Sglebius	    }
42754359Sroberto
428290001Sglebius	  /* Check for 8 digit per word max.  */
429290001Sglebius	  if (ndigit > 8)
430290001Sglebius	    as_bad (_("A bignum with underscores may not have more than 8 hex digits in any word."));
431200576Sroberto
432200576Sroberto	  /* Add this chunk to the bignum.
433200576Sroberto	     Shift things down 2 little digits.  */
434200576Sroberto	  know (LITTLENUM_NUMBER_OF_BITS == 16);
435290001Sglebius	  for (i = min (num_little_digits + 1, SIZE_OF_LARGE_NUMBER - 1);
436132451Sroberto	       i >= 2;
437290001Sglebius	       i--)
438290001Sglebius	    generic_bignum[i] = generic_bignum[i - 2];
439106163Sroberto
440132451Sroberto	  /* Add the new digits as the least significant new ones.  */
441106163Sroberto	  generic_bignum[0] = number & 0xffffffff;
442182007Sroberto	  generic_bignum[1] = number >> 16;
443182007Sroberto	}
444132451Sroberto
445132451Sroberto      /* Again, c is char after number, input_line_pointer->after c.  */
446132451Sroberto
447132451Sroberto      if (num_little_digits > SIZE_OF_LARGE_NUMBER - 1)
448132451Sroberto	num_little_digits = SIZE_OF_LARGE_NUMBER - 1;
449132451Sroberto
450200576Sroberto      assert (num_little_digits >= 4);
451132451Sroberto
452200576Sroberto      if (num_little_digits != 8)
453200576Sroberto	as_bad (_("A bignum with underscores must have exactly 4 words."));
454200576Sroberto
455132451Sroberto      /* We might have some leading zeros.  These can be trimmed to give
456132451Sroberto	 us a change to fit this constant into a small number.  */
457132451Sroberto      while (generic_bignum[num_little_digits - 1] == 0
458132451Sroberto	     && num_little_digits > 1)
459132451Sroberto	num_little_digits--;
460132451Sroberto
461200576Sroberto      if (num_little_digits <= 2)
462132451Sroberto	{
463132451Sroberto	  /* will fit into 32 bits.  */
46456746Sroberto	  number = generic_bignum_to_int32 ();
465132451Sroberto	  small = 1;
466132451Sroberto	}
467200576Sroberto#ifdef BFD64
468132451Sroberto      else if (num_little_digits <= 4)
469132451Sroberto	{
470182007Sroberto	  /* Will fit into 64 bits.  */
471132451Sroberto	  number = generic_bignum_to_int64 ();
472200576Sroberto	  small = 1;
473132451Sroberto	}
474132451Sroberto#endif
475200576Sroberto      else
476132451Sroberto	{
477132451Sroberto	  small = 0;
478200576Sroberto
479132451Sroberto	  /* Number of littlenums in the bignum.  */
480132451Sroberto	  number = num_little_digits;
481132451Sroberto	}
482200576Sroberto    }
483200576Sroberto  else if (!small)
484200576Sroberto    {
485290001Sglebius      /* We saw a lot of digits. manufacture a bignum the hard way.  */
486290001Sglebius      LITTLENUM_TYPE *leader;	/* -> high order littlenum of the bignum.  */
487290001Sglebius      LITTLENUM_TYPE *pointer;	/* -> littlenum we are frobbing now.  */
488290001Sglebius      long carry;
489290001Sglebius
490290001Sglebius      leader = generic_bignum;
491290001Sglebius      generic_bignum[0] = 0;
492290001Sglebius      generic_bignum[1] = 0;
493290001Sglebius      generic_bignum[2] = 0;
494290001Sglebius      generic_bignum[3] = 0;
495290001Sglebius      input_line_pointer = start;	/* -> 1st digit.  */
496290001Sglebius      c = *input_line_pointer++;
49754359Sroberto      for (; (carry = hex_value (c)) < maxdig; c = *input_line_pointer++)
49854359Sroberto	{
499182007Sroberto	  for (pointer = generic_bignum; pointer <= leader; pointer++)
500290001Sglebius	    {
501182007Sroberto	      long work;
502182007Sroberto
503182007Sroberto	      work = carry + radix * *pointer;
504200576Sroberto	      *pointer = work & LITTLENUM_MASK;
505200576Sroberto	      carry = work >> LITTLENUM_NUMBER_OF_BITS;
506182007Sroberto	    }
507182007Sroberto	  if (carry)
508182007Sroberto	    {
509200576Sroberto	      if (leader < generic_bignum + SIZE_OF_LARGE_NUMBER - 1)
510200576Sroberto		{
511200576Sroberto		  /* Room to grow a longer bignum.  */
512182007Sroberto		  *++leader = carry;
513182007Sroberto		}
514182007Sroberto	    }
515182007Sroberto	}
516182007Sroberto      /* Again, c is char after number.  */
517182007Sroberto      /* input_line_pointer -> after c.  */
518182007Sroberto      know (LITTLENUM_NUMBER_OF_BITS == 16);
519182007Sroberto      if (leader < generic_bignum + 2)
520290001Sglebius	{
52154359Sroberto	  /* Will fit into 32 bits.  */
522182007Sroberto	  number = generic_bignum_to_int32 ();
523182007Sroberto	  small = 1;
524182007Sroberto	}
525182007Sroberto#ifdef BFD64
526182007Sroberto      else if (leader < generic_bignum + 4)
527182007Sroberto	{
528182007Sroberto	  /* Will fit into 64 bits.  */
529200576Sroberto	  number = generic_bignum_to_int64 ();
530182007Sroberto	  small = 1;
53154359Sroberto	}
532200576Sroberto#endif
533200576Sroberto      else
534200576Sroberto	{
535200576Sroberto	  /* Number of littlenums in the bignum.  */
536200576Sroberto	  number = leader - generic_bignum + 1;
537200576Sroberto	}
538200576Sroberto    }
539290001Sglebius
540290001Sglebius  if ((NUMBERS_WITH_SUFFIX || flag_m68k_mri)
541290001Sglebius      && suffix != NULL
542290001Sglebius      && input_line_pointer - 1 == suffix)
543290001Sglebius    c = *input_line_pointer++;
544290001Sglebius
545106163Sroberto  if (small)
546290001Sglebius    {
54754359Sroberto      /* Here with number, in correct radix. c is the next char.
54854359Sroberto	 Note that unlike un*x, we allow "011f" "0x9f" to both mean
549182007Sroberto	 the same as the (conventional) "9f".
55054359Sroberto	 This is simply easier than checking for strict canonical
55154359Sroberto	 form.  Syntax sux!  */
55254359Sroberto
55354359Sroberto      if (LOCAL_LABELS_FB && c == 'b')
554290001Sglebius	{
555290001Sglebius	  /* Backward ref to local label.
55654359Sroberto	     Because it is backward, expect it to be defined.  */
557106163Sroberto	  /* Construct a local label.  */
558290001Sglebius	  name = fb_label_name ((int) number, 0);
559290001Sglebius
560290001Sglebius	  /* Seen before, or symbol is defined: OK.  */
561182007Sroberto	  symbolP = symbol_find (name);
562290001Sglebius	  if ((symbolP != NULL) && (S_IS_DEFINED (symbolP)))
563106163Sroberto	    {
564106163Sroberto	      /* Local labels are never absolute.  Don't waste time
565290001Sglebius		 checking absoluteness.  */
566290001Sglebius	      know (SEG_NORMAL (S_GET_SEGMENT (symbolP)));
567290001Sglebius
568182007Sroberto	      expressionP->X_op = O_symbol;
569290001Sglebius	      expressionP->X_add_symbol = symbolP;
570182007Sroberto	    }
571182007Sroberto	  else
572290001Sglebius	    {
573290001Sglebius	      /* Either not seen or not defined.  */
574290001Sglebius	      /* @@ Should print out the original string instead of
575182007Sroberto		 the parsed number.  */
576290001Sglebius	      as_bad (_("backw. ref to unknown label \"%d:\", 0 assumed."),
57754359Sroberto		      (int) number);
578182007Sroberto	      expressionP->X_op = O_constant;
579182007Sroberto	    }
580132451Sroberto
581182007Sroberto	  expressionP->X_add_number = 0;
582182007Sroberto	}			/* case 'b' */
583132451Sroberto      else if (LOCAL_LABELS_FB && c == 'f')
584290001Sglebius	{
585290001Sglebius	  /* Forward reference.  Expect symbol to be undefined or
586290001Sglebius	     unknown.  undefined: seen it before.  unknown: never seen
587290001Sglebius	     it before.
58854359Sroberto
589290001Sglebius	     Construct a local label name, then an undefined symbol.
590200576Sroberto	     Don't create a xseg frag for it: caller may do that.
59154359Sroberto	     Just return it as never seen before.  */
592290001Sglebius	  name = fb_label_name ((int) number, 1);
593200576Sroberto	  symbolP = symbol_find_or_make (name);
594200576Sroberto	  /* We have no need to check symbol properties.  */
595182007Sroberto#ifndef many_segments
596200576Sroberto	  /* Since "know" puts its arg into a "string", we
597200576Sroberto	     can't have newlines in the argument.  */
598200576Sroberto	  know (S_GET_SEGMENT (symbolP) == undefined_section || S_GET_SEGMENT (symbolP) == text_section || S_GET_SEGMENT (symbolP) == data_section);
599200576Sroberto#endif
600200576Sroberto	  expressionP->X_op = O_symbol;
601200576Sroberto	  expressionP->X_add_symbol = symbolP;
602200576Sroberto	  expressionP->X_add_number = 0;
603182007Sroberto	}			/* case 'f' */
604290001Sglebius      else if (LOCAL_LABELS_DOLLAR && c == '$')
605290001Sglebius	{
606290001Sglebius	  /* If the dollar label is *currently* defined, then this is just
607290001Sglebius	     another reference to it.  If it is not *currently* defined,
608290001Sglebius	     then this is a fresh instantiation of that number, so create
609200576Sroberto	     it.  */
610132451Sroberto
611200576Sroberto	  if (dollar_label_defined ((long) number))
612132451Sroberto	    {
61382498Sroberto	      name = dollar_label_name ((long) number, 0);
614132451Sroberto	      symbolP = symbol_find (name);
615200576Sroberto	      know (symbolP != NULL);
616200576Sroberto	    }
617290001Sglebius	  else
61854359Sroberto	    {
619290001Sglebius	      name = dollar_label_name ((long) number, 1);
620290001Sglebius	      symbolP = symbol_find_or_make (name);
621290001Sglebius	    }
622290001Sglebius
623290001Sglebius	  expressionP->X_op = O_symbol;
624290001Sglebius	  expressionP->X_add_symbol = symbolP;
625290001Sglebius	  expressionP->X_add_number = 0;
626290001Sglebius	}			/* case '$' */
627290001Sglebius      else
628290001Sglebius	{
629290001Sglebius	  expressionP->X_op = O_constant;
630290001Sglebius#ifdef TARGET_WORD_SIZE
631290001Sglebius	  /* Sign extend NUMBER.  */
632290001Sglebius	  number |= (-(number >> (TARGET_WORD_SIZE - 1))) << (TARGET_WORD_SIZE - 1);
63354359Sroberto#endif
634132451Sroberto	  expressionP->X_add_number = number;
63582498Sroberto	  input_line_pointer--;	/* Restore following character.  */
63682498Sroberto	}			/* Really just a number.  */
637200576Sroberto    }
638200576Sroberto  else
639200576Sroberto    {
640200576Sroberto      /* Not a small number.  */
641200576Sroberto      expressionP->X_op = O_big;
642200576Sroberto      expressionP->X_add_number = number;	/* Number of littlenums.  */
643200576Sroberto      input_line_pointer--;	/* -> char following number.  */
644200576Sroberto    }
645200576Sroberto}
646200576Sroberto
647200576Sroberto/* Parse an MRI multi character constant.  */
648200576Sroberto
649132451Srobertostatic void
65082498Srobertomri_char_constant (expressionP)
651200576Sroberto     expressionS *expressionP;
652200576Sroberto{
653200576Sroberto  int i;
654200576Sroberto
655132451Sroberto  if (*input_line_pointer == '\''
656200576Sroberto      && input_line_pointer[1] != '\'')
657200576Sroberto    {
658132451Sroberto      expressionP->X_op = O_constant;
659200576Sroberto      expressionP->X_add_number = 0;
66082498Sroberto      return;
661200576Sroberto    }
662200576Sroberto
66382498Sroberto  /* In order to get the correct byte ordering, we must build the
66482498Sroberto     number in reverse.  */
66582498Sroberto  for (i = SIZE_OF_LARGE_NUMBER - 1; i >= 0; i--)
66654359Sroberto    {
667290001Sglebius      int j;
668290001Sglebius
66982498Sroberto      generic_bignum[i] = 0;
67082498Sroberto      for (j = 0; j < CHARS_PER_LITTLENUM; j++)
671290001Sglebius	{
672290001Sglebius	  if (*input_line_pointer == '\'')
67354359Sroberto	    {
67454359Sroberto	      if (input_line_pointer[1] != '\'')
67582498Sroberto		break;
67654359Sroberto	      ++input_line_pointer;
67754359Sroberto	    }
67854359Sroberto	  generic_bignum[i] <<= 8;
67982498Sroberto	  generic_bignum[i] += *input_line_pointer;
68082498Sroberto	  ++input_line_pointer;
68154359Sroberto	}
682290001Sglebius
683290001Sglebius      if (i < SIZE_OF_LARGE_NUMBER - 1)
684290001Sglebius	{
685290001Sglebius	  /* If there is more than one littlenum, left justify the
686290001Sglebius             last one to make it match the earlier ones.  If there is
687290001Sglebius             only one, we can just use the value directly.  */
688290001Sglebius	  for (; j < CHARS_PER_LITTLENUM; j++)
689290001Sglebius	    generic_bignum[i] <<= 8;
690290001Sglebius	}
69154359Sroberto
69254359Sroberto      if (*input_line_pointer == '\''
69354359Sroberto	  && input_line_pointer[1] != '\'')
694290001Sglebius	break;
69554359Sroberto    }
69654359Sroberto
697182007Sroberto  if (i < 0)
698200576Sroberto    {
69954359Sroberto      as_bad (_("Character constant too large"));
70054359Sroberto      i = 0;
70182498Sroberto    }
70282498Sroberto
703290001Sglebius  if (i > 0)
70482498Sroberto    {
70554359Sroberto      int c;
706182007Sroberto      int j;
707182007Sroberto
70854359Sroberto      c = SIZE_OF_LARGE_NUMBER - i;
70982498Sroberto      for (j = 0; j < c; j++)
710132451Sroberto	generic_bignum[j] = generic_bignum[i + j];
711132451Sroberto      i = c;
712132451Sroberto    }
713200576Sroberto
71454359Sroberto  know (LITTLENUM_NUMBER_OF_BITS == 16);
715106163Sroberto  if (i > 2)
71654359Sroberto    {
71782498Sroberto      expressionP->X_op = O_big;
71854359Sroberto      expressionP->X_add_number = i;
719182007Sroberto    }
720182007Sroberto  else
721200576Sroberto    {
722200576Sroberto      expressionP->X_op = O_constant;
723106163Sroberto      if (i < 2)
72454359Sroberto	expressionP->X_add_number = generic_bignum[0] & LITTLENUM_MASK;
72582498Sroberto      else
72682498Sroberto	expressionP->X_add_number =
72782498Sroberto	  (((generic_bignum[1] & LITTLENUM_MASK)
72882498Sroberto	    << LITTLENUM_NUMBER_OF_BITS)
729200576Sroberto	   | (generic_bignum[0] & LITTLENUM_MASK));
730200576Sroberto    }
731200576Sroberto
732200576Sroberto  /* Skip the final closing quote.  */
73382498Sroberto  ++input_line_pointer;
73482498Sroberto}
735200576Sroberto
736200576Sroberto/* Return an expression representing the current location.  This
737200576Sroberto   handles the magic symbol `.'.  */
738200576Sroberto
739106163Srobertostatic void
74082498Srobertocurrent_location (expressionp)
741200576Sroberto     expressionS *expressionp;
742200576Sroberto{
74382498Sroberto  if (now_seg == absolute_section)
74482498Sroberto    {
745200576Sroberto      expressionp->X_op = O_constant;
746200576Sroberto      expressionp->X_add_number = abs_section_offset;
747200576Sroberto    }
748200576Sroberto  else
749200576Sroberto    {
750200576Sroberto      symbolS *symbolp;
751200576Sroberto
752200576Sroberto      symbolp = symbol_new (FAKE_LABEL_NAME, now_seg,
75382498Sroberto			    (valueT) frag_now_fix (),
75482498Sroberto			    frag_now);
75554359Sroberto      expressionp->X_op = O_symbol;
756132451Sroberto      expressionp->X_add_symbol = symbolp;
757132451Sroberto      expressionp->X_add_number = 0;
75882498Sroberto    }
75954359Sroberto}
76082498Sroberto
76182498Sroberto/* In:	Input_line_pointer points to 1st char of operand, which may
762290001Sglebius	be a space.
763182007Sroberto
76482498Sroberto   Out:	A expressionS.
765132451Sroberto	The operand may have been empty: in this case X_op == O_absent.
766132451Sroberto	Input_line_pointer->(next non-blank) char after operand.  */
767132451Sroberto
768132451Srobertostatic segT
769132451Srobertooperand (expressionP)
770132451Sroberto     expressionS *expressionP;
771132451Sroberto{
772132451Sroberto  char c;
773200576Sroberto  symbolS *symbolP;	/* Points to symbol.  */
774106163Sroberto  char *name;		/* Points to name of symbol.  */
775290001Sglebius  segT segment;
776200576Sroberto
777290001Sglebius  /* All integers are regarded as unsigned unless they are negated.
778290001Sglebius     This is because the only thing which cares whether a number is
779290001Sglebius     unsigned is the code in emit_expr which extends constants into
780290001Sglebius     bignums.  It should only sign extend negative numbers, so that
781290001Sglebius     something like ``.quad 0x80000000'' is not sign extended even
782290001Sglebius     though it appears negative if valueT is 32 bits.  */
783290001Sglebius  expressionP->X_unsigned = 1;
784290001Sglebius
785290001Sglebius  /* Digits, assume it is a bignum.  */
786290001Sglebius
787290001Sglebius  SKIP_WHITESPACE ();		/* Leading whitespace is part of operand.  */
788290001Sglebius  c = *input_line_pointer++;	/* input_line_pointer -> past char in c.  */
789290001Sglebius
79082498Sroberto  if (is_end_of_line[(unsigned char) c])
791290001Sglebius    goto eol;
79254359Sroberto
793182007Sroberto  switch (c)
794290001Sglebius    {
795290001Sglebius    case '1':
79654359Sroberto    case '2':
797290001Sglebius    case '3':
798290001Sglebius    case '4':
799290001Sglebius    case '5':
800290001Sglebius    case '6':
801290001Sglebius    case '7':
802290001Sglebius    case '8':
803290001Sglebius    case '9':
804290001Sglebius      input_line_pointer--;
805290001Sglebius
806290001Sglebius      integer_constant ((NUMBERS_WITH_SUFFIX || flag_m68k_mri)
807290001Sglebius			? 0 : 10,
808290001Sglebius                        expressionP);
809290001Sglebius      break;
810290001Sglebius
811290001Sglebius#ifdef LITERAL_PREFIXDOLLAR_HEX
812290001Sglebius    case '$':
813290001Sglebius      integer_constant (16, expressionP);
814290001Sglebius      break;
815290001Sglebius#endif
816290001Sglebius
817290001Sglebius#ifdef LITERAL_PREFIXPERCENT_BIN
818290001Sglebius    case '%':
819290001Sglebius      integer_constant (2, expressionP);
820290001Sglebius      break;
821290001Sglebius#endif
822290001Sglebius
823290001Sglebius    case '0':
824200576Sroberto      /* Non-decimal radix.  */
825290001Sglebius
826290001Sglebius      if (NUMBERS_WITH_SUFFIX || flag_m68k_mri)
827290001Sglebius	{
828290001Sglebius	  char *s;
829290001Sglebius
830290001Sglebius	  /* Check for a hex constant.  */
831290001Sglebius	  for (s = input_line_pointer; hex_p (*s); s++)
832290001Sglebius	    ;
833290001Sglebius	  if (*s == 'h' || *s == 'H')
834290001Sglebius	    {
835290001Sglebius	      --input_line_pointer;
836290001Sglebius	      integer_constant (0, expressionP);
837290001Sglebius	      break;
838290001Sglebius	    }
839290001Sglebius	}
840290001Sglebius      c = *input_line_pointer;
841290001Sglebius      switch (c)
842290001Sglebius	{
843290001Sglebius	case 'o':
844290001Sglebius	case 'O':
845290001Sglebius	case 'q':
846290001Sglebius	case 'Q':
847290001Sglebius	case '8':
848290001Sglebius	case '9':
849290001Sglebius	  if (NUMBERS_WITH_SUFFIX || flag_m68k_mri)
850290001Sglebius	    {
851290001Sglebius	      integer_constant (0, expressionP);
852290001Sglebius	      break;
853290001Sglebius	    }
854290001Sglebius	  /* Fall through.  */
855290001Sglebius	default:
856290001Sglebius	default_case:
85754359Sroberto	  if (c && strchr (FLT_CHARS, c))
85854359Sroberto	    {
85954359Sroberto	      input_line_pointer++;
860	      floating_constant (expressionP);
861	      expressionP->X_add_number =
862		- (isupper ((unsigned char) c) ? tolower (c) : c);
863	    }
864	  else
865	    {
866	      /* The string was only zero.  */
867	      expressionP->X_op = O_constant;
868	      expressionP->X_add_number = 0;
869	    }
870
871	  break;
872
873	case 'x':
874	case 'X':
875	  if (flag_m68k_mri)
876	    goto default_case;
877	  input_line_pointer++;
878	  integer_constant (16, expressionP);
879	  break;
880
881	case 'b':
882	  if (LOCAL_LABELS_FB && ! (flag_m68k_mri || NUMBERS_WITH_SUFFIX))
883	    {
884	      /* This code used to check for '+' and '-' here, and, in
885		 some conditions, fall through to call
886		 integer_constant.  However, that didn't make sense,
887		 as integer_constant only accepts digits.  */
888	      /* Some of our code elsewhere does permit digits greater
889		 than the expected base; for consistency, do the same
890		 here.  */
891	      if (input_line_pointer[1] < '0'
892		  || input_line_pointer[1] > '9')
893		{
894		  /* Parse this as a back reference to label 0.  */
895		  input_line_pointer--;
896		  integer_constant (10, expressionP);
897		  break;
898		}
899	      /* Otherwise, parse this as a binary number.  */
900	    }
901	  /* Fall through.  */
902	case 'B':
903	  input_line_pointer++;
904	  if (flag_m68k_mri || NUMBERS_WITH_SUFFIX)
905	    goto default_case;
906	  integer_constant (2, expressionP);
907	  break;
908
909	case '0':
910	case '1':
911	case '2':
912	case '3':
913	case '4':
914	case '5':
915	case '6':
916	case '7':
917	  integer_constant ((flag_m68k_mri || NUMBERS_WITH_SUFFIX)
918			    ? 0 : 8,
919			    expressionP);
920	  break;
921
922	case 'f':
923	  if (LOCAL_LABELS_FB)
924	    {
925	      /* If it says "0f" and it could possibly be a floating point
926		 number, make it one.  Otherwise, make it a local label,
927		 and try to deal with parsing the rest later.  */
928	      if (!input_line_pointer[1]
929		  || (is_end_of_line[0xff & input_line_pointer[1]])
930		  || strchr (FLT_CHARS, 'f') == NULL)
931		goto is_0f_label;
932	      {
933		char *cp = input_line_pointer + 1;
934		int r = atof_generic (&cp, ".", EXP_CHARS,
935				      &generic_floating_point_number);
936		switch (r)
937		  {
938		  case 0:
939		  case ERROR_EXPONENT_OVERFLOW:
940		    if (*cp == 'f' || *cp == 'b')
941		      /* Looks like a difference expression.  */
942		      goto is_0f_label;
943		    else if (cp == input_line_pointer + 1)
944		      /* No characters has been accepted -- looks like
945			 end of operand.  */
946		      goto is_0f_label;
947		    else
948		      goto is_0f_float;
949		  default:
950		    as_fatal (_("expr.c(operand): bad atof_generic return val %d"),
951			      r);
952		  }
953	      }
954
955	      /* Okay, now we've sorted it out.  We resume at one of these
956		 two labels, depending on what we've decided we're probably
957		 looking at.  */
958	    is_0f_label:
959	      input_line_pointer--;
960	      integer_constant (10, expressionP);
961	      break;
962
963	    is_0f_float:
964	      /* Fall through.  */
965	      ;
966	    }
967
968	case 'd':
969	case 'D':
970	  if (flag_m68k_mri || NUMBERS_WITH_SUFFIX)
971	    {
972	      integer_constant (0, expressionP);
973	      break;
974	    }
975	  /* Fall through.  */
976	case 'F':
977	case 'r':
978	case 'e':
979	case 'E':
980	case 'g':
981	case 'G':
982	  input_line_pointer++;
983	  floating_constant (expressionP);
984	  expressionP->X_add_number =
985	    - (isupper ((unsigned char) c) ? tolower (c) : c);
986	  break;
987
988	case '$':
989	  if (LOCAL_LABELS_DOLLAR)
990	    {
991	      integer_constant (10, expressionP);
992	      break;
993	    }
994	  else
995	    goto default_case;
996	}
997
998      break;
999
1000    case '(':
1001#ifndef NEED_INDEX_OPERATOR
1002    case '[':
1003#endif
1004      /* Didn't begin with digit & not a name.  */
1005      segment = expression (expressionP);
1006      /* expression () will pass trailing whitespace.  */
1007      if ((c == '(' && *input_line_pointer != ')')
1008	  || (c == '[' && *input_line_pointer != ']'))
1009	{
1010#ifdef RELAX_PAREN_GROUPING
1011	  if (c != '(')
1012#endif
1013	    as_bad (_("Missing '%c' assumed"), c == '(' ? ')' : ']');
1014	}
1015      else
1016	input_line_pointer++;
1017      SKIP_WHITESPACE ();
1018      /* Here with input_line_pointer -> char after "(...)".  */
1019      return segment;
1020
1021#ifdef TC_M68K
1022    case 'E':
1023      if (! flag_m68k_mri || *input_line_pointer != '\'')
1024	goto de_fault;
1025      as_bad (_("EBCDIC constants are not supported"));
1026      /* Fall through.  */
1027    case 'A':
1028      if (! flag_m68k_mri || *input_line_pointer != '\'')
1029	goto de_fault;
1030      ++input_line_pointer;
1031      /* Fall through.  */
1032#endif
1033    case '\'':
1034      if (! flag_m68k_mri)
1035	{
1036	  /* Warning: to conform to other people's assemblers NO
1037	     ESCAPEMENT is permitted for a single quote.  The next
1038	     character, parity errors and all, is taken as the value
1039	     of the operand.  VERY KINKY.  */
1040	  expressionP->X_op = O_constant;
1041	  expressionP->X_add_number = *input_line_pointer++;
1042	  break;
1043	}
1044
1045      mri_char_constant (expressionP);
1046      break;
1047
1048    case '+':
1049      (void) operand (expressionP);
1050      break;
1051
1052#ifdef TC_M68K
1053    case '"':
1054      /* Double quote is the bitwise not operator in MRI mode.  */
1055      if (! flag_m68k_mri)
1056	goto de_fault;
1057      /* Fall through.  */
1058#endif
1059    case '~':
1060      /* '~' is permitted to start a label on the Delta.  */
1061      if (is_name_beginner (c))
1062	goto isname;
1063    case '!':
1064    case '-':
1065      {
1066	operand (expressionP);
1067	if (expressionP->X_op == O_constant)
1068	  {
1069	    /* input_line_pointer -> char after operand.  */
1070	    if (c == '-')
1071	      {
1072		expressionP->X_add_number = - expressionP->X_add_number;
1073		/* Notice: '-' may overflow: no warning is given.
1074		   This is compatible with other people's
1075		   assemblers.  Sigh.  */
1076		expressionP->X_unsigned = 0;
1077	      }
1078	    else if (c == '~' || c == '"')
1079	      expressionP->X_add_number = ~ expressionP->X_add_number;
1080	    else
1081	      expressionP->X_add_number = ! expressionP->X_add_number;
1082	  }
1083	else if (expressionP->X_op != O_illegal
1084		 && expressionP->X_op != O_absent)
1085	  {
1086	    expressionP->X_add_symbol = make_expr_symbol (expressionP);
1087	    if (c == '-')
1088	      expressionP->X_op = O_uminus;
1089	    else if (c == '~' || c == '"')
1090	      expressionP->X_op = O_bit_not;
1091	    else
1092	      expressionP->X_op = O_logical_not;
1093	    expressionP->X_add_number = 0;
1094	  }
1095	else
1096	  as_warn (_("Unary operator %c ignored because bad operand follows"),
1097		   c);
1098      }
1099      break;
1100
1101#if defined (DOLLAR_DOT) || defined (TC_M68K)
1102    case '$':
1103      /* '$' is the program counter when in MRI mode, or when
1104         DOLLAR_DOT is defined.  */
1105#ifndef DOLLAR_DOT
1106      if (! flag_m68k_mri)
1107	goto de_fault;
1108#endif
1109      if (flag_m68k_mri && hex_p (*input_line_pointer))
1110	{
1111	  /* In MRI mode, '$' is also used as the prefix for a
1112             hexadecimal constant.  */
1113	  integer_constant (16, expressionP);
1114	  break;
1115	}
1116
1117      if (is_part_of_name (*input_line_pointer))
1118	goto isname;
1119
1120      current_location (expressionP);
1121      break;
1122#endif
1123
1124    case '.':
1125      if (!is_part_of_name (*input_line_pointer))
1126	{
1127	  current_location (expressionP);
1128	  break;
1129	}
1130      else if ((strncasecmp (input_line_pointer, "startof.", 8) == 0
1131		&& ! is_part_of_name (input_line_pointer[8]))
1132	       || (strncasecmp (input_line_pointer, "sizeof.", 7) == 0
1133		   && ! is_part_of_name (input_line_pointer[7])))
1134	{
1135	  int start;
1136
1137	  start = (input_line_pointer[1] == 't'
1138		   || input_line_pointer[1] == 'T');
1139	  input_line_pointer += start ? 8 : 7;
1140	  SKIP_WHITESPACE ();
1141	  if (*input_line_pointer != '(')
1142	    as_bad (_("syntax error in .startof. or .sizeof."));
1143	  else
1144	    {
1145	      char *buf;
1146
1147	      ++input_line_pointer;
1148	      SKIP_WHITESPACE ();
1149	      name = input_line_pointer;
1150	      c = get_symbol_end ();
1151
1152	      buf = (char *) xmalloc (strlen (name) + 10);
1153	      if (start)
1154		sprintf (buf, ".startof.%s", name);
1155	      else
1156		sprintf (buf, ".sizeof.%s", name);
1157	      symbolP = symbol_make (buf);
1158	      free (buf);
1159
1160	      expressionP->X_op = O_symbol;
1161	      expressionP->X_add_symbol = symbolP;
1162	      expressionP->X_add_number = 0;
1163
1164	      *input_line_pointer = c;
1165	      SKIP_WHITESPACE ();
1166	      if (*input_line_pointer != ')')
1167		as_bad (_("syntax error in .startof. or .sizeof."));
1168	      else
1169		++input_line_pointer;
1170	    }
1171	  break;
1172	}
1173      else
1174	{
1175	  goto isname;
1176	}
1177
1178    case ',':
1179    eol:
1180      /* Can't imagine any other kind of operand.  */
1181      expressionP->X_op = O_absent;
1182      input_line_pointer--;
1183      break;
1184
1185#ifdef TC_M68K
1186    case '%':
1187      if (! flag_m68k_mri)
1188	goto de_fault;
1189      integer_constant (2, expressionP);
1190      break;
1191
1192    case '@':
1193      if (! flag_m68k_mri)
1194	goto de_fault;
1195      integer_constant (8, expressionP);
1196      break;
1197
1198    case ':':
1199      if (! flag_m68k_mri)
1200	goto de_fault;
1201
1202      /* In MRI mode, this is a floating point constant represented
1203         using hexadecimal digits.  */
1204
1205      ++input_line_pointer;
1206      integer_constant (16, expressionP);
1207      break;
1208
1209    case '*':
1210      if (! flag_m68k_mri || is_part_of_name (*input_line_pointer))
1211	goto de_fault;
1212
1213      current_location (expressionP);
1214      break;
1215#endif
1216
1217    default:
1218#ifdef TC_M68K
1219    de_fault:
1220#endif
1221      if (is_name_beginner (c))	/* Here if did not begin with a digit.  */
1222	{
1223	  /* Identifier begins here.
1224	     This is kludged for speed, so code is repeated.  */
1225	isname:
1226	  name = --input_line_pointer;
1227	  c = get_symbol_end ();
1228
1229#ifdef md_parse_name
1230	  /* This is a hook for the backend to parse certain names
1231             specially in certain contexts.  If a name always has a
1232             specific value, it can often be handled by simply
1233             entering it in the symbol table.  */
1234	  if (md_parse_name (name, expressionP))
1235	    {
1236	      *input_line_pointer = c;
1237	      break;
1238	    }
1239#endif
1240
1241#ifdef TC_I960
1242	  /* The MRI i960 assembler permits
1243	         lda sizeof code,g13
1244	     FIXME: This should use md_parse_name.  */
1245	  if (flag_mri
1246	      && (strcasecmp (name, "sizeof") == 0
1247		  || strcasecmp (name, "startof") == 0))
1248	    {
1249	      int start;
1250	      char *buf;
1251
1252	      start = (name[1] == 't'
1253		       || name[1] == 'T');
1254
1255	      *input_line_pointer = c;
1256	      SKIP_WHITESPACE ();
1257
1258	      name = input_line_pointer;
1259	      c = get_symbol_end ();
1260
1261	      buf = (char *) xmalloc (strlen (name) + 10);
1262	      if (start)
1263		sprintf (buf, ".startof.%s", name);
1264	      else
1265		sprintf (buf, ".sizeof.%s", name);
1266	      symbolP = symbol_make (buf);
1267	      free (buf);
1268
1269	      expressionP->X_op = O_symbol;
1270	      expressionP->X_add_symbol = symbolP;
1271	      expressionP->X_add_number = 0;
1272
1273	      *input_line_pointer = c;
1274	      SKIP_WHITESPACE ();
1275
1276	      break;
1277	    }
1278#endif
1279
1280	  symbolP = symbol_find_or_make (name);
1281
1282	  /* If we have an absolute symbol or a reg, then we know its
1283	     value now.  */
1284	  segment = S_GET_SEGMENT (symbolP);
1285	  if (segment == absolute_section)
1286	    {
1287	      expressionP->X_op = O_constant;
1288	      expressionP->X_add_number = S_GET_VALUE (symbolP);
1289	    }
1290	  else if (segment == reg_section)
1291	    {
1292	      expressionP->X_op = O_register;
1293	      expressionP->X_add_number = S_GET_VALUE (symbolP);
1294	    }
1295	  else
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	}
1303      else
1304	{
1305	  /* Let the target try to parse it.  Success is indicated by changing
1306	     the X_op field to something other than O_absent and pointing
1307	     input_line_pointer past the expression.  If it can't parse the
1308	     expression, X_op and input_line_pointer should be unchanged.  */
1309	  expressionP->X_op = O_absent;
1310	  --input_line_pointer;
1311	  md_operand (expressionP);
1312	  if (expressionP->X_op == O_absent)
1313	    {
1314	      ++input_line_pointer;
1315	      as_bad (_("Bad expression"));
1316	      expressionP->X_op = O_constant;
1317	      expressionP->X_add_number = 0;
1318	    }
1319	}
1320      break;
1321    }
1322
1323  /* It is more 'efficient' to clean up the expressionS when they are
1324     created.  Doing it here saves lines of code.  */
1325  clean_up_expression (expressionP);
1326  SKIP_WHITESPACE ();		/* -> 1st char after operand.  */
1327  know (*input_line_pointer != ' ');
1328
1329  /* The PA port needs this information.  */
1330  if (expressionP->X_add_symbol)
1331    symbol_mark_used (expressionP->X_add_symbol);
1332
1333  switch (expressionP->X_op)
1334    {
1335    default:
1336      return absolute_section;
1337    case O_symbol:
1338      return S_GET_SEGMENT (expressionP->X_add_symbol);
1339    case O_register:
1340      return reg_section;
1341    }
1342}
1343
1344/* Internal.  Simplify a struct expression for use by expr ().  */
1345
1346/* In:	address of a expressionS.
1347	The X_op field of the expressionS may only take certain values.
1348	Elsewise we waste time special-case testing. Sigh. Ditto SEG_ABSENT.
1349
1350   Out:	expressionS may have been modified:
1351	'foo-foo' symbol references cancelled to 0, which changes X_op
1352	from O_subtract to O_constant.
1353	Unused fields zeroed to help expr ().  */
1354
1355static void
1356clean_up_expression (expressionP)
1357     expressionS *expressionP;
1358{
1359  switch (expressionP->X_op)
1360    {
1361    case O_illegal:
1362    case O_absent:
1363      expressionP->X_add_number = 0;
1364      /* Fall through.  */
1365    case O_big:
1366    case O_constant:
1367    case O_register:
1368      expressionP->X_add_symbol = NULL;
1369      /* Fall through.  */
1370    case O_symbol:
1371    case O_uminus:
1372    case O_bit_not:
1373      expressionP->X_op_symbol = NULL;
1374      break;
1375    case O_subtract:
1376      if (expressionP->X_op_symbol == expressionP->X_add_symbol
1377	  || ((symbol_get_frag (expressionP->X_op_symbol)
1378	       == symbol_get_frag (expressionP->X_add_symbol))
1379	      && SEG_NORMAL (S_GET_SEGMENT (expressionP->X_add_symbol))
1380	      && (S_GET_VALUE (expressionP->X_op_symbol)
1381		  == S_GET_VALUE (expressionP->X_add_symbol))))
1382	{
1383	  addressT diff = (S_GET_VALUE (expressionP->X_add_symbol)
1384			   - S_GET_VALUE (expressionP->X_op_symbol));
1385
1386	  expressionP->X_op = O_constant;
1387	  expressionP->X_add_symbol = NULL;
1388	  expressionP->X_op_symbol = NULL;
1389	  expressionP->X_add_number += diff;
1390	}
1391      break;
1392    default:
1393      break;
1394    }
1395}
1396
1397/* Expression parser.  */
1398
1399/* We allow an empty expression, and just assume (absolute,0) silently.
1400   Unary operators and parenthetical expressions are treated as operands.
1401   As usual, Q==quantity==operand, O==operator, X==expression mnemonics.
1402
1403   We used to do a aho/ullman shift-reduce parser, but the logic got so
1404   warped that I flushed it and wrote a recursive-descent parser instead.
1405   Now things are stable, would anybody like to write a fast parser?
1406   Most expressions are either register (which does not even reach here)
1407   or 1 symbol. Then "symbol+constant" and "symbol-symbol" are common.
1408   So I guess it doesn't really matter how inefficient more complex expressions
1409   are parsed.
1410
1411   After expr(RANK,resultP) input_line_pointer->operator of rank <= RANK.
1412   Also, we have consumed any leading or trailing spaces (operand does that)
1413   and done all intervening operators.
1414
1415   This returns the segment of the result, which will be
1416   absolute_section or the segment of a symbol.  */
1417
1418#undef __
1419#define __ O_illegal
1420
1421/* Maps ASCII -> operators.  */
1422static const operatorT op_encoding[256] = {
1423  __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1424  __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1425
1426  __, O_bit_or_not, __, __, __, O_modulus, O_bit_and, __,
1427  __, __, O_multiply, O_add, __, O_subtract, __, O_divide,
1428  __, __, __, __, __, __, __, __,
1429  __, __, __, __, O_lt, __, O_gt, __,
1430  __, __, __, __, __, __, __, __,
1431  __, __, __, __, __, __, __, __,
1432  __, __, __, __, __, __, __, __,
1433  __, __, __,
1434#ifdef NEED_INDEX_OPERATOR
1435  O_index,
1436#else
1437  __,
1438#endif
1439  __, __, O_bit_exclusive_or, __,
1440  __, __, __, __, __, __, __, __,
1441  __, __, __, __, __, __, __, __,
1442  __, __, __, __, __, __, __, __,
1443  __, __, __, __, O_bit_inclusive_or, __, __, __,
1444
1445  __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1446  __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1447  __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1448  __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1449  __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1450  __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1451  __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1452  __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __
1453};
1454
1455/* Rank	Examples
1456   0	operand, (expression)
1457   1	||
1458   2	&&
1459   3	= <> < <= >= >
1460   4	+ -
1461   5	used for * / % in MRI mode
1462   6	& ^ ! |
1463   7	* / % << >>
1464   8	unary - unary ~
1465*/
1466static operator_rankT op_rank[] = {
1467  0,	/* O_illegal */
1468  0,	/* O_absent */
1469  0,	/* O_constant */
1470  0,	/* O_symbol */
1471  0,	/* O_symbol_rva */
1472  0,	/* O_register */
1473  0,	/* O_big */
1474  9,	/* O_uminus */
1475  9,	/* O_bit_not */
1476  9,	/* O_logical_not */
1477  8,	/* O_multiply */
1478  8,	/* O_divide */
1479  8,	/* O_modulus */
1480  8,	/* O_left_shift */
1481  8,	/* O_right_shift */
1482  7,	/* O_bit_inclusive_or */
1483  7,	/* O_bit_or_not */
1484  7,	/* O_bit_exclusive_or */
1485  7,	/* O_bit_and */
1486  5,	/* O_add */
1487  5,	/* O_subtract */
1488  4,	/* O_eq */
1489  4,	/* O_ne */
1490  4,	/* O_lt */
1491  4,	/* O_le */
1492  4,	/* O_ge */
1493  4,	/* O_gt */
1494  3,	/* O_logical_and */
1495  2,	/* O_logical_or */
1496  1,	/* O_index */
1497  0,	/* O_md1 */
1498  0,	/* O_md2 */
1499  0,	/* O_md3 */
1500  0,	/* O_md4 */
1501  0,	/* O_md5 */
1502  0,	/* O_md6 */
1503  0,	/* O_md7 */
1504  0,	/* O_md8 */
1505  0,	/* O_md9 */
1506  0,	/* O_md10 */
1507  0,	/* O_md11 */
1508  0,	/* O_md12 */
1509  0,	/* O_md13 */
1510  0,	/* O_md14 */
1511  0,	/* O_md15 */
1512  0,	/* O_md16 */
1513};
1514
1515/* Unfortunately, in MRI mode for the m68k, multiplication and
1516   division have lower precedence than the bit wise operators.  This
1517   function sets the operator precedences correctly for the current
1518   mode.  Also, MRI uses a different bit_not operator, and this fixes
1519   that as well.  */
1520
1521#define STANDARD_MUL_PRECEDENCE 8
1522#define MRI_MUL_PRECEDENCE 6
1523
1524void
1525expr_set_precedence ()
1526{
1527  if (flag_m68k_mri)
1528    {
1529      op_rank[O_multiply] = MRI_MUL_PRECEDENCE;
1530      op_rank[O_divide] = MRI_MUL_PRECEDENCE;
1531      op_rank[O_modulus] = MRI_MUL_PRECEDENCE;
1532    }
1533  else
1534    {
1535      op_rank[O_multiply] = STANDARD_MUL_PRECEDENCE;
1536      op_rank[O_divide] = STANDARD_MUL_PRECEDENCE;
1537      op_rank[O_modulus] = STANDARD_MUL_PRECEDENCE;
1538    }
1539}
1540
1541/* Initialize the expression parser.  */
1542
1543void
1544expr_begin ()
1545{
1546  expr_set_precedence ();
1547
1548  /* Verify that X_op field is wide enough.  */
1549  {
1550    expressionS e;
1551    e.X_op = O_max;
1552    assert (e.X_op == O_max);
1553  }
1554}
1555
1556/* Return the encoding for the operator at INPUT_LINE_POINTER, and
1557   sets NUM_CHARS to the number of characters in the operator.
1558   Does not advance INPUT_LINE_POINTER.  */
1559
1560static inline operatorT
1561operator (num_chars)
1562     int *num_chars;
1563{
1564  int c;
1565  operatorT ret;
1566
1567  c = *input_line_pointer & 0xff;
1568  *num_chars = 1;
1569
1570  if (is_end_of_line[c])
1571    return O_illegal;
1572
1573  switch (c)
1574    {
1575    default:
1576      return op_encoding[c];
1577
1578    case '<':
1579      switch (input_line_pointer[1])
1580	{
1581	default:
1582	  return op_encoding[c];
1583	case '<':
1584	  ret = O_left_shift;
1585	  break;
1586	case '>':
1587	  ret = O_ne;
1588	  break;
1589	case '=':
1590	  ret = O_le;
1591	  break;
1592	}
1593      *num_chars = 2;
1594      return ret;
1595
1596    case '=':
1597      if (input_line_pointer[1] != '=')
1598	return op_encoding[c];
1599
1600      *num_chars = 2;
1601      return O_eq;
1602
1603    case '>':
1604      switch (input_line_pointer[1])
1605	{
1606	default:
1607	  return op_encoding[c];
1608	case '>':
1609	  ret = O_right_shift;
1610	  break;
1611	case '=':
1612	  ret = O_ge;
1613	  break;
1614	}
1615      *num_chars = 2;
1616      return ret;
1617
1618    case '!':
1619      /* We accept !! as equivalent to ^ for MRI compatibility.  */
1620      if (input_line_pointer[1] != '!')
1621	{
1622	  if (flag_m68k_mri)
1623	    return O_bit_inclusive_or;
1624	  return op_encoding[c];
1625	}
1626      *num_chars = 2;
1627      return O_bit_exclusive_or;
1628
1629    case '|':
1630      if (input_line_pointer[1] != '|')
1631	return op_encoding[c];
1632
1633      *num_chars = 2;
1634      return O_logical_or;
1635
1636    case '&':
1637      if (input_line_pointer[1] != '&')
1638	return op_encoding[c];
1639
1640      *num_chars = 2;
1641      return O_logical_and;
1642    }
1643
1644  /* NOTREACHED  */
1645}
1646
1647/* Parse an expression.  */
1648
1649segT
1650expr (rankarg, resultP)
1651     int rankarg;	/* Larger # is higher rank.  */
1652     expressionS *resultP;	/* Deliver result here.  */
1653{
1654  operator_rankT rank = (operator_rankT) rankarg;
1655  segT retval;
1656  expressionS right;
1657  operatorT op_left;
1658  operatorT op_right;
1659  int op_chars;
1660
1661  know (rank >= 0);
1662
1663  retval = operand (resultP);
1664
1665  /* operand () gobbles spaces.  */
1666  know (*input_line_pointer != ' ');
1667
1668  op_left = operator (&op_chars);
1669  while (op_left != O_illegal && op_rank[(int) op_left] > rank)
1670    {
1671      segT rightseg;
1672
1673      input_line_pointer += op_chars;	/* -> after operator.  */
1674
1675      rightseg = expr (op_rank[(int) op_left], &right);
1676      if (right.X_op == O_absent)
1677	{
1678	  as_warn (_("missing operand; zero assumed"));
1679	  right.X_op = O_constant;
1680	  right.X_add_number = 0;
1681	  right.X_add_symbol = NULL;
1682	  right.X_op_symbol = NULL;
1683	}
1684
1685      know (*input_line_pointer != ' ');
1686
1687      if (op_left == O_index)
1688	{
1689	  if (*input_line_pointer != ']')
1690	    as_bad ("missing right bracket");
1691	  else
1692	    {
1693	      ++input_line_pointer;
1694	      SKIP_WHITESPACE ();
1695	    }
1696	}
1697
1698      if (retval == undefined_section)
1699	{
1700	  if (SEG_NORMAL (rightseg))
1701	    retval = rightseg;
1702	}
1703      else if (! SEG_NORMAL (retval))
1704	retval = rightseg;
1705      else if (SEG_NORMAL (rightseg)
1706	       && retval != rightseg
1707#ifdef DIFF_EXPR_OK
1708	       && op_left != O_subtract
1709#endif
1710	       )
1711	as_bad (_("operation combines symbols in different segments"));
1712
1713      op_right = operator (&op_chars);
1714
1715      know (op_right == O_illegal
1716	    || op_rank[(int) op_right] <= op_rank[(int) op_left]);
1717      know ((int) op_left >= (int) O_multiply
1718	    && (int) op_left <= (int) O_logical_or);
1719
1720      /* input_line_pointer->after right-hand quantity.  */
1721      /* left-hand quantity in resultP.  */
1722      /* right-hand quantity in right.  */
1723      /* operator in op_left.  */
1724
1725      if (resultP->X_op == O_big)
1726	{
1727	  if (resultP->X_add_number > 0)
1728	    as_warn (_("left operand is a bignum; integer 0 assumed"));
1729	  else
1730	    as_warn (_("left operand is a float; integer 0 assumed"));
1731	  resultP->X_op = O_constant;
1732	  resultP->X_add_number = 0;
1733	  resultP->X_add_symbol = NULL;
1734	  resultP->X_op_symbol = NULL;
1735	}
1736      if (right.X_op == O_big)
1737	{
1738	  if (right.X_add_number > 0)
1739	    as_warn (_("right operand is a bignum; integer 0 assumed"));
1740	  else
1741	    as_warn (_("right operand is a float; integer 0 assumed"));
1742	  right.X_op = O_constant;
1743	  right.X_add_number = 0;
1744	  right.X_add_symbol = NULL;
1745	  right.X_op_symbol = NULL;
1746	}
1747
1748      /* Optimize common cases.  */
1749#ifdef md_optimize_expr
1750      if (md_optimize_expr (resultP, op_left, &right))
1751	{
1752	  /* Skip.  */
1753	  ;
1754	}
1755      else
1756#endif
1757      if (op_left == O_add && right.X_op == O_constant)
1758	{
1759	  /* X + constant.  */
1760	  resultP->X_add_number += right.X_add_number;
1761	}
1762      /* This case comes up in PIC code.  */
1763      else if (op_left == O_subtract
1764	       && right.X_op == O_symbol
1765	       && resultP->X_op == O_symbol
1766	       && (symbol_get_frag (right.X_add_symbol)
1767		   == symbol_get_frag (resultP->X_add_symbol))
1768	       && SEG_NORMAL (S_GET_SEGMENT (right.X_add_symbol)))
1769
1770	{
1771	  resultP->X_add_number -= right.X_add_number;
1772	  resultP->X_add_number += (S_GET_VALUE (resultP->X_add_symbol)
1773				    - S_GET_VALUE (right.X_add_symbol));
1774	  resultP->X_op = O_constant;
1775	  resultP->X_add_symbol = 0;
1776	}
1777      else if (op_left == O_subtract && right.X_op == O_constant)
1778	{
1779	  /* X - constant.  */
1780	  resultP->X_add_number -= right.X_add_number;
1781	}
1782      else if (op_left == O_add && resultP->X_op == O_constant)
1783	{
1784	  /* Constant + X.  */
1785	  resultP->X_op = right.X_op;
1786	  resultP->X_add_symbol = right.X_add_symbol;
1787	  resultP->X_op_symbol = right.X_op_symbol;
1788	  resultP->X_add_number += right.X_add_number;
1789	  retval = rightseg;
1790	}
1791      else if (resultP->X_op == O_constant && right.X_op == O_constant)
1792	{
1793	  /* Constant OP constant.  */
1794	  offsetT v = right.X_add_number;
1795	  if (v == 0 && (op_left == O_divide || op_left == O_modulus))
1796	    {
1797	      as_warn (_("division by zero"));
1798	      v = 1;
1799	    }
1800	  switch (op_left)
1801	    {
1802	    default:			abort ();
1803	    case O_multiply:		resultP->X_add_number *= v; break;
1804	    case O_divide:		resultP->X_add_number /= v; break;
1805	    case O_modulus:		resultP->X_add_number %= v; break;
1806	    case O_left_shift:		resultP->X_add_number <<= v; break;
1807	    case O_right_shift:
1808	      /* We always use unsigned shifts, to avoid relying on
1809                 characteristics of the compiler used to compile gas.  */
1810	      resultP->X_add_number =
1811		(offsetT) ((valueT) resultP->X_add_number >> (valueT) v);
1812	      break;
1813	    case O_bit_inclusive_or:	resultP->X_add_number |= v; break;
1814	    case O_bit_or_not:		resultP->X_add_number |= ~v; break;
1815	    case O_bit_exclusive_or:	resultP->X_add_number ^= v; break;
1816	    case O_bit_and:		resultP->X_add_number &= v; break;
1817	    case O_add:			resultP->X_add_number += v; break;
1818	    case O_subtract:		resultP->X_add_number -= v; break;
1819	    case O_eq:
1820	      resultP->X_add_number =
1821		resultP->X_add_number == v ? ~ (offsetT) 0 : 0;
1822	      break;
1823	    case O_ne:
1824	      resultP->X_add_number =
1825		resultP->X_add_number != v ? ~ (offsetT) 0 : 0;
1826	      break;
1827	    case O_lt:
1828	      resultP->X_add_number =
1829		resultP->X_add_number <  v ? ~ (offsetT) 0 : 0;
1830	      break;
1831	    case O_le:
1832	      resultP->X_add_number =
1833		resultP->X_add_number <= v ? ~ (offsetT) 0 : 0;
1834	      break;
1835	    case O_ge:
1836	      resultP->X_add_number =
1837		resultP->X_add_number >= v ? ~ (offsetT) 0 : 0;
1838	      break;
1839	    case O_gt:
1840	      resultP->X_add_number =
1841		resultP->X_add_number >  v ? ~ (offsetT) 0 : 0;
1842	      break;
1843	    case O_logical_and:
1844	      resultP->X_add_number = resultP->X_add_number && v;
1845	      break;
1846	    case O_logical_or:
1847	      resultP->X_add_number = resultP->X_add_number || v;
1848	      break;
1849	    }
1850	}
1851      else if (resultP->X_op == O_symbol
1852	       && right.X_op == O_symbol
1853	       && (op_left == O_add
1854		   || op_left == O_subtract
1855		   || (resultP->X_add_number == 0
1856		       && right.X_add_number == 0)))
1857	{
1858	  /* Symbol OP symbol.  */
1859	  resultP->X_op = op_left;
1860	  resultP->X_op_symbol = right.X_add_symbol;
1861	  if (op_left == O_add)
1862	    resultP->X_add_number += right.X_add_number;
1863	  else if (op_left == O_subtract)
1864	    resultP->X_add_number -= right.X_add_number;
1865	}
1866      else
1867	{
1868	  /* The general case.  */
1869	  resultP->X_add_symbol = make_expr_symbol (resultP);
1870	  resultP->X_op_symbol = make_expr_symbol (&right);
1871	  resultP->X_op = op_left;
1872	  resultP->X_add_number = 0;
1873	  resultP->X_unsigned = 1;
1874	}
1875
1876      op_left = op_right;
1877    }				/* While next operator is >= this rank.  */
1878
1879  /* The PA port needs this information.  */
1880  if (resultP->X_add_symbol)
1881    symbol_mark_used (resultP->X_add_symbol);
1882
1883  return resultP->X_op == O_constant ? absolute_section : retval;
1884}
1885
1886/* This lives here because it belongs equally in expr.c & read.c.
1887   expr.c is just a branch office read.c anyway, and putting it
1888   here lessens the crowd at read.c.
1889
1890   Assume input_line_pointer is at start of symbol name.
1891   Advance input_line_pointer past symbol name.
1892   Turn that character into a '\0', returning its former value.
1893   This allows a string compare (RMS wants symbol names to be strings)
1894   of the symbol name.
1895   There will always be a char following symbol name, because all good
1896   lines end in end-of-line.  */
1897
1898char
1899get_symbol_end ()
1900{
1901  char c;
1902
1903  /* We accept \001 in a name in case this is being called with a
1904     constructed string.  */
1905  if (is_name_beginner (c = *input_line_pointer++) || c == '\001')
1906    {
1907      while (is_part_of_name (c = *input_line_pointer++)
1908	     || c == '\001')
1909	;
1910      if (is_name_ender (c))
1911	c = *input_line_pointer++;
1912    }
1913  *--input_line_pointer = 0;
1914  return (c);
1915}
1916
1917unsigned int
1918get_single_number ()
1919{
1920  expressionS exp;
1921  operand (&exp);
1922  return exp.X_add_number;
1923}
1924