opnsense-src/contrib/llvm/lib/CodeGen/AsmPrinter/DIE.cpp

369 lines
11 KiB
C++
Raw Normal View History

2009-06-02 13:52:33 -04:00
//===--- lib/CodeGen/DIE.cpp - DWARF Info Entries -------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Data structures for DWARF info entries.
//
//===----------------------------------------------------------------------===//
#include "DIE.h"
2010-01-23 06:09:33 -05:00
#include "llvm/ADT/Twine.h"
2009-06-02 13:52:33 -04:00
#include "llvm/CodeGen/AsmPrinter.h"
2009-10-14 13:57:32 -04:00
#include "llvm/MC/MCAsmInfo.h"
2010-01-23 06:09:33 -05:00
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSymbol.h"
2009-06-02 13:52:33 -04:00
#include "llvm/Target/TargetData.h"
2010-04-02 04:54:30 -04:00
#include "llvm/Support/Allocator.h"
2010-01-01 05:31:22 -05:00
#include "llvm/Support/Debug.h"
2009-10-14 13:57:32 -04:00
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Format.h"
2010-01-23 06:09:33 -05:00
#include "llvm/Support/FormattedStream.h"
2009-06-02 13:52:33 -04:00
using namespace llvm;
//===----------------------------------------------------------------------===//
// DIEAbbrevData Implementation
//===----------------------------------------------------------------------===//
/// Profile - Used to gather unique data for the abbreviation folding set.
///
void DIEAbbrevData::Profile(FoldingSetNodeID &ID) const {
ID.AddInteger(Attribute);
ID.AddInteger(Form);
}
//===----------------------------------------------------------------------===//
// DIEAbbrev Implementation
//===----------------------------------------------------------------------===//
/// Profile - Used to gather unique data for the abbreviation folding set.
///
void DIEAbbrev::Profile(FoldingSetNodeID &ID) const {
ID.AddInteger(Tag);
ID.AddInteger(ChildrenFlag);
// For each attribute description.
for (unsigned i = 0, N = Data.size(); i < N; ++i)
Data[i].Profile(ID);
}
/// Emit - Print the abbreviation using the specified asm printer.
///
2010-04-06 11:52:58 -04:00
void DIEAbbrev::Emit(AsmPrinter *AP) const {
2009-06-02 13:52:33 -04:00
// Emit its Dwarf tag type.
2010-01-23 06:09:33 -05:00
// FIXME: Doing work even in non-asm-verbose runs.
2010-04-06 11:52:58 -04:00
AP->EmitULEB128(Tag, dwarf::TagString(Tag));
2009-06-02 13:52:33 -04:00
// Emit whether it has children DIEs.
2010-01-23 06:09:33 -05:00
// FIXME: Doing work even in non-asm-verbose runs.
2010-04-06 11:52:58 -04:00
AP->EmitULEB128(ChildrenFlag, dwarf::ChildrenString(ChildrenFlag));
2009-06-02 13:52:33 -04:00
// For each attribute description.
for (unsigned i = 0, N = Data.size(); i < N; ++i) {
const DIEAbbrevData &AttrData = Data[i];
// Emit attribute type.
2010-01-23 06:09:33 -05:00
// FIXME: Doing work even in non-asm-verbose runs.
2010-04-06 11:52:58 -04:00
AP->EmitULEB128(AttrData.getAttribute(),
dwarf::AttributeString(AttrData.getAttribute()));
2009-06-02 13:52:33 -04:00
// Emit form type.
2010-01-23 06:09:33 -05:00
// FIXME: Doing work even in non-asm-verbose runs.
2010-04-06 11:52:58 -04:00
AP->EmitULEB128(AttrData.getForm(),
2010-01-23 06:09:33 -05:00
dwarf::FormEncodingString(AttrData.getForm()));
2009-06-02 13:52:33 -04:00
}
// Mark end of abbreviation.
2010-04-06 11:52:58 -04:00
AP->EmitULEB128(0, "EOM(1)");
AP->EmitULEB128(0, "EOM(2)");
2009-06-02 13:52:33 -04:00
}
#ifndef NDEBUG
2009-10-14 13:57:32 -04:00
void DIEAbbrev::print(raw_ostream &O) {
2009-06-02 13:52:33 -04:00
O << "Abbreviation @"
2009-10-14 13:57:32 -04:00
<< format("0x%lx", (long)(intptr_t)this)
2009-06-02 13:52:33 -04:00
<< " "
<< dwarf::TagString(Tag)
<< " "
<< dwarf::ChildrenString(ChildrenFlag)
2009-10-14 13:57:32 -04:00
<< '\n';
2009-06-02 13:52:33 -04:00
for (unsigned i = 0, N = Data.size(); i < N; ++i) {
O << " "
<< dwarf::AttributeString(Data[i].getAttribute())
<< " "
<< dwarf::FormEncodingString(Data[i].getForm())
2009-10-14 13:57:32 -04:00
<< '\n';
2009-06-02 13:52:33 -04:00
}
}
2010-01-01 05:31:22 -05:00
void DIEAbbrev::dump() { print(dbgs()); }
2009-06-02 13:52:33 -04:00
#endif
//===----------------------------------------------------------------------===//
// DIE Implementation
//===----------------------------------------------------------------------===//
DIE::~DIE() {
for (unsigned i = 0, N = Children.size(); i < N; ++i)
delete Children[i];
}
2009-12-01 06:07:05 -05:00
/// addSiblingOffset - Add a sibling offset field to the front of the DIE.
2009-06-02 13:52:33 -04:00
///
2010-04-02 04:54:30 -04:00
DIEValue *DIE::addSiblingOffset(BumpPtrAllocator &A) {
DIEInteger *DI = new (A) DIEInteger(0);
2009-06-02 13:52:33 -04:00
Values.insert(Values.begin(), DI);
Abbrev.AddFirstAttribute(dwarf::DW_AT_sibling, dwarf::DW_FORM_ref4);
2010-04-02 04:54:30 -04:00
return DI;
2009-06-02 13:52:33 -04:00
}
#ifndef NDEBUG
2009-10-14 13:57:32 -04:00
void DIE::print(raw_ostream &O, unsigned IncIndent) {
2009-06-02 13:52:33 -04:00
IndentCount += IncIndent;
const std::string Indent(IndentCount, ' ');
bool isBlock = Abbrev.getTag() == 0;
if (!isBlock) {
O << Indent
<< "Die: "
2009-10-14 13:57:32 -04:00
<< format("0x%lx", (long)(intptr_t)this)
2009-06-02 13:52:33 -04:00
<< ", Offset: " << Offset
2010-03-10 12:45:15 -05:00
<< ", Size: " << Size << "\n";
2009-06-02 13:52:33 -04:00
O << Indent
<< dwarf::TagString(Abbrev.getTag())
<< " "
2010-03-10 12:45:15 -05:00
<< dwarf::ChildrenString(Abbrev.getChildrenFlag()) << "\n";
2009-06-02 13:52:33 -04:00
} else {
2010-03-10 12:45:15 -05:00
O << "Size: " << Size << "\n";
2009-06-02 13:52:33 -04:00
}
const SmallVector<DIEAbbrevData, 8> &Data = Abbrev.getData();
IndentCount += 2;
for (unsigned i = 0, N = Data.size(); i < N; ++i) {
O << Indent;
if (!isBlock)
O << dwarf::AttributeString(Data[i].getAttribute());
else
O << "Blk[" << i << "]";
O << " "
<< dwarf::FormEncodingString(Data[i].getForm())
<< " ";
Values[i]->print(O);
O << "\n";
}
IndentCount -= 2;
for (unsigned j = 0, M = Children.size(); j < M; ++j) {
Children[j]->print(O, 4);
}
if (!isBlock) O << "\n";
IndentCount -= IncIndent;
}
void DIE::dump() {
2010-01-01 05:31:22 -05:00
print(dbgs());
2009-06-02 13:52:33 -04:00
}
#endif
#ifndef NDEBUG
void DIEValue::dump() {
2010-01-01 05:31:22 -05:00
print(dbgs());
2009-06-02 13:52:33 -04:00
}
#endif
//===----------------------------------------------------------------------===//
// DIEInteger Implementation
//===----------------------------------------------------------------------===//
/// EmitValue - Emit integer of appropriate size.
///
2010-04-06 11:52:58 -04:00
void DIEInteger::EmitValue(AsmPrinter *Asm, unsigned Form) const {
2010-01-23 06:09:33 -05:00
unsigned Size = ~0U;
2009-06-02 13:52:33 -04:00
switch (Form) {
case dwarf::DW_FORM_flag: // Fall thru
case dwarf::DW_FORM_ref1: // Fall thru
2010-01-23 06:09:33 -05:00
case dwarf::DW_FORM_data1: Size = 1; break;
2009-06-02 13:52:33 -04:00
case dwarf::DW_FORM_ref2: // Fall thru
2010-01-23 06:09:33 -05:00
case dwarf::DW_FORM_data2: Size = 2; break;
2009-06-02 13:52:33 -04:00
case dwarf::DW_FORM_ref4: // Fall thru
2010-01-23 06:09:33 -05:00
case dwarf::DW_FORM_data4: Size = 4; break;
2009-06-02 13:52:33 -04:00
case dwarf::DW_FORM_ref8: // Fall thru
2010-01-23 06:09:33 -05:00
case dwarf::DW_FORM_data8: Size = 8; break;
2010-04-06 11:52:58 -04:00
case dwarf::DW_FORM_udata: Asm->EmitULEB128(Integer); return;
case dwarf::DW_FORM_sdata: Asm->EmitSLEB128(Integer); return;
2010-07-13 13:19:57 -04:00
case dwarf::DW_FORM_addr: Size = Asm->getTargetData().getPointerSize(); break;
2009-10-14 13:57:32 -04:00
default: llvm_unreachable("DIE Value form not supported yet");
2009-06-02 13:52:33 -04:00
}
2010-01-23 06:09:33 -05:00
Asm->OutStreamer.EmitIntValue(Integer, Size, 0/*addrspace*/);
2009-06-02 13:52:33 -04:00
}
/// SizeOf - Determine size of integer value in bytes.
///
2010-04-06 11:52:58 -04:00
unsigned DIEInteger::SizeOf(AsmPrinter *AP, unsigned Form) const {
2009-06-02 13:52:33 -04:00
switch (Form) {
case dwarf::DW_FORM_flag: // Fall thru
case dwarf::DW_FORM_ref1: // Fall thru
case dwarf::DW_FORM_data1: return sizeof(int8_t);
case dwarf::DW_FORM_ref2: // Fall thru
case dwarf::DW_FORM_data2: return sizeof(int16_t);
case dwarf::DW_FORM_ref4: // Fall thru
case dwarf::DW_FORM_data4: return sizeof(int32_t);
case dwarf::DW_FORM_ref8: // Fall thru
case dwarf::DW_FORM_data8: return sizeof(int64_t);
2009-10-14 13:57:32 -04:00
case dwarf::DW_FORM_udata: return MCAsmInfo::getULEB128Size(Integer);
case dwarf::DW_FORM_sdata: return MCAsmInfo::getSLEB128Size(Integer);
2010-07-13 13:19:57 -04:00
case dwarf::DW_FORM_addr: return AP->getTargetData().getPointerSize();
2009-10-14 13:57:32 -04:00
default: llvm_unreachable("DIE Value form not supported yet"); break;
2009-06-02 13:52:33 -04:00
}
return 0;
}
#ifndef NDEBUG
2009-10-14 13:57:32 -04:00
void DIEInteger::print(raw_ostream &O) {
2009-06-02 13:52:33 -04:00
O << "Int: " << (int64_t)Integer
2009-10-14 13:57:32 -04:00
<< format(" 0x%llx", (unsigned long long)Integer);
2009-06-02 13:52:33 -04:00
}
#endif
//===----------------------------------------------------------------------===//
// DIEString Implementation
//===----------------------------------------------------------------------===//
/// EmitValue - Emit string value.
///
2010-04-06 11:52:58 -04:00
void DIEString::EmitValue(AsmPrinter *AP, unsigned Form) const {
AP->OutStreamer.EmitBytes(Str, /*addrspace*/0);
2010-01-23 06:09:33 -05:00
// Emit nul terminator.
2010-04-06 11:52:58 -04:00
AP->OutStreamer.EmitIntValue(0, 1, /*addrspace*/0);
2009-06-02 13:52:33 -04:00
}
#ifndef NDEBUG
2009-10-14 13:57:32 -04:00
void DIEString::print(raw_ostream &O) {
2009-06-02 13:52:33 -04:00
O << "Str: \"" << Str << "\"";
}
#endif
//===----------------------------------------------------------------------===//
2010-03-10 12:45:15 -05:00
// DIELabel Implementation
2009-06-02 13:52:33 -04:00
//===----------------------------------------------------------------------===//
/// EmitValue - Emit label value.
///
2010-04-06 11:52:58 -04:00
void DIELabel::EmitValue(AsmPrinter *AP, unsigned Form) const {
AP->OutStreamer.EmitSymbolValue(Label, SizeOf(AP, Form), 0/*AddrSpace*/);
2009-06-02 13:52:33 -04:00
}
/// SizeOf - Determine size of label value in bytes.
///
2010-04-06 11:52:58 -04:00
unsigned DIELabel::SizeOf(AsmPrinter *AP, unsigned Form) const {
2009-06-02 13:52:33 -04:00
if (Form == dwarf::DW_FORM_data4) return 4;
2010-04-06 11:52:58 -04:00
return AP->getTargetData().getPointerSize();
2009-06-02 13:52:33 -04:00
}
#ifndef NDEBUG
2010-03-10 12:45:15 -05:00
void DIELabel::print(raw_ostream &O) {
O << "Lbl: " << Label->getName();
2009-06-02 13:52:33 -04:00
}
#endif
//===----------------------------------------------------------------------===//
// DIEDelta Implementation
//===----------------------------------------------------------------------===//
/// EmitValue - Emit delta value.
///
2010-04-06 11:52:58 -04:00
void DIEDelta::EmitValue(AsmPrinter *AP, unsigned Form) const {
AP->EmitLabelDifference(LabelHi, LabelLo, SizeOf(AP, Form));
2009-06-02 13:52:33 -04:00
}
/// SizeOf - Determine size of delta value in bytes.
///
2010-04-06 11:52:58 -04:00
unsigned DIEDelta::SizeOf(AsmPrinter *AP, unsigned Form) const {
2009-06-02 13:52:33 -04:00
if (Form == dwarf::DW_FORM_data4) return 4;
2010-04-06 11:52:58 -04:00
return AP->getTargetData().getPointerSize();
2009-06-02 13:52:33 -04:00
}
#ifndef NDEBUG
2009-10-14 13:57:32 -04:00
void DIEDelta::print(raw_ostream &O) {
2010-03-10 12:45:15 -05:00
O << "Del: " << LabelHi->getName() << "-" << LabelLo->getName();
2009-06-02 13:52:33 -04:00
}
#endif
//===----------------------------------------------------------------------===//
// DIEEntry Implementation
//===----------------------------------------------------------------------===//
/// EmitValue - Emit debug information entry offset.
///
2010-04-06 11:52:58 -04:00
void DIEEntry::EmitValue(AsmPrinter *AP, unsigned Form) const {
AP->EmitInt32(Entry->getOffset());
2009-06-02 13:52:33 -04:00
}
#ifndef NDEBUG
2009-10-14 13:57:32 -04:00
void DIEEntry::print(raw_ostream &O) {
O << format("Die: 0x%lx", (long)(intptr_t)Entry);
2009-06-02 13:52:33 -04:00
}
#endif
//===----------------------------------------------------------------------===//
// DIEBlock Implementation
//===----------------------------------------------------------------------===//
/// ComputeSize - calculate the size of the block.
///
2010-04-06 11:52:58 -04:00
unsigned DIEBlock::ComputeSize(AsmPrinter *AP) {
2009-06-02 13:52:33 -04:00
if (!Size) {
const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev.getData();
for (unsigned i = 0, N = Values.size(); i < N; ++i)
2010-04-06 11:52:58 -04:00
Size += Values[i]->SizeOf(AP, AbbrevData[i].getForm());
2009-06-02 13:52:33 -04:00
}
return Size;
}
/// EmitValue - Emit block data.
///
2010-04-06 11:52:58 -04:00
void DIEBlock::EmitValue(AsmPrinter *Asm, unsigned Form) const {
2009-06-02 13:52:33 -04:00
switch (Form) {
2010-04-06 11:52:58 -04:00
default: assert(0 && "Improper form for block"); break;
case dwarf::DW_FORM_block1: Asm->EmitInt8(Size); break;
case dwarf::DW_FORM_block2: Asm->EmitInt16(Size); break;
case dwarf::DW_FORM_block4: Asm->EmitInt32(Size); break;
case dwarf::DW_FORM_block: Asm->EmitULEB128(Size); break;
2009-06-02 13:52:33 -04:00
}
const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev.getData();
2010-03-10 12:45:15 -05:00
for (unsigned i = 0, N = Values.size(); i < N; ++i)
2010-04-06 11:52:58 -04:00
Values[i]->EmitValue(Asm, AbbrevData[i].getForm());
2009-06-02 13:52:33 -04:00
}
/// SizeOf - Determine size of block data in bytes.
///
2010-04-06 11:52:58 -04:00
unsigned DIEBlock::SizeOf(AsmPrinter *AP, unsigned Form) const {
2009-06-02 13:52:33 -04:00
switch (Form) {
case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
2010-04-06 11:52:58 -04:00
case dwarf::DW_FORM_block: return Size + MCAsmInfo::getULEB128Size(Size);
2009-10-14 13:57:32 -04:00
default: llvm_unreachable("Improper form for block"); break;
2009-06-02 13:52:33 -04:00
}
return 0;
}
#ifndef NDEBUG
2009-10-14 13:57:32 -04:00
void DIEBlock::print(raw_ostream &O) {
2009-06-02 13:52:33 -04:00
O << "Blk: ";
DIE::print(O, 5);
}
#endif