diff options
author | Nicolai Haehnle <nhaehnle@gmail.com> | 2018-03-19 14:13:54 +0000 |
---|---|---|
committer | Nicolai Haehnle <nhaehnle@gmail.com> | 2018-03-19 14:13:54 +0000 |
commit | 1eaebc62d75b0e59a752228f9766bb5acd9f4b62 (patch) | |
tree | 42708d5c7d108f980e7376b7d5f9b3c9bafa62a2 /llvm/lib/TableGen | |
parent | c47fe129cb3f4e775b903370f3e001ae656520aa (diff) | |
download | bcm5719-llvm-1eaebc62d75b0e59a752228f9766bb5acd9f4b62.tar.gz bcm5719-llvm-1eaebc62d75b0e59a752228f9766bb5acd9f4b62.zip |
TableGen: Move GenStrConcat to a helper function in BinOpInit
Summary:
Make it accessible for more users.
Change-Id: Ib05f09ba14e7942ced5d2f24b205efa285e40cd5
Reviewers: arsenm, craig.topper, tra, MartinO
Subscribers: wdng, llvm-commits
Differential Revision: https://reviews.llvm.org/D44196
llvm-svn: 327845
Diffstat (limited to 'llvm/lib/TableGen')
-rw-r--r-- | llvm/lib/TableGen/Record.cpp | 27 | ||||
-rw-r--r-- | llvm/lib/TableGen/TGParser.cpp | 14 |
2 files changed, 19 insertions, 22 deletions
diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp index 3bc398ff2d3..e76f2a05a48 100644 --- a/llvm/lib/TableGen/Record.cpp +++ b/llvm/lib/TableGen/Record.cpp @@ -816,6 +816,14 @@ static StringInit *ConcatStringInits(const StringInit *I0, return StringInit::get(Concat); } +Init *BinOpInit::getStrConcat(Init *I0, Init *I1) { + // Shortcut for the common case of concatenating two strings. + if (const StringInit *I0s = dyn_cast<StringInit>(I0)) + if (const StringInit *I1s = dyn_cast<StringInit>(I1)) + return ConcatStringInits(I0s, I1s); + return BinOpInit::get(BinOpInit::STRCONCAT, I0, I1, StringRecTy::get()); +} + Init *BinOpInit::Fold(Record *CurRec) const { switch (getOpcode()) { case CONCAT: { @@ -2148,22 +2156,15 @@ RecordKeeper::getAllDerivedDefinitions(StringRef ClassName) const { return Defs; } -static Init *GetStrConcat(Init *I0, Init *I1) { - // Shortcut for the common case of concatenating two strings. - if (const StringInit *I0s = dyn_cast<StringInit>(I0)) - if (const StringInit *I1s = dyn_cast<StringInit>(I1)) - return ConcatStringInits(I0s, I1s); - return BinOpInit::get(BinOpInit::STRCONCAT, I0, I1, StringRecTy::get()); -} - Init *llvm::QualifyName(Record &CurRec, MultiClass *CurMultiClass, Init *Name, StringRef Scoper) { - Init *NewName = GetStrConcat(CurRec.getNameInit(), StringInit::get(Scoper)); - NewName = GetStrConcat(NewName, Name); + Init *NewName = + BinOpInit::getStrConcat(CurRec.getNameInit(), StringInit::get(Scoper)); + NewName = BinOpInit::getStrConcat(NewName, Name); if (CurMultiClass && Scoper != "::") { - Init *Prefix = GetStrConcat(CurMultiClass->Rec.getNameInit(), - StringInit::get("::")); - NewName = GetStrConcat(Prefix, NewName); + Init *Prefix = BinOpInit::getStrConcat(CurMultiClass->Rec.getNameInit(), + StringInit::get("::")); + NewName = BinOpInit::getStrConcat(Prefix, NewName); } if (BinOpInit *BinOp = dyn_cast<BinOpInit>(NewName)) diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp index 4a4a510eefe..5f19d55e9e8 100644 --- a/llvm/lib/TableGen/TGParser.cpp +++ b/llvm/lib/TableGen/TGParser.cpp @@ -1994,9 +1994,7 @@ Init *TGParser::ParseValue(Record *CurRec, RecTy *ItemType, IDParseMode Mode) { break; } - Result = - BinOpInit::get(BinOpInit::STRCONCAT, LHS, RHS, StringRecTy::get()) - ->Fold(CurRec); + Result = BinOpInit::getStrConcat(LHS, RHS); break; } } @@ -2831,12 +2829,10 @@ Record *TGParser::InstantiateMulticlassDef(MultiClass &MC, Record *DefProto, if (DefNameString) { // We have a fully expanded string so there are no operators to // resolve. We should concatenate the given prefix and name. - DefName = BinOpInit::get( - BinOpInit::STRCONCAT, - UnOpInit::get(UnOpInit::CAST, DefmPrefix, StringRecTy::get()) - ->Fold(DefProto), - DefName, StringRecTy::get()) - ->Fold(DefProto); + DefName = BinOpInit::getStrConcat( + UnOpInit::get(UnOpInit::CAST, DefmPrefix, StringRecTy::get()) + ->Fold(DefProto), + DefName); } // Make a trail of SMLocs from the multiclass instantiations. |