blob: 9aba3f82ffb8a6be986f06902a7b240b7350641b [file] [log] [blame]
Adrian Prantlb16d9eb2015-01-12 22:19:22 +00001//===-- llvm/CodeGen/DwarfExpression.h - Dwarf Compile Unit ---*- 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// This file contains support for writing dwarf compile unit.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFEXPRESSION_H
15#define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFEXPRESSION_H
16
17#include "llvm/Support/DataTypes.h"
18
19namespace llvm {
20
Adrian Prantla4c30d62015-01-12 23:36:56 +000021class AsmPrinter;
Adrian Prantl66f25952015-01-13 00:04:06 +000022class ByteStreamer;
Adrian Prantla4c30d62015-01-12 23:36:56 +000023class TargetRegisterInfo;
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000024
25/// Base class containing the logic for constructing DWARF expressions
26/// independently of whether they are emitted into a DIE or into a .debug_loc
27/// entry.
28class DwarfExpression {
Adrian Prantl00dbc2a2015-01-12 22:19:26 +000029protected:
Adrian Prantla4c30d62015-01-12 23:36:56 +000030 const AsmPrinter ≈
31 // Various convenience accessors that extract things out of AsmPrinter.
32 const TargetRegisterInfo *getTRI() const;
Adrian Prantl66f25952015-01-13 00:04:06 +000033 unsigned getDwarfVersion() const;
Adrian Prantla4c30d62015-01-12 23:36:56 +000034
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000035public:
Adrian Prantla4c30d62015-01-12 23:36:56 +000036 DwarfExpression(const AsmPrinter &AP) : AP(AP) {}
Adrian Prantl9cffbd82015-01-12 23:36:50 +000037 virtual ~DwarfExpression() {}
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000038
39 virtual void EmitOp(uint8_t Op, const char* Comment = nullptr) = 0;
40 virtual void EmitSigned(int Value) = 0;
41 virtual void EmitUnsigned(unsigned Value) = 0;
Adrian Prantl00dbc2a2015-01-12 22:19:26 +000042
Adrian Prantl8995f5c2015-01-13 23:10:43 +000043 virtual bool isFrameRegister(unsigned MachineReg) = 0;
Adrian Prantl00dbc2a2015-01-12 22:19:26 +000044
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000045 /// Emit a dwarf register operation.
46 void AddReg(int DwarfReg, const char* Comment = nullptr);
47 /// Emit an (double-)indirect dwarf register operation.
48 void AddRegIndirect(int DwarfReg, int Offset, bool Deref = false);
49
50 /// Emit a dwarf register operation for describing
51 /// - a small value occupying only part of a register or
52 /// - a register representing only part of a value.
53 void AddOpPiece(unsigned SizeInBits, unsigned OffsetInBits = 0);
54 /// Emit a shift-right dwarf expression.
55 void AddShr(unsigned ShiftBy);
56
Adrian Prantl00dbc2a2015-01-12 22:19:26 +000057 /// Emit an indirect dwarf register operation for the given machine register.
58 /// Returns false if no DWARF register exists for MachineReg.
59 bool AddMachineRegIndirect(unsigned MachineReg, int Offset);
60
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000061 /// \brief Emit a partial DWARF register operation.
62 /// \param MLoc the register
63 /// \param PieceSize size and
64 /// \param PieceOffset offset of the piece in bits, if this is one
65 /// piece of an aggregate value.
66 ///
67 /// If size and offset is zero an operation for the entire
68 /// register is emitted: Some targets do not provide a DWARF
69 /// register number for every register. If this is the case, this
70 /// function will attempt to emit a DWARF register by emitting a
71 /// piece of a super-register or by piecing together multiple
72 /// subregisters that alias the register.
73 void AddMachineRegPiece(unsigned MachineReg,
74 unsigned PieceSizeInBits = 0,
75 unsigned PieceOffsetInBits = 0);
Adrian Prantl66f25952015-01-13 00:04:06 +000076
77 /// Emit a signed constant.
78 void AddSignedConstant(int Value);
79 /// Emit an unsigned constant.
80 void AddUnsignedConstant(unsigned Value);
81};
82
83
84/// DwarfExpression implementation for .debug_loc entries.
85class DebugLocDwarfExpression : public DwarfExpression {
86 ByteStreamer &BS;
87
88public:
89 DebugLocDwarfExpression(const AsmPrinter &AP, ByteStreamer &BS)
90 : DwarfExpression(AP), BS(BS) {}
91
92 void EmitOp(uint8_t Op, const char *Comment) override;
93 void EmitSigned(int Value) override;
94 void EmitUnsigned(unsigned Value) override;
Adrian Prantl8995f5c2015-01-13 23:10:43 +000095 bool isFrameRegister(unsigned MachineReg) override;
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000096};
97
98}
99
100#endif