1 //===--- DWARFExpression.h - DWARF Expression handling ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_DEBUGINFO_DWARFEXPRESSION_H
11 #define LLVM_DEBUGINFO_DWARFEXPRESSION_H
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/ADT/iterator.h"
15 #include "llvm/ADT/iterator_range.h"
16 #include "llvm/Support/DataExtractor.h"
23 class DWARFExpression {
27 /// This class represents an Operation in the Expression. Each operation can
28 /// have up to 2 oprerands.
30 /// An Operation can be in Error state (check with isError()). This
31 /// means that it couldn't be decoded successfully and if it is the
32 /// case, all others fields contain undefined values.
35 /// Size and signedness of expression operations' operands.
36 enum Encoding : uint8_t {
44 SizeBlock = 7, ///< Preceding operand contains block size
46 SignedSize1 = SignBit | Size1,
47 SignedSize2 = SignBit | Size2,
48 SignedSize4 = SignBit | Size4,
49 SignedSize8 = SignBit | Size8,
50 SignedSizeLEB = SignBit | SizeLEB,
51 SizeNA = 0xFF ///< Unused operands get this encoding.
54 enum DwarfVersion : uint8_t {
55 DwarfNA, ///< Serves as a marker for unused entries
61 /// Description of the encoding of one expression Op.
63 DwarfVersion Version; ///< Dwarf version where the Op was introduced.
64 Encoding Op[2]; ///< Encoding for Op operands, or SizeNA.
66 Description(DwarfVersion Version = DwarfNA, Encoding Op1 = SizeNA,
67 Encoding Op2 = SizeNA)
75 friend class DWARFExpression::iterator;
76 uint8_t Opcode; ///< The Op Opcode, DW_OP_<something>.
83 Description &getDescription() { return Desc; }
84 uint8_t getCode() { return Opcode; }
85 uint64_t getRawOperand(unsigned Idx) { return Operands[Idx]; }
86 uint32_t getEndOffset() { return EndOffset; }
87 bool extract(DataExtractor Data, uint16_t Version, uint8_t AddressSize,
89 bool isError() { return Error; }
90 bool print(raw_ostream &OS, const DWARFExpression *U,
91 const MCRegisterInfo *RegInfo, bool isEH);
94 /// An iterator to go through the expression operations.
96 : public iterator_facade_base<iterator, std::forward_iterator_tag,
98 friend class DWARFExpression;
99 const DWARFExpression *Expr;
102 iterator(const DWARFExpression *Expr, uint32_t Offset)
103 : Expr(Expr), Offset(Offset) {
105 Offset >= Expr->Data.getData().size() ||
106 !Op.extract(Expr->Data, Expr->Version, Expr->AddressSize, Offset);
110 class Operation &operator++() {
111 Offset = Op.isError() ? Expr->Data.getData().size() : Op.EndOffset;
113 Offset >= Expr->Data.getData().size() ||
114 !Op.extract(Expr->Data, Expr->Version, Expr->AddressSize, Offset);
118 class Operation &operator*() {
122 // Comparison operators are provided out of line.
123 friend bool operator==(const iterator &, const iterator &);
126 DWARFExpression(DataExtractor Data, uint16_t Version, uint8_t AddressSize)
127 : Data(Data), Version(Version), AddressSize(AddressSize) {
128 assert(AddressSize == 8 || AddressSize == 4);
131 iterator begin() const { return iterator(this, 0); }
132 iterator end() const { return iterator(this, Data.getData().size()); }
134 void print(raw_ostream &OS, const MCRegisterInfo *RegInfo,
135 bool IsEH = false) const;
143 inline bool operator==(const DWARFExpression::iterator &LHS,
144 const DWARFExpression::iterator &RHS) {
145 return LHS.Expr == RHS.Expr && LHS.Offset == RHS.Offset;
148 inline bool operator!=(const DWARFExpression::iterator &LHS,
149 const DWARFExpression::iterator &RHS) {
150 return !(LHS == RHS);