summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-01-20 02:54:07 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-01-20 02:54:07 +0000
commit8a07e7f657588791d308ebd712c1241edf499dd3 (patch)
tree324666f656d416f75aa406bd5520e814bdd816fe
parenta7477285b92a5e5ffd26143a6678b2f45b2cddff (diff)
downloadbcm5719-llvm-8a07e7f657588791d308ebd712c1241edf499dd3.tar.gz
bcm5719-llvm-8a07e7f657588791d308ebd712c1241edf499dd3.zip
IR: Simplify DIBuilder's HeaderBuilder API, NFC
Change `HeaderBuilder` API to work well even when it's not starting with a tag. There's already one case like this, and the tag is moving elsewhere as part of PR22235. llvm-svn: 226540
-rw-r--r--llvm/lib/IR/DIBuilder.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index eb686aa4bec..c6df3409a47 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -25,15 +25,23 @@ using namespace llvm::dwarf;
namespace {
class HeaderBuilder {
+ /// \brief Whether there are any fields yet.
+ ///
+ /// Note that this is not equivalent to \c Chars.empty(), since \a concat()
+ /// may have been called already with an empty string.
+ bool IsEmpty;
SmallVector<char, 256> Chars;
public:
- explicit HeaderBuilder(Twine T) { T.toVector(Chars); }
+ HeaderBuilder() : IsEmpty(true) {}
HeaderBuilder(const HeaderBuilder &X) : Chars(X.Chars) {}
HeaderBuilder(HeaderBuilder &&X) : Chars(std::move(X.Chars)) {}
template <class Twineable> HeaderBuilder &concat(Twineable &&X) {
- Chars.push_back(0);
+ if (IsEmpty)
+ IsEmpty = false;
+ else
+ Chars.push_back(0);
Twine(X).toVector(Chars);
return *this;
}
@@ -43,7 +51,7 @@ public:
}
static HeaderBuilder get(unsigned Tag) {
- return HeaderBuilder("0x" + Twine::utohexstr(Tag));
+ return HeaderBuilder().concat("0x" + Twine::utohexstr(Tag));
}
};
}
@@ -739,8 +747,10 @@ static HeaderBuilder setTypeFlagsInHeader(StringRef Header,
Flags = 0;
Flags |= FlagsToSet;
- return HeaderBuilder(Twine(I.getPrefix())).concat(Flags).concat(
- I.getSuffix());
+ return HeaderBuilder()
+ .concat(I.getPrefix())
+ .concat(Flags)
+ .concat(I.getSuffix());
}
static DIType createTypeWithFlags(LLVMContext &Context, DIType Ty,
OpenPOWER on IntegriCloud