forked from seank/FreeScale-s12x-binutils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread.c
5369 lines (4589 loc) · 126 KB
/
read.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
/* read.c - read a source file -
Copyright 1986, 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
1998, 1999, 2000, 2001, 2002, 2003 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 2, 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, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
#if 0
/* If your chars aren't 8 bits, you will change this a bit.
But then, GNU isn't spozed to run on your machine anyway.
(RMS is so shortsighted sometimes.) */
#define MASK_CHAR (0xFF)
#else
#define MASK_CHAR ((int)(unsigned char) -1)
#endif
/* This is the largest known floating point format (for now). It will
grow when we do 4361 style flonums. */
#define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
/* Routines that read assembler source text to build spagetti in memory.
Another group of these functions is in the expr.c module. */
#include "as.h"
#include "safe-ctype.h"
#include "subsegs.h"
#include "sb.h"
#include "macro.h"
#include "obstack.h"
#include "listing.h"
#include "ecoff.h"
#include "dw2gencfi.h"
#ifndef TC_START_LABEL
#define TC_START_LABEL(x,y) (x == ':')
#endif
/* Set by the object-format or the target. */
#ifndef TC_IMPLICIT_LCOMM_ALIGNMENT
#define TC_IMPLICIT_LCOMM_ALIGNMENT(SIZE, P2VAR) \
do \
{ \
if ((SIZE) >= 8) \
(P2VAR) = 3; \
else if ((SIZE) >= 4) \
(P2VAR) = 2; \
else if ((SIZE) >= 2) \
(P2VAR) = 1; \
else \
(P2VAR) = 0; \
} \
while (0)
#endif
char *input_line_pointer; /*->next char of source file to parse. */
#if BITS_PER_CHAR != 8
/* The following table is indexed by[(char)] and will break if
a char does not have exactly 256 states (hopefully 0:255!)! */
die horribly;
#endif
#ifndef LEX_AT
/* The m88k unfortunately uses @ as a label beginner. */
#define LEX_AT 0
#endif
#ifndef LEX_BR
/* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
#define LEX_BR 0
#endif
#ifndef LEX_PCT
/* The Delta 68k assembler permits % inside label names. */
#define LEX_PCT 0
#endif
#ifndef LEX_QM
/* The PowerPC Windows NT assemblers permits ? inside label names. */
#define LEX_QM 0
#endif
#ifndef LEX_HASH
/* The IA-64 assembler uses # as a suffix designating a symbol. We include
it in the symbol and strip it out in tc_canonicalize_symbol_name. */
#define LEX_HASH 0
#endif
#ifndef LEX_DOLLAR
/* The a29k assembler does not permits labels to start with $. */
#define LEX_DOLLAR 3
#endif
#ifndef LEX_TILDE
/* The Delta 68k assembler permits ~ at start of label names. */
#define LEX_TILDE 0
#endif
/* Used by is_... macros. our ctype[]. */
char lex_type[256] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
0, 0, 0, LEX_HASH, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM, /* 0123456789:;<=>? */
LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~. */
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
};
/* In: a character.
Out: 1 if this character ends a line. */
char is_end_of_line[256] = {
#ifdef CR_EOL
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, /* @abcdefghijklmno */
#else
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* @abcdefghijklmno */
#endif
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* _!"#$%&'()*+,-./ */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* */
};
#ifdef IGNORE_OPCODE_CASE
char original_case_string[128];
#endif
/* Functions private to this file. */
static char *buffer; /* 1st char of each buffer of lines is here. */
static char *buffer_limit; /*->1 + last char in buffer. */
/* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1
in the tc-<CPU>.h file. See the "Porting GAS" section of the
internals manual. */
int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
/* Variables for handling include file directory table. */
/* Table of pointers to directories to search for .include's. */
char **include_dirs;
/* How many are in the table. */
int include_dir_count;
/* Length of longest in table. */
int include_dir_maxlen = 1;
#ifndef WORKING_DOT_WORD
struct broken_word *broken_words;
int new_broken_words;
#endif
/* The current offset into the absolute section. We don't try to
build frags in the absolute section, since no data can be stored
there. We just keep track of the current offset. */
addressT abs_section_offset;
/* If this line had an MRI style label, it is stored in this variable.
This is used by some of the MRI pseudo-ops. */
symbolS *line_label;
/* This global variable is used to support MRI common sections. We
translate such sections into a common symbol. This variable is
non-NULL when we are in an MRI common section. */
symbolS *mri_common_symbol;
/* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
need to align to an even byte boundary unless the next pseudo-op is
dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
may be needed. */
static int mri_pending_align;
#ifndef NO_LISTING
#ifdef OBJ_ELF
/* This variable is set to be non-zero if the next string we see might
be the name of the source file in DWARF debugging information. See
the comment in emit_expr for the format we look for. */
static int dwarf_file_string;
#endif
#endif
static void cons_worker PARAMS ((int, int));
static int scrub_from_string PARAMS ((char *, int));
static void do_align PARAMS ((int, char *, int, int));
static void s_align PARAMS ((int, int));
static void s_lcomm_internal PARAMS ((int, int));
static int hex_float PARAMS ((int, char *));
static inline int sizeof_sleb128 PARAMS ((offsetT));
static inline int sizeof_uleb128 PARAMS ((valueT));
static inline int output_sleb128 PARAMS ((char *, offsetT));
static inline int output_uleb128 PARAMS ((char *, valueT));
static inline int output_big_sleb128 PARAMS ((char *, LITTLENUM_TYPE *, int));
static inline int output_big_uleb128 PARAMS ((char *, LITTLENUM_TYPE *, int));
static int output_big_leb128 PARAMS ((char *, LITTLENUM_TYPE *, int, int));
static void do_org PARAMS ((segT, expressionS *, int));
char *demand_copy_string PARAMS ((int *lenP));
static segT get_segmented_expression PARAMS ((expressionS *expP));
static segT get_known_segmented_expression PARAMS ((expressionS * expP));
static void pobegin PARAMS ((void));
static int get_line_sb PARAMS ((sb *));
static void generate_file_debug PARAMS ((void));
void
read_begin ()
{
const char *p;
pobegin ();
obj_read_begin_hook ();
/* Something close -- but not too close -- to a multiple of 1024.
The debugging malloc I'm using has 24 bytes of overhead. */
obstack_begin (¬es, chunksize);
obstack_begin (&cond_obstack, chunksize);
/* Use machine dependent syntax. */
for (p = line_separator_chars; *p; p++)
is_end_of_line[(unsigned char) *p] = 1;
/* Use more. FIXME-SOMEDAY. */
if (flag_mri)
lex_type['?'] = 3;
}
/* Set up pseudo-op tables. */
static struct hash_control *po_hash;
static const pseudo_typeS potable[] = {
{"abort", s_abort, 0},
{"align", s_align_ptwo, 0},
{"ascii", stringer, 0},
{"asciz", stringer, 1},
{"balign", s_align_bytes, 0},
{"balignw", s_align_bytes, -2},
{"balignl", s_align_bytes, -4},
/* block */
{"byte", cons, 1},
{"comm", s_comm, 0},
{"common", s_mri_common, 0},
{"common.s", s_mri_common, 1},
{"data", s_data, 0},
{"dc", cons, 2},
{"dc.b", cons, 1},
{"dc.d", float_cons, 'd'},
{"dc.l", cons, 4},
{"dc.s", float_cons, 'f'},
{"dc.w", cons, 2},
{"dc.x", float_cons, 'x'},
{"dcb", s_space, 2},
{"dcb.b", s_space, 1},
{"dcb.d", s_float_space, 'd'},
{"dcb.l", s_space, 4},
{"dcb.s", s_float_space, 'f'},
{"dcb.w", s_space, 2},
{"dcb.x", s_float_space, 'x'},
{"ds", s_space, 2},
{"ds.b", s_space, 1},
{"ds.d", s_space, 8},
{"ds.l", s_space, 4},
{"ds.p", s_space, 12},
{"ds.s", s_space, 4},
{"ds.w", s_space, 2},
{"ds.x", s_space, 12},
{"debug", s_ignore, 0},
#ifdef S_SET_DESC
{"desc", s_desc, 0},
#endif
/* dim */
{"double", float_cons, 'd'},
/* dsect */
{"eject", listing_eject, 0}, /* Formfeed listing. */
{"else", s_else, 0},
{"elsec", s_else, 0},
{"elseif", s_elseif, (int) O_ne},
{"end", s_end, 0},
{"endc", s_endif, 0},
{"endfunc", s_func, 1},
{"endif", s_endif, 0},
{"endr", s_bad_endr, 0},
/* endef */
{"equ", s_set, 0},
{"equiv", s_set, 1},
{"err", s_err, 0},
{"exitm", s_mexit, 0},
/* extend */
{"extern", s_ignore, 0}, /* We treat all undef as ext. */
{"appfile", s_app_file, 1},
{"appline", s_app_line, 0},
{"fail", s_fail, 0},
{"file", s_app_file, 0},
{"fill", s_fill, 0},
{"float", float_cons, 'f'},
{"format", s_ignore, 0},
{"func", s_func, 0},
{"global", s_globl, 0},
{"globl", s_globl, 0},
{"hword", cons, 2},
{"if", s_if, (int) O_ne},
{"ifc", s_ifc, 0},
{"ifdef", s_ifdef, 0},
{"ifeq", s_if, (int) O_eq},
{"ifeqs", s_ifeqs, 0},
{"ifge", s_if, (int) O_ge},
{"ifgt", s_if, (int) O_gt},
{"ifle", s_if, (int) O_le},
{"iflt", s_if, (int) O_lt},
{"ifnc", s_ifc, 1},
{"ifndef", s_ifdef, 1},
{"ifne", s_if, (int) O_ne},
{"ifnes", s_ifeqs, 1},
{"ifnotdef", s_ifdef, 1},
{"incbin", s_incbin, 0},
{"include", s_include, 0},
{"int", cons, 4},
{"irp", s_irp, 0},
{"irep", s_irp, 0},
{"irpc", s_irp, 1},
{"irepc", s_irp, 1},
{"lcomm", s_lcomm, 0},
{"lflags", listing_flags, 0}, /* Listing flags. */
{"linkonce", s_linkonce, 0},
{"list", listing_list, 1}, /* Turn listing on. */
{"llen", listing_psize, 1},
{"long", cons, 4},
{"lsym", s_lsym, 0},
{"macro", s_macro, 0},
{"mexit", s_mexit, 0},
{"mri", s_mri, 0},
{".mri", s_mri, 0}, /* Special case so .mri works in MRI mode. */
{"name", s_ignore, 0},
{"noformat", s_ignore, 0},
{"nolist", listing_list, 0}, /* Turn listing off. */
{"nopage", listing_nopage, 0},
{"octa", cons, 16},
{"offset", s_struct, 0},
{"org", s_org, 0},
{"p2align", s_align_ptwo, 0},
{"p2alignw", s_align_ptwo, -2},
{"p2alignl", s_align_ptwo, -4},
{"page", listing_eject, 0},
{"plen", listing_psize, 0},
{"print", s_print, 0},
{"psize", listing_psize, 0}, /* Set paper size. */
{"purgem", s_purgem, 0},
{"quad", cons, 8},
{"rep", s_rept, 0},
{"rept", s_rept, 0},
{"rva", s_rva, 4},
{"sbttl", listing_title, 1}, /* Subtitle of listing. */
/* scl */
/* sect */
{"set", s_set, 0},
{"short", cons, 2},
{"single", float_cons, 'f'},
/* size */
{"space", s_space, 0},
{"skip", s_space, 0},
{"sleb128", s_leb128, 1},
{"spc", s_ignore, 0},
{"stabd", s_stab, 'd'},
{"stabn", s_stab, 'n'},
{"stabs", s_stab, 's'},
{"string", stringer, 1},
{"struct", s_struct, 0},
/* tag */
{"text", s_text, 0},
/* This is for gcc to use. It's only just been added (2/94), so gcc
won't be able to use it for a while -- probably a year or more.
But once this has been released, check with gcc maintainers
before deleting it or even changing the spelling. */
{"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
/* If we're folding case -- done for some targets, not necessarily
all -- the above string in an input file will be converted to
this one. Match it either way... */
{"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
{"title", listing_title, 0}, /* Listing title. */
{"ttl", listing_title, 0},
/* type */
{"uleb128", s_leb128, 0},
/* use */
/* val */
{"xcom", s_comm, 0},
{"xdef", s_globl, 0},
{"xref", s_ignore, 0},
{"xstabs", s_xstab, 's'},
{"word", cons, 2},
{"zero", s_space, 0},
{NULL, NULL, 0} /* End sentinel. */
};
static int pop_override_ok = 0;
static const char *pop_table_name;
void
pop_insert (table)
const pseudo_typeS *table;
{
const char *errtxt;
const pseudo_typeS *pop;
for (pop = table; pop->poc_name; pop++)
{
errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name,
errtxt);
}
}
#ifndef md_pop_insert
#define md_pop_insert() pop_insert(md_pseudo_table)
#endif
#ifndef obj_pop_insert
#define obj_pop_insert() pop_insert(obj_pseudo_table)
#endif
#ifndef cfi_pop_insert
#define cfi_pop_insert() pop_insert(cfi_pseudo_table)
#endif
static void
pobegin ()
{
po_hash = hash_new ();
/* Do the target-specific pseudo ops. */
pop_table_name = "md";
md_pop_insert ();
/* Now object specific. Skip any that were in the target table. */
pop_table_name = "obj";
pop_override_ok = 1;
obj_pop_insert ();
/* Now portable ones. Skip any that we've seen already. */
pop_table_name = "standard";
pop_insert (potable);
#ifdef TARGET_USE_CFIPOP
pop_table_name = "cfi";
pop_override_ok = 1;
cfi_pop_insert ();
#endif
}
#define HANDLE_CONDITIONAL_ASSEMBLY() \
if (ignore_input ()) \
{ \
while (!is_end_of_line[(unsigned char) *input_line_pointer++]) \
if (input_line_pointer == buffer_limit) \
break; \
continue; \
}
/* This function is used when scrubbing the characters between #APP
and #NO_APP. */
static char *scrub_string;
static char *scrub_string_end;
static int
scrub_from_string (buf, buflen)
char *buf;
int buflen;
{
int copy;
copy = scrub_string_end - scrub_string;
if (copy > buflen)
copy = buflen;
memcpy (buf, scrub_string, copy);
scrub_string += copy;
return copy;
}
/* We read the file, putting things into a web that represents what we
have been reading. */
void
read_a_source_file (name)
char *name;
{
register char c;
register char *s; /* String of symbol, '\0' appended. */
register int temp;
pseudo_typeS *pop;
#ifdef WARN_COMMENTS
found_comment = 0;
#endif
buffer = input_scrub_new_file (name);
listing_file (name);
listing_newline (NULL);
register_dependency (name);
/* Generate debugging information before we've read anything in to denote
this file as the "main" source file and not a subordinate one
(e.g. N_SO vs N_SOL in stabs). */
generate_file_debug ();
while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
{ /* We have another line to parse. */
know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
while (input_line_pointer < buffer_limit)
{
/* We have more of this buffer to parse. */
/* We now have input_line_pointer->1st char of next line.
If input_line_pointer [-1] == '\n' then we just
scanned another line: so bump line counters. */
if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
{
#ifdef md_start_line_hook
md_start_line_hook ();
#endif
if (input_line_pointer[-1] == '\n')
bump_line_counters ();
line_label = NULL;
if (LABELS_WITHOUT_COLONS || flag_m68k_mri)
{
/* Text at the start of a line must be a label, we
run down and stick a colon in. */
if (is_name_beginner (*input_line_pointer))
{
char *line_start = input_line_pointer;
char c;
int mri_line_macro;
LISTING_NEWLINE ();
HANDLE_CONDITIONAL_ASSEMBLY ();
c = get_symbol_end ();
/* In MRI mode, the EQU and MACRO pseudoops must
be handled specially. */
mri_line_macro = 0;
if (flag_m68k_mri)
{
char *rest = input_line_pointer + 1;
if (*rest == ':')
++rest;
if (*rest == ' ' || *rest == '\t')
++rest;
if ((strncasecmp (rest, "EQU", 3) == 0
|| strncasecmp (rest, "SET", 3) == 0)
&& (rest[3] == ' ' || rest[3] == '\t'))
{
input_line_pointer = rest + 3;
equals (line_start,
strncasecmp (rest, "SET", 3) == 0);
continue;
}
if (strncasecmp (rest, "MACRO", 5) == 0
&& (rest[5] == ' '
|| rest[5] == '\t'
|| is_end_of_line[(unsigned char) rest[5]]))
mri_line_macro = 1;
}
/* In MRI mode, we need to handle the MACRO
pseudo-op specially: we don't want to put the
symbol in the symbol table. */
if (!mri_line_macro
#ifdef TC_START_LABEL_WITHOUT_COLON
&& TC_START_LABEL_WITHOUT_COLON(c,
input_line_pointer)
#endif
)
line_label = colon (line_start);
else
line_label = symbol_create (line_start,
absolute_section,
(valueT) 0,
&zero_address_frag);
*input_line_pointer = c;
if (c == ':')
input_line_pointer++;
}
}
}
/* We are at the begining of a line, or similar place.
We expect a well-formed assembler statement.
A "symbol-name:" is a statement.
Depending on what compiler is used, the order of these tests
may vary to catch most common case 1st.
Each test is independent of all other tests at the (top) level.
PLEASE make a compiler that doesn't use this assembler.
It is crufty to waste a compiler's time encoding things for this
assembler, which then wastes more time decoding it.
(And communicating via (linear) files is silly!
If you must pass stuff, please pass a tree!) */
if ((c = *input_line_pointer++) == '\t'
|| c == ' '
|| c == '\f'
|| c == 0)
c = *input_line_pointer++;
know (c != ' '); /* No further leading whitespace. */
#ifndef NO_LISTING
/* If listing is on, and we are expanding a macro, then give
the listing code the contents of the expanded line. */
if (listing)
{
if ((listing & LISTING_MACEXP) && macro_nest > 0)
{
char *copy;
int len;
/* Find the end of the current expanded macro line. */
for (s = input_line_pointer - 1; *s; ++s)
if (is_end_of_line[(unsigned char) *s])
break;
/* Copy it for safe keeping. Also give an indication of
how much macro nesting is involved at this point. */
len = s - (input_line_pointer - 1);
copy = (char *) xmalloc (len + macro_nest + 2);
memset (copy, '>', macro_nest);
copy[macro_nest] = ' ';
memcpy (copy + macro_nest + 1, input_line_pointer - 1, len);
copy[macro_nest + 1 + len] = '\0';
/* Install the line with the listing facility. */
listing_newline (copy);
}
else
listing_newline (NULL);
}
#endif
/* C is the 1st significant character.
Input_line_pointer points after that character. */
if (is_name_beginner (c))
{
/* Want user-defined label or pseudo/opcode. */
HANDLE_CONDITIONAL_ASSEMBLY ();
s = --input_line_pointer;
c = get_symbol_end (); /* name's delimiter. */
/* C is character after symbol.
That character's place in the input line is now '\0'.
S points to the beginning of the symbol.
[In case of pseudo-op, s->'.'.]
Input_line_pointer->'\0' where c was. */
if (TC_START_LABEL (c, input_line_pointer))
{
if (flag_m68k_mri)
{
char *rest = input_line_pointer + 1;
/* In MRI mode, \tsym: set 0 is permitted. */
if (*rest == ':')
++rest;
if (*rest == ' ' || *rest == '\t')
++rest;
if ((strncasecmp (rest, "EQU", 3) == 0
|| strncasecmp (rest, "SET", 3) == 0)
&& (rest[3] == ' ' || rest[3] == '\t'))
{
input_line_pointer = rest + 3;
equals (s, 1);
continue;
}
}
line_label = colon (s); /* User-defined label. */
/* Put ':' back for error messages' sake. */
*input_line_pointer++ = ':';
#ifdef tc_check_label
tc_check_label (line_label);
#endif
/* Input_line_pointer->after ':'. */
SKIP_WHITESPACE ();
}
else if (c == '='
|| ((c == ' ' || c == '\t')
&& input_line_pointer[1] == '='
#ifdef TC_EQUAL_IN_INSN
&& !TC_EQUAL_IN_INSN (c, input_line_pointer)
#endif
))
{
equals (s, 1);
demand_empty_rest_of_line ();
}
else
{
/* Expect pseudo-op or machine instruction. */
pop = NULL;
#ifdef IGNORE_OPCODE_CASE
{
char *s2 = s;
strncpy (original_case_string, s2, sizeof (original_case_string));
original_case_string[sizeof (original_case_string) - 1] = 0;
while (*s2)
{
*s2 = TOLOWER (*s2);
s2++;
}
}
#endif
if (NO_PSEUDO_DOT || flag_m68k_mri)
{
/* The MRI assembler and the m88k use pseudo-ops
without a period. */
pop = (pseudo_typeS *) hash_find (po_hash, s);
if (pop != NULL && pop->poc_handler == NULL)
pop = NULL;
}
if (pop != NULL
|| (!flag_m68k_mri && *s == '.'))
{
/* PSEUDO - OP.
WARNING: c has next char, which may be end-of-line.
We lookup the pseudo-op table with s+1 because we
already know that the pseudo-op begins with a '.'. */
if (pop == NULL)
pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
/* In MRI mode, we may need to insert an
automatic alignment directive. What a hack
this is. */
if (mri_pending_align
&& (pop == NULL
|| !((pop->poc_handler == cons
&& pop->poc_val == 1)
|| (pop->poc_handler == s_space
&& pop->poc_val == 1)
#ifdef tc_conditional_pseudoop
|| tc_conditional_pseudoop (pop)
#endif
|| pop->poc_handler == s_if
|| pop->poc_handler == s_ifdef
|| pop->poc_handler == s_ifc
|| pop->poc_handler == s_ifeqs
|| pop->poc_handler == s_else
|| pop->poc_handler == s_endif
|| pop->poc_handler == s_globl
|| pop->poc_handler == s_ignore)))
{
do_align (1, (char *) NULL, 0, 0);
mri_pending_align = 0;
if (line_label != NULL)
{
symbol_set_frag (line_label, frag_now);
S_SET_VALUE (line_label, frag_now_fix ());
}
}
/* Print the error msg now, while we still can. */
if (pop == NULL)
{
as_bad (_("unknown pseudo-op: `%s'"), s);
*input_line_pointer = c;
s_ignore (0);
continue;
}
/* Put it back for error messages etc. */
*input_line_pointer = c;
/* The following skip of whitespace is compulsory.
A well shaped space is sometimes all that separates
keyword from operands. */
if (c == ' ' || c == '\t')
input_line_pointer++;
/* Input_line is restored.
Input_line_pointer->1st non-blank char
after pseudo-operation. */
(*pop->poc_handler) (pop->poc_val);
/* If that was .end, just get out now. */
if (pop->poc_handler == s_end)
goto quit;
}
else
{
int inquote = 0;
#ifdef QUOTES_IN_INSN
int inescape = 0;
#endif
/* WARNING: c has char, which may be end-of-line. */
/* Also: input_line_pointer->`\0` where c was. */
*input_line_pointer = c;
while (!is_end_of_line[(unsigned char) *input_line_pointer]
|| inquote
#ifdef TC_EOL_IN_INSN
|| TC_EOL_IN_INSN (input_line_pointer)
#endif
)
{
if (flag_m68k_mri && *input_line_pointer == '\'')
inquote = !inquote;
#ifdef QUOTES_IN_INSN
if (inescape)
inescape = 0;
else if (*input_line_pointer == '"')
inquote = !inquote;
else if (*input_line_pointer == '\\')
inescape = 1;
#endif
input_line_pointer++;
}
c = *input_line_pointer;
*input_line_pointer = '\0';
generate_lineno_debug ();
if (macro_defined)
{
sb out;
const char *err;
macro_entry *macro;
if (check_macro (s, &out, &err, ¯o))
{
if (err != NULL)
as_bad ("%s", err);
*input_line_pointer++ = c;
input_scrub_include_sb (&out,
input_line_pointer, 1);
sb_kill (&out);
buffer_limit =
input_scrub_next_buffer (&input_line_pointer);
#ifdef md_macro_info
md_macro_info (macro);
#endif
continue;
}
}
if (mri_pending_align)
{
do_align (1, (char *) NULL, 0, 0);
mri_pending_align = 0;
if (line_label != NULL)
{
symbol_set_frag (line_label, frag_now);
S_SET_VALUE (line_label, frag_now_fix ());
}
}
md_assemble (s); /* Assemble 1 instruction. */
*input_line_pointer++ = c;
/* We resume loop AFTER the end-of-line from
this instruction. */
}
}
continue;
}
/* Empty statement? */
if (is_end_of_line[(unsigned char) c])
continue;
if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB) && ISDIGIT (c))
{
/* local label ("4:") */
char *backup = input_line_pointer;
HANDLE_CONDITIONAL_ASSEMBLY ();
temp = c - '0';
/* Read the whole number. */
while (ISDIGIT (*input_line_pointer))
{
temp = (temp * 10) + *input_line_pointer - '0';
++input_line_pointer;
}
if (LOCAL_LABELS_DOLLAR
&& *input_line_pointer == '$'
&& *(input_line_pointer + 1) == ':')
{
input_line_pointer += 2;
if (dollar_label_defined (temp))
{
as_fatal (_("label \"%d$\" redefined"), temp);
}
define_dollar_label (temp);
colon (dollar_label_name (temp, 0));
continue;
}
if (LOCAL_LABELS_FB
&& *input_line_pointer++ == ':')
{
fb_label_instance_inc (temp);
colon (fb_label_name (temp, 0));
continue;
}
input_line_pointer = backup;
} /* local label ("4:") */
if (c && strchr (line_comment_chars, c))
{ /* Its a comment. Better say APP or NO_APP. */
sb sbuf;
char *ends;
char *new_buf;
char *new_tmp;
unsigned int new_length;
char *tmp_buf = 0;
bump_line_counters ();
s = input_line_pointer;
if (strncmp (s, "APP\n", 4))
continue; /* We ignore it */
s += 4;
sb_new (&sbuf);
ends = strstr (s, "#NO_APP\n");
if (!ends)
{
unsigned int tmp_len;
unsigned int num;
/* The end of the #APP wasn't in this buffer. We
keep reading in buffers until we find the #NO_APP
that goes with this #APP There is one. The specs
guarentee it... */
tmp_len = buffer_limit - s;
tmp_buf = xmalloc (tmp_len + 1);
memcpy (tmp_buf, s, tmp_len);
do
{
new_tmp = input_scrub_next_buffer (&buffer);
if (!new_tmp)
break;
else
buffer_limit = new_tmp;
input_line_pointer = buffer;
ends = strstr (buffer, "#NO_APP\n");
if (ends)
num = ends - buffer;
else