blob: 2d4564531f1248b81e42d6685591f33083e56a43 [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 Lattnerbcc79432010-01-22 23:18:42 +000094 /// EmitSLEB128 - emit the specified signed leb128 value.
Chris Lattner20f334f2010-01-22 22:56:55 +000095 void EmitSLEB128(int Value, const char *Desc) const;
Chris Lattnerbcc79432010-01-22 23:18:42 +000096
97 /// EmitULEB128 - emit the specified unsigned leb128 value.
98 void EmitULEB128(unsigned Value, const char *Desc = 0) const;
99
Chris Lattner20f334f2010-01-22 22:56:55 +0000100
Chris Lattner57939f62010-01-22 22:19:51 +0000101 /// PrintLabelName - Print label name in form used by Dwarf writer.
102 ///
103 void PrintLabelName(const DWLabel &Label) const {
104 PrintLabelName(Label.getTag(), Label.getNumber());
105 }
106 void PrintLabelName(const char *Tag, unsigned Number) const;
107 void PrintLabelName(const char *Tag, unsigned Number,
108 const char *Suffix) const;
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000109
Chris Lattner57939f62010-01-22 22:19:51 +0000110 /// EmitLabel - Emit location label for internal use by Dwarf.
111 ///
112 void EmitLabel(const DWLabel &Label) const {
113 EmitLabel(Label.getTag(), Label.getNumber());
114 }
115 void EmitLabel(const char *Tag, unsigned Number) const;
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000116
Chris Lattner57939f62010-01-22 22:19:51 +0000117 /// EmitReference - Emit a reference to a label.
118 ///
119 void EmitReference(const DWLabel &Label, bool IsPCRelative = false,
120 bool Force32Bit = false) const {
121 EmitReference(Label.getTag(), Label.getNumber(),
122 IsPCRelative, Force32Bit);
123 }
124 void EmitReference(const char *Tag, unsigned Number,
125 bool IsPCRelative = false,
126 bool Force32Bit = false) const;
127 void EmitReference(const std::string &Name, bool IsPCRelative = false,
128 bool Force32Bit = false) const;
129 void EmitReference(const MCSymbol *Sym, bool IsPCRelative = false,
130 bool Force32Bit = false) const;
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000131
Chris Lattner57939f62010-01-22 22:19:51 +0000132 /// EmitDifference - Emit the difference between two labels. Some
133 /// assemblers do not behave with absolute expressions with data directives,
134 /// so there is an option (needsSet) to use an intermediary set expression.
135 void EmitDifference(const DWLabel &LabelHi, const DWLabel &LabelLo,
136 bool IsSmall = false) {
137 EmitDifference(LabelHi.getTag(), LabelHi.getNumber(),
138 LabelLo.getTag(), LabelLo.getNumber(),
139 IsSmall);
140 }
141 void EmitDifference(const char *TagHi, unsigned NumberHi,
142 const char *TagLo, unsigned NumberLo,
143 bool IsSmall = false);
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000144
Chris Lattner57939f62010-01-22 22:19:51 +0000145 void EmitSectionOffset(const char* Label, const char* Section,
146 unsigned LabelNumber, unsigned SectionNumber,
147 bool IsSmall = false, bool isEH = false,
148 bool useSet = true);
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000149
Chris Lattner57939f62010-01-22 22:19:51 +0000150 /// EmitFrameMoves - Emit frame instructions to describe the layout of the
151 /// frame.
152 void EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID,
153 const std::vector<MachineMove> &Moves, bool isEH);
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000154};
155
156} // end llvm namespace
157
158#endif