blob: 19c05b7a70b7421b0e6aed901dffc02f4b446999 [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 Lattner819669a2010-03-09 00:00:15 +000069 DwarfPrinter(raw_ostream &OS, AsmPrinter *A, const MCAsmInfo *T);
Chris Lattner57939f62010-01-22 22:19:51 +000070public:
Chris Lattnerd705acf2010-01-22 22:38:16 +000071
Chris Lattner57939f62010-01-22 22:19:51 +000072 //===------------------------------------------------------------------===//
73 // Accessors.
74 //
75 const AsmPrinter *getAsm() const { return Asm; }
76 MachineModuleInfo *getMMI() const { return MMI; }
77 const MCAsmInfo *getMCAsmInfo() const { return MAI; }
78 const TargetData *getTargetData() const { return TD; }
Bill Wendlingbbee8c92009-05-15 00:11:17 +000079
Chris Lattnerbe4c2fc2010-03-08 22:23:36 +000080 /// getDWLabel - Return the MCSymbol corresponding to the assembler temporary
81 /// label with the specified stem and unique ID.
82 MCSymbol *getDWLabel(const char *Name, unsigned ID) const;
83
84 /// getTempLabel - Return an assembler temporary label with the specified
85 /// name.
86 MCSymbol *getTempLabel(const char *Name) const;
87
Anton Korobeynikovd779bcb2010-02-15 22:35:59 +000088 /// SizeOfEncodedValue - Return the size of the encoding in bytes.
89 unsigned SizeOfEncodedValue(unsigned Encoding) const;
90
91 void PrintRelDirective(unsigned Encoding) const;
Chris Lattner57939f62010-01-22 22:19:51 +000092 void PrintRelDirective(bool Force32Bit = false,
93 bool isInSection = false) const;
Bill Wendlingbbee8c92009-05-15 00:11:17 +000094
Chris Lattner05ae1d22010-01-22 23:47:11 +000095 /// EOL - Print a newline character to asm stream. If a comment is present
96 /// then it will be printed first. Comments should not contain '\n'.
97 void EOL(const Twine &Comment) const;
98
Chris Lattnerd705acf2010-01-22 22:38:16 +000099 /// EmitEncodingByte - Emit a .byte 42 directive that corresponds to an
100 /// encoding. If verbose assembly output is enabled, we output comments
Chris Lattner20f334f2010-01-22 22:56:55 +0000101 /// describing the encoding. Desc is a string saying what the encoding is
102 /// specifying (e.g. "LSDA").
103 void EmitEncodingByte(unsigned Val, const char *Desc);
Chris Lattnerd705acf2010-01-22 22:38:16 +0000104
Chris Lattnerab4cf952010-01-22 23:40:08 +0000105 /// EmitCFAByte - Emit a .byte 42 directive for a DW_CFA_xxx value.
106 void EmitCFAByte(unsigned Val);
107
108
Chris Lattnerbcc79432010-01-22 23:18:42 +0000109 /// EmitSLEB128 - emit the specified signed leb128 value.
Chris Lattner20f334f2010-01-22 22:56:55 +0000110 void EmitSLEB128(int Value, const char *Desc) const;
Chris Lattnerbcc79432010-01-22 23:18:42 +0000111
112 /// EmitULEB128 - emit the specified unsigned leb128 value.
Bill Wendlinga7888ea2010-02-24 23:34:35 +0000113 void EmitULEB128(unsigned Value, const char *Desc = 0,
114 unsigned PadTo = 0) const;
Chris Lattnerbcc79432010-01-22 23:18:42 +0000115
Chris Lattner20f334f2010-01-22 22:56:55 +0000116
Chris Lattner57939f62010-01-22 22:19:51 +0000117 /// PrintLabelName - Print label name in form used by Dwarf writer.
118 ///
Chris Lattnerbe4c2fc2010-03-08 22:23:36 +0000119 void PrintLabelName(const MCSymbol *Label) const;
Chris Lattner57939f62010-01-22 22:19:51 +0000120 void PrintLabelName(const char *Tag, unsigned Number,
121 const char *Suffix) const;
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000122
Chris Lattner57939f62010-01-22 22:19:51 +0000123 /// EmitReference - Emit a reference to a label.
124 ///
Chris Lattnerbe4c2fc2010-03-08 22:23:36 +0000125 void EmitReference(const MCSymbol *Label, bool IsPCRelative = false,
126 bool Force32Bit = false) const;
Chris Lattner7bc33552010-03-08 22:47:57 +0000127
Anton Korobeynikovd779bcb2010-02-15 22:35:59 +0000128 void EmitReference(const MCSymbol *Sym, unsigned Encoding) const;
129 void EmitReference(const GlobalValue *GV, unsigned Encoding) const;
130
Chris Lattner1fd01822010-01-26 20:20:43 +0000131 /// EmitDifference - Emit the difference between two labels.
Chris Lattnerbe4c2fc2010-03-08 22:23:36 +0000132 void EmitDifference(const MCSymbol *LabelHi, const MCSymbol *LabelLo,
133 bool IsSmall = false);
Chris Lattnerf8bfa882010-03-08 23:23:25 +0000134
Chris Lattnerbe4c2fc2010-03-08 22:23:36 +0000135 void EmitSectionOffset(const MCSymbol *Label, const MCSymbol *Section,
Chris Lattnerf8bfa882010-03-08 23:23:25 +0000136 bool IsSmall = false, bool isEH = false);
Chris Lattnerbe4c2fc2010-03-08 22:23:36 +0000137
Chris Lattner57939f62010-01-22 22:19:51 +0000138 /// EmitFrameMoves - Emit frame instructions to describe the layout of the
139 /// frame.
140 void EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID,
141 const std::vector<MachineMove> &Moves, bool isEH);
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000142};
143
144} // end llvm namespace
145
146#endif