From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1861) id 6239D3858C56; Thu, 30 Nov 2023 07:49:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6239D3858C56 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Jose E. Marchesi To: bfd-cvs@sourceware.org Subject: [binutils-gdb] gas: support double-slash line comments in BPF assembly X-Act-Checkin: binutils-gdb X-Git-Author: Jose E. Marchesi X-Git-Refname: refs/heads/master X-Git-Oldrev: 0e78c95c497487aee110dbfc7ca2417b6b2e522d X-Git-Newrev: dd2947e76aa285a12aa26de63a59f5fb8092ef82 Message-Id: <20231130074953.6239D3858C56@sourceware.org> Date: Thu, 30 Nov 2023 07:49:53 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Nov 2023 07:49:53 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Ddd2947e76aa2= 85a12aa26de63a59f5fb8092ef82 commit dd2947e76aa285a12aa26de63a59f5fb8092ef82 Author: Jose E. Marchesi Date: Thu Nov 30 08:34:09 2023 +0100 gas: support double-slash line comments in BPF assembly =20 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: =20 - Line comments preceded by # or //. - Non-nestable block comments delimited by /* and */. =20 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. Diff: --- gas/ChangeLog | 11 +++++++++++ gas/NEWS | 3 +++ gas/config/tc-bpf.h | 3 +++ gas/doc/c-bpf.texi | 4 ++-- gas/testsuite/gas/bpf/bpf.exp | 4 ++++ gas/testsuite/gas/bpf/comments-pseudoc.d | 12 ++++++++++++ gas/testsuite/gas/bpf/comments-pseudoc.s | 5 +++++ gas/testsuite/gas/bpf/comments.d | 12 ++++++++++++ gas/testsuite/gas/bpf/comments.s | 5 +++++ 9 files changed, 57 insertions(+), 2 deletions(-) diff --git a/gas/ChangeLog b/gas/ChangeLog index 3d5cfcae58c..b1a568cc334 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,14 @@ +2023-11-30 Jose E. Marchesi + + * 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 =20 * NEWS: Add entry about change of comment syntax in the BPF diff --git a/gas/NEWS b/gas/NEWS index 6bfab08c5b8..143d9c836e5 100644 --- a/gas/NEWS +++ b/gas/NEWS @@ -41,6 +41,9 @@ therefore they cannot longer be used to begin line comments. This matche= s the behavior of the clang/LLVM BPF assembler. =20 +* The BPF assembler now allows using both hash (#) and double slash (//) to + begin line comments. + Changes in 2.41: =20 * Add support for the KVX instruction set. diff --git a/gas/config/tc-bpf.h b/gas/config/tc-bpf.h index 06096ef5926..91f3c1574b1 100644 --- a/gas/config/tc-bpf.h +++ b/gas/config/tc-bpf.h @@ -35,6 +35,9 @@ #define TARGET_BYTES_BIG_ENDIAN 0 #endif =20 +/* Permit // comments. */ +#define DOUBLESLASH_LINE_COMMENTS 1 + /* .-foo gets turned into PC relative relocs. */ #define DIFF_EXPR_OK 1 =20 diff --git a/gas/doc/c-bpf.texi b/gas/doc/c-bpf.texi index 7ff07e91764..307d28be942 100644 --- a/gas/doc/c-bpf.texi +++ b/gas/doc/c-bpf.texi @@ -68,8 +68,8 @@ the host endianness is used. =20 @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. =20 @cindex block comments, BPF @cindex BPF block comments diff --git a/gas/testsuite/gas/bpf/bpf.exp b/gas/testsuite/gas/bpf/bpf.exp index 5bcd8c483a0..5048693cec8 100644 --- a/gas/testsuite/gas/bpf/bpf.exp +++ b/gas/testsuite/gas/bpf/bpf.exp @@ -18,6 +18,10 @@ # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-130= 1, USA. =20 =20 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/b= pf/comments-pseudoc.d new file mode 100644 index 00000000000..6fc68e01e86 --- /dev/null +++ b/gas/testsuite/gas/bpf/comments-pseudoc.d @@ -0,0 +1,12 @@ +#as: -EL -mdialect=3Dpseudoc +#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/b= pf/comments-pseudoc.s new file mode 100644 index 00000000000..e64c46c2e6f --- /dev/null +++ b/gas/testsuite/gas/bpf/comments-pseudoc.s @@ -0,0 +1,5 @@ +# This is a comment + r2 +=3D 666 # This is also a comment + r3 +=3D -666 /* So is +this */ + r4 +=3D 0x7eadbeef // And this diff --git a/gas/testsuite/gas/bpf/comments.d b/gas/testsuite/gas/bpf/comme= nts.d new file mode 100644 index 00000000000..49711a3f07a --- /dev/null +++ b/gas/testsuite/gas/bpf/comments.d @@ -0,0 +1,12 @@ +#as: -EL -mdialect=3Dnormal +#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/comme= nts.s new file mode 100644 index 00000000000..d06fb4f9e54 --- /dev/null +++ b/gas/testsuite/gas/bpf/comments.s @@ -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