summaryrefslogtreecommitdiffstats
path: root/llvm/lib/TableGen/Record.cpp
diff options
context:
space:
mode:
authorTim Northover <tnorthover@apple.com>2016-07-05 21:22:55 +0000
committerTim Northover <tnorthover@apple.com>2016-07-05 21:22:55 +0000
commit88403d7a840f09395e45bb1e0a757cf8362beb5a (patch)
tree656c9a9ac1091389bf9493905c7b7925fdd8279a /llvm/lib/TableGen/Record.cpp
parentaaa0191be6643ad815b756877b37af50ee6e39cb (diff)
downloadbcm5719-llvm-88403d7a840f09395e45bb1e0a757cf8362beb5a.tar.gz
bcm5719-llvm-88403d7a840f09395e45bb1e0a757cf8362beb5a.zip
TableGen: promote "code" type from syntactic sugar.
It's being immediately converted to a "string", but being able to tell what type the field was originally can be useful in backends. llvm-svn: 274575
Diffstat (limited to 'llvm/lib/TableGen/Record.cpp')
-rw-r--r--llvm/lib/TableGen/Record.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp
index c98c5d3f0d7..9ee77816744 100644
--- a/llvm/lib/TableGen/Record.cpp
+++ b/llvm/lib/TableGen/Record.cpp
@@ -82,6 +82,7 @@ template<> struct DenseMapInfo<TableGenStringKey> {
//===----------------------------------------------------------------------===//
BitRecTy BitRecTy::Shared;
+CodeRecTy CodeRecTy::Shared;
IntRecTy IntRecTy::Shared;
StringRecTy StringRecTy::Shared;
DagRecTy DagRecTy::Shared;
@@ -453,6 +454,14 @@ IntInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) const {
return BitsInit::get(NewBits);
}
+CodeInit *CodeInit::get(StringRef V) {
+ static StringMap<std::unique_ptr<CodeInit>> ThePool;
+
+ std::unique_ptr<CodeInit> &I = ThePool[V];
+ if (!I) I.reset(new CodeInit(V));
+ return I.get();
+}
+
StringInit *StringInit::get(StringRef V) {
static StringMap<std::unique_ptr<StringInit>> ThePool;
@@ -468,6 +477,13 @@ Init *StringInit::convertInitializerTo(RecTy *Ty) const {
return nullptr;
}
+Init *CodeInit::convertInitializerTo(RecTy *Ty) const {
+ if (isa<CodeRecTy>(Ty))
+ return const_cast<CodeInit *>(this);
+
+ return nullptr;
+}
+
static void ProfileListInit(FoldingSetNodeID &ID,
ArrayRef<Init *> Range,
RecTy *EltTy) {
@@ -1158,6 +1174,12 @@ TypedInit::convertInitializerTo(RecTy *Ty) const {
return nullptr;
}
+ if (isa<CodeRecTy>(Ty)) {
+ if (isa<CodeRecTy>(getType()))
+ return const_cast<TypedInit *>(this);
+ return nullptr;
+ }
+
if (isa<BitRecTy>(Ty)) {
// Accept variable if it is already of bit type!
if (isa<BitRecTy>(getType()))
@@ -1744,6 +1766,9 @@ std::string Record::getValueAsString(StringRef FieldName) const {
if (StringInit *SI = dyn_cast<StringInit>(R->getValue()))
return SI->getValue();
+ if (CodeInit *CI = dyn_cast<CodeInit>(R->getValue()))
+ return CI->getValue();
+
PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
FieldName + "' does not have a string initializer!");
}
OpenPOWER on IntegriCloud