mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-19 03:24:09 +00:00
Encapsulate the DWARF string pool in a separate type.
Pulls out some more code from some of the rather monolithic DWARF classes. Unlike the address table, the string table won't move up into DwarfDebug - each DWARF file has its own string table (but there can be only one address table). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207277 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
74
lib/CodeGen/AsmPrinter/DwarfStringPool.cpp
Normal file
74
lib/CodeGen/AsmPrinter/DwarfStringPool.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
//===-- llvm/CodeGen/DwarfStringPool.cpp - Dwarf Debug Framework ----------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "DwarfStringPool.h"
|
||||
#include "llvm/MC/MCStreamer.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
MCSymbol *DwarfStringPool::getSectionSymbol() { return SectionSymbol; }
|
||||
|
||||
std::pair<MCSymbol *, unsigned> &
|
||||
getEntry(AsmPrinter &Asm,
|
||||
StringMap<std::pair<MCSymbol *, unsigned>, BumpPtrAllocator &> &Pool,
|
||||
StringRef Prefix, StringRef Str) {
|
||||
std::pair<MCSymbol *, unsigned> &Entry =
|
||||
Pool.GetOrCreateValue(Str).getValue();
|
||||
if (!Entry.first) {
|
||||
Entry.second = Pool.size() - 1;
|
||||
Entry.first = Asm.GetTempSymbol(Prefix, Entry.second);
|
||||
}
|
||||
return Entry;
|
||||
}
|
||||
|
||||
MCSymbol *DwarfStringPool::getSymbol(AsmPrinter &Asm, StringRef Str) {
|
||||
return getEntry(Asm, Pool, Prefix, Str).first;
|
||||
}
|
||||
|
||||
unsigned DwarfStringPool::getIndex(AsmPrinter &Asm, StringRef Str) {
|
||||
return getEntry(Asm, Pool, Prefix, Str).second;
|
||||
}
|
||||
|
||||
void DwarfStringPool::emit(AsmPrinter &Asm, const MCSection *StrSection,
|
||||
const MCSection *OffsetSection,
|
||||
const MCSymbol *StrSecSym) {
|
||||
if (Pool.empty())
|
||||
return;
|
||||
|
||||
// Start the dwarf str section.
|
||||
Asm.OutStreamer.SwitchSection(StrSection);
|
||||
|
||||
// Get all of the string pool entries and put them in an array by their ID so
|
||||
// we can sort them.
|
||||
SmallVector<const StringMapEntry<std::pair<MCSymbol *, unsigned>> *, 64>
|
||||
Entries(Pool.size());
|
||||
|
||||
for (const auto &E : Pool)
|
||||
Entries[E.getValue().second] = &E;
|
||||
|
||||
for (const auto &Entry : Entries) {
|
||||
// Emit a label for reference from debug information entries.
|
||||
Asm.OutStreamer.EmitLabel(Entry->getValue().first);
|
||||
|
||||
// Emit the string itself with a terminating null byte.
|
||||
Asm.OutStreamer.EmitBytes(
|
||||
StringRef(Entry->getKeyData(), Entry->getKeyLength() + 1));
|
||||
}
|
||||
|
||||
// If we've got an offset section go ahead and emit that now as well.
|
||||
if (OffsetSection) {
|
||||
Asm.OutStreamer.SwitchSection(OffsetSection);
|
||||
unsigned offset = 0;
|
||||
unsigned size = 4; // FIXME: DWARF64 is 8.
|
||||
for (const auto &Entry : Entries) {
|
||||
Asm.OutStreamer.EmitIntValue(offset, size);
|
||||
offset += Entry->getKeyLength() + 1;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user