#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H
#define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H
#include "DwarfStringPool.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/CodeGen/DIE.h"
#include "llvm/Support/Allocator.h"
#include <map>
#include <memory>
#include <utility>
namespace llvm {
class AsmPrinter;
class DbgEntity;
class DbgVariable;
class DbgLabel;
class DINode;
class DwarfCompileUnit;
class DwarfUnit;
class LexicalScope;
class MCSection;
class MDNode;
struct RangeSpan {
const MCSymbol *Begin;
const MCSymbol *End;
};
struct RangeSpanList {
MCSymbol *Label;
const DwarfCompileUnit *CU;
SmallVector<RangeSpan, 2> Ranges;
};
class DwarfFile {
AsmPrinter *Asm;
BumpPtrAllocator AbbrevAllocator;
DIEAbbrevSet Abbrevs;
SmallVector<std::unique_ptr<DwarfCompileUnit>, 1> CUs;
DwarfStringPool StrPool;
SmallVector<RangeSpanList, 1> CURangeLists;
MCSymbol *StringOffsetsStartSym = nullptr;
MCSymbol *RnglistsTableBaseSym = nullptr;
struct ScopeVars {
std::map<unsigned, DbgVariable *> Args;
SmallVector<DbgVariable *, 8> Locals;
};
DenseMap<LexicalScope *, ScopeVars> ScopeVariables;
using LabelList = SmallVector<DbgLabel *, 4>;
DenseMap<LexicalScope *, LabelList> ScopeLabels;
DenseMap<const MDNode *, DIE *> AbstractSPDies;
DenseMap<const DINode *, std::unique_ptr<DbgEntity>> AbstractEntities;
DenseMap<const MDNode *, DIE *> DITypeNodeToDieMap;
public:
DwarfFile(AsmPrinter *AP, StringRef Pref, BumpPtrAllocator &DA);
const SmallVectorImpl<std::unique_ptr<DwarfCompileUnit>> &getUnits() {
return CUs;
}
std::pair<uint32_t, RangeSpanList *> addRange(const DwarfCompileUnit &CU,
SmallVector<RangeSpan, 2> R);
const SmallVectorImpl<RangeSpanList> &getRangeLists() const {
return CURangeLists;
}
unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
void computeSizeAndOffsets();
unsigned computeSizeAndOffsetsForUnit(DwarfUnit *TheU);
void addUnit(std::unique_ptr<DwarfCompileUnit> U);
void emitUnits(bool UseOffsets);
void emitUnit(DwarfUnit *TheU, bool UseOffsets);
void emitAbbrevs(MCSection *);
void emitStrings(MCSection *StrSection, MCSection *OffsetSection = nullptr,
bool UseRelativeOffsets = false);
DwarfStringPool &getStringPool() { return StrPool; }
MCSymbol *getStringOffsetsStartSym() const { return StringOffsetsStartSym; }
void setStringOffsetsStartSym(MCSymbol *Sym) { StringOffsetsStartSym = Sym; }
MCSymbol *getRnglistsTableBaseSym() const { return RnglistsTableBaseSym; }
void setRnglistsTableBaseSym(MCSymbol *Sym) { RnglistsTableBaseSym = Sym; }
bool addScopeVariable(LexicalScope *LS, DbgVariable *Var);
void addScopeLabel(LexicalScope *LS, DbgLabel *Label);
DenseMap<LexicalScope *, ScopeVars> &getScopeVariables() {
return ScopeVariables;
}
DenseMap<LexicalScope *, LabelList> &getScopeLabels() {
return ScopeLabels;
}
DenseMap<const MDNode *, DIE *> &getAbstractSPDies() {
return AbstractSPDies;
}
DenseMap<const DINode *, std::unique_ptr<DbgEntity>> &getAbstractEntities() {
return AbstractEntities;
}
void insertDIE(const MDNode *TypeMD, DIE *Die) {
DITypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
}
DIE *getDIE(const MDNode *TypeMD) {
return DITypeNodeToDieMap.lookup(TypeMD);
}
};
}
#endif