blob: 2549692dd701205247d65d00191e1ea3ebe5b310 [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;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000032
Chris Lattnerb21f1042010-01-22 22:23:57 +000033class DwarfPrinter {
Chris Lattner57939f62010-01-22 22:19:51 +000034protected:
35 //===-------------------------------------------------------------==---===//
36 // Core attributes used by the DWARF printer.
37 //
Bill Wendlingbbee8c92009-05-15 00:11:17 +000038
Chris Lattner57939f62010-01-22 22:19:51 +000039 /// O - Stream to .s file.
40 raw_ostream &O;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000041
Chris Lattner57939f62010-01-22 22:19:51 +000042 /// Asm - Target of Dwarf emission.
43 AsmPrinter *Asm;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000044
Chris Lattner57939f62010-01-22 22:19:51 +000045 /// MAI - Target asm information.
46 const MCAsmInfo *MAI;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000047
Chris Lattner57939f62010-01-22 22:19:51 +000048 /// TD - Target data.
49 const TargetData *TD;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000050
Chris Lattner57939f62010-01-22 22:19:51 +000051 /// RI - Register Information.
52 const TargetRegisterInfo *RI;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000053
Chris Lattner57939f62010-01-22 22:19:51 +000054 /// M - Current module.
55 Module *M;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000056
Chris Lattner57939f62010-01-22 22:19:51 +000057 /// MF - Current machine function.
58 MachineFunction *MF;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000059
Chris Lattner57939f62010-01-22 22:19:51 +000060 /// MMI - Collected machine module information.
61 MachineModuleInfo *MMI;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000062
Chris Lattner57939f62010-01-22 22:19:51 +000063 /// SubprogramCount - The running count of functions being compiled.
64 unsigned SubprogramCount;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000065
Chris Lattner57939f62010-01-22 22:19:51 +000066 /// Flavor - A unique string indicating what dwarf producer this is, used to
67 /// unique labels.
68 const char * const Flavor;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000069
Chris Lattner57939f62010-01-22 22:19:51 +000070 /// SetCounter - A unique number for each '.set' directive.
71 unsigned SetCounter;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000072
Chris Lattnerb21f1042010-01-22 22:23:57 +000073 DwarfPrinter(raw_ostream &OS, AsmPrinter *A, const MCAsmInfo *T,
74 const char *flavor);
Chris Lattner57939f62010-01-22 22:19:51 +000075public:
Chris Lattnerd705acf2010-01-22 22:38:16 +000076
Chris Lattner57939f62010-01-22 22:19:51 +000077 //===------------------------------------------------------------------===//
78 // Accessors.
79 //
80 const AsmPrinter *getAsm() const { return Asm; }
81 MachineModuleInfo *getMMI() const { return MMI; }
82 const MCAsmInfo *getMCAsmInfo() const { return MAI; }
83 const TargetData *getTargetData() const { return TD; }
Bill Wendlingbbee8c92009-05-15 00:11:17 +000084
Chris Lattner57939f62010-01-22 22:19:51 +000085 void PrintRelDirective(bool Force32Bit = false,
86 bool isInSection = false) const;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000087
Chris Lattnerd705acf2010-01-22 22:38:16 +000088 /// EmitEncodingByte - Emit a .byte 42 directive that corresponds to an
89 /// encoding. If verbose assembly output is enabled, we output comments
Chris Lattner20f334f2010-01-22 22:56:55 +000090 /// describing the encoding. Desc is a string saying what the encoding is
91 /// specifying (e.g. "LSDA").
92 void EmitEncodingByte(unsigned Val, const char *Desc);
Chris Lattnerd705acf2010-01-22 22:38:16 +000093
Chris Lattnerab4cf952010-01-22 23:40:08 +000094 /// EmitCFAByte - Emit a .byte 42 directive for a DW_CFA_xxx value.
95 void EmitCFAByte(unsigned Val);
96
97
Chris Lattnerbcc79432010-01-22 23:18:42 +000098 /// EmitSLEB128 - emit the specified signed leb128 value.
Chris Lattner20f334f2010-01-22 22:56:55 +000099 void EmitSLEB128(int Value, const char *Desc) const;
Chris Lattnerbcc79432010-01-22 23:18:42 +0000100
101 /// EmitULEB128 - emit the specified unsigned leb128 value.
102 void EmitULEB128(unsigned Value, const char *Desc = 0) const;
103
Chris Lattner20f334f2010-01-22 22:56:55 +0000104
Chris Lattner57939f62010-01-22 22:19:51 +0000105 /// PrintLabelName - Print label name in form used by Dwarf writer.
106 ///
107 void PrintLabelName(const DWLabel &Label) const {
108 PrintLabelName(Label.getTag(), Label.getNumber());
109 }
110 void PrintLabelName(const char *Tag, unsigned Number) const;
111 void PrintLabelName(const char *Tag, unsigned Number,
112 const char *Suffix) const;
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000113
Chris Lattner57939f62010-01-22 22:19:51 +0000114 /// EmitLabel - Emit location label for internal use by Dwarf.
115 ///
116 void EmitLabel(const DWLabel &Label) const {
117 EmitLabel(Label.getTag(), Label.getNumber());
118 }
119 void EmitLabel(const char *Tag, unsigned Number) const;
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000120
Chris Lattner57939f62010-01-22 22:19:51 +0000121 /// EmitReference - Emit a reference to a label.
122 ///
123 void EmitReference(const DWLabel &Label, bool IsPCRelative = false,
124 bool Force32Bit = false) const {
125 EmitReference(Label.getTag(), Label.getNumber(),
126 IsPCRelative, Force32Bit);
127 }
128 void EmitReference(const char *Tag, unsigned Number,
129 bool IsPCRelative = false,
130 bool Force32Bit = false) const;
131 void EmitReference(const std::string &Name, bool IsPCRelative = false,
132 bool Force32Bit = false) const;
133 void EmitReference(const MCSymbol *Sym, bool IsPCRelative = false,
134 bool Force32Bit = false) const;
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000135
Chris Lattner57939f62010-01-22 22:19:51 +0000136 /// EmitDifference - Emit the difference between two labels. Some
137 /// assemblers do not behave with absolute expressions with data directives,
138 /// so there is an option (needsSet) to use an intermediary set expression.
139 void EmitDifference(const DWLabel &LabelHi, const DWLabel &LabelLo,
140 bool IsSmall = false) {
141 EmitDifference(LabelHi.getTag(), LabelHi.getNumber(),
142 LabelLo.getTag(), LabelLo.getNumber(),
143 IsSmall);
144 }
145 void EmitDifference(const char *TagHi, unsigned NumberHi,
146 const char *TagLo, unsigned NumberLo,
147 bool IsSmall = false);
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000148
Chris Lattner57939f62010-01-22 22:19:51 +0000149 void EmitSectionOffset(const char* Label, const char* Section,
150 unsigned LabelNumber, unsigned SectionNumber,
151 bool IsSmall = false, bool isEH = false,
152 bool useSet = true);
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000153
Chris Lattner57939f62010-01-22 22:19:51 +0000154 /// EmitFrameMoves - Emit frame instructions to describe the layout of the
155 /// frame.
156 void EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID,
157 const std::vector<MachineMove> &Moves, bool isEH);
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000158};
159
160} // end llvm namespace
161
162#endif