blob: 5228ca53032f889e884d12fae3bc882e4fc498f2 [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
Bill Wendlingbbee8c92009-05-15 00:11:17 +000017#include "llvm/CodeGen/MachineLocation.h"
18#include "llvm/Support/Compiler.h"
Chris Lattnerad653482010-01-22 22:09:00 +000019#include "llvm/Support/FormattedStream.h"
Bill Wendlingbbee8c92009-05-15 00:11:17 +000020#include <vector>
21
22namespace llvm {
Chris Lattner57939f62010-01-22 22:19:51 +000023class AsmPrinter;
24class MachineFunction;
25class MachineModuleInfo;
26class Module;
27class MCAsmInfo;
28class TargetData;
29class TargetRegisterInfo;
Anton Korobeynikovd779bcb2010-02-15 22:35:59 +000030class GlobalValue;
Chris Lattner57939f62010-01-22 22:19:51 +000031class 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 Lattnerbe4c2fc2010-03-08 22:23:36 +000088 /// getDWLabel - Return the MCSymbol corresponding to the assembler temporary
89 /// label with the specified stem and unique ID.
90 MCSymbol *getDWLabel(const char *Name, unsigned ID) const;
91
92 /// getTempLabel - Return an assembler temporary label with the specified
93 /// name.
94 MCSymbol *getTempLabel(const char *Name) const;
95
Anton Korobeynikovd779bcb2010-02-15 22:35:59 +000096 /// SizeOfEncodedValue - Return the size of the encoding in bytes.
97 unsigned SizeOfEncodedValue(unsigned Encoding) const;
98
99 void PrintRelDirective(unsigned Encoding) const;
Chris Lattner57939f62010-01-22 22:19:51 +0000100 void PrintRelDirective(bool Force32Bit = false,
101 bool isInSection = false) const;
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000102
Chris Lattner05ae1d22010-01-22 23:47:11 +0000103 /// EOL - Print a newline character to asm stream. If a comment is present
104 /// then it will be printed first. Comments should not contain '\n'.
105 void EOL(const Twine &Comment) const;
106
Chris Lattnerd705acf2010-01-22 22:38:16 +0000107 /// EmitEncodingByte - Emit a .byte 42 directive that corresponds to an
108 /// encoding. If verbose assembly output is enabled, we output comments
Chris Lattner20f334f2010-01-22 22:56:55 +0000109 /// describing the encoding. Desc is a string saying what the encoding is
110 /// specifying (e.g. "LSDA").
111 void EmitEncodingByte(unsigned Val, const char *Desc);
Chris Lattnerd705acf2010-01-22 22:38:16 +0000112
Chris Lattnerab4cf952010-01-22 23:40:08 +0000113 /// EmitCFAByte - Emit a .byte 42 directive for a DW_CFA_xxx value.
114 void EmitCFAByte(unsigned Val);
115
116
Chris Lattnerbcc79432010-01-22 23:18:42 +0000117 /// EmitSLEB128 - emit the specified signed leb128 value.
Chris Lattner20f334f2010-01-22 22:56:55 +0000118 void EmitSLEB128(int Value, const char *Desc) const;
Chris Lattnerbcc79432010-01-22 23:18:42 +0000119
120 /// EmitULEB128 - emit the specified unsigned leb128 value.
Bill Wendlinga7888ea2010-02-24 23:34:35 +0000121 void EmitULEB128(unsigned Value, const char *Desc = 0,
122 unsigned PadTo = 0) const;
Chris Lattnerbcc79432010-01-22 23:18:42 +0000123
Chris Lattner20f334f2010-01-22 22:56:55 +0000124
Chris Lattner57939f62010-01-22 22:19:51 +0000125 /// PrintLabelName - Print label name in form used by Dwarf writer.
126 ///
Chris Lattnerbe4c2fc2010-03-08 22:23:36 +0000127 void PrintLabelName(const MCSymbol *Label) const;
Chris Lattner57939f62010-01-22 22:19:51 +0000128 void PrintLabelName(const char *Tag, unsigned Number,
129 const char *Suffix) const;
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000130
Chris Lattner57939f62010-01-22 22:19:51 +0000131 /// EmitReference - Emit a reference to a label.
132 ///
Chris Lattnerbe4c2fc2010-03-08 22:23:36 +0000133 void EmitReference(const MCSymbol *Label, bool IsPCRelative = false,
134 bool Force32Bit = false) const;
Chris Lattner7bc33552010-03-08 22:47:57 +0000135
Anton Korobeynikovd779bcb2010-02-15 22:35:59 +0000136 void EmitReference(const MCSymbol *Sym, unsigned Encoding) const;
137 void EmitReference(const GlobalValue *GV, unsigned Encoding) const;
138
Chris Lattner1fd01822010-01-26 20:20:43 +0000139 /// EmitDifference - Emit the difference between two labels.
Chris Lattnerbe4c2fc2010-03-08 22:23:36 +0000140 void EmitDifference(const MCSymbol *LabelHi, const MCSymbol *LabelLo,
141 bool IsSmall = false);
Chris Lattnerf8bfa882010-03-08 23:23:25 +0000142
Chris Lattnerbe4c2fc2010-03-08 22:23:36 +0000143 void EmitSectionOffset(const MCSymbol *Label, const MCSymbol *Section,
Chris Lattnerf8bfa882010-03-08 23:23:25 +0000144 bool IsSmall = false, bool isEH = false);
Chris Lattnerbe4c2fc2010-03-08 22:23:36 +0000145
Chris Lattner57939f62010-01-22 22:19:51 +0000146 /// EmitFrameMoves - Emit frame instructions to describe the layout of the
147 /// frame.
148 void EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID,
149 const std::vector<MachineMove> &Moves, bool isEH);
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000150};
151
152} // end llvm namespace
153
154#endif