Files
revng-revng/lib/Lift/SelfReferencingDbgAnnotationWriter.cpp
Alessandro Di Federico f8bd4c3bac Move around some files in preparation for libtcg
* Make the following private headers public:
  * Lift/CPUStateAccessAnalysisPass.h
  * Lift/CSVOffsets.h
  * Lift/PTCDump.h
  * Lift/VariableManager.h
* Move from revngSupport to revngLift:
  * IRAnnotators.{h,cpp}
  * SelfReferencingDbgAnnotationWriter.{h,cpp}
* Move from revngSupport to revngModel:
  * FunctionTags.{h,cpp}
  * ProgramCounterHandler.{h,cpp}
* Move from revngSupport to revngRecompile:
  * OriginalAssemblyAnnotationWriter.{h,cpp}
2025-10-24 15:34:11 +02:00

44 lines
1.4 KiB
C++

/// \file SelfReferencingDbgAnnotationWriter.cpp
/// 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);
}