[llvm] [TableGen][Docs] Fix grammar for bits literals (PR #124958)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 29 09:40:53 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-tablegen
Author: Jay Foad (jayfoad)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/124958.diff
1 Files Affected:
- (modified) llvm/docs/TableGen/ProgRef.rst (+10-4)
``````````diff
diff --git a/llvm/docs/TableGen/ProgRef.rst b/llvm/docs/TableGen/ProgRef.rst
index cfe61382658ec47..26f058e16fb6cc3 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.
``````````
</details>
https://github.com/llvm/llvm-project/pull/124958
More information about the llvm-commits
mailing list