llvm.org GIT mirror llvm / d5dc4cf
Move the accessor functions from DIExpression::iterator into a wrapper DIExpression::Operand, so we can write range-based for loops. Thanks to David Blaikie for the idea. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226939 91177308-0d34-0410-b5e6-96231b3b80d8 Adrian Prantl 5 years ago
3 changed file(s) with 30 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
866866 /// \brief Return the size of this piece in bytes.
867867 uint64_t getPieceSize() const;
868868
869 class Operand;
870
869871 /// \brief An iterator for DIExpression elements.
870872 class iterator : public std::iterator
871873 unsigned, const uint64_t *, uint64_t> {
872874 DIHeaderFieldIterator I;
873875 iterator(DIHeaderFieldIterator I) : I(I) {}
874
875876 public:
876877 iterator() {}
877878 iterator(const DIExpression &Expr) : I(++Expr.header_begin()) {}
878 uint64_t operator*() const { return I.getNumber(); }
879 Operand operator*() const { return Operand(I); }
879880 iterator &operator++() {
880881 increment();
881882 return *this;
888889 bool operator==(const iterator &X) const { return I == X.I; }
889890 bool operator!=(const iterator &X) const { return !(*this == X); }
890891
891 uint64_t getArg(unsigned N) const {
892 auto In = I;
893 std::advance(In, N);
894 return In.getNumber();
895 }
896
897892 const DIHeaderFieldIterator &getBase() const { return I; }
898
899893 private:
900894 void increment() {
901895 switch (**this) {
910904
911905 iterator begin() const;
912906 iterator end() const;
907
908 /// \brief A lightweight wrapper around an element of a DIExpression.
909 class Operand {
910 DIHeaderFieldIterator I;
911 public:
912 Operand(DIHeaderFieldIterator I) : I(I) {}
913 /// \brief Operands such as DW_OP_piece have explicit (non-stack) arguments.
914 /// Argument 0 is the operand itself.
915 uint64_t getArg(unsigned N) const {
916 DIHeaderFieldIterator In = I;
917 std::advance(In, N);
918 return In.getNumber();
919 }
920
921 operator uint64_t () const { return I.getNumber(); }
922 };
913923 };
914924
915925 /// \brief This object holds location information.
209209 switch (*I) {
210210 case dwarf::DW_OP_piece: {
211211 unsigned SizeOfByte = 8;
212 unsigned OffsetInBits = I.getArg(1) * SizeOfByte;
213 unsigned SizeInBits = I.getArg(2) * SizeOfByte;
212 unsigned OffsetInBits = (*I).getArg(1) * SizeOfByte;
213 unsigned SizeInBits = (*I).getArg(2) * SizeOfByte;
214214 // Piece always comes at the end of the expression.
215215 return AddMachineRegPiece(MachineReg, SizeInBits,
216216 getOffsetOrZero(OffsetInBits, PieceOffsetInBits));
218218 case dwarf::DW_OP_plus:
219219 // [DW_OP_reg,Offset,DW_OP_plus,DW_OP_deref] --> [DW_OP_breg,Offset].
220220 if (*std::next(I) == dwarf::DW_OP_deref) {
221 unsigned Offset = I.getArg(1);
221 unsigned Offset = (*I).getArg(1);
222222 ValidReg = AddMachineRegIndirect(MachineReg, Offset);
223223 std::advance(I, 2);
224224 break;
247247 switch (*I) {
248248 case dwarf::DW_OP_piece: {
249249 unsigned SizeOfByte = 8;
250 unsigned OffsetInBits = I.getArg(1) * SizeOfByte;
251 unsigned SizeInBits = I.getArg(2) * SizeOfByte;
250 unsigned OffsetInBits = (*I).getArg(1) * SizeOfByte;
251 unsigned SizeInBits = (*I).getArg(2) * SizeOfByte;
252252 AddOpPiece(SizeInBits, getOffsetOrZero(OffsetInBits, PieceOffsetInBits));
253253 break;
254254 }
255255 case dwarf::DW_OP_plus:
256256 EmitOp(dwarf::DW_OP_plus_uconst);
257 EmitUnsigned(I.getArg(1));
257 EmitUnsigned((*I).getArg(1));
258258 break;
259259 case dwarf::DW_OP_deref:
260260 EmitOp(dwarf::DW_OP_deref);
14051405 }
14061406
14071407 void DIExpression::printInternal(raw_ostream &OS) const {
1408 for (auto E = end(), I = begin(); I != E; ++I) {
1409 uint64_t OpCode = *I;
1410 OS << " [" << OperationEncodingString(OpCode);
1411 switch (OpCode) {
1408 for (auto Op : *this) {
1409 OS << " [" << OperationEncodingString(Op);
1410 switch (Op) {
14121411 case DW_OP_plus: {
1413 OS << " " << I.getArg(1);
1412 OS << " " << Op.getArg(1);
14141413 break;
14151414 }
14161415 case DW_OP_piece: {
1417 OS << " offset=" << I.getArg(1) << ", size=" << I.getArg(2);
1416 OS << " offset=" << Op.getArg(1) << ", size=" << Op.getArg(2);
14181417 break;
14191418 }
14201419 case DW_OP_deref: