From: David Greene Date: Wed, 19 Oct 2011 13:02:33 +0000 (+0000) Subject: Make VarInit Name an Init X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=ee6dca17252de152720655282fb4b74b76fb2fe9;p=oota-llvm.git Make VarInit Name an Init Make the VarInit name an Init itself. We need this to implement paste functionality so we can reference variables whose names are not yet completely resolved. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142497 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/TableGen/Record.h b/include/llvm/TableGen/Record.h index 4502aa72a73..47d4f7f2cea 100644 --- a/include/llvm/TableGen/Record.h +++ b/include/llvm/TableGen/Record.h @@ -1058,9 +1058,11 @@ public: /// VarInit - 'Opcode' - Represent a reference to an entire variable object. /// class VarInit : public TypedInit { - std::string VarName; + Init *VarName; explicit VarInit(const std::string &VN, RecTy *T) + : TypedInit(T), VarName(StringInit::get(VN)) {} + explicit VarInit(Init *VN, RecTy *T) : TypedInit(T), VarName(VN) {} VarInit(const VarInit &Other); // Do not define. @@ -1074,7 +1076,11 @@ public: return Ty->convertValue(const_cast(this)); } - const std::string &getName() const { return VarName; } + const std::string &getName() const; + Init *getNameInit() const { return VarName; } + std::string getNameInitAsString() const { + return getNameInit()->getAsUnquotedString(); + } virtual Init *resolveBitReference(Record &R, const RecordVal *RV, unsigned Bit) const; @@ -1092,7 +1098,7 @@ public: /// virtual Init *resolveReferences(Record &R, const RecordVal *RV) const; - virtual std::string getAsString() const { return VarName; } + virtual std::string getAsString() const { return getName(); } }; diff --git a/lib/TableGen/Record.cpp b/lib/TableGen/Record.cpp index 06a41c9eb26..64975e46564 100644 --- a/lib/TableGen/Record.cpp +++ b/lib/TableGen/Record.cpp @@ -1298,7 +1298,12 @@ TypedInit::convertInitListSlice(const std::vector &Elements) const { VarInit *VarInit::get(const std::string &VN, RecTy *T) { - typedef std::pair Key; + Init *Value = StringInit::get(VN); + return VarInit::get(Value, T); +} + +VarInit *VarInit::get(Init *VN, RecTy *T) { + typedef std::pair Key; typedef DenseMap Pool; static Pool ThePool; @@ -1309,6 +1314,13 @@ VarInit *VarInit::get(const std::string &VN, RecTy *T) { return I; } +const std::string &VarInit::getName() const { + StringInit *NameString = + dynamic_cast(getNameInit()); + assert(NameString && "VarInit name is not a string!"); + return NameString->getValue(); +} + Init *VarInit::resolveBitReference(Record &R, const RecordVal *IRV, unsigned Bit) const { if (R.isTemplateArg(getName())) return 0;