blob: f164f1c85133ba5bf58e530708a510614f79e015 [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"
Adrian Prantl092d9482015-01-13 23:39:11 +000018#include "llvm/IR/DebugInfo.h"
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000019
20namespace llvm {
21
Adrian Prantla4c30d62015-01-12 23:36:56 +000022class AsmPrinter;
Adrian Prantl66f25952015-01-13 00:04:06 +000023class ByteStreamer;
Adrian Prantla4c30d62015-01-12 23:36:56 +000024class TargetRegisterInfo;
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000025
26/// Base class containing the logic for constructing DWARF expressions
27/// independently of whether they are emitted into a DIE or into a .debug_loc
28/// entry.
29class DwarfExpression {
Adrian Prantl00dbc2a2015-01-12 22:19:26 +000030protected:
Adrian Prantla4c30d62015-01-12 23:36:56 +000031 const AsmPrinter ≈
32 // Various convenience accessors that extract things out of AsmPrinter.
33 const TargetRegisterInfo *getTRI() const;
Adrian Prantl66f25952015-01-13 00:04:06 +000034 unsigned getDwarfVersion() const;
Adrian Prantla4c30d62015-01-12 23:36:56 +000035
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000036public:
Adrian Prantla4c30d62015-01-12 23:36:56 +000037 DwarfExpression(const AsmPrinter &AP) : AP(AP) {}
Adrian Prantl9cffbd82015-01-12 23:36:50 +000038 virtual ~DwarfExpression() {}
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000039
Adrian Prantl172ab662015-01-13 23:11:07 +000040 /// Output a dwarf operand and an optional assembler comment.
41 virtual void EmitOp(uint8_t Op, const char *Comment = nullptr) = 0;
42 /// Emit a raw signed value.
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000043 virtual void EmitSigned(int Value) = 0;
Adrian Prantl172ab662015-01-13 23:11:07 +000044 /// Emit a raw unsigned value.
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000045 virtual void EmitUnsigned(unsigned Value) = 0;
Adrian Prantl172ab662015-01-13 23:11:07 +000046 /// Return whether the given machine register is the frame register in the
47 /// current function.
Adrian Prantl8995f5c2015-01-13 23:10:43 +000048 virtual bool isFrameRegister(unsigned MachineReg) = 0;
Adrian Prantl00dbc2a2015-01-12 22:19:26 +000049
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000050 /// Emit a dwarf register operation.
Adrian Prantl172ab662015-01-13 23:11:07 +000051 void AddReg(int DwarfReg, const char *Comment = nullptr);
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000052 /// Emit an (double-)indirect dwarf register operation.
53 void AddRegIndirect(int DwarfReg, int Offset, bool Deref = false);
54
55 /// Emit a dwarf register operation for describing
56 /// - a small value occupying only part of a register or
57 /// - a register representing only part of a value.
58 void AddOpPiece(unsigned SizeInBits, unsigned OffsetInBits = 0);
59 /// Emit a shift-right dwarf expression.
60 void AddShr(unsigned ShiftBy);
61
Adrian Prantl00dbc2a2015-01-12 22:19:26 +000062 /// Emit an indirect dwarf register operation for the given machine register.
63 /// Returns false if no DWARF register exists for MachineReg.
Adrian Prantl172ab662015-01-13 23:11:07 +000064 bool AddMachineRegIndirect(unsigned MachineReg, int Offset = 0);
Adrian Prantl00dbc2a2015-01-12 22:19:26 +000065
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000066 /// \brief Emit a partial DWARF register operation.
Adrian Prantl172ab662015-01-13 23:11:07 +000067 /// \param MachineReg the register
68 /// \param PieceSizeInBits size and
69 /// \param PieceOffsetInBits offset of the piece in bits, if this is one
70 /// piece of an aggregate value.
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000071 ///
72 /// If size and offset is zero an operation for the entire
73 /// register is emitted: Some targets do not provide a DWARF
74 /// register number for every register. If this is the case, this
75 /// function will attempt to emit a DWARF register by emitting a
76 /// piece of a super-register or by piecing together multiple
77 /// subregisters that alias the register.
Adrian Prantl172ab662015-01-13 23:11:07 +000078 void AddMachineRegPiece(unsigned MachineReg, unsigned PieceSizeInBits = 0,
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000079 unsigned PieceOffsetInBits = 0);
Adrian Prantl66f25952015-01-13 00:04:06 +000080
81 /// Emit a signed constant.
82 void AddSignedConstant(int Value);
83 /// Emit an unsigned constant.
84 void AddUnsignedConstant(unsigned Value);
Adrian Prantl66f25952015-01-13 00:04:06 +000085
Adrian Prantl092d9482015-01-13 23:39:11 +000086 /// Emit an entire DIExpression on top of a machine register location.
87 /// \param PieceOffsetInBits If this is one piece out of a fragmented
88 /// location, this is the offset of the piece inside the entire variable.
89 void AddMachineRegExpression(DIExpression Expr, unsigned MachineReg,
90 unsigned PieceOffsetInBits = 0);
91 /// Emit a the operations in a DIExpression, starting from element I.
92 /// \param PieceOffsetInBits If this is one piece out of a fragmented
93 /// location, this is the offset of the piece inside the entire variable.
94 void AddExpression(DIExpression Expr, unsigned PieceOffsetInBits = 0,
95 unsigned I = 0);
96};
Adrian Prantl66f25952015-01-13 00:04:06 +000097
98/// DwarfExpression implementation for .debug_loc entries.
99class DebugLocDwarfExpression : public DwarfExpression {
100 ByteStreamer &BS;
101
102public:
103 DebugLocDwarfExpression(const AsmPrinter &AP, ByteStreamer &BS)
104 : DwarfExpression(AP), BS(BS) {}
105
Adrian Prantl172ab662015-01-13 23:11:07 +0000106 void EmitOp(uint8_t Op, const char *Comment = nullptr) override;
Adrian Prantl66f25952015-01-13 00:04:06 +0000107 void EmitSigned(int Value) override;
108 void EmitUnsigned(unsigned Value) override;
Adrian Prantl8995f5c2015-01-13 23:10:43 +0000109 bool isFrameRegister(unsigned MachineReg) override;
Adrian Prantlb16d9eb2015-01-12 22:19:22 +0000110};
Adrian Prantlb16d9eb2015-01-12 22:19:22 +0000111}
112
113#endif