mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
1429b526ab
This commit drops libptc in favor of its new form libtcg. It brings several improvements, among which: * The QEMU version we work on has been upgraded. * CPUStateAccessAnalysis has been reimplemented in a way that makes it easier to debug and solves some limitations (e.g., tracking leaking pointers). * Identification of pieces of the CPU state that are read by each helper and fixing access to the CPU state is now performed at build-time. * We no longer mmap the code we need to translate, dropping all the issues related to code that needed to be mapped where something is already present. * We now have two distinct flavors of helper modules: the full one and the "slim" one. The latter contains the definition only of functions we intend to inline. It is used in most of the pipeline, a good thing since we spend less time optimizing code we don't really care about. The full module is only used on the re-compilation branch of the pipeline. * We no longer split the `cpu_loop` function. * We change MetaAddress to rely on architectures from `model::` as opposed to the LLVM ones. * We no longer attach debug info to LLVM IR containing the original assembly. * We now verify that the lifted code only contains code we expect.
76 lines
2.0 KiB
C++
76 lines
2.0 KiB
C++
#pragma once
|
|
|
|
//
|
|
// This file is distributed under the MIT License. See LICENSE.md for details.
|
|
//
|
|
|
|
#include "llvm/IR/AssemblyAnnotationWriter.h"
|
|
#include "llvm/Support/FormattedStream.h"
|
|
|
|
#include "ArgumentUsageAnalysis.h"
|
|
#include "CPUStateUsage.h"
|
|
|
|
namespace aua {
|
|
|
|
class AnnotationWriter : public llvm::AssemblyAnnotationWriter {
|
|
private:
|
|
ArgumentUsageAnalysis &AUA;
|
|
CPUStateUsageAnalysis &CSUA;
|
|
const Function *CurrentAUA = nullptr;
|
|
|
|
public:
|
|
AnnotationWriter(ArgumentUsageAnalysis &AUA, CPUStateUsageAnalysis &CSUA) :
|
|
AUA(AUA), CSUA(CSUA) {}
|
|
~AnnotationWriter() override = default;
|
|
|
|
public:
|
|
virtual void emitFunctionAnnot(const llvm::Function *F,
|
|
llvm::formatted_raw_ostream &Output) override {
|
|
auto It = AUA.find(F);
|
|
if (It == AUA.end()) {
|
|
CurrentAUA = nullptr;
|
|
} else {
|
|
const Function &Results = It->second;
|
|
CurrentAUA = &Results;
|
|
|
|
if (auto *Results = CSUA.get(*const_cast<llvm::Function *>(F)))
|
|
Results->dump(Output, "; ");
|
|
|
|
Results.dump(Output, "; ");
|
|
}
|
|
}
|
|
|
|
virtual void
|
|
emitInstructionAnnot(const llvm::Instruction *I,
|
|
llvm::formatted_raw_ostream &Output) override {
|
|
if (CurrentAUA != nullptr) {
|
|
if (const Value *V = CurrentAUA->tryGet(*I)) {
|
|
Output << " ; " << V->toString() << "\n";
|
|
}
|
|
|
|
if (CSUA.isEscaping(*I))
|
|
Output << " ; CPU state escapes!\n";
|
|
|
|
for (unsigned J = 0; J < I->getNumOperands(); ++J) {
|
|
const auto &Accesses = CSUA.getOffsets(I->getOperandUse(J));
|
|
if (Accesses.size() > 0) {
|
|
Output << " ; Offsets for operand " << J << ": {";
|
|
for (const auto &[Offset, Size] : Accesses)
|
|
Output << " i" << (Size * 8) << " @ " << Offset;
|
|
Output << " }\n";
|
|
}
|
|
}
|
|
|
|
if (auto *Call = dyn_cast<llvm::CallInst>(I)) {
|
|
for (const auto &Call : CurrentAUA->calls()) {
|
|
if (&Call.callInstruction() == I) {
|
|
Call.dump(Output, " ; ", true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
} // namespace aua
|