Files
revng-revng/lib/Lift/SelfReferencingDbgAnnotationWriter.cpp
Alessandro Di Federico 5820908675 Remove and ban \file
2025-12-16 17:41:55 +01:00

43 lines
1.3 KiB
C++

/// This file handles debugging information generation.
//
// This file is distributed under the MIT License. See LICENSE.md for details.
//
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instruction.h"
#include "llvm/Support/FormattedStream.h"
#include "revng/Lift/SelfReferencingDbgAnnotationWriter.h"
#include "revng/Model/FunctionTags.h"
using namespace llvm;
using SRDAW = SelfReferencingDbgAnnotationWriter;
void SRDAW::emitInstructionAnnot(const Instruction *I,
formatted_raw_ostream &Output) {
if (InnerAAW != nullptr)
InnerAAW->emitInstructionAnnot(I, Output);
DISubprogram *Subprogram = I->getParent()->getParent()->getSubprogram();
// Ignore whatever is outside the root and the isolated functions
const Function *F = I->getParent()->getParent();
if (Subprogram == nullptr or not isRootOrLifted(F))
return;
// Flushing is required to have correct line and column numbers
Output.flush();
auto *Location = DILocation::get(Context,
Output.getLine() + 1,
Output.getColumn(),
Subprogram);
// Sorry Bjarne
auto *NonConstInstruction = const_cast<Instruction *>(I);
NonConstInstruction->setMetadata(DbgKind, Location);
}