forked from bminor/binutils-gdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpr.c
2634 lines (2347 loc) · 66.7 KB
/
expr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* expr.c -operands, expressions-
Copyright (C) 1987-2025 Free Software Foundation, Inc.
This file is part of GAS, the GNU Assembler.
GAS is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GAS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GAS; see the file COPYING. If not, write to the Free
Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
02110-1301, USA. */
/* This is really a branch office of as-read.c. I split it out to clearly
distinguish the world of expressions from the world of statements.
(It also gives smaller files to re-compile.)
Here, "operand"s are of expressions, not instructions. */
#define min(a, b) ((a) < (b) ? (a) : (b))
#include "as.h"
#include "safe-ctype.h"
#include <limits.h>
#ifndef CHAR_BIT
#define CHAR_BIT 8
#endif
bool literal_prefix_dollar_hex = false;
static void clean_up_expression (expressionS * expressionP);
/* We keep a mapping of expression symbols to file positions, so that
we can provide better error messages. */
struct expr_symbol_line {
struct expr_symbol_line *next;
symbolS *sym;
const char *file;
unsigned int line;
};
static struct expr_symbol_line *expr_symbol_lines;
static const expressionS zero = { .X_op = O_constant };
/* Build a dummy symbol to hold a complex expression. This is how we
build expressions up out of other expressions. The symbol is put
into the fake section expr_section. */
symbolS *
make_expr_symbol (const expressionS *expressionP)
{
symbolS *symbolP;
struct expr_symbol_line *n;
if (expressionP->X_op == O_symbol
&& expressionP->X_add_number == 0)
return expressionP->X_add_symbol;
if (expressionP->X_op == O_big)
{
/* This won't work, because the actual value is stored in
generic_floating_point_number or generic_bignum, and we are
going to lose it if we haven't already. */
if (expressionP->X_add_number > 0)
as_bad (_("bignum invalid"));
else
as_bad (_("floating point number invalid"));
expressionP = &zero;
}
/* Putting constant symbols in absolute_section rather than
expr_section is convenient for the old a.out code, for which
S_GET_SEGMENT does not always retrieve the value put in by
S_SET_SEGMENT. */
symbolP = symbol_create (FAKE_LABEL_NAME,
(expressionP->X_op == O_constant
? absolute_section
: expressionP->X_op == O_register
? reg_section
: expr_section),
&zero_address_frag, 0);
symbol_set_value_expression (symbolP, expressionP);
if (expressionP->X_op == O_constant)
resolve_symbol_value (symbolP);
n = notes_alloc (sizeof (*n));
n->sym = symbolP;
n->file = as_where (&n->line);
n->next = expr_symbol_lines;
expr_symbol_lines = n;
return symbolP;
}
/* Return the file and line number for an expr symbol. Return
non-zero if something was found, 0 if no information is known for
the symbol. */
int
expr_symbol_where (symbolS *sym, const char **pfile, unsigned int *pline)
{
struct expr_symbol_line *l;
for (l = expr_symbol_lines; l != NULL; l = l->next)
{
if (l->sym == sym)
{
*pfile = l->file;
*pline = l->line;
return 1;
}
}
return 0;
}
/* Look up a previously used .startof. / .sizeof. symbol, or make a fresh
one. */
static symbolS **seen[2];
static unsigned int nr_seen[2];
static symbolS *
symbol_lookup_or_make (const char *name, bool start)
{
char *buf = concat (start ? ".startof." : ".sizeof.", name, NULL);
symbolS *symbolP;
unsigned int i;
for (i = 0; i < nr_seen[start]; ++i)
{
symbolP = seen[start][i];
if (! symbolP)
break;
name = S_GET_NAME (symbolP);
if ((symbols_case_sensitive
? strcmp (buf, name)
: strcasecmp (buf, name)) == 0)
{
free (buf);
return symbolP;
}
}
symbolP = symbol_make (buf);
free (buf);
if (i >= nr_seen[start])
{
unsigned int nr = (i + 1) * 2;
seen[start] = XRESIZEVEC (symbolS *, seen[start], nr);
nr_seen[start] = nr;
memset (&seen[start][i + 1], 0, (nr - i - 1) * sizeof(seen[0][0]));
}
seen[start][i] = symbolP;
return symbolP;
}
/* Utilities for building expressions.
Since complex expressions are recorded as symbols for use in other
expressions these return a symbolS * and not an expressionS *.
These explicitly do not take an "add_number" argument. */
/* ??? For completeness' sake one might want expr_build_symbol.
It would just return its argument. */
/* Build an expression for an unsigned constant.
The corresponding one for signed constants is missing because
there's currently no need for it. One could add an unsigned_p flag
but that seems more clumsy. */
symbolS *
expr_build_uconstant (offsetT value)
{
expressionS e;
e.X_op = O_constant;
e.X_add_number = value;
e.X_unsigned = 1;
e.X_extrabit = 0;
return make_expr_symbol (&e);
}
/* Build any floating-point literal here.
Also build any bignum literal here. */
/* Seems atof_machine can backscan through generic_bignum and hit whatever
happens to be loaded before it in memory. And its way too complicated
for me to fix right. Thus a hack. JF: Just make generic_bignum bigger,
and never write into the early words, thus they'll always be zero.
I hate Dean's floating-point code. Bleh. */
LITTLENUM_TYPE generic_bignum[SIZE_OF_LARGE_NUMBER + 6];
FLONUM_TYPE generic_floating_point_number = {
&generic_bignum[6], /* low. (JF: Was 0) */
&generic_bignum[SIZE_OF_LARGE_NUMBER + 6 - 1], /* high. JF: (added +6) */
0, /* leader. */
0, /* exponent. */
0 /* sign. */
};
static void
floating_constant (expressionS *expressionP)
{
/* input_line_pointer -> floating-point constant. */
int error_code;
error_code = atof_generic (&input_line_pointer, ".", EXP_CHARS,
&generic_floating_point_number);
if (error_code)
{
if (error_code == ERROR_EXPONENT_OVERFLOW)
{
as_bad (_("bad floating-point constant: exponent overflow"));
}
else
{
as_bad (_("bad floating-point constant: unknown error code=%d"),
error_code);
}
}
expressionP->X_op = O_big;
/* input_line_pointer -> just after constant, which may point to
whitespace. */
expressionP->X_add_number = -1;
}
uint32_t
generic_bignum_to_int32 (void)
{
return ((((uint32_t) generic_bignum[1] & LITTLENUM_MASK)
<< LITTLENUM_NUMBER_OF_BITS)
| ((uint32_t) generic_bignum[0] & LITTLENUM_MASK));
}
uint64_t
generic_bignum_to_int64 (void)
{
return ((((((((uint64_t) generic_bignum[3] & LITTLENUM_MASK)
<< LITTLENUM_NUMBER_OF_BITS)
| ((uint64_t) generic_bignum[2] & LITTLENUM_MASK))
<< LITTLENUM_NUMBER_OF_BITS)
| ((uint64_t) generic_bignum[1] & LITTLENUM_MASK))
<< LITTLENUM_NUMBER_OF_BITS)
| ((uint64_t) generic_bignum[0] & LITTLENUM_MASK));
}
static void
integer_constant (int radix, expressionS *expressionP)
{
char *start; /* Start of number. */
char *suffix = NULL;
char c;
valueT number; /* Offset or (absolute) value. */
short int digit; /* Value of next digit in current radix. */
int too_many_digits = 0; /* If we see >= this number of. */
char *name; /* Points to name of symbol. */
symbolS *symbolP; /* Points to symbol. */
bool small; /* True if fits in 32 bits (64 bits with BFD64). */
/* May be bignum, or may fit in 32 bits. */
/* Most numbers fit into 32 bits, and we want this case to be fast.
so we pretend it will fit into 32 bits. If, after making up a 32
bit number, we realise that we have scanned more digits than
comfortably fit into 32 bits, we re-scan the digits coding them
into a bignum. For decimal and octal numbers we are
conservative: Some numbers may be assumed bignums when in fact
they do fit into 32 bits. Numbers of any radix can have excess
leading zeros: We strive to recognise this and cast them back
into 32 bits. We must check that the bignum really is more than
32 bits, and change it back to a 32-bit number if it fits. The
number we are looking for is expected to be positive, but if it
fits into 32 bits as an unsigned number, we let it be a 32-bit
number. The cavalier approach is for speed in ordinary cases. */
/* This has been extended for 64 bits. We blindly assume that if
you're compiling in 64-bit mode, the target is a 64-bit machine.
This should be cleaned up. */
#ifdef BFD64
#define valuesize 64
#else /* includes non-bfd case, mostly */
#define valuesize 32
#endif
if (is_end_of_stmt (*input_line_pointer))
{
expressionP->X_op = O_absent;
return;
}
if ((NUMBERS_WITH_SUFFIX || flag_m68k_mri) && radix == 0)
{
int flt = 0;
/* In MRI mode, the number may have a suffix indicating the
radix. For that matter, it might actually be a floating
point constant. */
for (suffix = input_line_pointer; ISALNUM (*suffix); suffix++)
{
if (*suffix == 'e' || *suffix == 'E')
flt = 1;
}
if (suffix == input_line_pointer)
{
radix = 10;
suffix = NULL;
}
else
{
c = *--suffix;
c = TOUPPER (c);
/* If we have both NUMBERS_WITH_SUFFIX and LOCAL_LABELS_FB,
we distinguish between 'B' and 'b'. This is the case for
Z80. */
if ((NUMBERS_WITH_SUFFIX && LOCAL_LABELS_FB ? *suffix : c) == 'B')
radix = 2;
else if (c == 'D')
radix = 10;
else if (c == 'O' || c == 'Q')
radix = 8;
else if (c == 'H')
radix = 16;
else if (suffix[1] == '.' || c == 'E' || flt)
{
floating_constant (expressionP);
return;
}
else
{
radix = 10;
suffix = NULL;
}
}
}
switch (radix)
{
case 2:
too_many_digits = valuesize + 1;
break;
case 8:
too_many_digits = (valuesize + 2) / 3 + 1;
break;
case 16:
too_many_digits = (valuesize + 3) / 4 + 1;
break;
case 10:
too_many_digits = (valuesize + 11) / 4; /* Very rough. */
break;
}
#undef valuesize
start = input_line_pointer;
c = *input_line_pointer++;
for (number = 0;
(digit = hex_value (c)) < radix;
c = *input_line_pointer++)
{
number = number * radix + digit;
}
/* c contains character after number. */
/* input_line_pointer->char after c. */
small = (input_line_pointer - start - 1) < too_many_digits;
if (radix == 16 && c == '_')
{
/* This is literal of the form 0x333_0_12345678_1.
This example is equivalent to 0x00000333000000001234567800000001. */
int num_little_digits = 0;
int i;
input_line_pointer = start; /* -> 1st digit. */
know (LITTLENUM_NUMBER_OF_BITS == 16);
for (c = '_'; c == '_'; num_little_digits += 2)
{
/* Convert one 64-bit word. */
int ndigit = 0;
number = 0;
for (c = *input_line_pointer++;
(digit = hex_value (c)) < radix;
c = *(input_line_pointer++))
{
number = number * radix + digit;
ndigit++;
}
/* Check for 8 digit per word max. */
if (ndigit > 8)
as_bad (_("a bignum with underscores may not have more than 8 hex digits in any word"));
/* Add this chunk to the bignum.
Shift things down 2 little digits. */
know (LITTLENUM_NUMBER_OF_BITS == 16);
for (i = min (num_little_digits + 1, SIZE_OF_LARGE_NUMBER - 1);
i >= 2;
i--)
generic_bignum[i] = generic_bignum[i - 2];
/* Add the new digits as the least significant new ones. */
generic_bignum[0] = number & 0xffffffff;
generic_bignum[1] = number >> 16;
}
/* Again, c is char after number, input_line_pointer->after c. */
if (num_little_digits > SIZE_OF_LARGE_NUMBER - 1)
num_little_digits = SIZE_OF_LARGE_NUMBER - 1;
gas_assert (num_little_digits >= 4);
if (num_little_digits != 8)
as_bad (_("a bignum with underscores must have exactly 4 words"));
/* We might have some leading zeros. These can be trimmed to give
us a change to fit this constant into a small number. */
while (generic_bignum[num_little_digits - 1] == 0
&& num_little_digits > 1)
num_little_digits--;
if (num_little_digits <= 2)
{
/* will fit into 32 bits. */
number = generic_bignum_to_int32 ();
small = 1;
}
#ifdef BFD64
else if (num_little_digits <= 4)
{
/* Will fit into 64 bits. */
number = generic_bignum_to_int64 ();
small = 1;
}
#endif
else
{
small = 0;
/* Number of littlenums in the bignum. */
number = num_little_digits;
}
}
else if (!small)
{
/* We saw a lot of digits. manufacture a bignum the hard way. */
LITTLENUM_TYPE *leader; /* -> high order littlenum of the bignum. */
LITTLENUM_TYPE *pointer; /* -> littlenum we are frobbing now. */
long carry;
leader = generic_bignum;
generic_bignum[0] = 0;
generic_bignum[1] = 0;
generic_bignum[2] = 0;
generic_bignum[3] = 0;
input_line_pointer = start; /* -> 1st digit. */
c = *input_line_pointer++;
for (; (carry = hex_value (c)) < radix; c = *input_line_pointer++)
{
for (pointer = generic_bignum; pointer <= leader; pointer++)
{
long work;
work = carry + radix * *pointer;
*pointer = work & LITTLENUM_MASK;
carry = work >> LITTLENUM_NUMBER_OF_BITS;
}
if (carry)
{
if (leader < generic_bignum + SIZE_OF_LARGE_NUMBER - 1)
{
/* Room to grow a longer bignum. */
*++leader = carry;
}
}
}
/* Again, c is char after number. */
/* input_line_pointer -> after c. */
know (LITTLENUM_NUMBER_OF_BITS == 16);
if (leader < generic_bignum + 2)
{
/* Will fit into 32 bits. */
number = generic_bignum_to_int32 ();
small = 1;
}
#ifdef BFD64
else if (leader < generic_bignum + 4)
{
/* Will fit into 64 bits. */
number = generic_bignum_to_int64 ();
small = 1;
}
#endif
else
{
/* Number of littlenums in the bignum. */
number = leader - generic_bignum + 1;
}
}
if ((NUMBERS_WITH_SUFFIX || flag_m68k_mri)
&& suffix != NULL
&& input_line_pointer - 1 == suffix)
c = *input_line_pointer++;
#ifndef tc_allow_U_suffix
#define tc_allow_U_suffix 1
#endif
bool u_seen = !tc_allow_U_suffix;
/* PR 19910: Look for, and ignore, a U suffix to the number. */
if (!u_seen && (c == 'U' || c == 'u'))
{
c = *input_line_pointer++;
u_seen = true;
}
#ifndef tc_allow_L_suffix
#define tc_allow_L_suffix 1
#endif
bool l_seen = !tc_allow_L_suffix;
/* PR 20732: Look for, and ignore, a L or LL suffix to the number. */
if (tc_allow_L_suffix && (c == 'L' || c == 'l'))
{
c = * input_line_pointer++;
l_seen = true;
if (c == 'L' || c == 'l')
c = *input_line_pointer++;
if (!u_seen && (c == 'U' || c == 'u'))
c = *input_line_pointer++;
}
if (small)
{
/* Here with number, in correct radix. c is the next char. */
bool maybe_label = suffix == NULL
&& (!tc_allow_U_suffix || !u_seen)
&& (!tc_allow_L_suffix || !l_seen)
&& (radix == 10 ||
(radix == 8 && input_line_pointer == start + 1));
if (LOCAL_LABELS_FB && c == 'b' && maybe_label)
{
/* Backward ref to local label.
Because it is backward, expect it to be defined. */
/* Construct a local label. */
name = fb_label_name (number, 0);
/* Seen before, or symbol is defined: OK. */
symbolP = symbol_find (name);
if ((symbolP != NULL) && (S_IS_DEFINED (symbolP)))
{
expressionP->X_op = O_symbol;
expressionP->X_add_symbol = symbolP;
}
else
{
/* Either not seen or not defined. */
/* @@ Should print out the original string instead of
the parsed number. */
as_bad (_("backward ref to unknown label \"%d:\""),
(int) number);
expressionP->X_op = O_constant;
}
expressionP->X_add_number = 0;
} /* case 'b' */
else if (LOCAL_LABELS_FB && c == 'f' && maybe_label)
{
/* Forward reference. Expect symbol to be undefined or
unknown. undefined: seen it before. unknown: never seen
it before.
Construct a local label name, then an undefined symbol.
Don't create a xseg frag for it: caller may do that.
Just return it as never seen before. */
name = fb_label_name (number, 1);
symbolP = symbol_find_or_make (name);
/* We have no need to check symbol properties. */
expressionP->X_op = O_symbol;
expressionP->X_add_symbol = symbolP;
expressionP->X_add_number = 0;
} /* case 'f' */
else if (LOCAL_LABELS_DOLLAR && c == '$' && maybe_label)
{
/* If the dollar label is *currently* defined, then this is just
another reference to it. If it is not *currently* defined,
then this is a fresh instantiation of that number, so create
it. */
if (dollar_label_defined (number))
{
name = dollar_label_name (number, 0);
symbolP = symbol_find (name);
know (symbolP != NULL);
}
else
{
name = dollar_label_name (number, 1);
symbolP = symbol_find_or_make (name);
}
expressionP->X_op = O_symbol;
expressionP->X_add_symbol = symbolP;
expressionP->X_add_number = 0;
} /* case '$' */
else
{
expressionP->X_op = O_constant;
expressionP->X_add_number = number;
input_line_pointer--; /* Restore following character. */
} /* Really just a number. */
}
else
{
/* Not a small number. */
expressionP->X_op = O_big;
expressionP->X_add_number = number; /* Number of littlenums. */
input_line_pointer--; /* -> char following number. */
}
}
/* Parse an MRI multi character constant. */
static void
mri_char_constant (expressionS *expressionP)
{
int i;
if (*input_line_pointer == '\''
&& input_line_pointer[1] != '\'')
{
expressionP->X_op = O_constant;
expressionP->X_add_number = 0;
return;
}
/* In order to get the correct byte ordering, we must build the
number in reverse. */
for (i = SIZE_OF_LARGE_NUMBER - 1; i >= 0; i--)
{
int j;
generic_bignum[i] = 0;
for (j = 0; j < CHARS_PER_LITTLENUM; j++)
{
if (*input_line_pointer == '\'')
{
if (input_line_pointer[1] != '\'')
break;
++input_line_pointer;
}
generic_bignum[i] <<= 8;
generic_bignum[i] += *input_line_pointer;
++input_line_pointer;
}
if (i < SIZE_OF_LARGE_NUMBER - 1)
{
/* If there is more than one littlenum, left justify the
last one to make it match the earlier ones. If there is
only one, we can just use the value directly. */
for (; j < CHARS_PER_LITTLENUM; j++)
generic_bignum[i] <<= 8;
}
if (*input_line_pointer == '\''
&& input_line_pointer[1] != '\'')
break;
}
if (i < 0)
{
as_bad (_("character constant too large"));
i = 0;
}
if (i > 0)
{
int c;
int j;
c = SIZE_OF_LARGE_NUMBER - i;
for (j = 0; j < c; j++)
generic_bignum[j] = generic_bignum[i + j];
i = c;
}
know (LITTLENUM_NUMBER_OF_BITS == 16);
if (i > 2)
{
expressionP->X_op = O_big;
expressionP->X_add_number = i;
}
else
{
expressionP->X_op = O_constant;
if (i < 2)
expressionP->X_add_number = generic_bignum[0] & LITTLENUM_MASK;
else
expressionP->X_add_number =
(((generic_bignum[1] & LITTLENUM_MASK)
<< LITTLENUM_NUMBER_OF_BITS)
| (generic_bignum[0] & LITTLENUM_MASK));
}
/* Skip the final closing quote. */
++input_line_pointer;
}
/* Return an expression representing the current location. This
handles the magic symbol `.'. */
void
current_location (expressionS *expressionp, enum expr_mode mode)
{
if (now_seg == absolute_section)
{
expressionp->X_op = O_constant;
expressionp->X_add_number = abs_section_offset;
}
else
{
expressionp->X_op = O_symbol;
if (mode != expr_defer_incl_dot)
{
expressionp->X_add_symbol = symbol_temp_new_now ();
#ifdef tc_new_dot_label
tc_new_dot_label (expressionp->X_add_symbol);
#endif
}
else
expressionp->X_add_symbol = &dot_symbol;
expressionp->X_add_number = 0;
}
}
/* Make a symbol for the current location ('.'). */
symbolS *
expr_build_dot (void)
{
if (now_seg != absolute_section)
{
symbolS *symbolP = symbol_temp_new_now ();
#ifdef tc_new_dot_label
tc_new_dot_label (symbolP);
#endif
return symbolP;
}
return expr_build_uconstant (abs_section_offset);
}
/* Copy an expression, preserving X_md. */
static void expr_copy (expressionS *dst, const expressionS *src)
{
unsigned short md = dst->X_md;
*dst = *src;
dst->X_md = md;
}
#ifndef md_register_arithmetic
# define md_register_arithmetic 1
#endif
/* In: Input_line_pointer points to 1st char of operand, which may
be a space.
Out: An expressionS.
The operand may have been empty: in this case X_op == O_absent.
Input_line_pointer->(next non-blank) char after operand. */
static segT
operand (expressionS *expressionP, enum expr_mode mode)
{
char c;
symbolS *symbolP; /* Points to symbol. */
char *name; /* Points to name of symbol. */
segT segment;
operatorT op = O_absent; /* For unary operators. */
/* All integers are regarded as unsigned unless they are negated.
This is because the only thing which cares whether a number is
unsigned is the code in emit_expr which extends constants into
bignums. It should only sign extend negative numbers, so that
something like ``.quad 0x80000000'' is not sign extended even
though it appears negative if valueT is 32 bits. */
expressionP->X_unsigned = 1;
expressionP->X_extrabit = 0;
/* Digits, assume it is a bignum. */
SKIP_WHITESPACE (); /* Leading whitespace is part of operand. */
c = *input_line_pointer++; /* input_line_pointer -> past char in c. */
if (is_end_of_stmt (c))
goto eol;
switch (c)
{
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
input_line_pointer--;
integer_constant ((NUMBERS_WITH_SUFFIX || flag_m68k_mri)
? 0 : 10,
expressionP);
break;
#ifdef LITERAL_PREFIXPERCENT_BIN
case '%':
integer_constant (2, expressionP);
break;
#endif
case '0':
/* Non-decimal radix. */
if (NUMBERS_WITH_SUFFIX || flag_m68k_mri)
{
char *s;
/* Check for a hex or float constant. */
for (s = input_line_pointer; hex_p (*s); s++)
;
if (*s == 'h' || *s == 'H' || *input_line_pointer == '.')
{
--input_line_pointer;
integer_constant (0, expressionP);
break;
}
}
c = *input_line_pointer;
switch (c)
{
case 'o':
case 'O':
case 'q':
case 'Q':
case '8':
case '9':
if (NUMBERS_WITH_SUFFIX || flag_m68k_mri)
{
integer_constant (0, expressionP);
break;
}
/* Fall through. */
default:
default_case:
if (c && strchr (FLT_CHARS, c))
{
input_line_pointer++;
floating_constant (expressionP);
expressionP->X_add_number = - TOLOWER (c);
}
else
{
/* The string was only zero. */
expressionP->X_op = O_constant;
expressionP->X_add_number = 0;
}
break;
case 'x':
case 'X':
if (flag_m68k_mri)
goto default_case;
input_line_pointer++;
integer_constant (16, expressionP);
break;
case 'b':
if (LOCAL_LABELS_FB && !flag_m68k_mri
&& input_line_pointer[1] != '0'
&& input_line_pointer[1] != '1')
{
/* Parse this as a back reference to label 0. */
input_line_pointer--;
integer_constant (10, expressionP);
break;
}
/* Otherwise, parse this as a binary number. */
/* Fall through. */
case 'B':
if (input_line_pointer[1] == '0'
|| input_line_pointer[1] == '1')
{
input_line_pointer++;
integer_constant (2, expressionP);
break;
}
if (flag_m68k_mri || NUMBERS_WITH_SUFFIX)
input_line_pointer++;
goto default_case;
case 'l':
case 'L':
/* Accept an L suffix to the zero. */
if (tc_allow_L_suffix)
goto numeric;
goto default_case;
case 'u':
case 'U':
/* Accept a U suffix to the zero. */
if (!tc_allow_U_suffix)
goto default_case;
/* Fall through. */
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
numeric:
integer_constant ((flag_m68k_mri || NUMBERS_WITH_SUFFIX)
? 0 : 8,
expressionP);
break;
case 'f':
if (LOCAL_LABELS_FB)
{
int is_label = 1;
/* If it says "0f" and it could possibly be a floating point
number, make it one. Otherwise, make it a local label,
and try to deal with parsing the rest later. */
if (!is_end_of_stmt (input_line_pointer[1])
&& strchr (FLT_CHARS, 'f') != NULL)
{
char *cp = input_line_pointer + 1;
atof_generic (&cp, ".", EXP_CHARS,
&generic_floating_point_number);
/* Was nothing parsed, or does it look like an
expression? */
is_label = (cp == input_line_pointer + 1
|| (cp == input_line_pointer + 2
&& (cp[-1] == '-' || cp[-1] == '+'))
|| *cp == 'f'
|| *cp == 'b');
}
if (is_label)
{
input_line_pointer--;
integer_constant (10, expressionP);
break;
}
}
/* Fall through. */
case 'd':
case 'D':
if (flag_m68k_mri || NUMBERS_WITH_SUFFIX)
{
integer_constant (0, expressionP);
break;
}
/* Fall through. */
case 'F':
case 'r':
case 'e':
case 'E':
case 'g':
case 'G':
input_line_pointer++;
floating_constant (expressionP);
expressionP->X_add_number = - TOLOWER (c);