1 /* This is the Assembler Pre-Processor
2 Copyright (C) 1987-2024 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
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)
11 GAS is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
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
21 /* Modified by Allen Wirfs-Brock, Instantiations Inc 2/90. */
22 /* App, the assembler pre-processor. This pre-processor strips out
23 excess spaces, turns single-quoted characters into a decimal
24 constant, and turns the # in # <number> <filename> <garbage> into a
25 .linefile. This needs better error-handling. */
31 #define const /* empty */
36 int enable_h_tick_hex
= 0;
40 /* Whether we are scrubbing in m68k MRI mode. This is different from
41 flag_m68k_mri, because the two flags will be affected by the .mri
42 pseudo-op at different times. */
43 static int scrub_m68k_mri
;
45 /* The pseudo-op which switches in and out of MRI mode. See the
46 comment in do_scrub_chars. */
47 static const char mri_pseudo
[] = ".mri 0";
48 static const char *mri_state
;
49 static char mri_last_ch
;
51 #define scrub_m68k_mri 0
54 #if defined TC_ARM && defined OBJ_ELF
55 /* The pseudo-op for which we need to special-case `@' characters.
56 See the comment in do_scrub_chars. */
57 static const char symver_pseudo
[] = ".symver";
58 static const char * symver_state
;
61 /* The pseudo-op (without leading dot) at which we want to (perhaps just
62 temporarily) stop processing. See the comments in do_scrub_chars(). */
63 static const char end_pseudo
[] = "end ";
64 static const char * end_state
;
66 /* Whether, considering the state at start of assembly, NO_PSEUDO_DOT is
68 static bool no_pseudo_dot
;
70 static char last_char
;
72 #define LEX_IS_SYMBOL_COMPONENT 1
73 #define LEX_IS_WHITESPACE 2
74 #define LEX_IS_LINE_SEPARATOR 3
75 #define LEX_IS_COMMENT_START 4
76 #define LEX_IS_LINE_COMMENT_START 5
77 #define LEX_IS_TWOCHAR_COMMENT_1ST 6
78 #define LEX_IS_STRINGQUOTE 8
79 #define LEX_IS_COLON 9
80 #define LEX_IS_NEWLINE 10
81 #define LEX_IS_ONECHAR_QUOTE 11
83 #define LEX_IS_DOUBLEDASH_1ST 12
85 #ifdef DOUBLEBAR_PARALLEL
86 #define LEX_IS_DOUBLEBAR_1ST 13
88 #define LEX_IS_PARALLEL_SEPARATOR 14
92 #define IS_SYMBOL_COMPONENT(c) (lex[c] == LEX_IS_SYMBOL_COMPONENT)
93 #define IS_WHITESPACE(c) (lex[c] == LEX_IS_WHITESPACE)
94 #define IS_LINE_SEPARATOR(c) (lex[c] == LEX_IS_LINE_SEPARATOR)
95 #define IS_PARALLEL_SEPARATOR(c) (lex[c] == LEX_IS_PARALLEL_SEPARATOR)
96 #define IS_COMMENT(c) (lex[c] == LEX_IS_COMMENT_START)
97 #define IS_LINE_COMMENT(c) (lex[c] == LEX_IS_LINE_COMMENT_START)
98 #define IS_TWOCHAR_COMMENT_1ST(c) (lex[c] == LEX_IS_TWOCHAR_COMMENT_1ST)
99 #define IS_NEWLINE(c) (lex[c] == LEX_IS_NEWLINE)
101 static char lex
[256] = {
102 [' '] = LEX_IS_WHITESPACE
,
103 ['\t'] = LEX_IS_WHITESPACE
,
105 ['\r'] = LEX_IS_LINE_SEPARATOR
,
107 ['\r'] = LEX_IS_WHITESPACE
,
109 ['\n'] = LEX_IS_NEWLINE
,
110 [':'] = LEX_IS_COLON
,
111 ['$'] = LEX_IS_SYMBOL_COMPONENT
,
112 ['.'] = LEX_IS_SYMBOL_COMPONENT
,
113 ['_'] = LEX_IS_SYMBOL_COMPONENT
,
114 ['A'] = LEX_IS_SYMBOL_COMPONENT
, ['a'] = LEX_IS_SYMBOL_COMPONENT
,
115 ['B'] = LEX_IS_SYMBOL_COMPONENT
, ['b'] = LEX_IS_SYMBOL_COMPONENT
,
116 ['C'] = LEX_IS_SYMBOL_COMPONENT
, ['c'] = LEX_IS_SYMBOL_COMPONENT
,
117 ['D'] = LEX_IS_SYMBOL_COMPONENT
, ['d'] = LEX_IS_SYMBOL_COMPONENT
,
118 ['E'] = LEX_IS_SYMBOL_COMPONENT
, ['e'] = LEX_IS_SYMBOL_COMPONENT
,
119 ['F'] = LEX_IS_SYMBOL_COMPONENT
, ['f'] = LEX_IS_SYMBOL_COMPONENT
,
120 ['G'] = LEX_IS_SYMBOL_COMPONENT
, ['g'] = LEX_IS_SYMBOL_COMPONENT
,
121 ['H'] = LEX_IS_SYMBOL_COMPONENT
, ['h'] = LEX_IS_SYMBOL_COMPONENT
,
122 ['I'] = LEX_IS_SYMBOL_COMPONENT
, ['i'] = LEX_IS_SYMBOL_COMPONENT
,
123 ['J'] = LEX_IS_SYMBOL_COMPONENT
, ['j'] = LEX_IS_SYMBOL_COMPONENT
,
124 ['K'] = LEX_IS_SYMBOL_COMPONENT
, ['k'] = LEX_IS_SYMBOL_COMPONENT
,
125 ['L'] = LEX_IS_SYMBOL_COMPONENT
, ['l'] = LEX_IS_SYMBOL_COMPONENT
,
126 ['M'] = LEX_IS_SYMBOL_COMPONENT
, ['m'] = LEX_IS_SYMBOL_COMPONENT
,
127 ['N'] = LEX_IS_SYMBOL_COMPONENT
, ['n'] = LEX_IS_SYMBOL_COMPONENT
,
128 ['O'] = LEX_IS_SYMBOL_COMPONENT
, ['o'] = LEX_IS_SYMBOL_COMPONENT
,
129 ['P'] = LEX_IS_SYMBOL_COMPONENT
, ['p'] = LEX_IS_SYMBOL_COMPONENT
,
130 ['Q'] = LEX_IS_SYMBOL_COMPONENT
, ['q'] = LEX_IS_SYMBOL_COMPONENT
,
131 ['R'] = LEX_IS_SYMBOL_COMPONENT
, ['r'] = LEX_IS_SYMBOL_COMPONENT
,
132 ['S'] = LEX_IS_SYMBOL_COMPONENT
, ['s'] = LEX_IS_SYMBOL_COMPONENT
,
133 ['T'] = LEX_IS_SYMBOL_COMPONENT
, ['t'] = LEX_IS_SYMBOL_COMPONENT
,
134 ['U'] = LEX_IS_SYMBOL_COMPONENT
, ['u'] = LEX_IS_SYMBOL_COMPONENT
,
135 ['V'] = LEX_IS_SYMBOL_COMPONENT
, ['v'] = LEX_IS_SYMBOL_COMPONENT
,
136 ['W'] = LEX_IS_SYMBOL_COMPONENT
, ['w'] = LEX_IS_SYMBOL_COMPONENT
,
137 ['X'] = LEX_IS_SYMBOL_COMPONENT
, ['x'] = LEX_IS_SYMBOL_COMPONENT
,
138 ['Y'] = LEX_IS_SYMBOL_COMPONENT
, ['y'] = LEX_IS_SYMBOL_COMPONENT
,
139 ['Z'] = LEX_IS_SYMBOL_COMPONENT
, ['z'] = LEX_IS_SYMBOL_COMPONENT
,
140 ['0'] = LEX_IS_SYMBOL_COMPONENT
,
141 ['1'] = LEX_IS_SYMBOL_COMPONENT
,
142 ['2'] = LEX_IS_SYMBOL_COMPONENT
,
143 ['3'] = LEX_IS_SYMBOL_COMPONENT
,
144 ['4'] = LEX_IS_SYMBOL_COMPONENT
,
145 ['5'] = LEX_IS_SYMBOL_COMPONENT
,
146 ['6'] = LEX_IS_SYMBOL_COMPONENT
,
147 ['7'] = LEX_IS_SYMBOL_COMPONENT
,
148 ['8'] = LEX_IS_SYMBOL_COMPONENT
,
149 ['9'] = LEX_IS_SYMBOL_COMPONENT
,
150 #define INIT2(n) [n] = LEX_IS_SYMBOL_COMPONENT, \
151 [(n) + 1] = LEX_IS_SYMBOL_COMPONENT
152 #define INIT4(n) INIT2 (n), INIT2 ((n) + 2)
153 #define INIT8(n) INIT4 (n), INIT4 ((n) + 4)
154 #define INIT16(n) INIT8 (n), INIT8 ((n) + 8)
155 #define INIT32(n) INIT16 (n), INIT16 ((n) + 16)
156 #define INIT64(n) INIT32 (n), INIT32 ((n) + 32)
157 #define INIT128(n) INIT64 (n), INIT64 ((n) + 64)
169 do_scrub_begin (int m68k_mri ATTRIBUTE_UNUSED
)
173 /* Latch this once at start. xtensa uses a hook function, yet context isn't
174 meaningful for scrubbing (or else we'd need to sync scrubber behavior as
177 no_pseudo_dot
= NO_PSEUDO_DOT
;
180 scrub_m68k_mri
= m68k_mri
;
185 lex
['"'] = LEX_IS_STRINGQUOTE
;
187 #if ! defined (TC_HPPA)
188 lex
['\''] = LEX_IS_ONECHAR_QUOTE
;
191 #ifdef SINGLE_QUOTE_STRINGS
192 lex
['\''] = LEX_IS_STRINGQUOTE
;
196 /* Note: if any other character can be LEX_IS_STRINGQUOTE, the loop
197 in state 5 of do_scrub_chars must be changed. */
199 /* Note that these override the previous defaults, e.g. if ';' is a
200 comment char, then it isn't a line separator. */
202 #ifdef tc_symbol_chars
203 /* This macro permits the processor to specify all characters which
204 may appears in an operand. This will prevent the scrubber from
205 discarding meaningful whitespace in certain cases. The i386
206 backend uses this to support prefixes, which can confuse the
207 scrubber as to whether it is parsing operands or opcodes. */
208 for (p
= tc_symbol_chars
; *p
; ++p
)
209 lex
[(unsigned char) *p
] = LEX_IS_SYMBOL_COMPONENT
;
212 /* The m68k backend wants to be able to change comment_chars. */
213 #ifndef tc_comment_chars
214 #define tc_comment_chars comment_chars
216 for (p
= tc_comment_chars
; *p
; p
++)
217 lex
[(unsigned char) *p
] = LEX_IS_COMMENT_START
;
219 /* While counter intuitive to have more special purpose line comment chars
220 override more general purpose ordinary ones, logic in do_scrub_chars()
221 depends on this ordering. */
222 for (p
= line_comment_chars
; *p
; p
++)
223 lex
[(unsigned char) *p
] = LEX_IS_LINE_COMMENT_START
;
225 #ifndef tc_line_separator_chars
226 #define tc_line_separator_chars line_separator_chars
228 for (p
= tc_line_separator_chars
; *p
; p
++)
229 lex
[(unsigned char) *p
] = LEX_IS_LINE_SEPARATOR
;
231 #ifdef tc_parallel_separator_chars
232 /* This macro permits the processor to specify all characters which
233 separate parallel insns on the same line. */
234 for (p
= tc_parallel_separator_chars
; *p
; p
++)
235 lex
[(unsigned char) *p
] = LEX_IS_PARALLEL_SEPARATOR
;
238 /* Only allow slash-star comments if slash is not in use. Certain
239 other cases are dealt with in LEX_IS_LINE_COMMENT_START handling.
240 FIXME: This isn't right. We should always permit them. */
242 lex
['/'] = LEX_IS_TWOCHAR_COMMENT_1ST
;
247 lex
['\''] = LEX_IS_STRINGQUOTE
;
248 lex
[';'] = LEX_IS_COMMENT_START
;
249 lex
['*'] = LEX_IS_LINE_COMMENT_START
;
250 /* The MRI documentation says '!' is LEX_IS_COMMENT_START, but
251 then it can't be used in an expression. */
252 lex
['!'] = LEX_IS_LINE_COMMENT_START
;
257 lex
['-'] = LEX_IS_DOUBLEDASH_1ST
;
259 #ifdef DOUBLEBAR_PARALLEL
260 lex
['|'] = LEX_IS_DOUBLEBAR_1ST
;
263 /* Must do this is we want VLIW instruction with "->" or "<-". */
264 lex
['-'] = LEX_IS_SYMBOL_COMPONENT
;
268 if (enable_h_tick_hex
)
276 /* Saved state of the scrubber. */
278 static int old_state
;
279 static const char *out_string
;
280 static char out_buf
[20];
281 static int add_newlines
;
282 static char *saved_input
;
283 static size_t saved_input_len
;
284 static char input_buffer
[32 * 1024];
286 /* Data structure for saving the state of app across #include's. Note that
287 app is called asynchronously to the parsing of the .include's, so our
288 state at the time .include is interpreted is completely unrelated.
289 That's why we have to save it all. */
295 const char * out_string
;
296 char out_buf
[sizeof (out_buf
)];
299 size_t saved_input_len
;
300 const char * end_state
;
303 const char * mri_state
;
306 #if defined TC_ARM && defined OBJ_ELF
307 const char * symver_state
;
315 struct app_save
*saved
;
317 saved
= XNEW (struct app_save
);
318 saved
->state
= state
;
319 saved
->old_state
= old_state
;
320 saved
->out_string
= out_string
;
321 memcpy (saved
->out_buf
, out_buf
, sizeof (out_buf
));
322 saved
->add_newlines
= add_newlines
;
323 if (saved_input
== NULL
)
324 saved
->saved_input
= NULL
;
327 saved
->saved_input
= XNEWVEC (char, saved_input_len
);
328 memcpy (saved
->saved_input
, saved_input
, saved_input_len
);
329 saved
->saved_input_len
= saved_input_len
;
331 saved
->end_state
= end_state
;
333 saved
->scrub_m68k_mri
= scrub_m68k_mri
;
334 saved
->mri_state
= mri_state
;
335 saved
->mri_last_ch
= mri_last_ch
;
337 #if defined TC_ARM && defined OBJ_ELF
338 saved
->symver_state
= symver_state
;
340 saved
->last_char
= last_char
;
342 /* do_scrub_begin() is not useful, just wastes time. */
348 return (char *) saved
;
354 struct app_save
*saved
= (struct app_save
*) arg
;
356 /* There is no do_scrub_end (). */
357 state
= saved
->state
;
358 old_state
= saved
->old_state
;
359 out_string
= saved
->out_string
;
360 memcpy (out_buf
, saved
->out_buf
, sizeof (out_buf
));
361 add_newlines
= saved
->add_newlines
;
362 if (saved
->saved_input
== NULL
)
366 gas_assert (saved
->saved_input_len
<= sizeof (input_buffer
));
367 memcpy (input_buffer
, saved
->saved_input
, saved
->saved_input_len
);
368 saved_input
= input_buffer
;
369 saved_input_len
= saved
->saved_input_len
;
370 free (saved
->saved_input
);
372 end_state
= saved
->end_state
;
374 scrub_m68k_mri
= saved
->scrub_m68k_mri
;
375 mri_state
= saved
->mri_state
;
376 mri_last_ch
= saved
->mri_last_ch
;
378 #if defined TC_ARM && defined OBJ_ELF
379 symver_state
= saved
->symver_state
;
381 last_char
= saved
->last_char
;
386 /* @@ This assumes that \n &c are the same on host and target. This is not
390 process_escape (int ch
)
413 #define MULTIBYTE_WARN_COUNT_LIMIT 10
414 static unsigned int multibyte_warn_count
= 0;
417 scan_for_multibyte_characters (const unsigned char * start
,
418 const unsigned char * end
,
424 if (warn
&& multibyte_warn_count
> MULTIBYTE_WARN_COUNT_LIMIT
)
433 if ((c
= * start
++) <= 0x7f)
441 const char * filename
;
444 filename
= as_where (& lineno
);
445 if (filename
== NULL
)
446 as_warn (_("multibyte character (%#x) encountered in input"), c
);
447 else if (lineno
== 0)
448 as_warn (_("multibyte character (%#x) encountered in %s"), c
, filename
);
450 as_warn (_("multibyte character (%#x) encountered in %s at or near line %u"), c
, filename
, lineno
);
452 if (++ multibyte_warn_count
== MULTIBYTE_WARN_COUNT_LIMIT
)
454 as_warn (_("further multibyte character warnings suppressed"));
462 /* This function is called to process input characters. The GET
463 parameter is used to retrieve more input characters. GET should
464 set its parameter to point to a buffer, and return the length of
465 the buffer; it should return 0 at end of file. The scrubbed output
466 characters are put into the buffer starting at TOSTART; the TOSTART
467 buffer is TOLEN bytes in length. The function returns the number
468 of scrubbed characters put into TOSTART. This will be TOLEN unless
469 end of file was seen. This function is arranged as a state
470 machine, and saves its state so that it may return at any point.
471 This is the way the old code used to work. */
474 do_scrub_chars (size_t (*get
) (char *, size_t), char *tostart
, size_t tolen
,
475 bool check_multibyte
)
478 char *toend
= tostart
+ tolen
;
483 /* Character that started the string we're working on. */
484 static char quotechar
;
486 /*State 0: beginning of normal line
487 1: After first whitespace on line (flush more white)
488 2: After first non-white (opcode) on line (keep 1white)
489 3: after second white on line (into operands) (flush white)
490 4: after putting out a .linefile, put out digits
491 5: parsing a string, then go to old-state
492 6: putting out \ escape in a "d string.
495 9: After seeing symbol char in state 3 (keep 1white after symchar)
496 10: After seeing whitespace in state 9 (keep white before symchar)
497 11: After seeing a symbol character in state 0 (eg a label definition)
498 -1: output string in out_string and go to the state in old_state
500 #ifdef DOUBLEBAR_PARALLEL
501 13: After seeing a vertical bar, looking for a second
502 vertical bar as a parallel expression separator.
504 #ifdef TC_PREDICATE_START_CHAR
505 14: After seeing a predicate start character at state 0, looking
506 for a predicate end character as predicate.
507 15: After seeing a predicate start character at state 1, looking
508 for a predicate end character as predicate.
511 16: After seeing an 'a' or an 'A' at the start of a symbol
512 17: After seeing an 'f' or an 'F' in state 16
516 /* I added states 9 and 10 because the MIPS ECOFF assembler uses
517 constructs like ``.loc 1 20''. This was turning into ``.loc
518 120''. States 9 and 10 ensure that a space is never dropped in
519 between characters which could appear in an identifier. Ian
520 Taylor, ian@cygnus.com.
522 I added state 11 so that something like "Lfoo add %r25,%r26,%r27" works
523 correctly on the PA (and any other target where colons are optional).
524 Jeff Law, law@cs.utah.edu.
526 I added state 13 so that something like "cmp r1, r2 || trap #1" does not
527 get squashed into "cmp r1,r2||trap#1", with the all important space
528 between the 'trap' and the '#1' being eliminated. nickc@cygnus.com */
530 /* This macro gets the next input character. */
534 ? * (unsigned char *) (from++) \
535 : (saved_input = NULL, \
536 fromlen = (*get) (input_buffer, sizeof input_buffer), \
537 from = input_buffer, \
538 fromend = from + fromlen, \
541 : * (unsigned char *) (from++))))
543 /* This macro pushes a character back on the input stream. */
545 #define UNGET(uch) (*--from = (uch))
547 /* This macro puts a character into the output buffer. If this
548 character fills the output buffer, this macro jumps to the label
549 TOFULL. We use this rather ugly approach because we need to
550 handle two different termination conditions: EOF on the input
551 stream, and a full output buffer. It would be simpler if we
552 always read in the entire input stream before processing it, but
553 I don't want to make such a significant change to the assembler's
565 if (saved_input
!= NULL
)
568 fromend
= from
+ saved_input_len
;
572 fromlen
= (*get
) (input_buffer
, sizeof input_buffer
);
576 fromend
= from
+ fromlen
;
579 (void) scan_for_multibyte_characters ((const unsigned char *) from
,
580 (const unsigned char* ) fromend
,
581 true /* Generate warnings. */);
586 /* The cases in this switch end with continue, in order to
587 branch back to the top of this while loop and generate the
588 next output character in the appropriate state. */
593 if (*out_string
== '\0')
605 else if (ch
>= '0' && ch
<= '9')
609 while (ch
!= EOF
&& IS_WHITESPACE (ch
))
620 while (ch
!= EOF
&& ch
!= '\n')
629 /* We are going to copy everything up to a quote character,
630 with special handling for a backslash. We try to
631 optimize the copying in the simple case without using the
632 GET and PUT macros. */
637 for (s
= from
; s
< fromend
; s
++)
646 if (len
> toend
- to
)
650 memcpy (to
, from
, len
);
661 /* This buffer is here specifically so
662 that the UNGET below will work. */
663 static char one_char_buf
[1];
665 as_warn (_("end of file in string; '%c' inserted"), quotechar
);
667 from
= fromend
= one_char_buf
+ 1;
672 else if (ch
== quotechar
)
677 else if (TC_STRING_ESCAPES
&& ch
== '\\')
682 else if (scrub_m68k_mri
&& ch
== '\n')
684 /* Just quietly terminate the string. This permits lines like
685 bne label loop if we haven't reach end yet. */
701 /* Handle strings broken across lines, by turning '\n' into
710 as_warn (_("end of file in string; '%c' inserted"), quotechar
);
714 /* These two are used inside macros. */
740 #ifdef ONLY_STANDARD_ESCAPES
741 as_warn (_("unknown escape '\\%c' in string; ignored"), ch
);
748 #ifdef DOUBLEBAR_PARALLEL
754 /* Reset back to state 1 and pretend that we are parsing a
755 line from just after the first white space. */
762 /* We have seen an 'a' at the start of a symbol, look for an 'f'. */
764 if (ch
== 'f' || ch
== 'F')
778 /* We have seen "af" at the start of a symbol,
779 a ' here is a part of that symbol. */
783 /* Change to avoid warning about unclosed string. */
791 /* OK, we are somewhere in states 0 through 4 or 9 through 11. */
796 #ifdef TC_PREDICATE_START_CHAR
797 if (ch
== TC_PREDICATE_START_CHAR
&& (state
== 0 || state
== 1))
803 else if (state
== 14 || state
== 15)
805 if (ch
== TC_PREDICATE_END_CHAR
)
821 /* We need to watch out for .end directives: We should in particular not
822 issue diagnostics for anything after an active one. */
823 if (end_state
== NULL
)
825 if ((state
== 0 || state
== 1)
827 || (no_pseudo_dot
&& ch
== end_pseudo
[0])))
828 end_state
= end_pseudo
+ (ch
!= '.');
832 /* Avoid triggering on directives like .endif or .endr. */
833 || (*end_state
== ' ' && !IS_SYMBOL_COMPONENT (ch
))))
835 if (IS_NEWLINE (ch
) || IS_LINE_SEPARATOR (ch
))
839 else if (*end_state
!= '\0')
840 /* We did not get the expected character, or we didn't
841 get a valid terminating character after seeing the
842 entire pseudo-op, so we must go back to the beginning. */
844 else if (IS_NEWLINE (ch
) || IS_LINE_SEPARATOR (ch
))
847 /* We've read the entire pseudo-op. If this is the end of the line,
848 bail out now by (ab)using the output-full path. This allows the
849 caller to process input up to here and terminate processing if this
850 directive is actually active (not on the false branch of a
851 conditional and not in a macro definition). */
858 #if defined TC_ARM && defined OBJ_ELF
859 /* We need to watch out for .symver directives. See the comment later
861 if (symver_state
== NULL
)
863 if ((state
== 0 || state
== 1)
864 && strchr (tc_comment_chars
, '@') != NULL
865 && ch
== symver_pseudo
[0])
866 symver_state
= symver_pseudo
+ 1;
870 /* We advance to the next state if we find the right
872 if (ch
!= '\0' && (*symver_state
== ch
))
874 else if (*symver_state
!= '\0')
875 /* We did not get the expected character, or we didn't
876 get a valid terminating character after seeing the
877 entire pseudo-op, so we must go back to the beginning. */
881 /* We've read the entire pseudo-op. If this is the end
882 of the line, go back to the beginning. */
883 if (IS_NEWLINE (ch
) || IS_LINE_SEPARATOR (ch
))
887 #endif /* TC_ARM && OBJ_ELF */
890 /* We want to have pseudo-ops which control whether we are in
891 MRI mode or not. Unfortunately, since m68k MRI mode affects
892 the scrubber, that means that we need a special purpose
894 if (mri_state
== NULL
)
896 if ((state
== 0 || state
== 1)
897 && ch
== mri_pseudo
[0])
898 mri_state
= mri_pseudo
+ 1;
902 /* We advance to the next state if we find the right
903 character, or if we need a space character and we get any
904 whitespace character, or if we need a '0' and we get a
905 '1' (this is so that we only need one state to handle
906 ``.mri 0'' and ``.mri 1''). */
909 || (*mri_state
== ' '
910 && IS_WHITESPACE (ch
))
911 || (*mri_state
== '0'
917 else if (*mri_state
!= '\0'
918 || (!IS_WHITESPACE (ch
)
919 && !IS_LINE_SEPARATOR (ch
)
920 && !IS_NEWLINE (ch
)))
922 /* We did not get the expected character, or we didn't
923 get a valid terminating character after seeing the
924 entire pseudo-op, so we must go back to the
930 /* We've read the entire pseudo-op. mips_last_ch is
931 either '0' or '1' indicating whether to enter or
933 do_scrub_begin (mri_last_ch
== '1');
936 /* We continue handling the character as usual. The
937 main gas reader must also handle the .mri pseudo-op
938 to control expression parsing and the like. */
947 as_warn (_("end of file not at end of a line; newline inserted"));
956 case LEX_IS_WHITESPACE
:
961 while (ch
!= EOF
&& IS_WHITESPACE (ch
));
967 /* Preserve a single whitespace character at the
968 beginning of a line. */
975 #ifdef KEEP_WHITE_AROUND_COLON
976 if (lex
[ch
] == LEX_IS_COLON
)
978 /* Only keep this white if there's no white *after* the
983 if (!IS_WHITESPACE (ch2
))
993 /* Prune trailing whitespace. */
995 || (IS_LINE_COMMENT (ch
)
996 && (state
< 1 || strchr (tc_comment_chars
, ch
)))
998 || IS_LINE_SEPARATOR (ch
)
999 || IS_PARALLEL_SEPARATOR (ch
))
1003 /* In MRI mode, we keep these spaces. */
1010 #ifdef DOUBLESLASH_LINE_COMMENTS
1011 if (IS_TWOCHAR_COMMENT_1ST (ch
))
1021 /* If we're in state 2 or 11, we've seen a non-white
1022 character followed by whitespace. If the next character
1023 is ':', this is whitespace after a label name which we
1024 normally must ignore. In MRI mode, though, spaces are
1025 not permitted between the label and the colon. */
1026 if ((state
== 2 || state
== 11)
1027 && lex
[ch
] == LEX_IS_COLON
1028 && ! scrub_m68k_mri
)
1038 /* We can arrive here if we leave a leading whitespace
1039 character at the beginning of a line. */
1045 /* Optimize common case by skipping UNGET/GET. */
1046 PUT (' '); /* Sp after opco */
1053 #ifndef TC_KEEP_OPERAND_SPACES
1054 /* For TI C6X, we keep these spaces as they may separate
1055 functional unit specifiers from operands. */
1059 /* In MRI mode, we keep these spaces. */
1064 goto recycle
; /* Sp in operands */
1067 #ifndef TC_KEEP_OPERAND_SPACES
1071 /* In MRI mode, we keep these spaces. */
1077 state
= 10; /* Sp after symbol char */
1080 if (LABELS_WITHOUT_COLONS
|| flag_m68k_mri
)
1084 /* We know that ch is not ':', since we tested that
1085 case above. Therefore this is not a label, so it
1086 must be the opcode, and we've just seen the
1087 whitespace after it. */
1091 PUT (' '); /* Sp after label definition. */
1098 case LEX_IS_TWOCHAR_COMMENT_1ST
:
1108 if (ch2
!= EOF
&& IS_NEWLINE (ch2
))
1111 while (ch2
!= EOF
&& ch2
!= '*');
1116 if (ch2
== EOF
|| ch2
== '/')
1119 /* This UNGET will ensure that we count newlines
1125 as_warn (_("end of file in multiline comment"));
1130 #ifdef DOUBLESLASH_LINE_COMMENTS
1131 else if (ch2
== '/')
1137 while (ch
!= EOF
&& !IS_NEWLINE (ch
));
1139 as_warn ("end of file in comment; newline inserted");
1149 if (state
== 9 || state
== 10)
1155 case LEX_IS_STRINGQUOTE
:
1159 /* Preserve the whitespace in foo "bar". */
1164 /* PUT didn't jump out. We could just break, but we
1165 know what will happen, so optimize a bit. */
1169 else if (state
== 3)
1171 else if (state
== 0)
1172 old_state
= 11; /* Now seeing label definition. */
1179 case LEX_IS_ONECHAR_QUOTE
:
1181 if (state
== 9 && enable_h_tick_hex
)
1186 as_warn ("'%c found after symbol", c
);
1192 /* Preserve the whitespace in foo 'b'. */
1201 as_warn (_("end of file after a one-character quote; \\0 inserted"));
1209 as_warn (_("end of file in escape character"));
1213 ch
= process_escape (ch
);
1215 sprintf (out_buf
, "%d", (int) (unsigned char) ch
);
1217 /* None of these 'x constants for us. We want 'x'. */
1218 if ((ch
= GET ()) != '\'')
1220 #ifdef REQUIRE_CHAR_CLOSE_QUOTE
1221 as_warn (_("missing close quote; (assumed)"));
1227 if (strlen (out_buf
) == 1)
1237 out_string
= out_buf
;
1238 PUT (*out_string
++);
1242 #ifdef KEEP_WHITE_AROUND_COLON
1245 if (state
== 9 || state
== 10)
1247 else if (state
!= 3)
1253 case LEX_IS_NEWLINE
:
1254 /* Roll out a bunch of newlines from inside comments, etc. */
1262 case LEX_IS_LINE_SEPARATOR
:
1267 case LEX_IS_PARALLEL_SEPARATOR
:
1273 case LEX_IS_DOUBLEDASH_1ST
:
1281 /* Read and skip to end of line. */
1286 while (ch
!= EOF
&& ch
!= '\n');
1289 as_warn (_("end of file in comment; newline inserted"));
1295 #ifdef DOUBLEBAR_PARALLEL
1296 case LEX_IS_DOUBLEBAR_1ST
:
1303 /* Handle '||' in two states as invoking PUT twice might
1304 result in the first one jumping out of this loop. We'd
1305 then lose track of the state and one '|' char. */
1310 case LEX_IS_LINE_COMMENT_START
:
1311 /* FIXME-someday: The two character comment stuff was badly
1312 thought out. On i386, we want '/' as line comment start
1313 AND we want C style comments. hence this hack. The
1314 whole lexical process should be reworked. xoxorich. */
1319 goto twochar_comment
;
1324 if (state
== 0 || state
== 1) /* Only comment at start of line. */
1334 while (ch
!= EOF
&& IS_WHITESPACE (ch
));
1338 as_warn (_("end of file in comment; newline inserted"));
1343 if (ch
< '0' || ch
> '9' || state
!= 0 || startch
!= '#')
1345 /* Not a cpp line. */
1346 while (ch
!= EOF
&& !IS_NEWLINE (ch
))
1350 as_warn (_("end of file in comment; newline inserted"));
1353 else /* IS_NEWLINE (ch) */
1355 /* To process non-zero add_newlines. */
1361 /* Looks like `# 123 "filename"' from cpp. */
1366 out_string
= "\tlinefile ";
1368 out_string
= "\t.linefile ";
1369 PUT (*out_string
++);
1374 /* All insns end in a char for which LEX_IS_SYMBOL_COMPONENT is true.
1375 Trap is the only short insn that has a first operand that is
1376 neither register nor label.
1377 We must prevent exef0f ||trap #1 to degenerate to exef0f ||trap#1 .
1378 We can't make '#' LEX_IS_SYMBOL_COMPONENT because it is
1379 already LEX_IS_LINE_COMMENT_START. However, it is the
1380 only character in line_comment_chars for d10v, hence we
1381 can recognize it as such. */
1382 /* An alternative approach would be to reset the state to 1 when
1383 we see '||', '<'- or '->', but that seems to be overkill. */
1387 /* We have a line comment character which is not at the
1388 start of a line. If this is also a normal comment
1389 character, fall through. Otherwise treat it as a default
1391 if (strchr (tc_comment_chars
, ch
) == NULL
)
1394 && (ch
== '!' || ch
== '*' || ch
== '#'))
1397 case LEX_IS_COMMENT_START
:
1398 #if defined TC_ARM && defined OBJ_ELF
1399 /* On the ARM, `@' is the comment character.
1400 Unfortunately this is also a special character in ELF .symver
1401 directives (and .type, though we deal with those another way).
1402 So we check if this line is such a directive, and treat
1403 the character as default if so. This is a hack. */
1404 if ((symver_state
!= NULL
) && (*symver_state
== 0))
1408 /* Care is needed not to damage occurrences of \<comment-char>
1409 by stripping the <comment-char> onwards. Yuck. */
1410 if ((to
> tostart
? to
[-1] : last_char
) == '\\')
1411 /* Do not treat the <comment-char> as a start-of-comment. */
1414 #ifdef WARN_COMMENTS
1416 found_comment_file
= as_where (&found_comment
);
1422 while (ch
!= EOF
&& !IS_NEWLINE (ch
));
1424 as_warn (_("end of file in comment; newline inserted"));
1431 /* Look for strings like H'[0-9A-Fa-f] and if found, replace
1432 the H' with 0x to make them gas-style hex characters. */
1433 if (enable_h_tick_hex
)
1449 case LEX_IS_SYMBOL_COMPONENT
:
1452 /* This is a symbol character following another symbol
1453 character, with whitespace in between. We skipped
1454 the whitespace earlier, so output it now. */
1462 /* "af'" is a symbol containing '\''. */
1463 if (state
== 3 && (ch
== 'a' || ch
== 'A'))
1468 if (ch
== 'f' || ch
== 'F')
1477 if (ch
== EOF
|| !IS_SYMBOL_COMPONENT (ch
))
1489 /* This is a common case. Quickly copy CH and all the
1490 following symbol component or normal characters. */
1493 && mri_state
== NULL
1495 #if defined TC_ARM && defined OBJ_ELF
1496 && symver_state
== NULL
1498 && end_state
== NULL
)
1503 for (s
= from
; s
< fromend
; s
++)
1507 ch2
= *(unsigned char *) s
;
1510 && type
!= LEX_IS_SYMBOL_COMPONENT
)
1515 /* Handle the last character normally, for
1521 if (len
> (toend
- to
) - 1)
1522 len
= (toend
- to
) - 1;
1527 memcpy (to
, from
, len
);
1539 /* Some relatively `normal' character. */
1542 state
= 11; /* Now seeing label definition. */
1544 else if (state
== 1)
1546 state
= 2; /* Ditto. */
1548 else if (state
== 9)
1550 if (!IS_SYMBOL_COMPONENT (ch
))
1553 else if (state
== 10)
1557 /* Special handling for backslash: a backslash may
1558 be the beginning of a formal parameter (of a
1559 macro) following another symbol character, with
1560 whitespace in between. If that is the case, we
1561 output a space before the parameter. Strictly
1562 speaking, correct handling depends upon what the
1563 macro parameter expands into; if the parameter
1564 expands into something which does not start with
1565 an operand character, then we don't want to keep
1566 the space. We don't have enough information to
1567 make the right choice, so here we are making the
1568 choice which is more likely to be correct. */
1569 if (to
+ 1 >= toend
)
1571 /* If we're near the end of the buffer, save the
1572 character for the next time round. Otherwise
1573 we'll lose our state. */
1590 /* We have reached the end of the input. */
1593 return to
- tostart
;
1596 /* The output buffer is full. Save any input we have not yet
1601 saved_input_len
= fromend
- from
;
1608 return to
- tostart
;
1611 /* Return amount of pending input. */
1614 do_scrub_pending (void)
1618 len
+= saved_input_len
;
1620 len
+= strlen (out_string
);