blob: 69d9c27ff0b09e94a3ae15d2feec2a91c258ed19 [file] [log] [blame]
Bill Wendlingbbee8c92009-05-15 00:11:17 +00001//===--- lib/CodeGen/DwarfPrinter.h - Dwarf Printer -------------*- 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// Emit general DWARF directives.
11//
12//===----------------------------------------------------------------------===//
13
Bill Wendlingb12b3d72009-05-15 09:23:25 +000014#ifndef CODEGEN_ASMPRINTER_DWARFPRINTER_H__
15#define CODEGEN_ASMPRINTER_DWARFPRINTER_H__
Bill Wendlingbbee8c92009-05-15 00:11:17 +000016
17#include "DwarfLabel.h"
18#include "llvm/CodeGen/MachineLocation.h"
19#include "llvm/Support/Compiler.h"
Chris Lattnerad653482010-01-22 22:09:00 +000020#include "llvm/Support/FormattedStream.h"
Bill Wendlingbbee8c92009-05-15 00:11:17 +000021#include <vector>
22
23namespace llvm {
Chris Lattner57939f62010-01-22 22:19:51 +000024class AsmPrinter;
25class MachineFunction;
26class MachineModuleInfo;
27class Module;
28class MCAsmInfo;
29class TargetData;
30class TargetRegisterInfo;
31class MCSymbol;
Chris Lattner05ae1d22010-01-22 23:47:11 +000032class Twine;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000033
Chris Lattnerb21f1042010-01-22 22:23:57 +000034class DwarfPrinter {
Chris Lattner57939f62010-01-22 22:19:51 +000035protected:
Duncan Sands3ef960d2010-02-07 21:09:22 +000036 ~DwarfPrinter() {}
37
Chris Lattner57939f62010-01-22 22:19:51 +000038 //===-------------------------------------------------------------==---===//
39 // Core attributes used by the DWARF printer.
40 //
Bill Wendlingbbee8c92009-05-15 00:11:17 +000041
Chris Lattner57939f62010-01-22 22:19:51 +000042 /// O - Stream to .s file.
43 raw_ostream &O;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000044
Chris Lattner57939f62010-01-22 22:19:51 +000045 /// Asm - Target of Dwarf emission.
46 AsmPrinter *Asm;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000047
Chris Lattner57939f62010-01-22 22:19:51 +000048 /// MAI - Target asm information.
49 const MCAsmInfo *MAI;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000050
Chris Lattner57939f62010-01-22 22:19:51 +000051 /// TD - Target data.
52 const TargetData *TD;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000053
Chris Lattner57939f62010-01-22 22:19:51 +000054 /// RI - Register Information.
55 const TargetRegisterInfo *RI;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000056
Chris Lattner57939f62010-01-22 22:19:51 +000057 /// M - Current module.
58 Module *M;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000059
Chris Lattner57939f62010-01-22 22:19:51 +000060 /// MF - Current machine function.
Chris Lattner69a76972010-01-26 23:18:02 +000061 const MachineFunction *MF;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000062
Chris Lattner57939f62010-01-22 22:19:51 +000063 /// MMI - Collected machine module information.
64 MachineModuleInfo *MMI;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000065
Chris Lattner57939f62010-01-22 22:19:51 +000066 /// SubprogramCount - The running count of functions being compiled.
67 unsigned SubprogramCount;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000068
Chris Lattner57939f62010-01-22 22:19:51 +000069 /// Flavor - A unique string indicating what dwarf producer this is, used to
70 /// unique labels.
71 const char * const Flavor;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000072
Chris Lattner57939f62010-01-22 22:19:51 +000073 /// SetCounter - A unique number for each '.set' directive.
74 unsigned SetCounter;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000075
Chris Lattnerb21f1042010-01-22 22:23:57 +000076 DwarfPrinter(raw_ostream &OS, AsmPrinter *A, const MCAsmInfo *T,
77 const char *flavor);
Chris Lattner57939f62010-01-22 22:19:51 +000078public:
Chris Lattnerd705acf2010-01-22 22:38:16 +000079
Chris Lattner57939f62010-01-22 22:19:51 +000080 //===------------------------------------------------------------------===//
81 // Accessors.
82 //
83 const AsmPrinter *getAsm() const { return Asm; }
84 MachineModuleInfo *getMMI() const { return MMI; }
85 const MCAsmInfo *getMCAsmInfo() const { return MAI; }
86 const TargetData *getTargetData() const { return TD; }
Bill Wendlingbbee8c92009-05-15 00:11:17 +000087
Chris Lattner57939f62010-01-22 22:19:51 +000088 void PrintRelDirective(bool Force32Bit = false,
89 bool isInSection = false) const;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000090
Chris Lattner05ae1d22010-01-22 23:47:11 +000091 /// EOL - Print a newline character to asm stream. If a comment is present
92 /// then it will be printed first. Comments should not contain '\n'.
93 void EOL(const Twine &Comment) const;
94
Chris Lattnerd705acf2010-01-22 22:38:16 +000095 /// EmitEncodingByte - Emit a .byte 42 directive that corresponds to an
96 /// encoding. If verbose assembly output is enabled, we output comments
Chris Lattner20f334f2010-01-22 22:56:55 +000097 /// describing the encoding. Desc is a string saying what the encoding is
98 /// specifying (e.g. "LSDA").
99 void EmitEncodingByte(unsigned Val, const char *Desc);
Chris Lattnerd705acf2010-01-22 22:38:16 +0000100
Chris Lattnerab4cf952010-01-22 23:40:08 +0000101 /// EmitCFAByte - Emit a .byte 42 directive for a DW_CFA_xxx value.
102 void EmitCFAByte(unsigned Val);
103
104
Chris Lattnerbcc79432010-01-22 23:18:42 +0000105 /// EmitSLEB128 - emit the specified signed leb128 value.
Chris Lattner20f334f2010-01-22 22:56:55 +0000106 void EmitSLEB128(int Value, const char *Desc) const;
Chris Lattnerbcc79432010-01-22 23:18:42 +0000107
108 /// EmitULEB128 - emit the specified unsigned leb128 value.
109 void EmitULEB128(unsigned Value, const char *Desc = 0) const;
110
Chris Lattner20f334f2010-01-22 22:56:55 +0000111
Chris Lattner57939f62010-01-22 22:19:51 +0000112 /// PrintLabelName - Print label name in form used by Dwarf writer.
113 ///
114 void PrintLabelName(const DWLabel &Label) const {
115 PrintLabelName(Label.getTag(), Label.getNumber());
116 }
117 void PrintLabelName(const char *Tag, unsigned Number) const;
118 void PrintLabelName(const char *Tag, unsigned Number,
119 const char *Suffix) const;
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000120
Chris Lattner57939f62010-01-22 22:19:51 +0000121 /// EmitLabel - Emit location label for internal use by Dwarf.
122 ///
123 void EmitLabel(const DWLabel &Label) const {
124 EmitLabel(Label.getTag(), Label.getNumber());
125 }
126 void EmitLabel(const char *Tag, unsigned Number) const;
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000127
Chris Lattner57939f62010-01-22 22:19:51 +0000128 /// EmitReference - Emit a reference to a label.
129 ///
130 void EmitReference(const DWLabel &Label, bool IsPCRelative = false,
131 bool Force32Bit = false) const {
132 EmitReference(Label.getTag(), Label.getNumber(),
133 IsPCRelative, Force32Bit);
134 }
135 void EmitReference(const char *Tag, unsigned Number,
136 bool IsPCRelative = false,
137 bool Force32Bit = false) const;
138 void EmitReference(const std::string &Name, bool IsPCRelative = false,
139 bool Force32Bit = false) const;
140 void EmitReference(const MCSymbol *Sym, bool IsPCRelative = false,
141 bool Force32Bit = false) const;
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000142
Chris Lattner1fd01822010-01-26 20:20:43 +0000143 /// EmitDifference - Emit the difference between two labels.
Chris Lattner57939f62010-01-22 22:19:51 +0000144 void EmitDifference(const DWLabel &LabelHi, const DWLabel &LabelLo,
145 bool IsSmall = false) {
146 EmitDifference(LabelHi.getTag(), LabelHi.getNumber(),
147 LabelLo.getTag(), LabelLo.getNumber(),
148 IsSmall);
149 }
150 void EmitDifference(const char *TagHi, unsigned NumberHi,
151 const char *TagLo, unsigned NumberLo,
152 bool IsSmall = false);
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000153
Chris Lattner57939f62010-01-22 22:19:51 +0000154 void EmitSectionOffset(const char* Label, const char* Section,
155 unsigned LabelNumber, unsigned SectionNumber,
156 bool IsSmall = false, bool isEH = false,
157 bool useSet = true);
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000158
Chris Lattner57939f62010-01-22 22:19:51 +0000159 /// EmitFrameMoves - Emit frame instructions to describe the layout of the
160 /// frame.
161 void EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID,
162 const std::vector<MachineMove> &Moves, bool isEH);
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000163};
164
165} // end llvm namespace
166
167#endif