Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Zentrik committed Oct 13, 2024
1 parent 342a23e commit 9cbc166
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
// for outputting assembly
#include <llvm/CodeGen/AsmPrinter.h>
#include <llvm/CodeGen/AsmPrinterHandler.h>
#include <llvm/CodeGen/DebugHandlerBase.h>
#include <llvm/CodeGen/MachineModuleInfo.h>
#include <llvm/CodeGen/Passes.h>
#include <llvm/CodeGen/TargetPassConfig.h>
Expand Down Expand Up @@ -1154,7 +1155,11 @@ addPassesToGenerateCode(LLVMTargetMachine *TM, PassManagerBase &PM) {
return &MMIWP->getMMI().getContext();
}

#if JL_LLVM_VERSION >= 190000
class LineNumberPrinterHandler : public DebugHandlerBase {
#else
class LineNumberPrinterHandler : public AsmPrinterHandler {
#endif
MCStreamer &S;
LineNumberAnnotatedWriter LinePrinter;
std::string Buffer;
Expand All @@ -1163,7 +1168,11 @@ class LineNumberPrinterHandler : public AsmPrinterHandler {

public:
LineNumberPrinterHandler(AsmPrinter &Printer, const char *debuginfo)
: S(*Printer.OutStreamer),
:
#if JL_LLVM_VERSION >= 190000
DebugHandlerBase(&Printer),
#endif
S(*Printer.OutStreamer),
LinePrinter("; ", true, debuginfo),
RawStream(Buffer),
Stream(RawStream) {}
Expand All @@ -1182,12 +1191,20 @@ class LineNumberPrinterHandler : public AsmPrinterHandler {
//virtual void beginModule(Module *M) override {}
virtual void endModule() override {}
/// note that some AsmPrinter implementations may not call beginFunction at all
#if JL_LLVM_VERSION >= 190000
virtual void beginFunctionImpl(const MachineFunction *MF) override {
#else
virtual void beginFunction(const MachineFunction *MF) override {
#endif
LinePrinter.emitFunctionAnnot(&MF->getFunction(), Stream);
emitAndReset();
}
//virtual void markFunctionEnd() override {}
#if JL_LLVM_VERSION >= 190000
virtual void endFunctionImpl(const MachineFunction *MF) override {
#else
virtual void endFunction(const MachineFunction *MF) override {
#endif
LinePrinter.emitEnd(Stream);
emitAndReset();
}
Expand Down Expand Up @@ -1272,9 +1289,14 @@ jl_value_t *jl_dump_function_asm_impl(jl_llvmf_dump_t* dump, char emit_mc, const
));
std::unique_ptr<AsmPrinter> Printer(
TM->getTarget().createAsmPrinter(*TM, std::move(S)));
#if JL_LLVM_VERSION >= 190000
Printer->addDebugHandler(
std::make_unique<LineNumberPrinterHandler>(*Printer, debuginfo));
#else
Printer->addAsmPrinterHandler(AsmPrinter::HandlerInfo(
std::unique_ptr<AsmPrinterHandler>(new LineNumberPrinterHandler(*Printer, debuginfo)),
"emit", "Debug Info Emission", "Julia", "Julia::LineNumberPrinterHandler Markup"));
#endif
if (!Printer)
return jl_an_empty_string;
PM.add(Printer.release());
Expand Down

0 comments on commit 9cbc166

Please sign in to comment.