WinCodeViewLineTables.h [plain text]
#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_WINCODEVIEWLINETABLES_H
#define LLVM_LIB_CODEGEN_ASMPRINTER_WINCODEVIEWLINETABLES_H
#include "AsmPrinterHandler.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/CodeGen/LexicalScopes.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/Target/TargetLoweringObjectFile.h"
namespace llvm {
class WinCodeViewLineTables : public AsmPrinterHandler {
AsmPrinter *Asm;
DebugLoc PrevInstLoc;
struct FunctionInfo {
SmallVector<MCSymbol *, 10> Instrs;
MCSymbol *End;
FunctionInfo() : End(nullptr) {}
} *CurFn;
typedef DenseMap<const Function *, FunctionInfo> FnDebugInfoTy;
FnDebugInfoTy FnDebugInfo;
SmallVector<const Function *, 10> VisitedFunctions;
struct InstrInfoTy {
StringRef Filename;
unsigned LineNumber;
InstrInfoTy() : LineNumber(0) {}
InstrInfoTy(StringRef Filename, unsigned LineNumber)
: Filename(Filename), LineNumber(LineNumber) {}
};
DenseMap<MCSymbol *, InstrInfoTy> InstrInfo;
struct FileNameRegistryTy {
SmallVector<StringRef, 10> Filenames;
struct PerFileInfo {
size_t FilenameID, StartOffset;
};
StringMap<PerFileInfo> Infos;
size_t LastOffset;
FileNameRegistryTy() {
clear();
}
void add(StringRef Filename) {
if (Infos.count(Filename))
return;
size_t OldSize = Infos.size();
Infos[Filename].FilenameID = OldSize;
Infos[Filename].StartOffset = LastOffset;
LastOffset += Filename.size() + 1;
Filenames.push_back(Filename);
}
void clear() {
LastOffset = 1;
Infos.clear();
Filenames.clear();
}
} FileNameRegistry;
typedef std::map<std::pair<StringRef, StringRef>, char *>
DirAndFilenameToFilepathMapTy;
DirAndFilenameToFilepathMapTy DirAndFilenameToFilepathMap;
StringRef getFullFilepath(const MDNode *S);
void maybeRecordLocation(DebugLoc DL, const MachineFunction *MF);
void clear() {
assert(CurFn == nullptr);
FileNameRegistry.clear();
InstrInfo.clear();
}
void emitDebugInfoForFunction(const Function *GV);
public:
WinCodeViewLineTables(AsmPrinter *Asm);
~WinCodeViewLineTables() {
for (DirAndFilenameToFilepathMapTy::iterator
I = DirAndFilenameToFilepathMap.begin(),
E = DirAndFilenameToFilepathMap.end();
I != E; ++I)
free(I->second);
}
void setSymbolSize(const llvm::MCSymbol *, uint64_t) override {}
void endModule() override;
void beginFunction(const MachineFunction *MF) override;
void endFunction(const MachineFunction *) override;
void beginInstruction(const MachineInstr *MI) override;
void endInstruction() override {}
};
}
#endif