[llvm] [TableGen][Docs] Accept "code" as a Type (PR #124902)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 29 02:03:39 PST 2025
https://github.com/jayfoad created https://github.com/llvm/llvm-project/pull/124902
Previously the Type production did not include "code", which was only
accepted in one place in the grammar:
BodyItem: (`Type` | "code") `TokIdentifier` ["=" `Value`] ";"
However the parser implementation accepts "code" as a Type with only one
place where it is *not* allowed, corresponding to this production:
SimpleValue9: `BangOperator` ["<" `Type` ">"] "(" `ValueListNE` ")"
This patch changes the production for Type to include "code", thereby
fixing most occurrences of Type in the grammar, and documents the
restriction for BangOperator Types in the text instead of codifying it
in the grammar.
>From 1c3a3dbc7008056b458901157280b14e08e44478 Mon Sep 17 00:00:00 2001
From: Jay Foad <jay.foad at amd.com>
Date: Wed, 29 Jan 2025 07:53:05 +0000
Subject: [PATCH] [TableGen][Docs] Accept "code" as a Type
Previously the Type production did not include "code", which was only
accepted in one place in the grammar:
BodyItem: (`Type` | "code") `TokIdentifier` ["=" `Value`] ";"
However the parser implementation accepts "code" as a Type with only one
place where it is *not* allowed, corresponding to this production:
SimpleValue9: `BangOperator` ["<" `Type` ">"] "(" `ValueListNE` ")"
This patch changes the production for Type to include "code", thereby
fixing most occurrences of Type in the grammar, and documents the
restriction for BangOperator Types in the text instead of codifying it
in the grammar.
---
llvm/docs/TableGen/ProgRef.rst | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/llvm/docs/TableGen/ProgRef.rst b/llvm/docs/TableGen/ProgRef.rst
index cfe61382658ec4..f26056475162fd 100644
--- a/llvm/docs/TableGen/ProgRef.rst
+++ b/llvm/docs/TableGen/ProgRef.rst
@@ -268,7 +268,7 @@ high-level types (e.g., ``dag``). This flexibility allows you to describe a
wide range of records conveniently and compactly.
.. productionlist::
- Type: "bit" | "int" | "string" | "dag"
+ Type: "bit" | "int" | "string" | "dag" | "code"
:| "bits" "<" `TokInteger` ">"
:| "list" "<" `Type` ">"
:| `ClassID`
@@ -285,6 +285,10 @@ wide range of records conveniently and compactly.
The ``string`` type represents an ordered sequence of characters of arbitrary
length.
+``code``
+ The keyword ``code`` is an alias for ``string`` which may be used to
+ indicate string values that are code.
+
``bits<``\ *n*\ ``>``
The ``bits`` type is a fixed-sized integer of arbitrary length *n* that
is treated as separate bits. These bits can be accessed individually.
@@ -498,6 +502,8 @@ arguments, producing a value for that bang operator. The ``!cond`` operator
takes a list of pairs of arguments separated by colons. See `Appendix A:
Bang Operators`_ for a description of each bang operator.
+The `Type` is only accepted for certain bang operators, and must not be
+``code``.
Suffixed values
---------------
@@ -670,7 +676,7 @@ arguments.
.. productionlist::
Body: ";" | "{" `BodyItem`* "}"
- BodyItem: (`Type` | "code") `TokIdentifier` ["=" `Value`] ";"
+ BodyItem: `Type` `TokIdentifier` ["=" `Value`] ";"
:| "let" `TokIdentifier` ["{" `RangeList` "}"] "=" `Value` ";"
:| "defvar" `TokIdentifier` "=" `Value` ";"
:| `Assert`
@@ -678,8 +684,7 @@ arguments.
A field definition in the body specifies a field to be included in the class
or record. If no initial value is specified, then the field's value is
uninitialized. The type must be specified; TableGen will not infer it from
-the value. The keyword ``code`` may be used to emphasize that the field
-has a string value that is code.
+the value.
The ``let`` form is used to reset a field to a new value. This can be done
for fields defined directly in the body or fields inherited from parent
More information about the llvm-commits
mailing list