#ifndef LLVM_DWARFLINKER_DWARFSTREAMER_H
#define LLVM_DWARFLINKER_DWARFSTREAMER_H
#include "llvm/BinaryFormat/Swift.h"
#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/DWARFLinker/DWARFLinker.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCInstrInfo.h"
#include "llvm/MC/MCObjectFileInfo.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/Target/TargetMachine.h"
namespace llvm {
template <typename DataT> class AccelTable;
enum class OutputFileType {
Object,
Assembly,
};
class MCCodeEmitter;
class DwarfStreamer : public DwarfEmitter {
public:
DwarfStreamer(OutputFileType OutFileType, raw_pwrite_stream &OutFile,
std::function<StringRef(StringRef Input)> Translator,
messageHandler Error, messageHandler Warning)
: OutFile(OutFile), OutFileType(OutFileType), Translator(Translator),
ErrorHandler(Error), WarningHandler(Warning) {}
bool init(Triple TheTriple, StringRef Swift5ReflectionSegmentName);
void finish();
AsmPrinter &getAsmPrinter() const { return *Asm; }
void switchToDebugInfoSection(unsigned DwarfVersion);
void emitCompileUnitHeader(CompileUnit &Unit, unsigned DwarfVersion) override;
void emitDIE(DIE &Die) override;
void emitAbbrevs(const std::vector<std::unique_ptr<DIEAbbrev>> &Abbrevs,
unsigned DwarfVersion) override;
void emitPaperTrailWarningsDie(DIE &Die) override;
void emitSectionContents(StringRef SecData, StringRef SecName) override;
void emitStrings(const NonRelocatableStringpool &Pool) override;
void emitSwiftAST(StringRef Buffer);
void emitSwiftReflectionSection(
llvm::binaryformat::Swift5ReflectionSectionKind ReflSectionKind,
StringRef Buffer, uint32_t Alignment, uint32_t Size);
void emitRangesEntries(
int64_t UnitPcOffset, uint64_t OrigLowPc,
Optional<std::pair<AddressRange, int64_t>> FuncRange,
const std::vector<DWARFDebugRangeList::RangeListEntry> &Entries,
unsigned AddressSize) override;
void emitUnitRangesEntries(CompileUnit &Unit, bool DoRangesSection) override;
uint64_t getRangesSectionSize() const override { return RangesSectionSize; }
void emitLocationsForUnit(
const CompileUnit &Unit, DWARFContext &Dwarf,
std::function<void(StringRef, SmallVectorImpl<uint8_t> &)> ProcessExpr)
override;
void emitLineTableForUnit(MCDwarfLineTableParams Params,
StringRef PrologueBytes, unsigned MinInstLength,
std::vector<DWARFDebugLine::Row> &Rows,
unsigned AdddressSize) override;
void translateLineTable(DataExtractor LineData, uint64_t Offset) override;
uint64_t getLineSectionSize() const override { return LineSectionSize; }
void emitPubNamesForUnit(const CompileUnit &Unit) override;
void emitPubTypesForUnit(const CompileUnit &Unit) override;
void emitCIE(StringRef CIEBytes) override;
void emitFDE(uint32_t CIEOffset, uint32_t AddreSize, uint32_t Address,
StringRef Bytes) override;
void emitDebugNames(AccelTable<DWARF5AccelTableStaticData> &Table) override;
void emitAppleNamespaces(
AccelTable<AppleAccelTableStaticOffsetData> &Table) override;
void
emitAppleNames(AccelTable<AppleAccelTableStaticOffsetData> &Table) override;
void
emitAppleObjc(AccelTable<AppleAccelTableStaticOffsetData> &Table) override;
void
emitAppleTypes(AccelTable<AppleAccelTableStaticTypeData> &Table) override;
uint64_t getFrameSectionSize() const override { return FrameSectionSize; }
uint64_t getDebugInfoSectionSize() const override {
return DebugInfoSectionSize;
}
private:
inline void error(const Twine &Error, StringRef Context = "") {
if (ErrorHandler)
ErrorHandler(Error, Context, nullptr);
}
inline void warn(const Twine &Warning, StringRef Context = "") {
if (WarningHandler)
WarningHandler(Warning, Context, nullptr);
}
std::unique_ptr<MCRegisterInfo> MRI;
std::unique_ptr<MCAsmInfo> MAI;
std::unique_ptr<MCObjectFileInfo> MOFI;
std::unique_ptr<MCContext> MC;
MCAsmBackend *MAB; std::unique_ptr<MCInstrInfo> MII;
std::unique_ptr<MCSubtargetInfo> MSTI;
MCInstPrinter *MIP; MCCodeEmitter *MCE; MCStreamer *MS; std::unique_ptr<TargetMachine> TM;
std::unique_ptr<AsmPrinter> Asm;
raw_pwrite_stream &OutFile;
OutputFileType OutFileType = OutputFileType::Object;
std::function<StringRef(StringRef Input)> Translator;
uint64_t RangesSectionSize = 0;
uint64_t LocSectionSize = 0;
uint64_t LineSectionSize = 0;
uint64_t FrameSectionSize = 0;
uint64_t DebugInfoSectionSize = 0;
struct EmittedUnit {
unsigned ID;
MCSymbol *LabelBegin;
};
std::vector<EmittedUnit> EmittedUnits;
void emitPubSectionForUnit(MCSection *Sec, StringRef Name,
const CompileUnit &Unit,
const std::vector<CompileUnit::AccelInfo> &Names);
messageHandler ErrorHandler = nullptr;
messageHandler WarningHandler = nullptr;
};
}
#endif