summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorDavid Greene <greened@obbligato.org>2011-10-19 13:04:13 +0000
committerDavid Greene <greened@obbligato.org>2011-10-19 13:04:13 +0000
commitd699161a997082c4cc8e57ddd712eb8bdb68722c (patch)
treee5f9f948817e7e38a9a6416f3fb627109d4f9f15 /llvm
parent7b6e641144d8ef95f3b38e1c8146930075ef4c7d (diff)
downloadbcm5719-llvm-d699161a997082c4cc8e57ddd712eb8bdb68722c.tar.gz
bcm5719-llvm-d699161a997082c4cc8e57ddd712eb8bdb68722c.zip
Add NAME Member
Add a Value named "NAME" to each Record. This will be set to the def or defm name when instantiating multiclasses. This will replace the #NAME# processing hack once paste functionality is in place. llvm-svn: 142518
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/TableGen/Record.h7
-rw-r--r--llvm/lib/TableGen/Record.cpp5
-rw-r--r--llvm/lib/TableGen/TGParser.cpp2
-rw-r--r--llvm/test/TableGen/Dag.td2
-rw-r--r--llvm/test/TableGen/foreach.td2
5 files changed, 16 insertions, 2 deletions
diff --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h
index f7a48c4dfbd..0cf1725a981 100644
--- a/llvm/include/llvm/TableGen/Record.h
+++ b/llvm/include/llvm/TableGen/Record.h
@@ -1473,6 +1473,13 @@ public:
void addValue(const RecordVal &RV) {
assert(getValue(RV.getName()) == 0 && "Value already added!");
Values.push_back(RV);
+ if (Values.size() > 1)
+ // Keep NAME at the end of the list. It makes record dumps a
+ // bit prettier and allows TableGen tests to be written more
+ // naturally. Tests can use CHECK-NEXT to look for Record
+ // fields they expect to see after a def. They can't do that if
+ // NAME is the first Record field.
+ std::swap(Values[Values.size() - 2], Values[Values.size() - 1]);
}
void removeValue(Init *Name) {
diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp
index a22c80c5e2e..92559d15b5f 100644
--- a/llvm/lib/TableGen/Record.cpp
+++ b/llvm/lib/TableGen/Record.cpp
@@ -1686,6 +1686,11 @@ unsigned Record::LastID = 0;
void Record::init() {
checkName();
+
+ // Every record potentially has a def at the top. This value is
+ // replaced with the top-level def name at instantiation time.
+ RecordVal DN("NAME", StringRecTy::get(), 0);
+ addValue(DN);
}
void Record::checkName() {
diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp
index 45625f98d98..085136d4815 100644
--- a/llvm/lib/TableGen/TGParser.cpp
+++ b/llvm/lib/TableGen/TGParser.cpp
@@ -1744,7 +1744,7 @@ bool TGParser::ParseClass() {
Record *CurRec = Records.getClass(Lex.getCurStrVal());
if (CurRec) {
// If the body was previously defined, this is an error.
- if (!CurRec->getValues().empty() ||
+ if (CurRec->getValues().size() > 1 || // Account for NAME.
!CurRec->getSuperClasses().empty() ||
!CurRec->getTemplateArgs().empty())
return TokError("Class '" + CurRec->getNameInitAsString()
diff --git a/llvm/test/TableGen/Dag.td b/llvm/test/TableGen/Dag.td
index 9ed2301cef0..7ceb4e74b2f 100644
--- a/llvm/test/TableGen/Dag.td
+++ b/llvm/test/TableGen/Dag.td
@@ -60,6 +60,7 @@ def VAL3 : bar<foo1, somedef1>;
// CHECK-NEXT: dag Dag1 = (somedef1 1);
// CHECK-NEXT: dag Dag2 = (somedef1 2);
// CHECK-NEXT: dag Dag3 = (somedef1 2);
+// CHECK-NEXT: NAME = ?
// CHECK-NEXT: }
@@ -68,4 +69,5 @@ def VAL4 : bar<foo2, somedef2>;
// CHECK-NEXT: dag Dag1 = (somedef1 1);
// CHECK-NEXT: dag Dag2 = (somedef2 2);
// CHECK-NEXT: dag Dag3 = (somedef2 2);
+// CHECK-NEXT: NAME = ?
// CHECK-NEXT: }
diff --git a/llvm/test/TableGen/foreach.td b/llvm/test/TableGen/foreach.td
index cbcade921b9..814ae6ef936 100644
--- a/llvm/test/TableGen/foreach.td
+++ b/llvm/test/TableGen/foreach.td
@@ -1,6 +1,6 @@
// RUN: llvm-tblgen %s | grep {Jr} | count 2
// RUN: llvm-tblgen %s | grep {Sr} | count 2
-// RUN: llvm-tblgen %s | grep {NAME} | count 1
+// RUN: llvm-tblgen %s | grep {"NAME"} | count 1
// XFAIL: vg_leak
// Variables for foreach
OpenPOWER on IntegriCloud