blob: 470453fbe26fd9d9896edbe44fa4909c8e22dbbf [file] [log] [blame]
Stephen Hines36b56882014-04-23 16:57:46 -07001//===-- llvm/CodeGen/DebugLocEntry.h - Entry in debug_loc list -*- C++ -*--===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef CODEGEN_ASMPRINTER_DEBUGLOCENTRY_H__
11#define CODEGEN_ASMPRINTER_DEBUGLOCENTRY_H__
12#include "llvm/IR/Constants.h"
13#include "llvm/MC/MachineLocation.h"
14#include "llvm/MC/MCSymbol.h"
15
16namespace llvm {
17class DwarfCompileUnit;
18class MDNode;
19/// \brief This struct describes location entries emitted in the .debug_loc
20/// section.
21class DebugLocEntry {
22 // Begin and end symbols for the address range that this location is valid.
23 const MCSymbol *Begin;
24 const MCSymbol *End;
25
26 // Type of entry that this represents.
27 enum EntryType { E_Location, E_Integer, E_ConstantFP, E_ConstantInt };
28 enum EntryType EntryKind;
29
30 union {
31 int64_t Int;
32 const ConstantFP *CFP;
33 const ConstantInt *CIP;
34 } Constants;
35
36 // The location in the machine frame.
37 MachineLocation Loc;
38
39 // The variable to which this location entry corresponds.
40 const MDNode *Variable;
41
42 // The compile unit to which this location entry is referenced by.
43 const DwarfCompileUnit *Unit;
44
45 bool hasSameValueOrLocation(const DebugLocEntry &Next) {
46 if (EntryKind != Next.EntryKind)
47 return false;
48
49 bool EqualValues;
50 switch (EntryKind) {
51 case E_Location:
52 EqualValues = Loc == Next.Loc;
53 break;
54 case E_Integer:
55 EqualValues = Constants.Int == Next.Constants.Int;
56 break;
57 case E_ConstantFP:
58 EqualValues = Constants.CFP == Next.Constants.CFP;
59 break;
60 case E_ConstantInt:
61 EqualValues = Constants.CIP == Next.Constants.CIP;
62 break;
63 }
64
65 return EqualValues;
66 }
67
68public:
69 DebugLocEntry() : Begin(0), End(0), Variable(0), Unit(0) {
70 Constants.Int = 0;
71 }
72 DebugLocEntry(const MCSymbol *B, const MCSymbol *E, MachineLocation &L,
73 const MDNode *V, const DwarfCompileUnit *U)
74 : Begin(B), End(E), Loc(L), Variable(V), Unit(U) {
75 Constants.Int = 0;
76 EntryKind = E_Location;
77 }
78 DebugLocEntry(const MCSymbol *B, const MCSymbol *E, int64_t i,
79 const DwarfCompileUnit *U)
80 : Begin(B), End(E), Variable(0), Unit(U) {
81 Constants.Int = i;
82 EntryKind = E_Integer;
83 }
84 DebugLocEntry(const MCSymbol *B, const MCSymbol *E, const ConstantFP *FPtr,
85 const DwarfCompileUnit *U)
86 : Begin(B), End(E), Variable(0), Unit(U) {
87 Constants.CFP = FPtr;
88 EntryKind = E_ConstantFP;
89 }
90 DebugLocEntry(const MCSymbol *B, const MCSymbol *E, const ConstantInt *IPtr,
91 const DwarfCompileUnit *U)
92 : Begin(B), End(E), Variable(0), Unit(U) {
93 Constants.CIP = IPtr;
94 EntryKind = E_ConstantInt;
95 }
96
97 /// \brief Attempt to merge this DebugLocEntry with Next and return
98 /// true if the merge was successful. Entries can be merged if they
99 /// share the same Loc/Constant and if Next immediately follows this
100 /// Entry.
101 bool Merge(const DebugLocEntry &Next) {
102 if (End == Next.Begin && hasSameValueOrLocation(Next)) {
103 End = Next.End;
104 return true;
105 }
106 return false;
107 }
108 bool isLocation() const { return EntryKind == E_Location; }
109 bool isInt() const { return EntryKind == E_Integer; }
110 bool isConstantFP() const { return EntryKind == E_ConstantFP; }
111 bool isConstantInt() const { return EntryKind == E_ConstantInt; }
112 int64_t getInt() const { return Constants.Int; }
113 const ConstantFP *getConstantFP() const { return Constants.CFP; }
114 const ConstantInt *getConstantInt() const { return Constants.CIP; }
115 const MDNode *getVariable() const { return Variable; }
116 const MCSymbol *getBeginSym() const { return Begin; }
117 const MCSymbol *getEndSym() const { return End; }
118 const DwarfCompileUnit *getCU() const { return Unit; }
119 MachineLocation getLoc() const { return Loc; }
120};
121
122}
123#endif