blob: d76caf9a4ee10e7ee0c2af7c110fa626d6c9bcc6 [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
90 /// describing the encoding. Desc is an optional string saying what the
91 /// encoding is specifying (e.g. "LSDA").
92 void EmitEncodingByte(unsigned Val, const char *Desc = 0);
93
Bill Wendlingbbee8c92009-05-15 00:11:17 +000094
Chris Lattner57939f62010-01-22 22:19:51 +000095 /// PrintLabelName - Print label name in form used by Dwarf writer.
96 ///
97 void PrintLabelName(const DWLabel &Label) const {
98 PrintLabelName(Label.getTag(), Label.getNumber());
99 }
100 void PrintLabelName(const char *Tag, unsigned Number) const;
101 void PrintLabelName(const char *Tag, unsigned Number,
102 const char *Suffix) const;
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000103
Chris Lattner57939f62010-01-22 22:19:51 +0000104 /// EmitLabel - Emit location label for internal use by Dwarf.
105 ///
106 void EmitLabel(const DWLabel &Label) const {
107 EmitLabel(Label.getTag(), Label.getNumber());
108 }
109 void EmitLabel(const char *Tag, unsigned Number) const;
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000110
Chris Lattner57939f62010-01-22 22:19:51 +0000111 /// EmitReference - Emit a reference to a label.
112 ///
113 void EmitReference(const DWLabel &Label, bool IsPCRelative = false,
114 bool Force32Bit = false) const {
115 EmitReference(Label.getTag(), Label.getNumber(),
116 IsPCRelative, Force32Bit);
117 }
118 void EmitReference(const char *Tag, unsigned Number,
119 bool IsPCRelative = false,
120 bool Force32Bit = false) const;
121 void EmitReference(const std::string &Name, bool IsPCRelative = false,
122 bool Force32Bit = false) const;
123 void EmitReference(const MCSymbol *Sym, bool IsPCRelative = false,
124 bool Force32Bit = false) const;
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000125
Chris Lattner57939f62010-01-22 22:19:51 +0000126 /// EmitDifference - Emit the difference between two labels. Some
127 /// assemblers do not behave with absolute expressions with data directives,
128 /// so there is an option (needsSet) to use an intermediary set expression.
129 void EmitDifference(const DWLabel &LabelHi, const DWLabel &LabelLo,
130 bool IsSmall = false) {
131 EmitDifference(LabelHi.getTag(), LabelHi.getNumber(),
132 LabelLo.getTag(), LabelLo.getNumber(),
133 IsSmall);
134 }
135 void EmitDifference(const char *TagHi, unsigned NumberHi,
136 const char *TagLo, unsigned NumberLo,
137 bool IsSmall = false);
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000138
Chris Lattner57939f62010-01-22 22:19:51 +0000139 void EmitSectionOffset(const char* Label, const char* Section,
140 unsigned LabelNumber, unsigned SectionNumber,
141 bool IsSmall = false, bool isEH = false,
142 bool useSet = true);
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000143
Chris Lattner57939f62010-01-22 22:19:51 +0000144 /// EmitFrameMoves - Emit frame instructions to describe the layout of the
145 /// frame.
146 void EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID,
147 const std::vector<MachineMove> &Moves, bool isEH);
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000148};
149
150} // end llvm namespace
151
152#endif