LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AsmPrinterDwarf.cpp
Go to the documentation of this file.
1 //===-- AsmPrinterDwarf.cpp - AsmPrinter Dwarf Support --------------------===//
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 // This file implements the Dwarf emissions parts of AsmPrinter.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #define DEBUG_TYPE "asm-printer"
16 #include "llvm/ADT/Twine.h"
17 #include "llvm/IR/DataLayout.h"
18 #include "llvm/MC/MCAsmInfo.h"
19 #include "llvm/MC/MCSection.h"
20 #include "llvm/MC/MCStreamer.h"
21 #include "llvm/MC/MCSymbol.h"
23 #include "llvm/Support/Dwarf.h"
29 using namespace llvm;
30 
31 //===----------------------------------------------------------------------===//
32 // Dwarf Emission Helper Routines
33 //===----------------------------------------------------------------------===//
34 
35 /// EmitSLEB128 - emit the specified signed leb128 value.
36 void AsmPrinter::EmitSLEB128(int64_t Value, const char *Desc) const {
37  if (isVerbose() && Desc)
38  OutStreamer.AddComment(Desc);
39 
41 }
42 
43 /// EmitULEB128 - emit the specified signed leb128 value.
44 void AsmPrinter::EmitULEB128(uint64_t Value, const char *Desc,
45  unsigned PadTo) const {
46  if (isVerbose() && Desc)
47  OutStreamer.AddComment(Desc);
48 
49  OutStreamer.EmitULEB128IntValue(Value, PadTo);
50 }
51 
52 /// EmitCFAByte - Emit a .byte 42 directive for a DW_CFA_xxx value.
53 void AsmPrinter::EmitCFAByte(unsigned Val) const {
54  if (isVerbose()) {
55  if (Val >= dwarf::DW_CFA_offset && Val < dwarf::DW_CFA_offset+64)
56  OutStreamer.AddComment("DW_CFA_offset + Reg (" +
57  Twine(Val-dwarf::DW_CFA_offset) + ")");
58  else
60  }
61  OutStreamer.EmitIntValue(Val, 1);
62 }
63 
64 static const char *DecodeDWARFEncoding(unsigned Encoding) {
65  switch (Encoding) {
66  case dwarf::DW_EH_PE_absptr: return "absptr";
67  case dwarf::DW_EH_PE_omit: return "omit";
68  case dwarf::DW_EH_PE_pcrel: return "pcrel";
69  case dwarf::DW_EH_PE_udata4: return "udata4";
70  case dwarf::DW_EH_PE_udata8: return "udata8";
71  case dwarf::DW_EH_PE_sdata4: return "sdata4";
72  case dwarf::DW_EH_PE_sdata8: return "sdata8";
73  case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata4: return "pcrel udata4";
74  case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4: return "pcrel sdata4";
75  case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8: return "pcrel udata8";
76  case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8: return "pcrel sdata8";
78  return "indirect pcrel udata4";
80  return "indirect pcrel sdata4";
82  return "indirect pcrel udata8";
84  return "indirect pcrel sdata8";
85  }
86 
87  return "<unknown encoding>";
88 }
89 
90 
91 /// EmitEncodingByte - Emit a .byte 42 directive that corresponds to an
92 /// encoding. If verbose assembly output is enabled, we output comments
93 /// describing the encoding. Desc is an optional string saying what the
94 /// encoding is specifying (e.g. "LSDA").
95 void AsmPrinter::EmitEncodingByte(unsigned Val, const char *Desc) const {
96  if (isVerbose()) {
97  if (Desc != 0)
98  OutStreamer.AddComment(Twine(Desc)+" Encoding = " +
100  else
101  OutStreamer.AddComment(Twine("Encoding = ") +
102  DecodeDWARFEncoding(Val));
103  }
104 
105  OutStreamer.EmitIntValue(Val, 1);
106 }
107 
108 /// GetSizeOfEncodedValue - Return the size of the encoding in bytes.
109 unsigned AsmPrinter::GetSizeOfEncodedValue(unsigned Encoding) const {
110  if (Encoding == dwarf::DW_EH_PE_omit)
111  return 0;
112 
113  switch (Encoding & 0x07) {
114  default: llvm_unreachable("Invalid encoded value.");
116  case dwarf::DW_EH_PE_udata2: return 2;
117  case dwarf::DW_EH_PE_udata4: return 4;
118  case dwarf::DW_EH_PE_udata8: return 8;
119  }
120 }
121 
123  unsigned Encoding) const {
124  if (GV) {
126 
127  const MCExpr *Exp =
128  TLOF.getTTypeGlobalReference(GV, Mang, MMI, Encoding, OutStreamer);
130  } else
132 }
133 
134 /// EmitSectionOffset - Emit the 4-byte offset of Label from the start of its
135 /// section. This can be done with a special directive if the target supports
136 /// it (e.g. cygwin) or by emitting it as an offset from a label at the start
137 /// of the section.
138 ///
139 /// SectionLabel is a temporary label emitted at the start of the section that
140 /// Label lives in.
142  const MCSymbol *SectionLabel) const {
143  // On COFF targets, we have to emit the special .secrel32 directive.
146  return;
147  }
148 
149  // Get the section that we're referring to, based on SectionLabel.
150  const MCSection &Section = SectionLabel->getSection();
151 
152  // If Label has already been emitted, verify that it is in the same section as
153  // section label for sanity.
154  assert((!Label->isInSection() || &Label->getSection() == &Section) &&
155  "Section offset using wrong section base for label");
156 
157  // If the section in question will end up with an address of 0 anyway, we can
158  // just emit an absolute reference to save a relocation.
159  if (Section.isBaseAddressKnownZero()) {
160  OutStreamer.EmitSymbolValue(Label, 4);
161  return;
162  }
163 
164  // Otherwise, emit it as a label difference from the start of the section.
165  EmitLabelDifference(Label, SectionLabel, 4);
166 }
167 
168 //===----------------------------------------------------------------------===//
169 // Dwarf Lowering Routines
170 //===----------------------------------------------------------------------===//
171 
173  switch (Inst.getOperation()) {
174  default:
175  llvm_unreachable("Unexpected instruction");
178  break;
181  break;
184  break;
187  break;
190  break;
193  break;
194  }
195 }
virtual void AddComment(const Twine &T)
Definition: MCStreamer.h:207
void EmitSLEB128IntValue(int64_t Value)
Definition: MCStreamer.cpp:128
unsigned getPointerSize(unsigned AS=0) const
Definition: DataLayout.h:261
void EmitLabelDifference(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size) const
virtual void EmitCFIRegister(int64_t Register1, int64_t Register2)
Definition: MCStreamer.cpp:401
virtual void EmitCFIDefCfaOffset(int64_t Offset)
Definition: MCStreamer.cpp:294
void emitCFIInstruction(const MCCFIInstruction &Inst) const
Emit frame instruction to describe the layout of the frame.
unsigned getRegister() const
Definition: MCDwarf.h:411
int getOffset() const
Definition: MCDwarf.h:424
const MCSection & getSection() const
Definition: MCSymbol.h:111
#define llvm_unreachable(msg)
const char * CallFrameString(unsigned Encoding)
Definition: Dwarf.cpp:693
bool isInSection() const
Definition: MCSymbol.h:95
Mangler * Mang
Definition: AsmPrinter.h:88
MCStreamer & OutStreamer
Definition: AsmPrinter.h:78
virtual void EmitIntValue(uint64_t Value, unsigned Size)
Definition: MCStreamer.cpp:104
void EmitValue(const MCExpr *Value, unsigned Size)
Definition: MCStreamer.cpp:141
MachineModuleInfo * MMI
MMI - This is a pointer to the current MachineModuleInfo.
Definition: AsmPrinter.h:84
bool needsDwarfSectionOffsetDirective() const
Definition: MCAsmInfo.h:391
const MCAsmInfo * MAI
Definition: AsmPrinter.h:66
unsigned GetSizeOfEncodedValue(unsigned Encoding) const
GetSizeOfEncodedValue - Return the size of the encoding in bytes.
TargetMachine & TM
Definition: AsmPrinter.h:62
virtual void EmitCFIDefCfaRegister(int64_t Register)
Definition: MCStreamer.cpp:310
virtual void EmitCOFFSecRel32(MCSymbol const *Symbol)
Definition: MCStreamer.cpp:569
void EmitSLEB128(int64_t Value, const char *Desc=0) const
EmitSLEB128 - emit the specified signed leb128 value.
OpType getOperation() const
Definition: MCDwarf.h:408
virtual bool isBaseAddressKnownZero() const
Definition: MCSection.h:64
virtual void EmitCFIOffset(int64_t Register, int64_t Offset)
Definition: MCStreamer.cpp:318
void EmitSectionOffset(const MCSymbol *Label, const MCSymbol *SectionLabel) const
unsigned getRegister2() const
Definition: MCDwarf.h:419
void EmitTTypeReference(const GlobalValue *GV, unsigned Encoding) const
EmitReference - Emit reference to a ttype global with a specified encoding.
static const char * DecodeDWARFEncoding(unsigned Encoding)
void EmitULEB128(uint64_t Value, const char *Desc=0, unsigned PadTo=0) const
EmitULEB128 - emit the specified unsigned leb128 value.
virtual const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang, MachineModuleInfo *MMI, unsigned Encoding, MCStreamer &Streamer) const
void EmitEncodingByte(unsigned Val, const char *Desc=0) const
virtual const DataLayout * getDataLayout() const
virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset)
Definition: MCStreamer.cpp:286
void EmitCFAByte(unsigned Val) const
EmitCFAByte - Emit a .byte 42 directive for a DW_CFA_xxx value.
void EmitULEB128IntValue(uint64_t Value, unsigned Padding=0)
Definition: MCStreamer.cpp:119
const TargetLoweringObjectFile & getObjFileLowering() const
getObjFileLowering - Return information about object file lowering.
Definition: AsmPrinter.cpp:129
LLVM Value Representation.
Definition: Value.h:66
void EmitSymbolValue(const MCSymbol *Sym, unsigned Size)
Definition: MCStreamer.cpp:145
bool isVerbose() const
Definition: AsmPrinter.h:130
virtual void EmitCFIWindowSave()
Definition: MCStreamer.cpp:409