[PATCH 07/11] gas: consistently drop trailing whitespace when scrubbing
Jan Beulich
jbeulich@suse.com
Fri Jun 28 13:22:02 GMT 2024
>From especially the checks for the two separator forms it appears to
follow that the construct being touched is about trailing whitespace. In
such a case, considering that for many targets ordinary and line comment
chars overlap, take into account that line comment chars override
ordinary ones in lex[] (logic elsewhere in do_scrub_chars() actually
depends on that ordering, and also accounts for this overriding).
Plus of course IS_NEWLINE() would better also be consulted. Note also
that the DOUBLESLASH_LINE_COMMENTS change should generally have no
effect just yet; it's a prereq for a later change but better fits here.
Leave respective comments as well, and update documentation to correct
which comment form is actually replaced by a single blank (i.e. neither
the ones starting with what {,tc_}comment_chars[] has nor the ones
starting with what line_comment_chars[] has).
---
In the MIPS testsuite adjustments I wasn't sure how exactly to make the
necessary changes: I could also have zapped the two blanks each, but
then I wondered why they were part of the expectations in the first
place.
Why are there both comment_chars[] and tc_comment_chars[]? The former is
per-arch anyway, so why would there be a need for an arch override? Is
this perhaps merely a historical leftover, which could be eliminated?
--- a/gas/app.c
+++ b/gas/app.c
@@ -87,6 +87,7 @@ static char last_char;
#define IS_PARALLEL_SEPARATOR(c) (lex[c] == LEX_IS_PARALLEL_SEPARATOR)
#define IS_COMMENT(c) (lex[c] == LEX_IS_COMMENT_START)
#define IS_LINE_COMMENT(c) (lex[c] == LEX_IS_LINE_COMMENT_START)
+#define IS_TWOCHAR_COMMENT_1ST(c) (lex[c] == LEX_IS_TWOCHAR_COMMENT_1ST)
#define IS_NEWLINE(c) (lex[c] == LEX_IS_NEWLINE)
static char lex[256] = {
@@ -149,6 +150,9 @@ do_scrub_begin (int m68k_mri ATTRIBUTE_U
for (p = tc_comment_chars; *p; p++)
lex[(unsigned char) *p] = LEX_IS_COMMENT_START;
+ /* While counter intuitive to have more special purpose line comment chars
+ override more general purpose ordinary ones, logic in do_scrub_chars()
+ depends on this ordering. */
for (p = line_comment_chars; *p; p++)
lex[(unsigned char) *p] = LEX_IS_LINE_COMMENT_START;
@@ -888,7 +892,12 @@ do_scrub_chars (size_t (*get) (char *, s
}
}
#endif
+
+ /* Prune trailing whitespace. */
if (IS_COMMENT (ch)
+ || (IS_LINE_COMMENT (ch)
+ && (state < 1 || strchr (tc_comment_chars, ch)))
+ || IS_NEWLINE (ch)
|| IS_LINE_SEPARATOR (ch)
|| IS_PARALLEL_SEPARATOR (ch))
{
@@ -901,6 +910,16 @@ do_scrub_chars (size_t (*get) (char *, s
}
goto recycle;
}
+#ifdef DOUBLESLASH_LINE_COMMENTS
+ if (IS_TWOCHAR_COMMENT_1ST (ch))
+ {
+ ch2 = GET ();
+ if (ch2 != EOF)
+ UNGET (ch2);
+ if (ch2 == '/')
+ goto recycle;
+ }
+#endif
/* If we're in state 2 or 11, we've seen a non-white
character followed by whitespace. If the next character
--- a/gas/doc/as.texi
+++ b/gas/doc/as.texi
@@ -2987,11 +2987,11 @@ as exactly one space.
@section Comments
@cindex comments
-There are two ways of rendering comments to @command{@value{AS}}. In both
-cases the comment is equivalent to one space.
+There are two ways of rendering comments to @command{@value{AS}}.
Anything from @samp{/*} through the next @samp{*/} is a comment.
-This means you may not nest these comments.
+This means you may not nest these comments. Such a comment is equivalent to
+one space, plus bumping the line counter accordingly.
@smallexample
/*
--- a/gas/testsuite/gas/mips/mips16-32@mips16-insn-e.l
+++ b/gas/testsuite/gas/mips/mips16-32@mips16-insn-e.l
@@ -25,7 +25,7 @@
.*:50: Warning: extended operand requested but not required
.*:51: Error: opcode not supported on this processor: mips1 \(mips1\) `restore\.e 128'
.*:52: Error: opcode not supported on this processor: mips1 \(mips1\) `save\.e 128'
-.*:53: Error: unrecognized extended version of MIPS16 opcode `nop\.e '
+.*:53: Error: unrecognized extended version of MIPS16 opcode `nop\.e ?'
.*:54: Error: unrecognized extended version of MIPS16 opcode `move\.e \$0,\$16'
.*:55: Error: unrecognized extended version of MIPS16 opcode `move\.e \$16,\$0'
.*:57: Warning: extended operand requested but not required
@@ -71,7 +71,7 @@
.*:123: Error: unrecognized extended version of MIPS16 opcode `srav\.e \$16,\$16'
.*:124: Error: operand 2 must be an immediate expression `sra\.e \$16,\$16'
.*:125: Error: opcode not supported on this processor: mips1 \(mips1\) `dsrl\.e \$16,8'
-.*:126: Error: unrecognized extended version of MIPS16 opcode `entry\.e '
+.*:126: Error: unrecognized extended version of MIPS16 opcode `entry\.e ?'
.*:127: Error: unrecognized extended version of MIPS16 opcode `entry\.e \$31'
.*:128: Error: unrecognized extended version of MIPS16 opcode `exit\.e \$f0'
.*:129: Error: unrecognized extended version of MIPS16 opcode `exit\.e'
--- a/gas/testsuite/gas/mips/mips16-64@mips16-insn-e.l
+++ b/gas/testsuite/gas/mips/mips16-64@mips16-insn-e.l
@@ -25,7 +25,7 @@
.*:50: Warning: extended operand requested but not required
.*:51: Error: opcode not supported on this processor: mips3 \(mips3\) `restore\.e 128'
.*:52: Error: opcode not supported on this processor: mips3 \(mips3\) `save\.e 128'
-.*:53: Error: unrecognized extended version of MIPS16 opcode `nop\.e '
+.*:53: Error: unrecognized extended version of MIPS16 opcode `nop\.e ?'
.*:54: Error: unrecognized extended version of MIPS16 opcode `move\.e \$0,\$16'
.*:55: Error: unrecognized extended version of MIPS16 opcode `move\.e \$16,\$0'
.*:57: Warning: extended operand requested but not required
@@ -71,7 +71,7 @@
.*:123: Error: unrecognized extended version of MIPS16 opcode `srav\.e \$16,\$16'
.*:124: Error: operand 2 must be an immediate expression `sra\.e \$16,\$16'
.*:125: Warning: extended operand requested but not required
-.*:126: Error: unrecognized extended version of MIPS16 opcode `entry\.e '
+.*:126: Error: unrecognized extended version of MIPS16 opcode `entry\.e ?'
.*:127: Error: unrecognized extended version of MIPS16 opcode `entry\.e \$31'
.*:128: Error: unrecognized extended version of MIPS16 opcode `exit\.e \$f0'
.*:129: Error: unrecognized extended version of MIPS16 opcode `exit\.e'
--- a/gas/testsuite/gas/mips/mips16-insn-e.l
+++ b/gas/testsuite/gas/mips/mips16-insn-e.l
@@ -23,7 +23,7 @@
.*:48: Warning: extended operand requested but not required
.*:49: Warning: extended operand requested but not required
.*:50: Warning: extended operand requested but not required
-.*:53: Error: unrecognized extended version of MIPS16 opcode `nop\.e '
+.*:53: Error: unrecognized extended version of MIPS16 opcode `nop\.e ?'
.*:54: Error: unrecognized extended version of MIPS16 opcode `move\.e \$0,\$16'
.*:55: Error: unrecognized extended version of MIPS16 opcode `move\.e \$16,\$0'
.*:57: Warning: extended operand requested but not required
@@ -69,7 +69,7 @@
.*:123: Error: unrecognized extended version of MIPS16 opcode `srav\.e \$16,\$16'
.*:124: Error: operand 2 must be an immediate expression `sra\.e \$16,\$16'
.*:125: Warning: extended operand requested but not required
-.*:126: Error: unrecognized extended version of MIPS16 opcode `entry\.e '
+.*:126: Error: unrecognized extended version of MIPS16 opcode `entry\.e ?'
.*:127: Error: unrecognized extended version of MIPS16 opcode `entry\.e \$31'
.*:128: Error: unrecognized extended version of MIPS16 opcode `exit\.e \$f0'
.*:129: Error: unrecognized extended version of MIPS16 opcode `exit\.e'
--- a/gas/testsuite/gas/mips/mips16e-32@mips16-insn-e.l
+++ b/gas/testsuite/gas/mips/mips16e-32@mips16-insn-e.l
@@ -23,7 +23,7 @@
.*:48: Warning: extended operand requested but not required
.*:49: Warning: extended operand requested but not required
.*:50: Warning: extended operand requested but not required
-.*:53: Error: unrecognized extended version of MIPS16 opcode `nop\.e '
+.*:53: Error: unrecognized extended version of MIPS16 opcode `nop\.e ?'
.*:54: Error: unrecognized extended version of MIPS16 opcode `move\.e \$0,\$16'
.*:55: Error: unrecognized extended version of MIPS16 opcode `move\.e \$16,\$0'
.*:57: Warning: extended operand requested but not required
@@ -69,7 +69,7 @@
.*:123: Error: unrecognized extended version of MIPS16 opcode `srav\.e \$16,\$16'
.*:124: Error: operand 2 must be an immediate expression `sra\.e \$16,\$16'
.*:125: Error: opcode not supported on this processor: mips32 \(mips32\) `dsrl\.e \$16,8'
-.*:126: Error: unrecognized extended version of MIPS16 opcode `entry\.e '
+.*:126: Error: unrecognized extended version of MIPS16 opcode `entry\.e ?'
.*:127: Error: unrecognized extended version of MIPS16 opcode `entry\.e \$31'
.*:128: Error: unrecognized extended version of MIPS16 opcode `exit\.e \$f0'
.*:129: Error: unrecognized extended version of MIPS16 opcode `exit\.e'
--- a/gas/testsuite/gas/mips/mips16e2-32@mips16-insn-e.l
+++ b/gas/testsuite/gas/mips/mips16e2-32@mips16-insn-e.l
@@ -23,7 +23,7 @@
.*:48: Warning: extended operand requested but not required
.*:49: Warning: extended operand requested but not required
.*:50: Warning: extended operand requested but not required
-.*:53: Error: unrecognized extended version of MIPS16 opcode `nop\.e '
+.*:53: Error: unrecognized extended version of MIPS16 opcode `nop\.e ?'
.*:54: Error: unrecognized extended version of MIPS16 opcode `move\.e \$0,\$16'
.*:55: Error: unrecognized extended version of MIPS16 opcode `move\.e \$16,\$0'
.*:57: Warning: extended operand requested but not required
@@ -69,7 +69,7 @@
.*:123: Error: unrecognized extended version of MIPS16 opcode `srav\.e \$16,\$16'
.*:124: Error: operand 2 must be an immediate expression `sra\.e \$16,\$16'
.*:125: Error: opcode not supported on this processor: mips32r2 \(mips32r2\) `dsrl\.e \$16,8'
-.*:126: Error: unrecognized extended version of MIPS16 opcode `entry\.e '
+.*:126: Error: unrecognized extended version of MIPS16 opcode `entry\.e ?'
.*:127: Error: unrecognized extended version of MIPS16 opcode `entry\.e \$31'
.*:128: Error: unrecognized extended version of MIPS16 opcode `exit\.e \$f0'
.*:129: Error: unrecognized extended version of MIPS16 opcode `exit\.e'
--- a/gas/testsuite/gas/mips/mips16e2-interaptiv-mr2@mips16-insn-e.l
+++ b/gas/testsuite/gas/mips/mips16e2-interaptiv-mr2@mips16-insn-e.l
@@ -23,7 +23,7 @@
.*:48: Warning: extended operand requested but not required
.*:49: Warning: extended operand requested but not required
.*:50: Warning: extended operand requested but not required
-.*:53: Error: unrecognized extended version of MIPS16 opcode `nop\.e '
+.*:53: Error: unrecognized extended version of MIPS16 opcode `nop\.e ?'
.*:54: Error: unrecognized extended version of MIPS16 opcode `move\.e \$0,\$16'
.*:55: Error: unrecognized extended version of MIPS16 opcode `move\.e \$16,\$0'
.*:57: Warning: extended operand requested but not required
@@ -69,7 +69,7 @@
.*:123: Error: unrecognized extended version of MIPS16 opcode `srav\.e \$16,\$16'
.*:124: Error: operand 2 must be an immediate expression `sra\.e \$16,\$16'
.*:125: Error: opcode not supported on this processor: interaptiv-mr2 \(mips32r3\) `dsrl\.e \$16,8'
-.*:126: Error: unrecognized extended version of MIPS16 opcode `entry\.e '
+.*:126: Error: unrecognized extended version of MIPS16 opcode `entry\.e ?'
.*:127: Error: unrecognized extended version of MIPS16 opcode `entry\.e \$31'
.*:128: Error: unrecognized extended version of MIPS16 opcode `exit\.e \$f0'
.*:129: Error: unrecognized extended version of MIPS16 opcode `exit\.e'
More information about the Binutils
mailing list