[llvm] [TableGen][Docs] Fix grammar for bits literals (PR #124958)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 29 09:39:56 PST 2025


https://github.com/jayfoad created https://github.com/llvm/llvm-project/pull/124958

Previsouly the grammar for bits literals (written as binary integers
like `0b0101`) made them a kind of TokInteger, but this does not reflect
how they work in reality:

- They have a different type from other integers, `bits<n>` instead of
  `int`.
- The parser does not accept them in most places where an integer is
  accepted, only as a kind of `SimpleValue`.

This patch splits them out into a new `TokBits` token and updates
`SimpleValue` accordingly.


>From ce489324ad80706f73e3770751794539c8f0b30d Mon Sep 17 00:00:00 2001
From: Jay Foad <jay.foad at amd.com>
Date: Wed, 29 Jan 2025 17:31:13 +0000
Subject: [PATCH] [TableGen][Docs] Fix grammar for bits literals

Previsouly the grammar for bits literals (written as binary integers
like `0b0101`) made them a kind of TokInteger, but this does not reflect
how they work in reality:

- They have a different type from other integers, `bits<n>` instead of
  `int`.
- The parser does not accept them in most places where an integer is
  accepted, only as a kind of `SimpleValue`.

This patch splits them out into a new `TokBits` token and updates
`SimpleValue` accordingly.
---
 llvm/docs/TableGen/ProgRef.rst | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/llvm/docs/TableGen/ProgRef.rst b/llvm/docs/TableGen/ProgRef.rst
index cfe61382658ec4..26f058e16fb6cc 100644
--- a/llvm/docs/TableGen/ProgRef.rst
+++ b/llvm/docs/TableGen/ProgRef.rst
@@ -161,15 +161,20 @@ Literals
 Numeric literals take one of the following forms:
 
 .. productionlist::
-   TokInteger: `DecimalInteger` | `HexInteger` | `BinInteger`
+   TokInteger: `DecimalInteger` | `HexInteger`
    DecimalInteger: ["+" | "-"] ("0"..."9")+
    HexInteger: "0x" ("0"..."9" | "a"..."f" | "A"..."F")+
-   BinInteger: "0b" ("0" | "1")+
 
 Observe that the :token:`DecimalInteger` token includes the optional ``+``
 or ``-`` sign, unlike most languages where the sign would be treated as a
 unary operator.
 
+A bits literal is written as a binary integer where the number of digits is
+significant and forms part of its type:
+
+.. productionlist::
+   TokBits: "0b" ("0" | "1")+
+
 TableGen has two kinds of string literals:
 
 .. productionlist::
@@ -363,9 +368,10 @@ Simple values
 The :token:`SimpleValue` has a number of forms.
 
 .. productionlist::
-   SimpleValue: `TokInteger` | `TokString`+ | `TokCode`
+   SimpleValue: `TokInteger` | `TokBits` | `TokString`+ | `TokCode`
 
-A value can be an integer literal, a string literal, or a code literal.
+A value can be an integer literal, a bits literal, a string literal, or a code
+literal.
 Multiple adjacent string literals are concatenated as in C/C++; the simple
 value is the concatenation of the strings. Code literals become strings and
 are then indistinguishable from them.



More information about the llvm-commits mailing list