Coverage Report

Created: 2026-04-04 08:16

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