mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-04 12:15:46 +00:00
Address more review comments for DIExpression::iterator.
- input_iterator - define an operator-> - make constructors private were possible llvm-svn: 226967
This commit is contained in:
parent
009c1a931e
commit
70f2a736db
@ -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.
|
||||
|
@ -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);
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user