blob: 5bc9ebc893ae2dc855ec415bc730dbc0d42b4534 [file] [log] [blame]
David Blaikie1275e4f2014-04-01 21:49:04 +00001//===-- 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
David Blaikied306baf2014-04-01 22:04:07 +000045 bool hasSameValueOrLocation(const DebugLocEntry &Next) {
46 if (EntryKind != Next.EntryKind)
47 return false;
48
49 switch (EntryKind) {
50 case E_Location:
51 if (Loc != Next.Loc) return false;
52 case E_Integer:
53 if (Constants.Int != Next.Constants.Int) return false;
54 case E_ConstantFP:
55 if (Constants.CFP != Next.Constants.CFP) return false;
56 case E_ConstantInt:
57 if (Constants.CIP != Next.Constants.CIP) return false;
58 }
59
60 return true;
61 }
62
David Blaikie1275e4f2014-04-01 21:49:04 +000063public:
64 DebugLocEntry() : Begin(0), End(0), Variable(0), Unit(0) {
65 Constants.Int = 0;
66 }
67 DebugLocEntry(const MCSymbol *B, const MCSymbol *E, MachineLocation &L,
68 const MDNode *V, const DwarfCompileUnit *U)
69 : Begin(B), End(E), Loc(L), Variable(V), Unit(U) {
70 Constants.Int = 0;
71 EntryKind = E_Location;
72 }
73 DebugLocEntry(const MCSymbol *B, const MCSymbol *E, int64_t i,
74 const DwarfCompileUnit *U)
75 : Begin(B), End(E), Variable(0), Unit(U) {
76 Constants.Int = i;
77 EntryKind = E_Integer;
78 }
79 DebugLocEntry(const MCSymbol *B, const MCSymbol *E, const ConstantFP *FPtr,
80 const DwarfCompileUnit *U)
81 : Begin(B), End(E), Variable(0), Unit(U) {
82 Constants.CFP = FPtr;
83 EntryKind = E_ConstantFP;
84 }
85 DebugLocEntry(const MCSymbol *B, const MCSymbol *E, const ConstantInt *IPtr,
86 const DwarfCompileUnit *U)
87 : Begin(B), End(E), Variable(0), Unit(U) {
88 Constants.CIP = IPtr;
89 EntryKind = E_ConstantInt;
90 }
91
92 /// \brief Empty entries are also used as a trigger to emit temp label. Such
93 /// labels are referenced is used to find debug_loc offset for a given DIE.
94 bool isEmpty() const { return Begin == 0 && End == 0; }
95 bool Merge(const DebugLocEntry &Next) {
David Blaikied306baf2014-04-01 22:04:07 +000096 return End == Next.Begin && hasSameValueOrLocation(Next);
David Blaikie1275e4f2014-04-01 21:49:04 +000097 }
98 bool isLocation() const { return EntryKind == E_Location; }
99 bool isInt() const { return EntryKind == E_Integer; }
100 bool isConstantFP() const { return EntryKind == E_ConstantFP; }
101 bool isConstantInt() const { return EntryKind == E_ConstantInt; }
102 int64_t getInt() const { return Constants.Int; }
103 const ConstantFP *getConstantFP() const { return Constants.CFP; }
104 const ConstantInt *getConstantInt() const { return Constants.CIP; }
105 const MDNode *getVariable() const { return Variable; }
106 const MCSymbol *getBeginSym() const { return Begin; }
107 const MCSymbol *getEndSym() const { return End; }
108 const DwarfCompileUnit *getCU() const { return Unit; }
109 MachineLocation getLoc() const { return Loc; }
110};
111
112}
113#endif