blob: 0b94645a8c7b335e69fa42f3147ca85da438f5fa [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 Lattnerc3421bb2010-03-09 00:00:15 +000069 DwarfPrinter(raw_ostream &OS, AsmPrinter *A, const MCAsmInfo *T);
Chris Lattner3c653352010-01-22 22:19:51 +000070public:
Chris Lattnerf61ed8e2010-01-22 22:38:16 +000071
Chris Lattner3c653352010-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 Wendling88423ee2009-05-15 00:11:17 +000079
Chris Lattnerb98b1bf2010-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 Korobeynikov9184b252010-02-15 22:35:59 +000088 /// SizeOfEncodedValue - Return the size of the encoding in bytes.
89 unsigned SizeOfEncodedValue(unsigned Encoding) const;
90
Chris Lattnerf61ed8e2010-01-22 22:38:16 +000091 /// EmitEncodingByte - Emit a .byte 42 directive that corresponds to an
92 /// encoding. If verbose assembly output is enabled, we output comments
Chris Lattnerbb9078a2010-01-22 22:56:55 +000093 /// describing the encoding. Desc is a string saying what the encoding is
94 /// specifying (e.g. "LSDA").
95 void EmitEncodingByte(unsigned Val, const char *Desc);
Chris Lattnerf61ed8e2010-01-22 22:38:16 +000096
Chris Lattner245834d2010-01-22 23:40:08 +000097 /// EmitCFAByte - Emit a .byte 42 directive for a DW_CFA_xxx value.
98 void EmitCFAByte(unsigned Val);
99
100
Chris Lattner894d75a2010-01-22 23:18:42 +0000101 /// EmitSLEB128 - emit the specified signed leb128 value.
Chris Lattnerbb9078a2010-01-22 22:56:55 +0000102 void EmitSLEB128(int Value, const char *Desc) const;
Chris Lattner894d75a2010-01-22 23:18:42 +0000103
104 /// EmitULEB128 - emit the specified unsigned leb128 value.
Bill Wendling3dc9b482010-02-24 23:34:35 +0000105 void EmitULEB128(unsigned Value, const char *Desc = 0,
106 unsigned PadTo = 0) const;
Chris Lattner894d75a2010-01-22 23:18:42 +0000107
Chris Lattnerbb9078a2010-01-22 22:56:55 +0000108
Chris Lattner3c653352010-01-22 22:19:51 +0000109 /// EmitReference - Emit a reference to a label.
110 ///
Anton Korobeynikov9184b252010-02-15 22:35:59 +0000111 void EmitReference(const MCSymbol *Sym, unsigned Encoding) const;
112 void EmitReference(const GlobalValue *GV, unsigned Encoding) const;
113
Chris Lattner6a315c32010-01-26 20:20:43 +0000114 /// EmitDifference - Emit the difference between two labels.
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000115 void EmitDifference(const MCSymbol *LabelHi, const MCSymbol *LabelLo,
116 bool IsSmall = false);
Chris Lattner57578762010-03-08 23:23:25 +0000117
Chris Lattneref6b14f2010-03-09 00:17:58 +0000118 /// EmitSectionOffset - Emit Label-Section or use a special purpose directive
119 /// to emit a section offset if the target has one.
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000120 void EmitSectionOffset(const MCSymbol *Label, const MCSymbol *Section,
Chris Lattner57578762010-03-08 23:23:25 +0000121 bool IsSmall = false, bool isEH = false);
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000122
Chris Lattner3c653352010-01-22 22:19:51 +0000123 /// EmitFrameMoves - Emit frame instructions to describe the layout of the
124 /// frame.
Chris Lattner5e6cbe02010-03-13 08:05:25 +0000125 void EmitFrameMoves(MCSymbol *BaseLabel,
Chris Lattner3c653352010-01-22 22:19:51 +0000126 const std::vector<MachineMove> &Moves, bool isEH);
Bill Wendling88423ee2009-05-15 00:11:17 +0000127};
128
129} // end llvm namespace
130
131#endif