[llvm] 196e6f9 - Replace TableGen range piece punctuator with '...'
Nicolai Hähnle via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 21 14:34:07 PDT 2020
Author: Paul C. Anagnostopoulos
Date: 2020-08-21T23:33:57+02:00
New Revision: 196e6f9f18933ed33eee39a1c9350ccce6b18e2c
URL: https://github.com/llvm/llvm-project/commit/196e6f9f18933ed33eee39a1c9350ccce6b18e2c
DIFF: https://github.com/llvm/llvm-project/commit/196e6f9f18933ed33eee39a1c9350ccce6b18e2c.diff
LOG: Replace TableGen range piece punctuator with '...'
The TableGen range piece punctuator is currently '-' (e.g., {0-9}),
which interacts oddly with the fact that an integer literal's sign
is part of the literal. This patch replaces the '-' with the new
punctuator '...'. The '-' punctuator is deprecated.
Differential Revision: https://reviews.llvm.org/D85585
Change-Id: I3d53d14e23f878b142d8f84590dd465a0fb6c09c
Added:
llvm/test/TableGen/range-lists.td
Modified:
llvm/docs/ReleaseNotes.rst
llvm/docs/TableGen/ProgRef.rst
llvm/lib/TableGen/TGLexer.cpp
llvm/lib/TableGen/TGLexer.h
llvm/lib/TableGen/TGParser.cpp
Removed:
################################################################################
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index a939a4af43c1..2a2775f13dd1 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -65,6 +65,14 @@ Changes to the LLVM IR
Changes to building LLVM
------------------------
+Changes to TableGen
+-------------------
+
+* The syntax for specifying an integer range in a range list has changed.
+ The old syntax used a hyphen in the range (e.g., ``{0-9}``). The new syntax
+ uses the "`...`" range punctuator (e.g., ``{0...9}``). The hyphen syntax
+ is deprecated. The "TableGen Language Reference" document has been updated.
+
Changes to the ARM Backend
--------------------------
diff --git a/llvm/docs/TableGen/ProgRef.rst b/llvm/docs/TableGen/ProgRef.rst
index e331585510d4..83684ab41c28 100644
--- a/llvm/docs/TableGen/ProgRef.rst
+++ b/llvm/docs/TableGen/ProgRef.rst
@@ -321,7 +321,7 @@ to an entity of type ``bits<4>``.
:| "." `TokIdentifier`
RangeList: `RangePiece` ("," `RangePiece`)*
RangePiece: `TokInteger`
- :| `TokInteger` ".." `TokInteger`
+ :| `TokInteger` "..." `TokInteger`
:| `TokInteger` "-" `TokInteger`
:| `TokInteger` `TokInteger`
diff --git a/llvm/lib/TableGen/TGLexer.cpp b/llvm/lib/TableGen/TGLexer.cpp
index 9e6cc947925d..d9111f0068c2 100644
--- a/llvm/lib/TableGen/TGLexer.cpp
+++ b/llvm/lib/TableGen/TGLexer.cpp
@@ -161,7 +161,6 @@ tgtok::TokKind TGLexer::LexToken(bool FileOrLineStart) {
case ':': return tgtok::colon;
case ';': return tgtok::semi;
- case '.': return tgtok::period;
case ',': return tgtok::comma;
case '<': return tgtok::less;
case '>': return tgtok::greater;
@@ -181,6 +180,19 @@ tgtok::TokKind TGLexer::LexToken(bool FileOrLineStart) {
return tgtok::paste;
+ // The period is a separate case so we can recognize the "..."
+ // range punctuator.
+ case '.':
+ if (peekNextChar(0) == '.') {
+ ++CurPtr; // Eat second dot.
+ if (peekNextChar(0) == '.') {
+ ++CurPtr; // Eat third dot.
+ return tgtok::dotdotdot;
+ }
+ return ReturnError(TokStart, "Invalid '..' punctuation");
+ }
+ return tgtok::dot;
+
case '\r':
PrintFatalError("getNextChar() must never return '\r'");
return tgtok::Error;
diff --git a/llvm/lib/TableGen/TGLexer.h b/llvm/lib/TableGen/TGLexer.h
index 5b3b0a44e3ef..49f37890043f 100644
--- a/llvm/lib/TableGen/TGLexer.h
+++ b/llvm/lib/TableGen/TGLexer.h
@@ -40,9 +40,10 @@ namespace tgtok {
l_paren, r_paren, // ( )
less, greater, // < >
colon, semi, // : ;
- comma, period, // , .
+ comma, dot, // , .
equal, question, // = ?
paste, // #
+ dotdotdot, // ...
// Keywords. ('ElseKW' is named to distinguish it from the existing 'Else'
// that means the preprocessor #else.)
diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp
index 39c29d6108d5..7c6902a9b0fc 100644
--- a/llvm/lib/TableGen/TGParser.cpp
+++ b/llvm/lib/TableGen/TGParser.cpp
@@ -671,8 +671,10 @@ ParseSubMultiClassReference(MultiClass *CurMC) {
/// ParseRangePiece - Parse a bit/value range.
/// RangePiece ::= INTVAL
+/// RangePiece ::= INTVAL '...' INTVAL
/// RangePiece ::= INTVAL '-' INTVAL
-/// RangePiece ::= INTVAL INTVAL
+/// RangePiece ::= INTVAL INTVAL
+// The last two forms are deprecated.
bool TGParser::ParseRangePiece(SmallVectorImpl<unsigned> &Ranges,
TypedInit *FirstItem) {
Init *CurVal = FirstItem;
@@ -693,6 +695,8 @@ bool TGParser::ParseRangePiece(SmallVectorImpl<unsigned> &Ranges,
default:
Ranges.push_back(Start);
return false;
+
+ case tgtok::dotdotdot:
case tgtok::minus: {
Lex.Lex(); // eat
@@ -2167,7 +2171,7 @@ Init *TGParser::ParseValue(Record *CurRec, RecTy *ItemType, IDParseMode Mode) {
}
break;
}
- case tgtok::period: {
+ case tgtok::dot: {
if (Lex.Lex() != tgtok::Id) { // eat the .
TokError("expected field identifier after '.'");
return nullptr;
diff --git a/llvm/test/TableGen/range-lists.td b/llvm/test/TableGen/range-lists.td
new file mode 100644
index 000000000000..82f4338323e5
--- /dev/null
+++ b/llvm/test/TableGen/range-lists.td
@@ -0,0 +1,80 @@
+// RUN: llvm-tblgen %s | FileCheck %s
+// XFAIL: vg_leak
+
+// This file has tests for range lists and range pieces.
+
+// These are tests for bits ranges.
+
+def bit_range_hyphen {
+ bits<16> field1;
+ let field1{15, 14, 13, 12} = {1, 0, 1, 0};
+ let field1{11-8} = {1, 0, 1, 1};
+ let field1{+7-4} = {1, 1, 0, 0};
+ let field1{+3-+0} = {1, 1, 0, 1};
+ bit hyphen_field1_ok = !eq(field1, 0xABCD);
+}
+
+def bit_range_dotdotdot {
+ bits<16> field1;
+ let field1{15, 14, 13, 12} = {1, 0, 1, 0};
+ let field1{11...8} = {1, 0, 1, 1};
+ let field1{+7...4} = {1, 1, 0, 0};
+ let field1{+3...+0} = {1, 1, 0, 1};
+ bit dotdotdot_field1_ok = !eq(field1, 0xABCD);
+}
+
+if !eq(bit_range_hyphen.field1, bit_range_dotdotdot.field1) then
+ def bit_range_ok {}
+else
+ def bit_range_not_ok {}
+
+// These are tests for lists.
+
+def list_range_hyphen {
+ list<string> field1 = ["foo", "bar", "baz", "snork", "quux", "quuux",
+ "bazola", "ztesch", "bletch", "flarp"];
+ list<string> subfielda = field1[0, 1, 2, 3];
+ list<string> subfieldb = field1[4-5];
+ list<string> subfieldc = field1[+6-7];
+ list<string> subfieldd = field1[+8-+9];
+ bit hyphen_subfields_ok = !and(!eq(subfieldb[0], "quux"),
+ !eq(subfieldd[1], "flarp"));
+}
+
+def list_range_dotdotdot {
+ list<string> field1 = ["foo", "bar", "baz", "snork", "quux", "quuux",
+ "bazola", "ztesch", "bletch", "flarp"];
+ list<string> subfielda = field1[0, 1, 2, 3];
+ list<string> subfieldb = field1[4...5];
+ list<string> subfieldc = field1[+6...7];
+ list<string> subfieldd = field1[+8...+9];
+ bit dotdotdot_subfields_ok = !and(!eq(subfieldb[0], "quux"),
+ !eq(subfieldd[1], "flarp"));
+}
+
+if !eq(!head(list_range_hyphen.subfieldd),
+ !head(list_range_dotdotdot.subfieldd)) then
+ def list_range_ok {}
+else
+ def list_range_not_ok {}
+
+// This is a test of foreach.
+
+foreach i = {0-3} in
+ foreach j = {4...5} in
+ def eachrec#i#j {
+ int fi = i;
+ int fj = j;
+ }
+
+//CHECK: bit dotdotdot_field1_ok = 1
+//CHECK: bit hyphen_field1_ok = 1
+//CHECK: def bit_range_ok {
+
+//CHECK: def eachrec04 {
+//CHECK: def eachrec35 {
+
+//CHECK: bit dotdotdot_subfields_ok = 1
+//CHECK: bit hyphen_subfields_ok = 1
+//CHECK: def list_range_ok {
+
More information about the llvm-commits
mailing list