Coverage Report

Created: 2023-08-28 06:31

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