[PATCH] D68453: TableGen: Allow 'a+b' in TableGen language
Javed Absar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 16 14:59:04 PDT 2019
javed.absar updated this revision to Diff 225313.
javed.absar marked an inline comment as done.
javed.absar added a comment.
updated based on review comments
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D68453/new/
https://reviews.llvm.org/D68453
Files:
llvm/lib/TableGen/TGParser.cpp
llvm/test/TableGen/infix-add.td
Index: llvm/test/TableGen/infix-add.td
===================================================================
--- /dev/null
+++ llvm/test/TableGen/infix-add.td
@@ -0,0 +1,28 @@
+// RUN: llvm-tblgen %s | FileCheck %s
+// XFAIL: vg_leak
+
+class Int<int v> {
+ int Val = v;
+}
+
+// CHECK: def AA1 {
+// CHECK-NEXT: int Val = 1;
+// CHECK: def AB1 {
+// CHECK-NEXT: int Val = 11;
+foreach Index = 1-1 in {
+ def AA#Index : Int<Index>;
+ def AB#Index : Int<Index + 10>;
+}
+
+
+// CHECK: def I20 {
+// CHECK-NEXT : int Val = 20;
+def I20 : Int<20>;
+
+// CHECK: def I21 {
+// CHECK-NEXT : int Val = 21;
+def I21 : Int<!if(!eq(I20.Val,20), I20.Val + 1, 22)>;
+
+// CHECK: def I300 {
+// CHECK-NEXT: int Val = 300;
+def I300 : Int<155 + 145>;
Index: llvm/lib/TableGen/TGParser.cpp
===================================================================
--- llvm/lib/TableGen/TGParser.cpp
+++ llvm/lib/TableGen/TGParser.cpp
@@ -2100,6 +2100,7 @@
/// ValueSuffix ::= '{' BitList '}'
/// ValueSuffix ::= '[' BitList ']'
/// ValueSuffix ::= '.' ID
+/// ValueSuffix ::= '+' SimpleValue
///
Init *TGParser::ParseValue(Record *CurRec, RecTy *ItemType, IDParseMode Mode) {
Init *Result = ParseSimpleValue(CurRec, ItemType, Mode);
@@ -2173,6 +2174,28 @@
break;
}
+ case tgtok::plus: {
+ SMLoc PlusLoc = Lex.getLoc();
+
+ TypedInit *LHSt = dyn_cast<TypedInit>(Result);
+ if (!LHSt) {
+ Error(PlusLoc, "LHS of '+' is not typed!");
+ return nullptr;
+ }
+ Lex.Lex(); // Eat the '+'
+ Init *RHS = ParseValue(CurRec, ItemType, ParseNameMode);
+ TypedInit *RHSt = dyn_cast<TypedInit>(RHS);
+ if (!RHSt) {
+ Error(PlusLoc, "RHS of '+' is not typed!");
+ return nullptr;
+ }
+
+ RecTy *ResolvedTy = resolveTypes(LHSt->getType(), RHSt->getType());
+ Result = BinOpInit::get(BinOpInit::ADD, LHSt, RHSt,
+ ResolvedTy)->Fold(CurRec);
+ break;
+ }
+
case tgtok::paste:
SMLoc PasteLoc = Lex.getLoc();
TypedInit *LHS = dyn_cast<TypedInit>(Result);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68453.225313.patch
Type: text/x-patch
Size: 2097 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191016/39688b85/attachment.bin>
More information about the llvm-commits
mailing list