Coverage Report

Created: 2023-06-29 07:09

/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
425
#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
189k
{
61
189k
  symbolS *symbolP;
62
189k
  struct expr_symbol_line *n;
63
64
189k
  if (expressionP->X_op == O_symbol
65
189k
      && expressionP->X_add_number == 0)
66
62.1k
    return expressionP->X_add_symbol;
67
68
127k
  if (expressionP->X_op == O_big)
69
461
    {
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
461
      if (expressionP->X_add_number > 0)
74
4
  as_bad (_("bignum invalid"));
75
457
      else
76
457
  as_bad (_("floating point number invalid"));
77
461
      expressionP = &zero;
78
461
    }
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
127k
  symbolP = symbol_create (FAKE_LABEL_NAME,
85
127k
         (expressionP->X_op == O_constant
86
127k
          ? absolute_section
87
127k
          : expressionP->X_op == O_register
88
71.0k
            ? reg_section
89
71.0k
            : expr_section),
90
127k
         &zero_address_frag, 0);
91
127k
  symbol_set_value_expression (symbolP, expressionP);
92
93
127k
  if (expressionP->X_op == O_constant)
94
56.4k
    resolve_symbol_value (symbolP);
95
96
127k
  n = notes_alloc (sizeof (*n));
97
127k
  n->sym = symbolP;
98
127k
  n->file = as_where (&n->line);
99
127k
  n->next = expr_symbol_lines;
100
127k
  expr_symbol_lines = n;
101
102
127k
  return symbolP;
103
189k
}
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
436
{
135
436
  char *buf = concat (start ? ".startof." : ".sizeof.", name, NULL);
136
436
  symbolS *symbolP;
137
436
  unsigned int i;
138
139
722
  for (i = 0; i < nr_seen[start]; ++i)
140
640
    {
141
640
    symbolP = seen[start][i];
142
143
640
    if (! symbolP)
144
45
      break;
145
146
595
    name = S_GET_NAME (symbolP);
147
595
    if ((symbols_case_sensitive
148
595
   ? strcmp (buf, name)
149
595
   : strcasecmp (buf, name)) == 0)
150
309
      {
151
309
  free (buf);
152
309
  return symbolP;
153
309
      }
154
595
    }
155
156
127
  symbolP = symbol_make (buf);
157
127
  free (buf);
158
159
127
  if (i >= nr_seen[start])
160
82
    {
161
82
      unsigned int nr = (i + 1) * 2;
162
163
82
      seen[start] = XRESIZEVEC (symbolS *, seen[start], nr);
164
82
      nr_seen[start] = nr;
165
82
      memset (&seen[start][i + 1], 0, (nr - i - 1) * sizeof(seen[0][0]));
166
82
    }
167
168
127
  seen[start][i] = symbolP;
169
170
127
  return symbolP;
171
436
}
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
5.38k
{
230
  /* input_line_pointer -> floating-point constant.  */
231
5.38k
  int error_code;
232
233
5.38k
  error_code = atof_generic (&input_line_pointer, ".", EXP_CHARS,
234
5.38k
           &generic_floating_point_number);
235
236
5.38k
  if (error_code)
237
30
    {
238
30
      if (error_code == ERROR_EXPONENT_OVERFLOW)
239
30
  {
240
30
    as_bad (_("bad floating-point constant: exponent overflow"));
241
30
  }
242
0
      else
243
0
  {
244
0
    as_bad (_("bad floating-point constant: unknown error code=%d"),
245
0
      error_code);
246
0
  }
247
30
    }
248
5.38k
  expressionP->X_op = O_big;
249
  /* input_line_pointer -> just after constant, which may point to
250
     whitespace.  */
251
5.38k
  expressionP->X_add_number = -1;
252
5.38k
}
253
254
uint32_t
255
generic_bignum_to_int32 (void)
256
9
{
257
9
  return ((((uint32_t) generic_bignum[1] & LITTLENUM_MASK)
258
9
     << LITTLENUM_NUMBER_OF_BITS)
259
9
    | ((uint32_t) generic_bignum[0] & LITTLENUM_MASK));
260
9
}
261
262
uint64_t
263
generic_bignum_to_int64 (void)
264
3.37k
{
265
3.37k
  return ((((((((uint64_t) generic_bignum[3] & LITTLENUM_MASK)
266
3.37k
         << LITTLENUM_NUMBER_OF_BITS)
267
3.37k
        | ((uint64_t) generic_bignum[2] & LITTLENUM_MASK))
268
3.37k
       << LITTLENUM_NUMBER_OF_BITS)
269
3.37k
      | ((uint64_t) generic_bignum[1] & LITTLENUM_MASK))
270
3.37k
     << LITTLENUM_NUMBER_OF_BITS)
271
3.37k
    | ((uint64_t) generic_bignum[0] & LITTLENUM_MASK));
272
3.37k
}
273
274
static void
275
integer_constant (int radix, expressionS *expressionP)
276
384k
{
277
384k
  char *start;    /* Start of number.  */
278
384k
  char *suffix = NULL;
279
384k
  char c;
280
384k
  valueT number;  /* Offset or (absolute) value.  */
281
384k
  short int digit;  /* Value of next digit in current radix.  */
282
384k
  short int maxdig = 0; /* Highest permitted digit value.  */
283
384k
  int too_many_digits = 0;  /* If we see >= this number of.  */
284
384k
  char *name;   /* Points to name of symbol.  */
285
384k
  symbolS *symbolP; /* Points to symbol.  */
286
287
384k
  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
384k
#ifdef BFD64
308
384k
#define valuesize 64
309
#else /* includes non-bfd case, mostly */
310
#define valuesize 32
311
#endif
312
313
384k
  if (is_end_of_line[(unsigned char) *input_line_pointer])
314
4
    {
315
4
      expressionP->X_op = O_absent;
316
4
      return;
317
4
    }
318
319
384k
  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
384k
  switch (radix)
366
384k
    {
367
65
    case 2:
368
65
      maxdig = 2;
369
65
      too_many_digits = valuesize + 1;
370
65
      break;
371
13.4k
    case 8:
372
13.4k
      maxdig = radix = 8;
373
13.4k
      too_many_digits = (valuesize + 2) / 3 + 1;
374
13.4k
      break;
375
150
    case 16:
376
150
      maxdig = radix = 16;
377
150
      too_many_digits = (valuesize + 3) / 4 + 1;
378
150
      break;
379
370k
    case 10:
380
370k
      maxdig = radix = 10;
381
370k
      too_many_digits = (valuesize + 11) / 4; /* Very rough.  */
382
384k
    }
383
384k
#undef valuesize
384
384k
  start = input_line_pointer;
385
384k
  c = *input_line_pointer++;
386
384k
  for (number = 0;
387
1.50M
       (digit = hex_value (c)) < maxdig;
388
1.12M
       c = *input_line_pointer++)
389
1.12M
    {
390
1.12M
      number = number * radix + digit;
391
1.12M
    }
392
  /* c contains character after number.  */
393
  /* input_line_pointer->char after c.  */
394
384k
  small = (input_line_pointer - start - 1) < too_many_digits;
395
396
384k
  if (radix == 16 && c == '_')
397
142
    {
398
      /* This is literal of the form 0x333_0_12345678_1.
399
   This example is equivalent to 0x00000333000000001234567800000001.  */
400
401
142
      int num_little_digits = 0;
402
142
      int i;
403
142
      input_line_pointer = start; /* -> 1st digit.  */
404
405
142
      know (LITTLENUM_NUMBER_OF_BITS == 16);
406
407
567
      for (c = '_'; c == '_'; num_little_digits += 2)
408
425
  {
409
410
    /* Convert one 64-bit word.  */
411
425
    int ndigit = 0;
412
425
    number = 0;
413
425
    for (c = *input_line_pointer++;
414
709
         (digit = hex_value (c)) < maxdig;
415
425
         c = *(input_line_pointer++))
416
284
      {
417
284
        number = number * radix + digit;
418
284
        ndigit++;
419
284
      }
420
421
    /* Check for 8 digit per word max.  */
422
425
    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
425
    know (LITTLENUM_NUMBER_OF_BITS == 16);
428
425
    for (i = min (num_little_digits + 1, SIZE_OF_LARGE_NUMBER - 1);
429
1.27k
         i >= 2;
430
848
         i--)
431
848
      generic_bignum[i] = generic_bignum[i - 2];
432
433
    /* Add the new digits as the least significant new ones.  */
434
425
    generic_bignum[0] = number & 0xffffffff;
435
425
    generic_bignum[1] = number >> 16;
436
425
  }
437
438
      /* Again, c is char after number, input_line_pointer->after c.  */
439
440
142
      if (num_little_digits > SIZE_OF_LARGE_NUMBER - 1)
441
0
  num_little_digits = SIZE_OF_LARGE_NUMBER - 1;
442
443
142
      gas_assert (num_little_digits >= 4);
444
445
142
      if (num_little_digits != 8)
446
142
  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
286
      while (generic_bignum[num_little_digits - 1] == 0
451
286
       && num_little_digits > 1)
452
144
  num_little_digits--;
453
454
142
      if (num_little_digits <= 2)
455
1
  {
456
    /* will fit into 32 bits.  */
457
1
    number = generic_bignum_to_int32 ();
458
1
    small = 1;
459
1
  }
460
141
#ifdef BFD64
461
141
      else if (num_little_digits <= 4)
462
0
  {
463
    /* Will fit into 64 bits.  */
464
0
    number = generic_bignum_to_int64 ();
465
0
    small = 1;
466
0
  }
467
141
#endif
468
141
      else
469
141
  {
470
141
    small = 0;
471
472
    /* Number of littlenums in the bignum.  */
473
141
    number = num_little_digits;
474
141
  }
475
142
    }
476
384k
  else if (!small)
477
5.18k
    {
478
      /* We saw a lot of digits. manufacture a bignum the hard way.  */
479
5.18k
      LITTLENUM_TYPE *leader; /* -> high order littlenum of the bignum.  */
480
5.18k
      LITTLENUM_TYPE *pointer;  /* -> littlenum we are frobbing now.  */
481
5.18k
      long carry;
482
483
5.18k
      leader = generic_bignum;
484
5.18k
      generic_bignum[0] = 0;
485
5.18k
      generic_bignum[1] = 0;
486
5.18k
      generic_bignum[2] = 0;
487
5.18k
      generic_bignum[3] = 0;
488
5.18k
      input_line_pointer = start; /* -> 1st digit.  */
489
5.18k
      c = *input_line_pointer++;
490
123k
      for (; (carry = hex_value (c)) < maxdig; c = *input_line_pointer++)
491
118k
  {
492
468k
    for (pointer = generic_bignum; pointer <= leader; pointer++)
493
350k
      {
494
350k
        long work;
495
496
350k
        work = carry + radix * *pointer;
497
350k
        *pointer = work & LITTLENUM_MASK;
498
350k
        carry = work >> LITTLENUM_NUMBER_OF_BITS;
499
350k
      }
500
118k
    if (carry)
501
20.4k
      {
502
20.4k
        if (leader < generic_bignum + SIZE_OF_LARGE_NUMBER - 1)
503
20.4k
    {
504
      /* Room to grow a longer bignum.  */
505
20.4k
      *++leader = carry;
506
20.4k
    }
507
20.4k
      }
508
118k
  }
509
      /* Again, c is char after number.  */
510
      /* input_line_pointer -> after c.  */
511
5.18k
      know (LITTLENUM_NUMBER_OF_BITS == 16);
512
5.18k
      if (leader < generic_bignum + 2)
513
8
  {
514
    /* Will fit into 32 bits.  */
515
8
    number = generic_bignum_to_int32 ();
516
8
    small = 1;
517
8
  }
518
5.17k
#ifdef BFD64
519
5.17k
      else if (leader < generic_bignum + 4)
520
3.37k
  {
521
    /* Will fit into 64 bits.  */
522
3.37k
    number = generic_bignum_to_int64 ();
523
3.37k
    small = 1;
524
3.37k
  }
525
1.80k
#endif
526
1.80k
      else
527
1.80k
  {
528
    /* Number of littlenums in the bignum.  */
529
1.80k
    number = leader - generic_bignum + 1;
530
1.80k
  }
531
5.18k
    }
532
533
384k
  if ((NUMBERS_WITH_SUFFIX || flag_m68k_mri)
534
384k
      && suffix != NULL
535
384k
      && input_line_pointer - 1 == suffix)
536
0
    c = *input_line_pointer++;
537
538
384k
#ifndef tc_allow_U_suffix
539
769k
#define tc_allow_U_suffix 1
540
384k
#endif
541
  /* PR 19910: Look for, and ignore, a U suffix to the number.  */
542
384k
  if (tc_allow_U_suffix && (c == 'U' || c == 'u'))
543
74
    c = * input_line_pointer++;
544
545
384k
#ifndef tc_allow_L_suffix
546
384k
#define tc_allow_L_suffix 1
547
384k
#endif
548
  /* PR 20732: Look for, and ignore, a L or LL suffix to the number.  */
549
384k
  if (tc_allow_L_suffix)
550
388k
    while (c == 'L' || c == 'l')
551
3.84k
      c = * input_line_pointer++;
552
553
384k
  if (small)
554
382k
    {
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
382k
      if (LOCAL_LABELS_FB && c == 'b')
562
2.13k
  {
563
    /* Backward ref to local label.
564
       Because it is backward, expect it to be defined.  */
565
    /* Construct a local label.  */
566
2.13k
    name = fb_label_name (number, 0);
567
568
    /* Seen before, or symbol is defined: OK.  */
569
2.13k
    symbolP = symbol_find (name);
570
2.13k
    if ((symbolP != NULL) && (S_IS_DEFINED (symbolP)))
571
18
      {
572
18
        expressionP->X_op = O_symbol;
573
18
        expressionP->X_add_symbol = symbolP;
574
18
      }
575
2.11k
    else
576
2.11k
      {
577
        /* Either not seen or not defined.  */
578
        /* @@ Should print out the original string instead of
579
     the parsed number.  */
580
2.11k
        as_bad (_("backward ref to unknown label \"%d:\""),
581
2.11k
          (int) number);
582
2.11k
        expressionP->X_op = O_constant;
583
2.11k
      }
584
585
2.13k
    expressionP->X_add_number = 0;
586
2.13k
  }      /* case 'b' */
587
380k
      else if (LOCAL_LABELS_FB && c == 'f')
588
2.71k
  {
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
2.71k
    name = fb_label_name (number, 1);
597
2.71k
    symbolP = symbol_find_or_make (name);
598
    /* We have no need to check symbol properties.  */
599
2.71k
    expressionP->X_op = O_symbol;
600
2.71k
    expressionP->X_add_symbol = symbolP;
601
2.71k
    expressionP->X_add_number = 0;
602
2.71k
  }      /* case 'f' */
603
377k
      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
377k
      else
627
377k
  {
628
377k
    expressionP->X_op = O_constant;
629
377k
    expressionP->X_add_number = number;
630
377k
    input_line_pointer--; /* Restore following character.  */
631
377k
  }      /* Really just a number.  */
632
382k
    }
633
1.94k
  else
634
1.94k
    {
635
      /* Not a small number.  */
636
1.94k
      expressionP->X_op = O_big;
637
1.94k
      expressionP->X_add_number = number; /* Number of littlenums.  */
638
1.94k
      input_line_pointer--; /* -> char following number.  */
639
1.94k
    }
640
384k
}
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
12.3k
{
736
12.3k
  if (now_seg == absolute_section)
737
937
    {
738
937
      expressionp->X_op = O_constant;
739
937
      expressionp->X_add_number = abs_section_offset;
740
937
    }
741
11.3k
  else
742
11.3k
    {
743
11.3k
      expressionp->X_op = O_symbol;
744
11.3k
      expressionp->X_add_symbol = &dot_symbol;
745
11.3k
      expressionp->X_add_number = 0;
746
11.3k
    }
747
12.3k
}
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
1.00M
{
763
1.00M
  char c;
764
1.00M
  symbolS *symbolP; /* Points to symbol.  */
765
1.00M
  char *name;   /* Points to name of symbol.  */
766
1.00M
  segT segment;
767
1.00M
  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
1.00M
  expressionP->X_unsigned = 1;
776
1.00M
  expressionP->X_extrabit = 0;
777
778
  /* Digits, assume it is a bignum.  */
779
780
1.00M
  SKIP_WHITESPACE ();    /* Leading whitespace is part of operand.  */
781
1.00M
  c = *input_line_pointer++;  /* input_line_pointer -> past char in c.  */
782
783
1.00M
  if (is_end_of_line[(unsigned char) c])
784
32.9k
    goto eol;
785
786
970k
  switch (c)
787
970k
    {
788
106k
    case '1':
789
195k
    case '2':
790
226k
    case '3':
791
266k
    case '4':
792
283k
    case '5':
793
337k
    case '6':
794
345k
    case '7':
795
359k
    case '8':
796
370k
    case '9':
797
370k
      input_line_pointer--;
798
799
370k
      integer_constant ((NUMBERS_WITH_SUFFIX || flag_m68k_mri)
800
370k
      ? 0 : 10,
801
370k
      expressionP);
802
370k
      break;
803
804
#ifdef LITERAL_PREFIXPERCENT_BIN
805
    case '%':
806
      integer_constant (2, expressionP);
807
      break;
808
#endif
809
810
72.7k
    case '0':
811
      /* Non-decimal radix.  */
812
813
72.7k
      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
72.7k
      c = *input_line_pointer;
828
72.7k
      switch (c)
829
72.7k
  {
830
1
  case 'o':
831
1
  case 'O':
832
1
  case 'q':
833
1
  case 'Q':
834
11
  case '8':
835
5.51k
  case '9':
836
5.51k
    if (NUMBERS_WITH_SUFFIX || flag_m68k_mri)
837
0
      {
838
0
        integer_constant (0, expressionP);
839
0
        break;
840
0
      }
841
    /* Fall through.  */
842
52.8k
  default:
843
52.8k
  default_case:
844
52.8k
    if (c && strchr (FLT_CHARS, c))
845
3
      {
846
3
        input_line_pointer++;
847
3
        floating_constant (expressionP);
848
3
        expressionP->X_add_number = - TOLOWER (c);
849
3
      }
850
52.8k
    else
851
52.8k
      {
852
        /* The string was only zero.  */
853
52.8k
        expressionP->X_op = O_constant;
854
52.8k
        expressionP->X_add_number = 0;
855
52.8k
      }
856
857
52.8k
    break;
858
859
10
  case 'x':
860
154
  case 'X':
861
154
    if (flag_m68k_mri)
862
0
      goto default_case;
863
154
    input_line_pointer++;
864
154
    integer_constant (16, expressionP);
865
154
    break;
866
867
495
  case 'b':
868
495
    if (LOCAL_LABELS_FB && !flag_m68k_mri
869
495
        && input_line_pointer[1] != '0'
870
495
        && input_line_pointer[1] != '1')
871
430
      {
872
        /* Parse this as a back reference to label 0.  */
873
430
        input_line_pointer--;
874
430
        integer_constant (10, expressionP);
875
430
        break;
876
430
      }
877
    /* Otherwise, parse this as a binary number.  */
878
    /* Fall through.  */
879
66
  case 'B':
880
66
    if (input_line_pointer[1] == '0'
881
66
        || input_line_pointer[1] == '1')
882
65
      {
883
65
        input_line_pointer++;
884
65
        integer_constant (2, expressionP);
885
65
        break;
886
65
      }
887
1
    if (flag_m68k_mri || NUMBERS_WITH_SUFFIX)
888
0
      input_line_pointer++;
889
1
    goto default_case;
890
891
1.14k
  case '0':
892
5.29k
  case '1':
893
6.47k
  case '2':
894
7.40k
  case '3':
895
12.9k
  case '4':
896
13.0k
  case '5':
897
13.2k
  case '6':
898
13.4k
  case '7':
899
13.4k
    integer_constant ((flag_m68k_mri || NUMBERS_WITH_SUFFIX)
900
13.4k
          ? 0 : 8,
901
13.4k
          expressionP);
902
13.4k
    break;
903
904
4.18k
  case 'f':
905
4.18k
    if (LOCAL_LABELS_FB)
906
4.18k
      {
907
4.18k
        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
4.18k
        if (!is_end_of_line[(unsigned char) input_line_pointer[1]]
913
4.18k
      && strchr (FLT_CHARS, 'f') != NULL)
914
4.15k
    {
915
4.15k
      char *cp = input_line_pointer + 1;
916
917
4.15k
      atof_generic (&cp, ".", EXP_CHARS,
918
4.15k
        &generic_floating_point_number);
919
920
      /* Was nothing parsed, or does it look like an
921
         expression?  */
922
4.15k
      is_label = (cp == input_line_pointer + 1
923
4.15k
            || (cp == input_line_pointer + 2
924
3.92k
          && (cp[-1] == '-' || cp[-1] == '+'))
925
4.15k
            || *cp == 'f'
926
4.15k
            || *cp == 'b');
927
4.15k
    }
928
4.18k
        if (is_label)
929
374
    {
930
374
      input_line_pointer--;
931
374
      integer_constant (10, expressionP);
932
374
      break;
933
374
    }
934
4.18k
      }
935
    /* Fall through.  */
936
937
3.83k
  case 'd':
938
3.84k
  case 'D':
939
3.84k
    if (flag_m68k_mri || NUMBERS_WITH_SUFFIX)
940
0
      {
941
0
        integer_constant (0, expressionP);
942
0
        break;
943
0
      }
944
    /* Fall through.  */
945
3.84k
  case 'F':
946
4.69k
  case 'r':
947
4.69k
  case 'e':
948
5.30k
  case 'E':
949
5.37k
  case 'g':
950
5.37k
  case 'G':
951
5.37k
    input_line_pointer++;
952
5.37k
    floating_constant (expressionP);
953
5.37k
    expressionP->X_add_number = - TOLOWER (c);
954
5.37k
    break;
955
956
30
  case '$':
957
30
    if (LOCAL_LABELS_DOLLAR)
958
0
      {
959
0
        integer_constant (10, expressionP);
960
0
        break;
961
0
      }
962
30
    else
963
30
      goto default_case;
964
72.7k
  }
965
966
72.7k
      break;
967
968
72.7k
#ifndef NEED_INDEX_OPERATOR
969
72.7k
    case '[':
970
12.1k
# ifdef md_need_index_operator
971
12.1k
      if (md_need_index_operator())
972
0
  goto de_fault;
973
12.1k
# endif
974
12.1k
#endif
975
      /* Fall through.  */
976
20.1k
    case '(':
977
      /* Didn't begin with digit & not a name.  */
978
20.1k
      segment = expr (0, expressionP, mode);
979
      /* expression () will pass trailing whitespace.  */
980
20.1k
      if ((c == '(' && *input_line_pointer != ')')
981
20.1k
    || (c == '[' && *input_line_pointer != ']'))
982
19.5k
  {
983
19.5k
    if (* input_line_pointer)
984
17.1k
      as_bad (_("found '%c', expected: '%c'"),
985
17.1k
        * input_line_pointer, c == '(' ? ')' : ']');
986
2.42k
    else
987
2.42k
      as_bad (_("missing '%c'"), c == '(' ? ')' : ']');
988
19.5k
  }      
989
566
      else
990
566
  input_line_pointer++;
991
20.1k
      SKIP_ALL_WHITESPACE ();
992
      /* Here with input_line_pointer -> char after "(...)".  */
993
20.1k
      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
334
    case '\'':
1008
334
      if (! flag_m68k_mri)
1009
334
  {
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
334
    expressionP->X_op = O_constant;
1015
334
    expressionP->X_add_number = *input_line_pointer++;
1016
334
    break;
1017
334
  }
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
3.35k
    case '~':
1030
      /* '~' is permitted to start a label on the Delta.  */
1031
3.35k
      if (is_name_beginner (c))
1032
0
  goto isname;
1033
3.35k
      op = O_bit_not;
1034
3.35k
      goto unary;
1035
1036
17.7k
    case '!':
1037
17.7k
      op = O_logical_not;
1038
17.7k
      goto unary;
1039
1040
134k
    case '-':
1041
134k
      op = O_uminus;
1042
      /* Fall through.  */
1043
191k
    case '+':
1044
191k
      {
1045
213k
      unary:
1046
213k
  operand (expressionP, mode);
1047
1048
213k
#ifdef md_optimize_expr
1049
213k
  if (md_optimize_expr (NULL, op, expressionP))
1050
0
  {
1051
    /* Skip.  */
1052
0
    ;
1053
0
  }
1054
213k
  else
1055
213k
#endif
1056
213k
  if (expressionP->X_op == O_constant)
1057
156k
    {
1058
      /* input_line_pointer -> char after operand.  */
1059
156k
      if (op == O_uminus)
1060
114k
        {
1061
114k
    expressionP->X_add_number
1062
114k
      = - (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
114k
    expressionP->X_unsigned = 0;
1067
114k
    if (expressionP->X_add_number)
1068
92.7k
      expressionP->X_extrabit ^= 1;
1069
114k
        }
1070
41.3k
      else if (op == O_bit_not)
1071
2.63k
        {
1072
2.63k
    expressionP->X_add_number = ~ expressionP->X_add_number;
1073
2.63k
    expressionP->X_extrabit ^= 1;
1074
2.63k
    expressionP->X_unsigned = 0;
1075
2.63k
        }
1076
38.6k
      else if (op == O_logical_not)
1077
9.73k
        {
1078
9.73k
    expressionP->X_add_number = ! expressionP->X_add_number;
1079
9.73k
    expressionP->X_unsigned = 1;
1080
9.73k
    expressionP->X_extrabit = 0;
1081
9.73k
        }
1082
156k
    }
1083
56.7k
  else if (expressionP->X_op == O_big
1084
56.7k
     && expressionP->X_add_number <= 0
1085
56.7k
     && op == O_uminus
1086
56.7k
     && (generic_floating_point_number.sign == '+'
1087
527
         || generic_floating_point_number.sign == 'P'))
1088
525
    {
1089
      /* Negative flonum (eg, -1.000e0).  */
1090
525
      if (generic_floating_point_number.sign == '+')
1091
525
        generic_floating_point_number.sign = '-';
1092
0
      else
1093
0
        generic_floating_point_number.sign = 'N';
1094
525
    }
1095
56.2k
  else if (expressionP->X_op == O_big
1096
56.2k
     && expressionP->X_add_number > 0)
1097
1.07k
    {
1098
1.07k
      int i;
1099
1100
1.07k
      if (op == O_uminus || op == O_bit_not)
1101
976
        {
1102
17.6k
    for (i = 0; i < expressionP->X_add_number; ++i)
1103
16.6k
      generic_bignum[i] = ~generic_bignum[i];
1104
1105
    /* Extend the bignum to at least the size of .octa.  */
1106
976
    if (expressionP->X_add_number < SIZE_OF_LARGE_NUMBER)
1107
231
      {
1108
231
        expressionP->X_add_number = SIZE_OF_LARGE_NUMBER;
1109
3.11k
        for (; i < expressionP->X_add_number; ++i)
1110
2.88k
          generic_bignum[i] = ~(LITTLENUM_TYPE) 0;
1111
231
      }
1112
1113
976
    if (op == O_uminus)
1114
1.00k
      for (i = 0; i < expressionP->X_add_number; ++i)
1115
1.00k
        {
1116
1.00k
          generic_bignum[i] += 1;
1117
1.00k
          if (generic_bignum[i])
1118
963
      break;
1119
1.00k
        }
1120
976
        }
1121
94
      else if (op == O_logical_not)
1122
33
        {
1123
33
    for (i = 0; i < expressionP->X_add_number; ++i)
1124
33
      if (generic_bignum[i] != 0)
1125
33
        break;
1126
33
    expressionP->X_add_number = i >= expressionP->X_add_number;
1127
33
    expressionP->X_op = O_constant;
1128
33
    expressionP->X_unsigned = 1;
1129
33
    expressionP->X_extrabit = 0;
1130
33
        }
1131
1.07k
    }
1132
55.1k
  else if (expressionP->X_op != O_illegal
1133
55.1k
     && expressionP->X_op != O_absent)
1134
53.0k
    {
1135
53.0k
      if (op != O_absent)
1136
25.4k
        {
1137
25.4k
    expressionP->X_add_symbol = make_expr_symbol (expressionP);
1138
25.4k
    expressionP->X_op = op;
1139
25.4k
    expressionP->X_add_number = 0;
1140
25.4k
        }
1141
27.6k
      else if (!md_register_arithmetic && expressionP->X_op == O_register)
1142
1.97k
        {
1143
    /* Convert to binary '+'.  */
1144
1.97k
    expressionP->X_op_symbol = make_expr_symbol (expressionP);
1145
1.97k
    expressionP->X_add_symbol = make_expr_symbol (&zero);
1146
1.97k
    expressionP->X_add_number = 0;
1147
1.97k
    expressionP->X_op = O_add;
1148
1.97k
        }
1149
53.0k
    }
1150
2.10k
  else
1151
2.10k
    as_warn (_("Unary operator %c ignored because bad operand follows"),
1152
2.10k
       c);
1153
213k
      }
1154
213k
      break;
1155
1156
0
#if !defined (DOLLAR_DOT) && !defined (TC_M68K)
1157
1.12k
    case '$':
1158
1.12k
      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
1.12k
      else
1166
1.12k
  {
1167
1.12k
    goto isname;
1168
1.12k
  }
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
34.8k
    case '.':
1194
34.8k
      if (!is_part_of_name (*input_line_pointer))
1195
12.3k
  {
1196
12.3k
    current_location (expressionP);
1197
12.3k
    break;
1198
12.3k
  }
1199
22.4k
      else if ((strncasecmp (input_line_pointer, "startof.", 8) == 0
1200
22.4k
    && ! is_part_of_name (input_line_pointer[8]))
1201
22.4k
         || (strncasecmp (input_line_pointer, "sizeof.", 7) == 0
1202
21.9k
       && ! is_part_of_name (input_line_pointer[7])))
1203
585
  {
1204
585
    int start;
1205
1206
585
    start = (input_line_pointer[1] == 't'
1207
585
       || input_line_pointer[1] == 'T');
1208
585
    input_line_pointer += start ? 8 : 7;
1209
585
    SKIP_WHITESPACE ();
1210
1211
    /* Cover for the as_bad () invocations below.  */
1212
585
    expressionP->X_op = O_absent;
1213
1214
585
    if (*input_line_pointer != '(')
1215
95
      as_bad (_("syntax error in .startof. or .sizeof."));
1216
490
    else
1217
490
      {
1218
490
        ++input_line_pointer;
1219
490
        SKIP_WHITESPACE ();
1220
490
        c = get_symbol_name (& name);
1221
490
        if (! *name)
1222
54
    {
1223
54
      as_bad (_("expected symbol name"));
1224
54
      (void) restore_line_pointer (c);
1225
54
      if (c == ')')
1226
1
        ++input_line_pointer;
1227
54
      break;
1228
54
    }
1229
1230
436
        expressionP->X_op = O_symbol;
1231
436
        expressionP->X_add_symbol = symbol_lookup_or_make (name, start);
1232
436
        expressionP->X_add_number = 0;
1233
1234
436
        *input_line_pointer = c;
1235
436
        SKIP_WHITESPACE_AFTER_NAME ();
1236
436
        if (*input_line_pointer != ')')
1237
428
    as_bad (_("syntax error in .startof. or .sizeof."));
1238
8
        else
1239
8
    ++input_line_pointer;
1240
436
      }
1241
531
    break;
1242
585
  }
1243
21.9k
      else
1244
21.9k
  {
1245
21.9k
    goto isname;
1246
21.9k
  }
1247
1248
3.50k
    case ',':
1249
36.5k
    eol:
1250
      /* Can't imagine any other kind of operand.  */
1251
36.5k
      expressionP->X_op = O_absent;
1252
36.5k
      input_line_pointer--;
1253
36.5k
      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
255k
    default:
1288
255k
#if defined(md_need_index_operator) || defined(TC_M68K)
1289
255k
    de_fault:
1290
255k
#endif
1291
255k
      if (is_name_beginner (c) || c == '"')  /* Here if did not begin with a digit.  */
1292
153k
  {
1293
    /* Identifier begins here.
1294
       This is kludged for speed, so code is repeated.  */
1295
176k
  isname:
1296
176k
    -- input_line_pointer;
1297
176k
    c = get_symbol_name (&name);
1298
1299
176k
#ifdef md_operator
1300
176k
    {
1301
176k
      op = md_operator (name, 1, &c);
1302
176k
      switch (op)
1303
176k
        {
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
176k
        default:
1320
176k
    break;
1321
176k
        }
1322
1323
176k
      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
176k
    }
1334
176k
#endif
1335
1336
176k
#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
176k
    if (md_parse_name (name, expressionP, mode, &c))
1342
2
      {
1343
2
        restore_line_pointer (c);
1344
2
        break;
1345
2
      }
1346
176k
#endif
1347
1348
176k
    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
176k
    segment = S_GET_SEGMENT (symbolP);
1353
176k
    if (mode != expr_defer
1354
176k
        && segment == absolute_section
1355
176k
        && !S_FORCE_RELOC (symbolP, 0))
1356
12.1k
      {
1357
12.1k
        expressionP->X_op = O_constant;
1358
12.1k
        expressionP->X_add_number = S_GET_VALUE (symbolP);
1359
12.1k
      }
1360
164k
    else if (mode != expr_defer && segment == reg_section)
1361
627
      {
1362
627
        expressionP->X_op = O_register;
1363
627
        expressionP->X_add_number = S_GET_VALUE (symbolP);
1364
627
      }
1365
163k
    else
1366
163k
      {
1367
163k
        expressionP->X_op = O_symbol;
1368
163k
        expressionP->X_add_symbol = symbolP;
1369
163k
        expressionP->X_add_number = 0;
1370
163k
      }
1371
1372
176k
    restore_line_pointer (c);
1373
176k
  }
1374
101k
      else
1375
101k
  {
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
101k
    expressionP->X_op = O_absent;
1381
101k
    --input_line_pointer;
1382
101k
    md_operand (expressionP);
1383
101k
    if (expressionP->X_op == O_absent)
1384
99.2k
      {
1385
99.2k
        ++input_line_pointer;
1386
99.2k
        as_bad (_("bad expression"));
1387
99.2k
        expressionP->X_op = O_constant;
1388
99.2k
        expressionP->X_add_number = 0;
1389
99.2k
      }
1390
101k
  }
1391
278k
      break;
1392
970k
    }
1393
1394
  /* It is more 'efficient' to clean up the expressionS when they are
1395
     created.  Doing it here saves lines of code.  */
1396
983k
  clean_up_expression (expressionP);
1397
983k
  SKIP_ALL_WHITESPACE ();    /* -> 1st char after operand.  */
1398
983k
  know (*input_line_pointer != ' ');
1399
1400
  /* The PA port needs this information.  */
1401
983k
  if (expressionP->X_add_symbol)
1402
231k
    symbol_mark_used (expressionP->X_add_symbol);
1403
1404
983k
  if (mode != expr_defer)
1405
979k
    {
1406
979k
      expressionP->X_add_symbol
1407
979k
  = symbol_clone_if_forward_ref (expressionP->X_add_symbol);
1408
979k
      expressionP->X_op_symbol
1409
979k
  = symbol_clone_if_forward_ref (expressionP->X_op_symbol);
1410
979k
    }
1411
1412
983k
  switch (expressionP->X_op)
1413
983k
    {
1414
777k
    default:
1415
777k
      return absolute_section;
1416
203k
    case O_symbol:
1417
203k
      return S_GET_SEGMENT (expressionP->X_add_symbol);
1418
3.02k
    case O_register:
1419
3.02k
      return reg_section;
1420
983k
    }
1421
983k
}
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
983k
{
1435
983k
  switch (expressionP->X_op)
1436
983k
    {
1437
0
    case O_illegal:
1438
38.7k
    case O_absent:
1439
38.7k
      expressionP->X_add_number = 0;
1440
      /* Fall through.  */
1441
47.6k
    case O_big:
1442
749k
    case O_constant:
1443
752k
    case O_register:
1444
752k
      expressionP->X_add_symbol = NULL;
1445
      /* Fall through.  */
1446
956k
    case O_symbol:
1447
973k
    case O_uminus:
1448
973k
    case O_bit_not:
1449
973k
      expressionP->X_op_symbol = NULL;
1450
973k
      break;
1451
9.79k
    default:
1452
9.79k
      break;
1453
983k
    }
1454
983k
}
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
6.25k
#define STANDARD_MUL_PRECEDENCE 8
1569
0
#define MRI_MUL_PRECEDENCE 6
1570
1571
void
1572
expr_set_precedence (void)
1573
2.08k
{
1574
2.08k
  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
2.08k
  else
1581
2.08k
    {
1582
2.08k
      op_rank[O_multiply] = STANDARD_MUL_PRECEDENCE;
1583
2.08k
      op_rank[O_divide] = STANDARD_MUL_PRECEDENCE;
1584
2.08k
      op_rank[O_modulus] = STANDARD_MUL_PRECEDENCE;
1585
2.08k
    }
1586
2.08k
}
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
633
{
1600
633
  expr_set_precedence ();
1601
1602
  /* Verify that X_op field is wide enough.  */
1603
633
  {
1604
633
    expressionS e;
1605
633
    e.X_op = O_max;
1606
633
    gas_assert (e.X_op == O_max);
1607
633
  }
1608
1609
0
  memset (seen, 0, sizeof seen);
1610
633
  memset (nr_seen, 0, sizeof nr_seen);
1611
633
  expr_symbol_lines = NULL;
1612
633
}
1613
1614
void
1615
expr_end (void)
1616
633
{
1617
1.89k
  for (size_t i = 0; i < ARRAY_SIZE (seen); i++)
1618
1.26k
    free (seen[i]);
1619
633
}
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
961k
{
1628
961k
  int c;
1629
961k
  operatorT ret;
1630
1631
961k
  c = *input_line_pointer & 0xff;
1632
961k
  *num_chars = 1;
1633
1634
961k
  if (is_end_of_line[c])
1635
325k
    return O_illegal;
1636
1637
635k
#ifdef md_operator
1638
635k
  if (is_name_beginner (c))
1639
179k
    {
1640
179k
      char *name;
1641
179k
      char ec = get_symbol_name (& name);
1642
1643
179k
      ret = md_operator (name, 2, &ec);
1644
179k
      switch (ret)
1645
179k
  {
1646
179k
  case O_absent:
1647
179k
    *input_line_pointer = ec;
1648
179k
    input_line_pointer = name;
1649
179k
    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
179k
  }
1662
179k
    }
1663
635k
#endif
1664
1665
635k
  switch (c)
1666
635k
    {
1667
444k
    default:
1668
444k
      ret = op_encoding[c];
1669
444k
#ifdef md_operator
1670
444k
      if (ret == O_illegal)
1671
361k
  {
1672
361k
    char *start = input_line_pointer;
1673
1674
361k
    ret = md_operator (NULL, 2, NULL);
1675
361k
    if (ret != O_illegal)
1676
361k
      *num_chars = input_line_pointer - start;
1677
361k
    input_line_pointer = start;
1678
361k
  }
1679
444k
#endif
1680
444k
      return ret;
1681
1682
23.9k
    case '+':
1683
82.7k
    case '-':
1684
82.7k
      return op_encoding[c];
1685
1686
5.57k
    case '<':
1687
5.57k
      switch (input_line_pointer[1])
1688
5.57k
  {
1689
2.43k
  default:
1690
2.43k
    return op_encoding[c];
1691
1.39k
  case '<':
1692
1.39k
    ret = O_left_shift;
1693
1.39k
    break;
1694
396
  case '>':
1695
396
    ret = O_ne;
1696
396
    break;
1697
1.35k
  case '=':
1698
1.35k
    ret = O_le;
1699
1.35k
    break;
1700
5.57k
  }
1701
3.13k
      *num_chars = 2;
1702
3.13k
      return ret;
1703
1704
62.2k
    case '=':
1705
62.2k
      if (input_line_pointer[1] != '=')
1706
20.3k
  return op_encoding[c];
1707
1708
41.8k
      *num_chars = 2;
1709
41.8k
      return O_eq;
1710
1711
11.7k
    case '>':
1712
11.7k
      switch (input_line_pointer[1])
1713
11.7k
  {
1714
1.83k
  default:
1715
1.83k
    return op_encoding[c];
1716
7.16k
  case '>':
1717
7.16k
    ret = O_right_shift;
1718
7.16k
    break;
1719
2.76k
  case '=':
1720
2.76k
    ret = O_ge;
1721
2.76k
    break;
1722
11.7k
  }
1723
9.92k
      *num_chars = 2;
1724
9.92k
      return ret;
1725
1726
21.4k
    case '!':
1727
21.4k
      switch (input_line_pointer[1])
1728
21.4k
  {
1729
81
  case '!':
1730
    /* We accept !! as equivalent to ^ for MRI compatibility. */
1731
81
    *num_chars = 2;
1732
81
    return O_bit_exclusive_or;
1733
89
  case '=':
1734
    /* We accept != as equivalent to <>.  */
1735
89
    *num_chars = 2;
1736
89
    return O_ne;
1737
21.2k
  default:
1738
21.2k
    if (flag_m68k_mri)
1739
0
      return O_bit_inclusive_or;
1740
21.2k
    return op_encoding[c];
1741
21.4k
  }
1742
1743
4.35k
    case '|':
1744
4.35k
      if (input_line_pointer[1] != '|')
1745
789
  return op_encoding[c];
1746
1747
3.56k
      *num_chars = 2;
1748
3.56k
      return O_logical_or;
1749
1750
3.06k
    case '&':
1751
3.06k
      if (input_line_pointer[1] != '&')
1752
2.15k
  return op_encoding[c];
1753
1754
912
      *num_chars = 2;
1755
912
      return O_logical_and;
1756
635k
    }
1757
1758
  /* NOTREACHED  */
1759
635k
}
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
13.5k
{
1770
13.5k
  valueT ures = resultP->X_add_number;
1771
13.5k
  valueT uamount = amount;
1772
1773
13.5k
  resultP->X_add_number += uamount;
1774
1775
13.5k
  resultP->X_extrabit ^= rhs_highbit;
1776
1777
13.5k
  if (ures + uamount < ures)
1778
812
    resultP->X_extrabit ^= 1;
1779
13.5k
}
1780
1781
/* Similarly, for subtraction.  */
1782
1783
void
1784
subtract_from_result (expressionS *resultP, offsetT amount, int rhs_highbit)
1785
35.2k
{
1786
35.2k
  valueT ures = resultP->X_add_number;
1787
35.2k
  valueT uamount = amount;
1788
1789
35.2k
  resultP->X_add_number -= uamount;
1790
1791
35.2k
  resultP->X_extrabit ^= rhs_highbit;
1792
1793
35.2k
  if (ures < uamount)
1794
10.3k
    resultP->X_extrabit ^= 1;
1795
35.2k
}
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
790k
{
1804
790k
  operator_rankT rank = (operator_rankT) rankarg;
1805
790k
  segT retval;
1806
790k
  expressionS right;
1807
790k
  operatorT op_left;
1808
790k
  operatorT op_right;
1809
790k
  int op_chars;
1810
1811
790k
  know (rankarg >= 0);
1812
1813
  /* Save the value of dot for the fixup code.  */
1814
790k
  if (rank == 0)
1815
619k
    {
1816
619k
      dot_value = frag_now_fix ();
1817
619k
      dot_frag = frag_now;
1818
619k
    }
1819
1820
790k
  retval = operand (resultP, mode);
1821
1822
  /* operand () gobbles spaces.  */
1823
790k
  know (*input_line_pointer != ' ');
1824
1825
0
  op_left = operatorf (&op_chars);
1826
961k
  while (op_left != O_illegal && op_rank[(int) op_left] > rank)
1827
170k
    {
1828
170k
      segT rightseg;
1829
170k
      bool is_unsigned;
1830
170k
      offsetT frag_off;
1831
1832
170k
      input_line_pointer += op_chars; /* -> after operator.  */
1833
1834
170k
      right.X_md = 0;
1835
170k
      rightseg = expr (op_rank[(int) op_left], &right, mode);
1836
170k
      if (right.X_op == O_absent)
1837
9.02k
  {
1838
9.02k
    as_warn (_("missing operand; zero assumed"));
1839
9.02k
    right.X_op = O_constant;
1840
9.02k
    right.X_add_number = 0;
1841
9.02k
    right.X_add_symbol = NULL;
1842
9.02k
    right.X_op_symbol = NULL;
1843
9.02k
  }
1844
1845
170k
      know (*input_line_pointer != ' ');
1846
1847
170k
      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
170k
      op_right = operatorf (&op_chars);
1859
1860
170k
      know (op_right == O_illegal || op_left == O_index
1861
0
      || op_rank[(int) op_right] <= op_rank[(int) op_left]);
1862
170k
      know ((int) op_left >= (int) O_multiply);
1863
#ifndef md_operator
1864
      know ((int) op_left <= (int) O_index);
1865
#else
1866
170k
      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
170k
      if (resultP->X_op == O_big)
1875
483
  {
1876
483
    if (resultP->X_add_number > 0)
1877
233
      as_warn (_("left operand is a bignum; integer 0 assumed"));
1878
250
    else
1879
250
      as_warn (_("left operand is a float; integer 0 assumed"));
1880
483
    resultP->X_op = O_constant;
1881
483
    resultP->X_add_number = 0;
1882
483
    resultP->X_add_symbol = NULL;
1883
483
    resultP->X_op_symbol = NULL;
1884
483
  }
1885
170k
      if (right.X_op == O_big)
1886
865
  {
1887
865
    if (right.X_add_number > 0)
1888
859
      as_warn (_("right operand is a bignum; integer 0 assumed"));
1889
6
    else
1890
6
      as_warn (_("right operand is a float; integer 0 assumed"));
1891
865
    right.X_op = O_constant;
1892
865
    right.X_add_number = 0;
1893
865
    right.X_add_symbol = NULL;
1894
865
    right.X_op_symbol = NULL;
1895
865
  }
1896
1897
170k
      is_unsigned = resultP->X_unsigned && right.X_unsigned;
1898
1899
170k
      if (mode == expr_defer
1900
170k
    && ((resultP->X_add_symbol != NULL
1901
2.63k
         && S_IS_FORWARD_REF (resultP->X_add_symbol))
1902
2.63k
        || (right.X_add_symbol != NULL
1903
1.64k
      && S_IS_FORWARD_REF (right.X_add_symbol))))
1904
1.03k
  goto general;
1905
1906
      /* Optimize common cases.  */
1907
169k
#ifdef md_optimize_expr
1908
169k
      if (md_optimize_expr (resultP, op_left, &right))
1909
0
  {
1910
    /* Skip.  */
1911
0
    is_unsigned = resultP->X_unsigned;
1912
0
  }
1913
169k
      else
1914
169k
#endif
1915
169k
      if (op_left == O_add && right.X_op == O_constant
1916
169k
    && (md_register_arithmetic || resultP->X_op != O_register))
1917
9.70k
  {
1918
    /* X + constant.  */
1919
9.70k
    add_to_result (resultP, right.X_add_number, right.X_extrabit);
1920
9.70k
  }
1921
      /* This case comes up in PIC code.  */
1922
159k
      else if (op_left == O_subtract
1923
159k
         && right.X_op == O_symbol
1924
159k
         && resultP->X_op == O_symbol
1925
159k
         && retval == rightseg
1926
#ifdef md_allow_local_subtract
1927
         && md_allow_local_subtract (resultP, & right, rightseg)
1928
#endif
1929
159k
         && ((SEG_NORMAL (rightseg)
1930
3.99k
        && !S_FORCE_RELOC (resultP->X_add_symbol, 0)
1931
3.99k
        && !S_FORCE_RELOC (right.X_add_symbol, 0))
1932
3.99k
       || right.X_add_symbol == resultP->X_add_symbol)
1933
159k
         && frag_offset_fixed_p (symbol_get_frag (resultP->X_add_symbol),
1934
1.45k
               symbol_get_frag (right.X_add_symbol),
1935
1.45k
               &frag_off))
1936
969
  {
1937
969
    offsetT symval_diff = S_GET_VALUE (resultP->X_add_symbol)
1938
969
        - S_GET_VALUE (right.X_add_symbol);
1939
969
    subtract_from_result (resultP, right.X_add_number, right.X_extrabit);
1940
969
    subtract_from_result (resultP, frag_off / OCTETS_PER_BYTE, 0);
1941
969
    add_to_result (resultP, symval_diff, symval_diff < 0);
1942
969
    resultP->X_op = O_constant;
1943
969
    resultP->X_add_symbol = 0;
1944
969
    is_unsigned = false;
1945
969
  }
1946
158k
      else if (op_left == O_subtract && right.X_op == O_constant
1947
158k
         && (md_register_arithmetic || resultP->X_op != O_register))
1948
29.3k
  {
1949
    /* X - constant.  */
1950
29.3k
    subtract_from_result (resultP, right.X_add_number, right.X_extrabit);
1951
29.3k
    is_unsigned = false;
1952
29.3k
  }
1953
129k
      else if (op_left == O_add && resultP->X_op == O_constant
1954
129k
         && (md_register_arithmetic || right.X_op != O_register))
1955
1.81k
  {
1956
    /* Constant + X.  */
1957
1.81k
    resultP->X_op = right.X_op;
1958
1.81k
    resultP->X_add_symbol = right.X_add_symbol;
1959
1.81k
    resultP->X_op_symbol = right.X_op_symbol;
1960
1.81k
    add_to_result (resultP, right.X_add_number, right.X_extrabit);
1961
1.81k
    retval = rightseg;
1962
1.81k
  }
1963
127k
      else if (resultP->X_op == O_constant && right.X_op == O_constant)
1964
47.8k
  {
1965
    /* Constant OP constant.  */
1966
47.8k
    offsetT v = right.X_add_number;
1967
47.8k
    if (v == 0 && (op_left == O_divide || op_left == O_modulus))
1968
15.6k
      {
1969
15.6k
        as_warn (_("division by zero"));
1970
15.6k
        v = 1;
1971
15.6k
      }
1972
47.8k
    switch (op_left)
1973
47.8k
      {
1974
0
      default:      goto general;
1975
3.47k
      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
3.47k
        resultP->X_add_number *= (valueT) v;
1980
3.47k
        break;
1981
1.14k
      case O_divide:    resultP->X_add_number /= v; break;
1982
16.3k
      case O_modulus:   resultP->X_add_number %= v; break;
1983
668
      case O_left_shift:
1984
1.00k
      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.00k
        if ((valueT) v >= sizeof (valueT) * CHAR_BIT)
1994
149
    {
1995
149
      as_warn_value_out_of_range (_("shift count"), v, 0,
1996
149
                sizeof (valueT) * CHAR_BIT - 1,
1997
149
                NULL, 0);
1998
149
      resultP->X_add_number = 0;
1999
149
    }
2000
853
        else if (op_left == O_left_shift)
2001
541
    resultP->X_add_number
2002
541
      = (valueT) resultP->X_add_number << (valueT) v;
2003
312
        else
2004
312
    resultP->X_add_number
2005
312
      = (valueT) resultP->X_add_number >> (valueT) v;
2006
1.00k
        is_unsigned = resultP->X_unsigned;
2007
1.00k
        break;
2008
424
      case O_bit_inclusive_or:  resultP->X_add_number |= v; break;
2009
10.1k
      case O_bit_or_not:    resultP->X_add_number |= ~v; break;
2010
2.67k
      case O_bit_exclusive_or:  resultP->X_add_number ^= v; break;
2011
316
      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
9.58k
      case O_eq:
2020
9.58k
        resultP->X_add_number =
2021
9.58k
    resultP->X_add_number == v ? ~ (offsetT) 0 : 0;
2022
9.58k
        is_unsigned = false;
2023
9.58k
        break;
2024
88
      case O_ne:
2025
88
        resultP->X_add_number =
2026
88
    resultP->X_add_number != v ? ~ (offsetT) 0 : 0;
2027
88
        is_unsigned = false;
2028
88
        break;
2029
278
      case O_lt:
2030
278
        resultP->X_add_number =
2031
278
    resultP->X_add_number <  v ? ~ (offsetT) 0 : 0;
2032
278
        is_unsigned = false;
2033
278
        break;
2034
64
      case O_le:
2035
64
        resultP->X_add_number =
2036
64
    resultP->X_add_number <= v ? ~ (offsetT) 0 : 0;
2037
64
        is_unsigned = false;
2038
64
        break;
2039
45
      case O_ge:
2040
45
        resultP->X_add_number =
2041
45
    resultP->X_add_number >= v ? ~ (offsetT) 0 : 0;
2042
45
        is_unsigned = false;
2043
45
        break;
2044
587
      case O_gt:
2045
587
        resultP->X_add_number =
2046
587
    resultP->X_add_number >  v ? ~ (offsetT) 0 : 0;
2047
587
        is_unsigned = false;
2048
587
        break;
2049
159
      case O_logical_and:
2050
159
        resultP->X_add_number = resultP->X_add_number && v;
2051
159
        is_unsigned = true;
2052
159
        break;
2053
1.48k
      case O_logical_or:
2054
1.48k
        resultP->X_add_number = resultP->X_add_number || v;
2055
1.48k
        is_unsigned = true;
2056
1.48k
        break;
2057
47.8k
      }
2058
47.8k
  }
2059
79.8k
      else if (resultP->X_op == O_symbol
2060
79.8k
         && right.X_op == O_symbol
2061
79.8k
         && (op_left == O_add
2062
9.04k
       || op_left == O_subtract
2063
9.04k
       || (resultP->X_add_number == 0
2064
4.08k
           && right.X_add_number == 0)))
2065
8.84k
  {
2066
    /* Symbol OP symbol.  */
2067
8.84k
    resultP->X_op = op_left;
2068
8.84k
    resultP->X_op_symbol = right.X_add_symbol;
2069
8.84k
    if (op_left == O_add)
2070
1.03k
      add_to_result (resultP, right.X_add_number, right.X_extrabit);
2071
7.81k
    else if (op_left == O_subtract)
2072
3.92k
      {
2073
3.92k
        subtract_from_result (resultP, right.X_add_number,
2074
3.92k
            right.X_extrabit);
2075
3.92k
        if (retval == rightseg
2076
3.92k
      && SEG_NORMAL (retval)
2077
3.92k
      && !S_FORCE_RELOC (resultP->X_add_symbol, 0)
2078
3.92k
      && !S_FORCE_RELOC (right.X_add_symbol, 0))
2079
482
    {
2080
482
      retval = absolute_section;
2081
482
      rightseg = absolute_section;
2082
482
    }
2083
3.92k
      }
2084
8.84k
  }
2085
70.9k
      else
2086
70.9k
  {
2087
71.9k
        general:
2088
    /* The general case.  */
2089
71.9k
    resultP->X_add_symbol = make_expr_symbol (resultP);
2090
71.9k
    resultP->X_op_symbol = make_expr_symbol (&right);
2091
71.9k
    resultP->X_op = op_left;
2092
71.9k
    resultP->X_add_number = 0;
2093
71.9k
    resultP->X_extrabit = 0;
2094
71.9k
  }
2095
2096
170k
      resultP->X_unsigned = is_unsigned;
2097
2098
170k
      if (retval != rightseg)
2099
68.2k
  {
2100
68.2k
    if (retval == undefined_section)
2101
42.8k
      ;
2102
25.3k
    else if (rightseg == undefined_section)
2103
19.3k
      retval = rightseg;
2104
6.00k
    else if (retval == expr_section)
2105
513
      ;
2106
5.49k
    else if (rightseg == expr_section)
2107
538
      retval = rightseg;
2108
4.95k
    else if (retval == reg_section)
2109
884
      ;
2110
4.07k
    else if (rightseg == reg_section)
2111
371
      retval = rightseg;
2112
3.70k
    else if (rightseg == absolute_section)
2113
2.17k
      ;
2114
1.52k
    else if (retval == absolute_section)
2115
967
      retval = rightseg;
2116
562
#ifdef DIFF_EXPR_OK
2117
562
    else if (op_left == O_subtract)
2118
560
      ;
2119
2
#endif
2120
2
    else
2121
2
      as_bad (_("operation combines symbols in different segments"));
2122
68.2k
  }
2123
2124
170k
      op_left = op_right;
2125
170k
    }        /* While next operator is >= this rank.  */
2126
2127
  /* The PA port needs this information.  */
2128
790k
  if (resultP->X_add_symbol)
2129
219k
    symbol_mark_used (resultP->X_add_symbol);
2130
2131
790k
  if (rank == 0 && mode == expr_evaluate)
2132
249k
    resolve_expression (resultP);
2133
2134
790k
  return resultP->X_op == O_constant ? absolute_section : retval;
2135
790k
}
2136
2137
/* Resolve an expression without changing any symbols/sub-expressions
2138
   used.  */
2139
2140
int
2141
resolve_expression (expressionS *expressionP)
2142
469k
{
2143
  /* Help out with CSE.  */
2144
469k
  valueT final_val = expressionP->X_add_number;
2145
469k
  symbolS *add_symbol = expressionP->X_add_symbol;
2146
469k
  symbolS *orig_add_symbol = add_symbol;
2147
469k
  symbolS *op_symbol = expressionP->X_op_symbol;
2148
469k
  operatorT op = expressionP->X_op;
2149
469k
  valueT left, right;
2150
469k
  segT seg_left, seg_right;
2151
469k
  fragS *frag_left, *frag_right;
2152
469k
  offsetT frag_off;
2153
2154
469k
  switch (op)
2155
469k
    {
2156
8.70k
    default:
2157
8.70k
      return 0;
2158
2159
326k
    case O_constant:
2160
329k
    case O_register:
2161
329k
      left = 0;
2162
329k
      break;
2163
2164
23.8k
    case O_symbol:
2165
23.8k
    case O_symbol_rva:
2166
23.8k
      if (!snapshot_symbol (&add_symbol, &left, &seg_left, &frag_left))
2167
556
  return 0;
2168
2169
23.3k
      break;
2170
2171
23.3k
    case O_uminus:
2172
2.05k
    case O_bit_not:
2173
8.47k
    case O_logical_not:
2174
8.47k
      if (!snapshot_symbol (&add_symbol, &left, &seg_left, &frag_left))
2175
2.14k
  return 0;
2176
2177
6.32k
      if (seg_left != absolute_section)
2178
5.67k
  return 0;
2179
2180
658
      if (op == O_logical_not)
2181
504
  left = !left;
2182
154
      else if (op == O_uminus)
2183
154
  left = -left;
2184
0
      else
2185
0
  left = ~left;
2186
658
      op = O_constant;
2187
658
      break;
2188
2189
9.94k
    case O_multiply:
2190
10.4k
    case O_divide:
2191
13.7k
    case O_modulus:
2192
13.9k
    case O_left_shift:
2193
68.5k
    case O_right_shift:
2194
68.6k
    case O_bit_inclusive_or:
2195
73.2k
    case O_bit_or_not:
2196
75.2k
    case O_bit_exclusive_or:
2197
75.3k
    case O_bit_and:
2198
83.8k
    case O_add:
2199
88.4k
    case O_subtract:
2200
93.8k
    case O_eq:
2201
93.9k
    case O_ne:
2202
94.5k
    case O_lt:
2203
95.2k
    case O_le:
2204
96.5k
    case O_ge:
2205
99.3k
    case O_gt:
2206
99.4k
    case O_logical_and:
2207
99.4k
    case O_logical_or:
2208
99.4k
      if (!snapshot_symbol (&add_symbol, &left, &seg_left, &frag_left)
2209
99.4k
    || !snapshot_symbol (&op_symbol, &right, &seg_right, &frag_right))
2210
23.1k
  return 0;
2211
2212
      /* Simplify addition or subtraction of a constant by folding the
2213
   constant into X_add_number.  */
2214
76.3k
      if (op == O_add)
2215
2.89k
  {
2216
2.89k
    if (seg_right == absolute_section)
2217
214
      {
2218
214
        final_val += right;
2219
214
        op = O_symbol;
2220
214
        break;
2221
214
      }
2222
2.68k
    else if (seg_left == absolute_section)
2223
1.98k
      {
2224
1.98k
        final_val += left;
2225
1.98k
        left = right;
2226
1.98k
        seg_left = seg_right;
2227
1.98k
        add_symbol = op_symbol;
2228
1.98k
        orig_add_symbol = expressionP->X_op_symbol;
2229
1.98k
        op = O_symbol;
2230
1.98k
        break;
2231
1.98k
      }
2232
2.89k
  }
2233
73.4k
      else if (op == O_subtract)
2234
2.33k
  {
2235
2.33k
    if (seg_right == absolute_section)
2236
26
      {
2237
26
        final_val -= right;
2238
26
        op = O_symbol;
2239
26
        break;
2240
26
      }
2241
2.33k
  }
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
74.1k
      frag_off = 0;
2257
74.1k
      if (!(seg_left == absolute_section
2258
74.1k
         && seg_right == absolute_section)
2259
74.1k
    && !(op == O_eq || op == O_ne)
2260
74.1k
    && !((op == O_subtract
2261
64.6k
    || op == O_lt || op == O_le || op == O_ge || op == O_gt)
2262
64.6k
         && seg_left == seg_right
2263
64.6k
         && (finalize_syms
2264
1.43k
       || frag_offset_fixed_p (frag_left, frag_right, &frag_off)
2265
1.43k
       || (op == O_gt
2266
0
           && frag_gtoffset_p (left, frag_left,
2267
0
             right, frag_right, &frag_off)))
2268
64.6k
         && (seg_left != reg_section || left == right)
2269
64.6k
         && (seg_left != undefined_section || add_symbol == op_symbol)))
2270
64.6k
  {
2271
64.6k
    if ((seg_left == absolute_section && left == 0)
2272
64.6k
        || (seg_right == absolute_section && right == 0))
2273
47.8k
      {
2274
47.8k
        if (op == O_bit_exclusive_or || op == O_bit_inclusive_or)
2275
905
    {
2276
905
      if (!(seg_right == absolute_section && right == 0))
2277
61
        {
2278
61
          seg_left = seg_right;
2279
61
          left = right;
2280
61
          add_symbol = op_symbol;
2281
61
          orig_add_symbol = expressionP->X_op_symbol;
2282
61
        }
2283
905
      op = O_symbol;
2284
905
      break;
2285
905
    }
2286
46.9k
        else if (op == O_left_shift || op == O_right_shift)
2287
41.1k
    {
2288
41.1k
      if (!(seg_left == absolute_section && left == 0))
2289
39.8k
        {
2290
39.8k
          op = O_symbol;
2291
39.8k
          break;
2292
39.8k
        }
2293
41.1k
    }
2294
5.79k
        else if (op != O_multiply
2295
5.79k
           && op != O_bit_or_not && op != O_bit_and)
2296
4.00k
          return 0;
2297
47.8k
      }
2298
16.7k
    else if (op == O_multiply
2299
16.7k
       && seg_left == absolute_section && left == 1)
2300
3.95k
      {
2301
3.95k
        seg_left = seg_right;
2302
3.95k
        left = right;
2303
3.95k
        add_symbol = op_symbol;
2304
3.95k
        orig_add_symbol = expressionP->X_op_symbol;
2305
3.95k
        op = O_symbol;
2306
3.95k
        break;
2307
3.95k
      }
2308
12.8k
    else if ((op == O_multiply || op == O_divide)
2309
12.8k
       && seg_right == absolute_section && right == 1)
2310
87
      {
2311
87
        op = O_symbol;
2312
87
        break;
2313
87
      }
2314
12.7k
    else if (!(left == right
2315
12.7k
         && ((seg_left == reg_section && seg_right == reg_section)
2316
4.06k
       || (seg_left == undefined_section
2317
4.06k
           && seg_right == undefined_section
2318
4.06k
           && add_symbol == op_symbol))))
2319
12.5k
      return 0;
2320
212
    else if (op == O_bit_and || op == O_bit_inclusive_or)
2321
0
      {
2322
0
        op = O_symbol;
2323
0
        break;
2324
0
      }
2325
212
    else if (op != O_bit_exclusive_or && op != O_bit_or_not)
2326
0
      return 0;
2327
64.6k
  }
2328
2329
12.7k
      right += frag_off / OCTETS_PER_BYTE;
2330
12.7k
      switch (op)
2331
12.7k
  {
2332
0
  case O_add:     left += right; break;
2333
20
  case O_subtract:    left -= right; break;
2334
1.65k
  case O_multiply:    left *= right; break;
2335
18
  case O_divide:
2336
18
    if (right == 0)
2337
18
      return 0;
2338
0
    left = (offsetT) left / (offsetT) right;
2339
0
    break;
2340
38
  case O_modulus:
2341
38
    if (right == 0)
2342
19
      return 0;
2343
19
    left = (offsetT) left % (offsetT) right;
2344
19
    break;
2345
26
  case O_left_shift:
2346
26
    if (right >= sizeof (left) * CHAR_BIT)
2347
7
      left = 0;
2348
19
    else
2349
19
      left <<= right;
2350
26
    break;
2351
2.34k
  case O_right_shift:
2352
2.34k
    if (right >= sizeof (left) * CHAR_BIT)
2353
1.06k
      left = 0;
2354
1.28k
    else
2355
1.28k
      left >>= right;
2356
2.34k
    break;
2357
0
  case O_bit_inclusive_or:  left |= right; break;
2358
2.48k
  case O_bit_or_not:    left |= ~right; break;
2359
1.01k
  case O_bit_exclusive_or:  left ^= right; break;
2360
12
  case O_bit_and:     left &= right; break;
2361
3.74k
  case O_eq:
2362
3.84k
  case O_ne:
2363
3.84k
    left = (left == right
2364
3.84k
      && seg_left == seg_right
2365
3.84k
      && (finalize_syms || frag_left == frag_right)
2366
3.84k
      && (seg_left != undefined_section
2367
1.30k
          || add_symbol == op_symbol)
2368
3.84k
      ? ~ (valueT) 0 : 0);
2369
3.84k
    if (op == O_ne)
2370
96
      left = ~left;
2371
3.84k
    break;
2372
56
  case O_lt:
2373
56
    left = (offsetT) left <  (offsetT) right ? ~ (valueT) 0 : 0;
2374
56
    break;
2375
2
  case O_le:
2376
2
    left = (offsetT) left <= (offsetT) right ? ~ (valueT) 0 : 0;
2377
2
    break;
2378
1.22k
  case O_ge:
2379
1.22k
    left = (offsetT) left >= (offsetT) right ? ~ (valueT) 0 : 0;
2380
1.22k
    break;
2381
33
  case O_gt:
2382
33
    left = (offsetT) left >  (offsetT) right ? ~ (valueT) 0 : 0;
2383
33
    break;
2384
19
  case O_logical_and: left = left && right; break;
2385
4
  case O_logical_or:  left = left || right; break;
2386
0
  default:    abort ();
2387
12.7k
  }
2388
2389
12.7k
      op = O_constant;
2390
12.7k
      break;
2391
469k
    }
2392
2393
412k
  if (op == O_symbol)
2394
70.3k
    {
2395
70.3k
      if (seg_left == absolute_section)
2396
548
  op = O_constant;
2397
69.8k
      else if (seg_left == reg_section && final_val == 0)
2398
1.97k
  op = O_register;
2399
67.8k
      else if (!symbol_same_p (add_symbol, orig_add_symbol))
2400
37.1k
  final_val += left;
2401
70.3k
      expressionP->X_add_symbol = add_symbol;
2402
70.3k
    }
2403
412k
  expressionP->X_op = op;
2404
2405
412k
  if (op == O_constant || op == O_register)
2406
344k
    final_val += left;
2407
412k
  expressionP->X_add_number = final_val;
2408
2409
412k
  return 1;
2410
469k
}
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
2.25M
{
2459
2.25M
  char c;
2460
2461
2.25M
  * 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
2.25M
  if (is_name_beginner (c = *input_line_pointer++)
2465
2.25M
      || (input_from_string && c == FAKE_LABEL_CHAR))
2466
2.14M
    {
2467
11.0M
      while (is_part_of_name (c = *input_line_pointer++)
2468
11.0M
       || (input_from_string && c == FAKE_LABEL_CHAR))
2469
8.95M
  ;
2470
2.14M
      if (is_name_ender (c))
2471
0
  c = *input_line_pointer++;
2472
2.14M
    }
2473
116k
  else if (c == '"')
2474
15.7k
    {
2475
15.7k
      char *dst = input_line_pointer;
2476
2477
15.7k
      * ilp_return = input_line_pointer;
2478
15.7k
      for (;;)
2479
321k
  {
2480
321k
    c = *input_line_pointer++;
2481
2482
321k
    if (c == 0)
2483
4.35k
      {
2484
4.35k
        as_warn (_("missing closing '\"'"));
2485
4.35k
        break;
2486
4.35k
      }
2487
2488
316k
    if (c == '"')
2489
62.4k
      {
2490
62.4k
        char *ilp_save = input_line_pointer;
2491
2492
62.4k
        SKIP_WHITESPACE ();
2493
62.4k
        if (*input_line_pointer == '"')
2494
51.0k
    {
2495
51.0k
      ++input_line_pointer;
2496
51.0k
      continue;
2497
51.0k
    }
2498
11.3k
        input_line_pointer = ilp_save;
2499
11.3k
        break;
2500
62.4k
      }
2501
2502
254k
    if (c == '\\')
2503
1.38k
      switch (*input_line_pointer)
2504
1.38k
        {
2505
21
        case '"':
2506
487
        case '\\':
2507
487
    c = *input_line_pointer++;
2508
487
    break;
2509
2510
895
        default:
2511
895
    if (c != 0)
2512
895
      as_warn (_("'\\%c' in quoted symbol name; "
2513
895
           "behavior may change in the future"),
2514
895
         *input_line_pointer);
2515
895
    break;
2516
1.38k
        }
2517
2518
254k
    *dst++ = c;
2519
254k
  }
2520
15.7k
      *dst = 0;
2521
15.7k
    }
2522
2.25M
  *--input_line_pointer = 0;
2523
2.25M
  return c;
2524
2.25M
}
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
1.73M
{
2533
1.73M
  * input_line_pointer = c;
2534
1.73M
  if (c == '"')
2535
54.0k
    c = * ++ input_line_pointer;
2536
1.73M
  return c;
2537
1.73M
}
2538
2539
unsigned int
2540
get_single_number (void)
2541
357
{
2542
357
  expressionS exp;
2543
357
  operand (&exp, expr_normal);
2544
357
  return exp.X_add_number;
2545
357
}