summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-01-22 03:11:13 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-01-22 03:11:13 +0000
commitc6ed89497355bb7eee03b8061632c6f9c0b06cb5 (patch)
tree3328c28427a79736934ad377bc92d7b4ea52df48
parentde61ebafcfa3445869e223802bc2cd75b08aab60 (diff)
downloadbcm5719-llvm-c6ed89497355bb7eee03b8061632c6f9c0b06cb5.tar.gz
bcm5719-llvm-c6ed89497355bb7eee03b8061632c6f9c0b06cb5.zip
DIBuilder: Extract DIHeaderFieldIterator::getNumber(), NFC
Reduce code duplication between `DIBuilder` and `DIExpressionIterator` by implementing a `getNumber()` directly in the iterator. llvm-svn: 226772
-rw-r--r--llvm/include/llvm/IR/DebugInfo.h22
1 files changed, 12 insertions, 10 deletions
diff --git a/llvm/include/llvm/IR/DebugInfo.h b/llvm/include/llvm/IR/DebugInfo.h
index 13fa23c8fd6..fc4d95cfc14 100644
--- a/llvm/include/llvm/IR/DebugInfo.h
+++ b/llvm/include/llvm/IR/DebugInfo.h
@@ -99,6 +99,16 @@ public:
return Header.slice(Current.end() - Header.begin() + 1, StringRef::npos);
}
+ /// \brief Get the current field as a number.
+ ///
+ /// Convert the current field into a number. Return \c 0 on error.
+ template <class T> T getNumber() const {
+ T Int;
+ if (getCurrent().getAsInteger(0, Int))
+ return 0;
+ return Int;
+ }
+
private:
void increment() {
assert(Current.data() != nullptr && "Cannot increment past the end");
@@ -204,10 +214,7 @@ public:
}
template <class T> T getHeaderFieldAs(unsigned Index) const {
- T Int;
- if (getHeaderField(Index).getAsInteger(0, Int))
- return 0;
- return Int;
+ return getHeaderIterator(Index).getNumber<T>();
}
uint16_t getTag() const { return getHeaderFieldAs<uint16_t>(0); }
@@ -883,12 +890,7 @@ public:
DIExpressionIterator() {}
DIExpressionIterator(const DIExpression Expr)
: I(Expr.getHeader()) { ++I; }
- uint64_t operator*() const {
- uint64_t UInt;
- if (I->getAsInteger(0, UInt))
- return 0;
- return UInt;
- }
+ uint64_t operator*() const { return I.getNumber<uint64_t>(); }
DIExpressionIterator &operator++() {
increment();
return *this;
OpenPOWER on IntegriCloud