diff --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h index 47d4f7f2cea6..905126b2b395 100644 --- a/llvm/include/llvm/TableGen/Record.h +++ b/llvm/include/llvm/TableGen/Record.h @@ -1674,6 +1674,16 @@ struct LessRecordFieldName { raw_ostream &operator<<(raw_ostream &OS, const RecordKeeper &RK); +/// QualifyName - Return an Init with a qualifier prefix referring +/// to CurRec's name. +Init *QualifyName(Record &CurRec, MultiClass *CurMultiClass, + Init *Name, const std::string &Scoper); + +/// QualifyName - Return an Init with a qualifier prefix referring +/// to CurRec's name. +Init *QualifyName(Record &CurRec, MultiClass *CurMultiClass, + const std::string &Name, const std::string &Scoper); + } // End llvm namespace #endif diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp index 64975e46564a..a6407ab607b0 100644 --- a/llvm/lib/TableGen/Record.cpp +++ b/llvm/lib/TableGen/Record.cpp @@ -2041,3 +2041,39 @@ RecordKeeper::getAllDerivedDefinitions(const std::string &ClassName) const { return Defs; } +/// QualifyName - Return an Init with a qualifier prefix referring +/// to CurRec's name. +Init *llvm::QualifyName(Record &CurRec, MultiClass *CurMultiClass, + Init *Name, const std::string &Scoper) { + RecTy *Type = dynamic_cast(Name)->getType(); + + BinOpInit *NewName = + BinOpInit::get(BinOpInit::STRCONCAT, + BinOpInit::get(BinOpInit::STRCONCAT, + CurRec.getNameInit(), + StringInit::get(Scoper), + Type)->Fold(&CurRec, CurMultiClass), + Name, + Type); + + if (CurMultiClass && Scoper != "::") { + NewName = + BinOpInit::get(BinOpInit::STRCONCAT, + BinOpInit::get(BinOpInit::STRCONCAT, + CurMultiClass->Rec.getNameInit(), + StringInit::get("::"), + Type)->Fold(&CurRec, CurMultiClass), + NewName->Fold(&CurRec, CurMultiClass), + Type); + } + + return NewName->Fold(&CurRec, CurMultiClass); +} + +/// QualifyName - Return an Init with a qualifier prefix referring +/// to CurRec's name. +Init *llvm::QualifyName(Record &CurRec, MultiClass *CurMultiClass, + const std::string &Name, + const std::string &Scoper) { + return QualifyName(CurRec, CurMultiClass, StringInit::get(Name), Scoper); +}