18
18
#ifndef SWIFT_SIL_DEBUGINFOEXPRESSION_H
19
19
#define SWIFT_SIL_DEBUGINFOEXPRESSION_H
20
20
#include " swift/AST/Decl.h"
21
+ #include " llvm/ADT/APInt.h"
21
22
#include " llvm/ADT/ArrayRef.h"
22
23
#include " llvm/ADT/Optional.h"
23
24
#include " llvm/ADT/iterator_range.h"
@@ -36,17 +37,30 @@ enum class SILDIExprOperator : unsigned {
36
37
// / VarDecl operand pointing to the field declaration.
37
38
// / Note that this directive can only appear at the end of an
38
39
// / expression.
39
- Fragment
40
+ Fragment,
41
+ // / Perform arithmetic addition on the top two elements of the
42
+ // / expression stack and push the result back to the stack.
43
+ Plus,
44
+ // / Subtract the top element in expression stack by the second
45
+ // / element. Then push the result back to the stack.
46
+ Minus,
47
+ // / Push an unsigned integer constant onto the stack.
48
+ ConstUInt,
49
+ // / Push a signed integer constant onto the stack.
50
+ ConstSInt
40
51
};
41
52
42
53
// / Represents a single component in a debug info expression.
43
54
// / Including operator and operand.
44
55
struct SILDIExprElement {
45
56
enum Kind {
46
- // / A di-expression operator
57
+ // / A di-expression operator.
47
58
OperatorKind,
48
- // / An operand that has declaration type
49
- DeclKind
59
+ // / An operand that has declaration type.
60
+ DeclKind,
61
+ // / An integer constant value. Note that
62
+ // / we don't specify its signedness here.
63
+ ConstIntKind
50
64
};
51
65
52
66
private:
@@ -55,6 +69,7 @@ struct SILDIExprElement {
55
69
union {
56
70
SILDIExprOperator Operator;
57
71
Decl *Declaration;
72
+ uint64_t ConstantInt;
58
73
};
59
74
60
75
explicit SILDIExprElement (Kind OpK) : OpKind(OpK) {}
@@ -68,6 +83,13 @@ struct SILDIExprElement {
68
83
69
84
Decl *getAsDecl () const { return OpKind == DeclKind ? Declaration : nullptr ; }
70
85
86
+ Optional<uint64_t > getAsConstInt () const {
87
+ if (OpKind == ConstIntKind)
88
+ return ConstantInt;
89
+ else
90
+ return {};
91
+ }
92
+
71
93
static SILDIExprElement createOperator (SILDIExprOperator Op) {
72
94
SILDIExprElement DIOp (OperatorKind);
73
95
DIOp.Operator = Op;
@@ -79,6 +101,12 @@ struct SILDIExprElement {
79
101
DIOp.Declaration = D;
80
102
return DIOp;
81
103
}
104
+
105
+ static SILDIExprElement createConstInt (uint64_t V) {
106
+ SILDIExprElement DIOp (ConstIntKind);
107
+ DIOp.ConstantInt = V;
108
+ return DIOp;
109
+ }
82
110
};
83
111
84
112
// / For a given SILDIExprOperator, provides information
@@ -231,6 +259,19 @@ class SILDebugInfoExpression {
231
259
232
260
// / Create a op_fragment expression
233
261
static SILDebugInfoExpression createFragment (VarDecl *Field);
262
+
263
+ // / Return true if this DIExpression starts with op_deref
264
+ bool startsWithDeref () const {
265
+ return Elements.size () &&
266
+ Elements[0 ].getAsOperator () == SILDIExprOperator::Dereference;
267
+ }
268
+
269
+ // / Return true if this DIExpression has op_fragment (at the end)
270
+ bool hasFragment () const {
271
+ return Elements.size () >= 2 &&
272
+ Elements[Elements.size () - 2 ].getAsOperator () ==
273
+ SILDIExprOperator::Fragment;
274
+ }
234
275
};
235
276
} // end namespace swift
236
277
#endif
0 commit comments