diff options
author | Adrian Prantl <aprantl@apple.com> | 2015-01-23 23:40:47 +0000 |
---|---|---|
committer | Adrian Prantl <aprantl@apple.com> | 2015-01-23 23:40:47 +0000 |
commit | 70f2a736db55f89646f3478047926df2f509abb3 (patch) | |
tree | d37fc1a6866ffab317c0c9c41e83f37cc4f67925 | |
parent | 009c1a931e4e0751f84217de22d7755ee3149ef1 (diff) | |
download | bcm5719-llvm-70f2a736db55f89646f3478047926df2f509abb3.tar.gz bcm5719-llvm-70f2a736db55f89646f3478047926df2f509abb3.zip |
Address more review comments for DIExpression::iterator.
- input_iterator
- define an operator->
- make constructors private were possible
llvm-svn: 226967
-rw-r--r-- | llvm/include/llvm/IR/DebugInfo.h | 50 | ||||
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp | 14 | ||||
-rw-r--r-- | llvm/lib/IR/DebugInfo.cpp | 13 |
3 files changed, 44 insertions, 33 deletions
diff --git a/llvm/include/llvm/IR/DebugInfo.h b/llvm/include/llvm/IR/DebugInfo.h index 9292f4b5c35..539025f0df2 100644 --- a/llvm/include/llvm/IR/DebugInfo.h +++ b/llvm/include/llvm/IR/DebugInfo.h @@ -59,7 +59,7 @@ class DIObjCProperty; typedef DenseMap<const MDString *, MDNode *> DITypeIdentifierMap; class DIHeaderFieldIterator - : public std::iterator<std::forward_iterator_tag, StringRef, std::ptrdiff_t, + : public std::iterator<std::input_iterator_tag, StringRef, std::ptrdiff_t, const StringRef *, StringRef> { StringRef Header; StringRef Current; @@ -867,17 +867,40 @@ public: /// \brief Return the size of this piece in bytes. uint64_t getPieceSize() const; - class Operand; + class iterator; + /// \brief A lightweight wrapper around an element of a DIExpression. + class Operand { + friend class iterator; + DIHeaderFieldIterator I; + Operand() {} + Operand(DIHeaderFieldIterator I) : I(I) {} + public: + /// \brief Operands such as DW_OP_piece have explicit (non-stack) arguments. + /// Argument 0 is the operand itself. + uint64_t getArg(unsigned N) const { + DIHeaderFieldIterator In = I; + std::advance(In, N); + return In.getNumber<uint64_t>(); + } + operator uint64_t () const { return I.getNumber<uint64_t>(); } + /// \brief Returns underlying DIHeaderFieldIterator. + const DIHeaderFieldIterator &getBase() const { return I; } + /// \brief Returns the next operand. + const Operand &getNext() const; + }; /// \brief An iterator for DIExpression elements. - class iterator : public std::iterator<std::forward_iterator_tag, StringRef, - unsigned, const uint64_t *, uint64_t> { + class iterator : public std::iterator<std::input_iterator_tag, StringRef, + unsigned, const Operand*, Operand> { + friend class Operand; DIHeaderFieldIterator I; + Operand Tmp; iterator(DIHeaderFieldIterator I) : I(I) {} public: iterator() {} iterator(const DIExpression &Expr) : I(++Expr.header_begin()) {} - Operand operator*() const { return Operand(I); } + const Operand &operator*() { return Tmp = Operand(I); } + const Operand *operator->() { return &(Tmp = Operand(I)); } iterator &operator++() { increment(); return *this; @@ -890,7 +913,6 @@ public: bool operator==(const iterator &X) const { return I == X.I; } bool operator!=(const iterator &X) const { return !(*this == X); } - const DIHeaderFieldIterator &getBase() const { return I; } private: void increment() { switch (**this) { @@ -905,22 +927,6 @@ public: iterator begin() const; iterator end() const; - - /// \brief A lightweight wrapper around an element of a DIExpression. - class Operand { - DIHeaderFieldIterator I; - public: - Operand(DIHeaderFieldIterator I) : I(I) {} - /// \brief Operands such as DW_OP_piece have explicit (non-stack) arguments. - /// Argument 0 is the operand itself. - uint64_t getArg(unsigned N) const { - DIHeaderFieldIterator In = I; - std::advance(In, N); - return In.getNumber<uint64_t>(); - } - - operator uint64_t () const { return I.getNumber<uint64_t>(); } - }; }; /// \brief This object holds location information. diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp index 8515dd020c8..f3d3fb45bb2 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp @@ -210,16 +210,16 @@ bool DwarfExpression::AddMachineRegExpression(DIExpression Expr, switch (*I) { case dwarf::DW_OP_piece: { unsigned SizeOfByte = 8; - unsigned OffsetInBits = (*I).getArg(1) * SizeOfByte; - unsigned SizeInBits = (*I).getArg(2) * SizeOfByte; + unsigned OffsetInBits = I->getArg(1) * SizeOfByte; + unsigned SizeInBits = I->getArg(2) * SizeOfByte; // Piece always comes at the end of the expression. return AddMachineRegPiece(MachineReg, SizeInBits, getOffsetOrZero(OffsetInBits, PieceOffsetInBits)); } case dwarf::DW_OP_plus: // [DW_OP_reg,Offset,DW_OP_plus,DW_OP_deref] --> [DW_OP_breg,Offset]. - if (*std::next(I) == dwarf::DW_OP_deref) { - unsigned Offset = (*I).getArg(1); + if (I->getNext() == dwarf::DW_OP_deref) { + unsigned Offset = I->getArg(1); ValidReg = AddMachineRegIndirect(MachineReg, Offset); std::advance(I, 2); break; @@ -248,14 +248,14 @@ void DwarfExpression::AddExpression(DIExpression::iterator I, switch (*I) { case dwarf::DW_OP_piece: { unsigned SizeOfByte = 8; - unsigned OffsetInBits = (*I).getArg(1) * SizeOfByte; - unsigned SizeInBits = (*I).getArg(2) * SizeOfByte; + unsigned OffsetInBits = I->getArg(1) * SizeOfByte; + unsigned SizeInBits = I->getArg(2) * SizeOfByte; AddOpPiece(SizeInBits, getOffsetOrZero(OffsetInBits, PieceOffsetInBits)); break; } case dwarf::DW_OP_plus: EmitOp(dwarf::DW_OP_plus_uconst); - EmitUnsigned((*I).getArg(1)); + EmitUnsigned(I->getArg(1)); break; case dwarf::DW_OP_deref: EmitOp(dwarf::DW_OP_deref); diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp index 095fcbffde3..9b5a9c3da47 100644 --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -170,6 +170,11 @@ DIExpression::iterator DIExpression::end() const { return DIExpression::iterator(); } +const DIExpression::Operand &DIExpression::Operand::getNext() const { + iterator it(I); + return *(++it); +} + //===----------------------------------------------------------------------===// // Predicates //===----------------------------------------------------------------------===// @@ -606,13 +611,13 @@ bool DIExpression::Verify() const { if (!(isExpression() && DbgNode->getNumOperands() == 1)) return false; - for (auto E = end(), I = begin(); I != E; ++I) - switch (*I) { + for (auto Op : *this) + switch (Op) { case DW_OP_piece: // Must be the last element of the expression. - return std::distance(I.getBase(), DIHeaderFieldIterator()) == 3; + return std::distance(Op.getBase(), DIHeaderFieldIterator()) == 3; case DW_OP_plus: - if (std::distance(I.getBase(), DIHeaderFieldIterator()) < 2) + if (std::distance(Op.getBase(), DIHeaderFieldIterator()) < 2) return false; break; case DW_OP_deref: |