From 88403d7a840f09395e45bb1e0a757cf8362beb5a Mon Sep 17 00:00:00 2001 From: Tim Northover Date: Tue, 5 Jul 2016 21:22:55 +0000 Subject: 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 --- llvm/lib/TableGen/Record.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'llvm/lib/TableGen/Record.cpp') 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 { //===----------------------------------------------------------------------===// BitRecTy BitRecTy::Shared; +CodeRecTy CodeRecTy::Shared; IntRecTy IntRecTy::Shared; StringRecTy StringRecTy::Shared; DagRecTy DagRecTy::Shared; @@ -453,6 +454,14 @@ IntInit::convertInitializerBitRange(const std::vector &Bits) const { return BitsInit::get(NewBits); } +CodeInit *CodeInit::get(StringRef V) { + static StringMap> ThePool; + + std::unique_ptr &I = ThePool[V]; + if (!I) I.reset(new CodeInit(V)); + return I.get(); +} + StringInit *StringInit::get(StringRef V) { static StringMap> ThePool; @@ -468,6 +477,13 @@ Init *StringInit::convertInitializerTo(RecTy *Ty) const { return nullptr; } +Init *CodeInit::convertInitializerTo(RecTy *Ty) const { + if (isa(Ty)) + return const_cast(this); + + return nullptr; +} + static void ProfileListInit(FoldingSetNodeID &ID, ArrayRef Range, RecTy *EltTy) { @@ -1158,6 +1174,12 @@ TypedInit::convertInitializerTo(RecTy *Ty) const { return nullptr; } + if (isa(Ty)) { + if (isa(getType())) + return const_cast(this); + return nullptr; + } + if (isa(Ty)) { // Accept variable if it is already of bit type! if (isa(getType())) @@ -1744,6 +1766,9 @@ std::string Record::getValueAsString(StringRef FieldName) const { if (StringInit *SI = dyn_cast(R->getValue())) return SI->getValue(); + if (CodeInit *CI = dyn_cast(R->getValue())) + return CI->getValue(); + PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + FieldName + "' does not have a string initializer!"); } -- cgit v1.2.3