blob: 31aa69ab094fe5ae6f426204b55f3c9ef99a781a [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:
36 //===-------------------------------------------------------------==---===//
37 // Core attributes used by the DWARF printer.
38 //
Bill Wendlingbbee8c92009-05-15 00:11:17 +000039
Chris Lattner57939f62010-01-22 22:19:51 +000040 /// O - Stream to .s file.
41 raw_ostream &O;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000042
Chris Lattner57939f62010-01-22 22:19:51 +000043 /// Asm - Target of Dwarf emission.
44 AsmPrinter *Asm;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000045
Chris Lattner57939f62010-01-22 22:19:51 +000046 /// MAI - Target asm information.
47 const MCAsmInfo *MAI;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000048
Chris Lattner57939f62010-01-22 22:19:51 +000049 /// TD - Target data.
50 const TargetData *TD;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000051
Chris Lattner57939f62010-01-22 22:19:51 +000052 /// RI - Register Information.
53 const TargetRegisterInfo *RI;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000054
Chris Lattner57939f62010-01-22 22:19:51 +000055 /// M - Current module.
56 Module *M;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000057
Chris Lattner57939f62010-01-22 22:19:51 +000058 /// MF - Current machine function.
59 MachineFunction *MF;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000060
Chris Lattner57939f62010-01-22 22:19:51 +000061 /// MMI - Collected machine module information.
62 MachineModuleInfo *MMI;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000063
Chris Lattner57939f62010-01-22 22:19:51 +000064 /// SubprogramCount - The running count of functions being compiled.
65 unsigned SubprogramCount;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000066
Chris Lattner57939f62010-01-22 22:19:51 +000067 /// Flavor - A unique string indicating what dwarf producer this is, used to
68 /// unique labels.
69 const char * const Flavor;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000070
Chris Lattner57939f62010-01-22 22:19:51 +000071 /// SetCounter - A unique number for each '.set' directive.
72 unsigned SetCounter;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000073
Chris Lattnerb21f1042010-01-22 22:23:57 +000074 DwarfPrinter(raw_ostream &OS, AsmPrinter *A, const MCAsmInfo *T,
75 const char *flavor);
Chris Lattner57939f62010-01-22 22:19:51 +000076public:
Chris Lattnerd705acf2010-01-22 22:38:16 +000077
Chris Lattner57939f62010-01-22 22:19:51 +000078 //===------------------------------------------------------------------===//
79 // Accessors.
80 //
81 const AsmPrinter *getAsm() const { return Asm; }
82 MachineModuleInfo *getMMI() const { return MMI; }
83 const MCAsmInfo *getMCAsmInfo() const { return MAI; }
84 const TargetData *getTargetData() const { return TD; }
Bill Wendlingbbee8c92009-05-15 00:11:17 +000085
Chris Lattner57939f62010-01-22 22:19:51 +000086 void PrintRelDirective(bool Force32Bit = false,
87 bool isInSection = false) const;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000088
Chris Lattner05ae1d22010-01-22 23:47:11 +000089 /// EOL - Print a newline character to asm stream. If a comment is present
90 /// then it will be printed first. Comments should not contain '\n'.
91 void EOL(const Twine &Comment) const;
92
Chris Lattnerd705acf2010-01-22 22:38:16 +000093 /// EmitEncodingByte - Emit a .byte 42 directive that corresponds to an
94 /// encoding. If verbose assembly output is enabled, we output comments
Chris Lattner20f334f2010-01-22 22:56:55 +000095 /// describing the encoding. Desc is a string saying what the encoding is
96 /// specifying (e.g. "LSDA").
97 void EmitEncodingByte(unsigned Val, const char *Desc);
Chris Lattnerd705acf2010-01-22 22:38:16 +000098
Chris Lattnerab4cf952010-01-22 23:40:08 +000099 /// EmitCFAByte - Emit a .byte 42 directive for a DW_CFA_xxx value.
100 void EmitCFAByte(unsigned Val);
101
102
Chris Lattnerbcc79432010-01-22 23:18:42 +0000103 /// EmitSLEB128 - emit the specified signed leb128 value.
Chris Lattner20f334f2010-01-22 22:56:55 +0000104 void EmitSLEB128(int Value, const char *Desc) const;
Chris Lattnerbcc79432010-01-22 23:18:42 +0000105
106 /// EmitULEB128 - emit the specified unsigned leb128 value.
107 void EmitULEB128(unsigned Value, const char *Desc = 0) const;
108
Chris Lattner20f334f2010-01-22 22:56:55 +0000109
Chris Lattner57939f62010-01-22 22:19:51 +0000110 /// PrintLabelName - Print label name in form used by Dwarf writer.
111 ///
112 void PrintLabelName(const DWLabel &Label) const {
113 PrintLabelName(Label.getTag(), Label.getNumber());
114 }
115 void PrintLabelName(const char *Tag, unsigned Number) const;
116 void PrintLabelName(const char *Tag, unsigned Number,
117 const char *Suffix) const;
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000118
Chris Lattner57939f62010-01-22 22:19:51 +0000119 /// EmitLabel - Emit location label for internal use by Dwarf.
120 ///
121 void EmitLabel(const DWLabel &Label) const {
122 EmitLabel(Label.getTag(), Label.getNumber());
123 }
124 void EmitLabel(const char *Tag, unsigned Number) const;
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000125
Chris Lattner57939f62010-01-22 22:19:51 +0000126 /// EmitReference - Emit a reference to a label.
127 ///
128 void EmitReference(const DWLabel &Label, bool IsPCRelative = false,
129 bool Force32Bit = false) const {
130 EmitReference(Label.getTag(), Label.getNumber(),
131 IsPCRelative, Force32Bit);
132 }
133 void EmitReference(const char *Tag, unsigned Number,
134 bool IsPCRelative = false,
135 bool Force32Bit = false) const;
136 void EmitReference(const std::string &Name, bool IsPCRelative = false,
137 bool Force32Bit = false) const;
138 void EmitReference(const MCSymbol *Sym, bool IsPCRelative = false,
139 bool Force32Bit = false) const;
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000140
Chris Lattner1fd01822010-01-26 20:20:43 +0000141 /// EmitDifference - Emit the difference between two labels.
Chris Lattner57939f62010-01-22 22:19:51 +0000142 void EmitDifference(const DWLabel &LabelHi, const DWLabel &LabelLo,
143 bool IsSmall = false) {
144 EmitDifference(LabelHi.getTag(), LabelHi.getNumber(),
145 LabelLo.getTag(), LabelLo.getNumber(),
146 IsSmall);
147 }
148 void EmitDifference(const char *TagHi, unsigned NumberHi,
149 const char *TagLo, unsigned NumberLo,
150 bool IsSmall = false);
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000151
Chris Lattner57939f62010-01-22 22:19:51 +0000152 void EmitSectionOffset(const char* Label, const char* Section,
153 unsigned LabelNumber, unsigned SectionNumber,
154 bool IsSmall = false, bool isEH = false,
155 bool useSet = true);
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000156
Chris Lattner57939f62010-01-22 22:19:51 +0000157 /// EmitFrameMoves - Emit frame instructions to describe the layout of the
158 /// frame.
159 void EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID,
160 const std::vector<MachineMove> &Moves, bool isEH);
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000161};
162
163} // end llvm namespace
164
165#endif