Coverage Report

Created: 2024-05-21 06:29

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