]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gas: support double-slash line comments in BPF assembly
authorJose E. Marchesi <jose.marchesi@oracle.com>
Thu, 30 Nov 2023 07:34:09 +0000 (08:34 +0100)
committerJose E. Marchesi <jose.marchesi@oracle.com>
Thu, 30 Nov 2023 07:48:56 +0000 (08:48 +0100)
This patch makes the BPF assembler to support double-slash line
comments, like the llvm BPF assembler does.  At this point both
assemblers support the same commenting styles:

- Line comments preceded by # or //.
- Non-nestable block comments delimited by /* and */.

This patch also adds a couple of tests to make sure all the comment
styles work in both normal and pseudoc syntax.  The manual is also
updated to mention double-slash line comments.

gas/ChangeLog
gas/NEWS
gas/config/tc-bpf.h
gas/doc/c-bpf.texi
gas/testsuite/gas/bpf/bpf.exp
gas/testsuite/gas/bpf/comments-pseudoc.d [new file with mode: 0644]
gas/testsuite/gas/bpf/comments-pseudoc.s [new file with mode: 0644]
gas/testsuite/gas/bpf/comments.d [new file with mode: 0644]
gas/testsuite/gas/bpf/comments.s [new file with mode: 0644]

index 3d5cfcae58ce98b4ad71cdbfe18ccdc8704370ae..b1a568cc3340b086fd0e2a282d24958ddb74c2ce 100644 (file)
@@ -1,3 +1,14 @@
+2023-11-30  Jose E. Marchesi  <jose.marchesi@oracle.com>
+
+       * config/tc-bpf.h (DOUBLESLASH_LINE_COMMENTS): Define.
+       * testsuite/gas/bpf/comments.s: New file.
+       * testsuite/gas/bpf/comments.d: Likewise.
+       * testsuite/gas/bpf/comments-pseudoc.d: Likewise.
+       * testsuite/gas/bpf/comments-pseudoc.s: Likewise.
+       * testsuite/gas/bpf/bpf.exp: Run comments and comments-pseudoc.
+       * doc/c-bpf.texi (BPF Special Characters): Document // comments.
+       * NEWS: Update.
+
 2023-11-28  Jose E. Marchesi  <jose.marchesi@oracle.com>
 
        * NEWS: Add entry about change of comment syntax in the BPF
index 6bfab08c5b8b75714cef723825964f516875ed95..143d9c836e5d82ee9ff62bd0eb211903857bbabf 100644 (file)
--- a/gas/NEWS
+++ b/gas/NEWS
@@ -41,6 +41,9 @@
   therefore they cannot longer be used to begin line comments. This matches the
   behavior of the clang/LLVM BPF assembler.
 
+* The BPF assembler now allows using both hash (#) and double slash (//) to
+  begin line comments.
+
 Changes in 2.41:
 
 * Add support for the KVX instruction set.
index 06096ef59267fb8d623b4947ea821d8a0ce618e5..91f3c1574b1187289ab029663cdab3ffe437f5d0 100644 (file)
@@ -35,6 +35,9 @@
 #define TARGET_BYTES_BIG_ENDIAN 0
 #endif
 
+/* Permit // comments.  */
+#define DOUBLESLASH_LINE_COMMENTS 1
+
 /* .-foo gets turned into PC relative relocs.  */
 #define DIFF_EXPR_OK    1
 
index 7ff07e9176423e73731555874bdfc61443d15c6b..307d28be942cf1758b1a4e1052a23e73ee45934f 100644 (file)
@@ -68,8 +68,8 @@ the host endianness is used.
 
 @cindex line comment character, BPF
 @cindex BPF line comment character
-The presence of a @samp{#} on a line indicates the start of a comment
-that extends to the end of the current line.
+The presence of a @samp{#} or @samp{//} anywhere on a line indicates
+the start of a comment that extends to the end of the line.
 
 @cindex block comments, BPF
 @cindex BPF block comments
index 5bcd8c483a02f336e724116bf30d24b7e246c0b4..5048693cec81d373b40c566b117dd6f33cc40fa1 100644 (file)
 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  
 
 if {[istarget bpf*-*-*]} {
+    # Misc tests.
+    run_dump_test comments
+    run_dump_test comments-pseudoc
+
     # Little-endian BPF tests
     run_dump_test call
     run_dump_test exit
diff --git a/gas/testsuite/gas/bpf/comments-pseudoc.d b/gas/testsuite/gas/bpf/comments-pseudoc.d
new file mode 100644 (file)
index 0000000..6fc68e0
--- /dev/null
@@ -0,0 +1,12 @@
+#as: -EL -mdialect=pseudoc
+#objdump: -dr -M hex
+#name: BPF assembler comments - pseudoc
+
+.*: +file format .*bpf.*
+
+Disassembly of section .text:
+
+[0-9a-f]+ <.*>:
+   0:  07 02 00 00 9a 02 00 00         add %r2,0x29a
+   8:  07 03 00 00 66 fd ff ff         add %r3,0xfffffd66
+  10:  07 04 00 00 ef be ad 7e         add %r4,0x7eadbeef
diff --git a/gas/testsuite/gas/bpf/comments-pseudoc.s b/gas/testsuite/gas/bpf/comments-pseudoc.s
new file mode 100644 (file)
index 0000000..e64c46c
--- /dev/null
@@ -0,0 +1,5 @@
+# This is a comment
+        r2 += 666 # This is also a comment
+        r3 += -666 /* So is
+this */
+        r4 += 0x7eadbeef // And this
diff --git a/gas/testsuite/gas/bpf/comments.d b/gas/testsuite/gas/bpf/comments.d
new file mode 100644 (file)
index 0000000..49711a3
--- /dev/null
@@ -0,0 +1,12 @@
+#as: -EL -mdialect=normal
+#objdump: -dr -M hex
+#name: BPF assembler comments
+
+.*: +file format .*bpf.*
+
+Disassembly of section .text:
+
+[0-9a-f]+ <.*>:
+   0:  07 02 00 00 9a 02 00 00         add %r2,0x29a
+   8:  07 03 00 00 66 fd ff ff         add %r3,0xfffffd66
+  10:  07 04 00 00 ef be ad 7e         add %r4,0x7eadbeef
diff --git a/gas/testsuite/gas/bpf/comments.s b/gas/testsuite/gas/bpf/comments.s
new file mode 100644 (file)
index 0000000..d06fb4f
--- /dev/null
@@ -0,0 +1,5 @@
+# This is a comment
+        add %r2, 666 # This is also a comment
+        add %r3, -666 /* So is
+this */
+        add %r4, 0x7eadbeef // And this