mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-24 08:24:33 +00:00
Debug Info: Move support for constants into DwarfExpression.
Move the declaration of DebugLocDwarfExpression into DwarfExpression.h because it needs to be accessed from AsmPrinterDwarf.cpp and DwarfDebug.cpp NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225734 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -32,32 +32,24 @@ using namespace llvm;
|
|||||||
|
|
||||||
#define DEBUG_TYPE "asm-printer"
|
#define DEBUG_TYPE "asm-printer"
|
||||||
|
|
||||||
/// DwarfExpression implementation for .debug_loc entries.
|
|
||||||
class DebugLocDwarfExpression : public DwarfExpression {
|
|
||||||
ByteStreamer &BS;
|
|
||||||
|
|
||||||
public:
|
|
||||||
DebugLocDwarfExpression(const AsmPrinter &AP, ByteStreamer &BS)
|
|
||||||
: DwarfExpression(AP), BS(BS) {}
|
|
||||||
|
|
||||||
void EmitOp(uint8_t Op, const char *Comment) override;
|
|
||||||
void EmitSigned(int Value) override;
|
|
||||||
void EmitUnsigned(unsigned Value) override;
|
|
||||||
unsigned getFrameRegister() override { llvm_unreachable("not available"); };
|
|
||||||
};
|
|
||||||
|
|
||||||
void DebugLocDwarfExpression::EmitOp(uint8_t Op, const char *Comment) {
|
void DebugLocDwarfExpression::EmitOp(uint8_t Op, const char *Comment) {
|
||||||
BS.EmitInt8(
|
BS.EmitInt8(
|
||||||
Op, Comment ? Twine(Comment) + " " + dwarf::OperationEncodingString(Op)
|
Op, Comment ? Twine(Comment) + " " + dwarf::OperationEncodingString(Op)
|
||||||
: dwarf::OperationEncodingString(Op));
|
: dwarf::OperationEncodingString(Op));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugLocDwarfExpression::EmitSigned(int Value) {
|
void DebugLocDwarfExpression::EmitSigned(int Value) {
|
||||||
BS.EmitSLEB128(Value, Twine(Value));
|
BS.EmitSLEB128(Value, Twine(Value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugLocDwarfExpression::EmitUnsigned(unsigned Value) {
|
void DebugLocDwarfExpression::EmitUnsigned(unsigned Value) {
|
||||||
BS.EmitULEB128(Value, Twine(Value));
|
BS.EmitULEB128(Value, Twine(Value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned DebugLocDwarfExpression::getFrameRegister() {
|
||||||
|
llvm_unreachable("not available");
|
||||||
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// Dwarf Emission Helper Routines
|
// Dwarf Emission Helper Routines
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "DwarfDebug.h"
|
#include "DwarfDebug.h"
|
||||||
|
|
||||||
#include "ByteStreamer.h"
|
#include "ByteStreamer.h"
|
||||||
|
#include "DwarfExpression.h"
|
||||||
#include "DwarfCompileUnit.h"
|
#include "DwarfCompileUnit.h"
|
||||||
#include "DIEHash.h"
|
#include "DIEHash.h"
|
||||||
#include "DwarfUnit.h"
|
#include "DwarfUnit.h"
|
||||||
@ -1717,29 +1718,15 @@ void DwarfDebug::emitDebugLocEntry(ByteStreamer &Streamer,
|
|||||||
void DwarfDebug::emitDebugLocValue(ByteStreamer &Streamer,
|
void DwarfDebug::emitDebugLocValue(ByteStreamer &Streamer,
|
||||||
const DebugLocEntry::Value &Value) {
|
const DebugLocEntry::Value &Value) {
|
||||||
DIVariable DV = Value.getVariable();
|
DIVariable DV = Value.getVariable();
|
||||||
|
DebugLocDwarfExpression Expr(*Asm, Streamer);
|
||||||
// Regular entry.
|
// Regular entry.
|
||||||
if (Value.isInt()) {
|
if (Value.isInt()) {
|
||||||
DIBasicType BTy(resolve(DV.getType()));
|
DIBasicType BTy(resolve(DV.getType()));
|
||||||
if (BTy.Verify() && (BTy.getEncoding() == dwarf::DW_ATE_signed ||
|
if (BTy.Verify() && (BTy.getEncoding() == dwarf::DW_ATE_signed ||
|
||||||
BTy.getEncoding() == dwarf::DW_ATE_signed_char)) {
|
BTy.getEncoding() == dwarf::DW_ATE_signed_char))
|
||||||
Streamer.EmitInt8(dwarf::DW_OP_consts, "DW_OP_consts");
|
Expr.AddSignedConstant(Value.getInt());
|
||||||
Streamer.EmitSLEB128(Value.getInt());
|
else
|
||||||
} else {
|
Expr.AddUnsignedConstant(Value.getInt());
|
||||||
Streamer.EmitInt8(dwarf::DW_OP_constu, "DW_OP_constu");
|
|
||||||
Streamer.EmitULEB128(Value.getInt());
|
|
||||||
}
|
|
||||||
// The proper way to describe a constant value is
|
|
||||||
// DW_OP_constu <const>, DW_OP_stack_value.
|
|
||||||
// Unfortunately, DW_OP_stack_value was not available until DWARF-4,
|
|
||||||
// so we will continue to generate DW_OP_constu <const> for DWARF-2
|
|
||||||
// and DWARF-3. Technically, this is incorrect since DW_OP_const <const>
|
|
||||||
// actually describes a value at a constant addess, not a constant value.
|
|
||||||
// However, in the past there was no better way to describe a constant
|
|
||||||
// value, so the producers and consumers started to rely on heuristics
|
|
||||||
// to disambiguate the value vs. location status of the expression.
|
|
||||||
// See PR21176 for more details.
|
|
||||||
if (getDwarfVersion() >= 4)
|
|
||||||
Streamer.EmitInt8(dwarf::DW_OP_stack_value, "DW_OP_stack_value");
|
|
||||||
} else if (Value.isLocation()) {
|
} else if (Value.isLocation()) {
|
||||||
MachineLocation Loc = Value.getLoc();
|
MachineLocation Loc = Value.getLoc();
|
||||||
DIExpression Expr = Value.getExpression();
|
DIExpression Expr = Value.getExpression();
|
||||||
|
@ -21,14 +21,17 @@
|
|||||||
#include "llvm/Target/TargetRegisterInfo.h"
|
#include "llvm/Target/TargetRegisterInfo.h"
|
||||||
#include "llvm/Target/TargetSubtargetInfo.h"
|
#include "llvm/Target/TargetSubtargetInfo.h"
|
||||||
|
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
const TargetRegisterInfo *DwarfExpression::getTRI() const {
|
const TargetRegisterInfo *DwarfExpression::getTRI() const {
|
||||||
return AP.TM.getSubtargetImpl()->getRegisterInfo();
|
return AP.TM.getSubtargetImpl()->getRegisterInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DwarfExpression::AddReg(int DwarfReg, const char* Comment) {
|
unsigned DwarfExpression::getDwarfVersion() const {
|
||||||
|
return AP.getDwarfDebug()->getDwarfVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DwarfExpression::AddReg(int DwarfReg, const char *Comment) {
|
||||||
assert(DwarfReg >= 0 && "invalid negative dwarf register number");
|
assert(DwarfReg >= 0 && "invalid negative dwarf register number");
|
||||||
if (DwarfReg < 32) {
|
if (DwarfReg < 32) {
|
||||||
EmitOp(dwarf::DW_OP_reg0 + DwarfReg, Comment);
|
EmitOp(dwarf::DW_OP_reg0 + DwarfReg, Comment);
|
||||||
@ -51,8 +54,7 @@ void DwarfExpression::AddRegIndirect(int DwarfReg, int Offset, bool Deref) {
|
|||||||
EmitOp(dwarf::DW_OP_deref);
|
EmitOp(dwarf::DW_OP_deref);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DwarfExpression::AddOpPiece(unsigned SizeInBits,
|
void DwarfExpression::AddOpPiece(unsigned SizeInBits, unsigned OffsetInBits) {
|
||||||
unsigned OffsetInBits) {
|
|
||||||
assert(SizeInBits > 0 && "piece has size zero");
|
assert(SizeInBits > 0 && "piece has size zero");
|
||||||
const unsigned SizeOfByte = 8;
|
const unsigned SizeOfByte = 8;
|
||||||
if (OffsetInBits > 0 || SizeInBits % SizeOfByte) {
|
if (OffsetInBits > 0 || SizeInBits % SizeOfByte) {
|
||||||
@ -164,3 +166,28 @@ void DwarfExpression::AddMachineRegPiece(unsigned MachineReg,
|
|||||||
// FIXME: We have no reasonable way of handling errors in here.
|
// FIXME: We have no reasonable way of handling errors in here.
|
||||||
EmitOp(dwarf::DW_OP_nop, "nop (could not find a dwarf register number)");
|
EmitOp(dwarf::DW_OP_nop, "nop (could not find a dwarf register number)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DwarfExpression::AddSignedConstant(int Value) {
|
||||||
|
EmitOp(dwarf::DW_OP_consts);
|
||||||
|
EmitSigned(Value);
|
||||||
|
// The proper way to describe a constant value is
|
||||||
|
// DW_OP_constu <const>, DW_OP_stack_value.
|
||||||
|
// Unfortunately, DW_OP_stack_value was not available until DWARF-4,
|
||||||
|
// so we will continue to generate DW_OP_constu <const> for DWARF-2
|
||||||
|
// and DWARF-3. Technically, this is incorrect since DW_OP_const <const>
|
||||||
|
// actually describes a value at a constant addess, not a constant value.
|
||||||
|
// However, in the past there was no better way to describe a constant
|
||||||
|
// value, so the producers and consumers started to rely on heuristics
|
||||||
|
// to disambiguate the value vs. location status of the expression.
|
||||||
|
// See PR21176 for more details.
|
||||||
|
if (getDwarfVersion() >= 4)
|
||||||
|
EmitOp(dwarf::DW_OP_stack_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DwarfExpression::AddUnsignedConstant(unsigned Value) {
|
||||||
|
EmitOp(dwarf::DW_OP_constu);
|
||||||
|
EmitUnsigned(Value);
|
||||||
|
// cf. comment in DwarfExpression::AddSignedConstant().
|
||||||
|
if (getDwarfVersion() >= 4)
|
||||||
|
EmitOp(dwarf::DW_OP_stack_value);
|
||||||
|
}
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
class AsmPrinter;
|
class AsmPrinter;
|
||||||
|
class ByteStreamer;
|
||||||
class TargetRegisterInfo;
|
class TargetRegisterInfo;
|
||||||
|
|
||||||
/// Base class containing the logic for constructing DWARF expressions
|
/// Base class containing the logic for constructing DWARF expressions
|
||||||
@ -29,6 +30,7 @@ protected:
|
|||||||
const AsmPrinter &AP;
|
const AsmPrinter &AP;
|
||||||
// Various convenience accessors that extract things out of AsmPrinter.
|
// Various convenience accessors that extract things out of AsmPrinter.
|
||||||
const TargetRegisterInfo *getTRI() const;
|
const TargetRegisterInfo *getTRI() const;
|
||||||
|
unsigned getDwarfVersion() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DwarfExpression(const AsmPrinter &AP) : AP(AP) {}
|
DwarfExpression(const AsmPrinter &AP) : AP(AP) {}
|
||||||
@ -71,6 +73,26 @@ public:
|
|||||||
void AddMachineRegPiece(unsigned MachineReg,
|
void AddMachineRegPiece(unsigned MachineReg,
|
||||||
unsigned PieceSizeInBits = 0,
|
unsigned PieceSizeInBits = 0,
|
||||||
unsigned PieceOffsetInBits = 0);
|
unsigned PieceOffsetInBits = 0);
|
||||||
|
|
||||||
|
/// Emit a signed constant.
|
||||||
|
void AddSignedConstant(int Value);
|
||||||
|
/// Emit an unsigned constant.
|
||||||
|
void AddUnsignedConstant(unsigned Value);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/// DwarfExpression implementation for .debug_loc entries.
|
||||||
|
class DebugLocDwarfExpression : public DwarfExpression {
|
||||||
|
ByteStreamer &BS;
|
||||||
|
|
||||||
|
public:
|
||||||
|
DebugLocDwarfExpression(const AsmPrinter &AP, ByteStreamer &BS)
|
||||||
|
: DwarfExpression(AP), BS(BS) {}
|
||||||
|
|
||||||
|
void EmitOp(uint8_t Op, const char *Comment) override;
|
||||||
|
void EmitSigned(int Value) override;
|
||||||
|
void EmitUnsigned(unsigned Value) override;
|
||||||
|
unsigned getFrameRegister() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user