|
| 1 | +//===--- SILDebugVariable.h -----------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#ifndef SWIFT_SIL_SILDEBUGVARIABLE_H |
| 14 | +#define SWIFT_SIL_SILDEBUGVARIABLE_H |
| 15 | + |
| 16 | +#include "swift/Basic/LLVM.h" |
| 17 | +#include "swift/SIL/SILDebugInfoExpression.h" |
| 18 | +#include "swift/SIL/SILLocation.h" |
| 19 | +#include "swift/SIL/SILType.h" |
| 20 | +#include "llvm/ADT/StringRef.h" |
| 21 | + |
| 22 | +namespace swift { |
| 23 | + |
| 24 | +class AllocationInst; |
| 25 | + |
| 26 | +/// Holds common debug information about local variables and function |
| 27 | +/// arguments that are needed by DebugValueInst, AllocStackInst, |
| 28 | +/// and AllocBoxInst. |
| 29 | +struct SILDebugVariable { |
| 30 | + StringRef Name; |
| 31 | + unsigned ArgNo : 16; |
| 32 | + unsigned Constant : 1; |
| 33 | + unsigned Implicit : 1; |
| 34 | + Optional<SILType> Type; |
| 35 | + Optional<SILLocation> Loc; |
| 36 | + const SILDebugScope *Scope; |
| 37 | + SILDebugInfoExpression DIExpr; |
| 38 | + |
| 39 | + // Use vanilla copy ctor / operator |
| 40 | + SILDebugVariable(const SILDebugVariable &) = default; |
| 41 | + SILDebugVariable &operator=(const SILDebugVariable &) = default; |
| 42 | + |
| 43 | + SILDebugVariable() |
| 44 | + : ArgNo(0), Constant(false), Implicit(false), Scope(nullptr) {} |
| 45 | + SILDebugVariable(bool Constant, uint16_t ArgNo) |
| 46 | + : ArgNo(ArgNo), Constant(Constant), Implicit(false), Scope(nullptr) {} |
| 47 | + SILDebugVariable(StringRef Name, bool Constant, unsigned ArgNo, |
| 48 | + bool IsImplicit = false, Optional<SILType> AuxType = {}, |
| 49 | + Optional<SILLocation> DeclLoc = {}, |
| 50 | + const SILDebugScope *DeclScope = nullptr, |
| 51 | + llvm::ArrayRef<SILDIExprElement> ExprElements = {}) |
| 52 | + : Name(Name), ArgNo(ArgNo), Constant(Constant), Implicit(IsImplicit), |
| 53 | + Type(AuxType), Loc(DeclLoc), Scope(DeclScope), DIExpr(ExprElements) {} |
| 54 | + |
| 55 | + /// Created from either AllocStack or AllocBox instruction |
| 56 | + static Optional<SILDebugVariable> |
| 57 | + createFromAllocation(const AllocationInst *AI); |
| 58 | + |
| 59 | + bool operator==(const SILDebugVariable &V) { |
| 60 | + return ArgNo == V.ArgNo && Constant == V.Constant && Name == V.Name && |
| 61 | + Implicit == V.Implicit && Type == V.Type && Loc == V.Loc && |
| 62 | + Scope == V.Scope && DIExpr == V.DIExpr; |
| 63 | + } |
| 64 | + |
| 65 | + bool isLet() const { return Name.size() && Constant; } |
| 66 | + |
| 67 | + bool isVar() const { return Name.size() && !Constant; } |
| 68 | +}; |
| 69 | + |
| 70 | +} // namespace swift |
| 71 | + |
| 72 | +#endif |
0 commit comments