blob: 237501cfeffe446efea7dcebd02e80584ec699a2 [file] [log] [blame]
Bill Wendling88423ee2009-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 Wendling0310d762009-05-15 09:23:25 +000014#ifndef CODEGEN_ASMPRINTER_DWARFPRINTER_H__
15#define CODEGEN_ASMPRINTER_DWARFPRINTER_H__
Bill Wendling88423ee2009-05-15 00:11:17 +000016
Bill Wendling88423ee2009-05-15 00:11:17 +000017#include "llvm/CodeGen/MachineLocation.h"
18#include "llvm/Support/Compiler.h"
Chris Lattner0ad9c912010-01-22 22:09:00 +000019#include "llvm/Support/FormattedStream.h"
Bill Wendling88423ee2009-05-15 00:11:17 +000020#include <vector>
21
22namespace llvm {
Chris Lattner3c653352010-01-22 22:19:51 +000023class AsmPrinter;
24class MachineFunction;
25class MachineModuleInfo;
26class Module;
27class MCAsmInfo;
28class TargetData;
29class TargetRegisterInfo;
Anton Korobeynikov9184b252010-02-15 22:35:59 +000030class GlobalValue;
Chris Lattner3c653352010-01-22 22:19:51 +000031class MCSymbol;
Chris Lattnerfaca5492010-01-22 23:47:11 +000032class Twine;
Bill Wendling88423ee2009-05-15 00:11:17 +000033
Chris Lattner066c9ac2010-01-22 22:23:57 +000034class DwarfPrinter {
Chris Lattner3c653352010-01-22 22:19:51 +000035protected:
Duncan Sands3dc32ed2010-02-07 21:09:22 +000036 ~DwarfPrinter() {}
37
Chris Lattner3c653352010-01-22 22:19:51 +000038 //===-------------------------------------------------------------==---===//
39 // Core attributes used by the DWARF printer.
40 //
Bill Wendling88423ee2009-05-15 00:11:17 +000041
Chris Lattner3c653352010-01-22 22:19:51 +000042 /// O - Stream to .s file.
43 raw_ostream &O;
Bill Wendling88423ee2009-05-15 00:11:17 +000044
Chris Lattner3c653352010-01-22 22:19:51 +000045 /// Asm - Target of Dwarf emission.
46 AsmPrinter *Asm;
Bill Wendling88423ee2009-05-15 00:11:17 +000047
Chris Lattner3c653352010-01-22 22:19:51 +000048 /// MAI - Target asm information.
49 const MCAsmInfo *MAI;
Bill Wendling88423ee2009-05-15 00:11:17 +000050
Chris Lattner3c653352010-01-22 22:19:51 +000051 /// TD - Target data.
52 const TargetData *TD;
Bill Wendling88423ee2009-05-15 00:11:17 +000053
Chris Lattner3c653352010-01-22 22:19:51 +000054 /// RI - Register Information.
55 const TargetRegisterInfo *RI;
Bill Wendling88423ee2009-05-15 00:11:17 +000056
Chris Lattner3c653352010-01-22 22:19:51 +000057 /// M - Current module.
58 Module *M;
Bill Wendling88423ee2009-05-15 00:11:17 +000059
Chris Lattner3c653352010-01-22 22:19:51 +000060 /// MF - Current machine function.
Chris Lattnereec791a2010-01-26 23:18:02 +000061 const MachineFunction *MF;
Bill Wendling88423ee2009-05-15 00:11:17 +000062
Chris Lattner3c653352010-01-22 22:19:51 +000063 /// MMI - Collected machine module information.
64 MachineModuleInfo *MMI;
Bill Wendling88423ee2009-05-15 00:11:17 +000065
Chris Lattner3c653352010-01-22 22:19:51 +000066 /// SubprogramCount - The running count of functions being compiled.
67 unsigned SubprogramCount;
Bill Wendling88423ee2009-05-15 00:11:17 +000068
Chris Lattner3c653352010-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 Wendling88423ee2009-05-15 00:11:17 +000072
Chris Lattner066c9ac2010-01-22 22:23:57 +000073 DwarfPrinter(raw_ostream &OS, AsmPrinter *A, const MCAsmInfo *T,
74 const char *flavor);
Chris Lattner3c653352010-01-22 22:19:51 +000075public:
Chris Lattnerf61ed8e2010-01-22 22:38:16 +000076
Chris Lattner3c653352010-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 Wendling88423ee2009-05-15 00:11:17 +000084
Chris Lattnerb98b1bf2010-03-08 22:23:36 +000085 /// getDWLabel - Return the MCSymbol corresponding to the assembler temporary
86 /// label with the specified stem and unique ID.
87 MCSymbol *getDWLabel(const char *Name, unsigned ID) const;
88
89 /// getTempLabel - Return an assembler temporary label with the specified
90 /// name.
91 MCSymbol *getTempLabel(const char *Name) const;
92
Anton Korobeynikov9184b252010-02-15 22:35:59 +000093 /// SizeOfEncodedValue - Return the size of the encoding in bytes.
94 unsigned SizeOfEncodedValue(unsigned Encoding) const;
95
96 void PrintRelDirective(unsigned Encoding) const;
Chris Lattner3c653352010-01-22 22:19:51 +000097 void PrintRelDirective(bool Force32Bit = false,
98 bool isInSection = false) const;
Bill Wendling88423ee2009-05-15 00:11:17 +000099
Chris Lattnerfaca5492010-01-22 23:47:11 +0000100 /// EOL - Print a newline character to asm stream. If a comment is present
101 /// then it will be printed first. Comments should not contain '\n'.
102 void EOL(const Twine &Comment) const;
103
Chris Lattnerf61ed8e2010-01-22 22:38:16 +0000104 /// EmitEncodingByte - Emit a .byte 42 directive that corresponds to an
105 /// encoding. If verbose assembly output is enabled, we output comments
Chris Lattnerbb9078a2010-01-22 22:56:55 +0000106 /// describing the encoding. Desc is a string saying what the encoding is
107 /// specifying (e.g. "LSDA").
108 void EmitEncodingByte(unsigned Val, const char *Desc);
Chris Lattnerf61ed8e2010-01-22 22:38:16 +0000109
Chris Lattner245834d2010-01-22 23:40:08 +0000110 /// EmitCFAByte - Emit a .byte 42 directive for a DW_CFA_xxx value.
111 void EmitCFAByte(unsigned Val);
112
113
Chris Lattner894d75a2010-01-22 23:18:42 +0000114 /// EmitSLEB128 - emit the specified signed leb128 value.
Chris Lattnerbb9078a2010-01-22 22:56:55 +0000115 void EmitSLEB128(int Value, const char *Desc) const;
Chris Lattner894d75a2010-01-22 23:18:42 +0000116
117 /// EmitULEB128 - emit the specified unsigned leb128 value.
Bill Wendling3dc9b482010-02-24 23:34:35 +0000118 void EmitULEB128(unsigned Value, const char *Desc = 0,
119 unsigned PadTo = 0) const;
Chris Lattner894d75a2010-01-22 23:18:42 +0000120
Chris Lattnerbb9078a2010-01-22 22:56:55 +0000121
Chris Lattner3c653352010-01-22 22:19:51 +0000122 /// PrintLabelName - Print label name in form used by Dwarf writer.
123 ///
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000124 void PrintLabelName(const MCSymbol *Label) const;
Chris Lattner3c653352010-01-22 22:19:51 +0000125 void PrintLabelName(const char *Tag, unsigned Number,
126 const char *Suffix) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000127
Chris Lattner3c653352010-01-22 22:19:51 +0000128 /// EmitReference - Emit a reference to a label.
129 ///
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000130 void EmitReference(const MCSymbol *Label, bool IsPCRelative = false,
131 bool Force32Bit = false) const;
Chris Lattnerc7249da2010-03-08 22:47:57 +0000132
Anton Korobeynikov9184b252010-02-15 22:35:59 +0000133 void EmitReference(const MCSymbol *Sym, unsigned Encoding) const;
134 void EmitReference(const GlobalValue *GV, unsigned Encoding) const;
135
Chris Lattner6a315c32010-01-26 20:20:43 +0000136 /// EmitDifference - Emit the difference between two labels.
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000137 void EmitDifference(const MCSymbol *LabelHi, const MCSymbol *LabelLo,
138 bool IsSmall = false);
Chris Lattner57578762010-03-08 23:23:25 +0000139
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000140 void EmitSectionOffset(const MCSymbol *Label, const MCSymbol *Section,
Chris Lattner57578762010-03-08 23:23:25 +0000141 bool IsSmall = false, bool isEH = false);
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000142
Chris Lattner3c653352010-01-22 22:19:51 +0000143 /// EmitFrameMoves - Emit frame instructions to describe the layout of the
144 /// frame.
145 void EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID,
146 const std::vector<MachineMove> &Moves, bool isEH);
Bill Wendling88423ee2009-05-15 00:11:17 +0000147};
148
149} // end llvm namespace
150
151#endif