summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/TableGen/Record.cpp8
-rw-r--r--llvm/test/TableGen/cast-list-initializer.td10
2 files changed, 18 insertions, 0 deletions
diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp
index c9a31b64cfd..271e52567a2 100644
--- a/llvm/lib/TableGen/Record.cpp
+++ b/llvm/lib/TableGen/Record.cpp
@@ -673,6 +673,14 @@ Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
PrintFatalError(CurRec->getLoc(),
"Undefined reference:'" + Name + "'\n");
}
+
+ if (isa<IntRecTy>(getType())) {
+ if (BitsInit *BI = dyn_cast<BitsInit>(LHS)) {
+ if (Init *NewInit = BI->convertInitializerTo(IntRecTy::get()))
+ return NewInit;
+ break;
+ }
+ }
}
break;
}
diff --git a/llvm/test/TableGen/cast-list-initializer.td b/llvm/test/TableGen/cast-list-initializer.td
new file mode 100644
index 00000000000..4c83773a5a7
--- /dev/null
+++ b/llvm/test/TableGen/cast-list-initializer.td
@@ -0,0 +1,10 @@
+// RUN: llvm-tblgen %s | FileCheck %s
+
+class Foo<bits<8> b> {
+// CHECK: list<int> ListOfInts = [170];
+// CHECK: list<int> AnotherList = [170, 7];
+ list<int> ListOfInts = [!cast<int>(b)];
+ list<int> AnotherList = [!cast<int>(b), !cast<int>({1, 1, 1})];
+}
+
+def : Foo<{1, 0, 1, 0, 1, 0, 1, 0}>;
OpenPOWER on IntegriCloud