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.
83 lines
2.4 KiB
C++
83 lines
2.4 KiB
C++
#pragma once
|
|
|
|
//
|
|
// This file is distributed under the MIT License. See LICENSE.md for details.
|
|
//
|
|
|
|
#include "qemu/libtcg/libtcg.h"
|
|
|
|
#include "revng/Model/Architecture.h"
|
|
|
|
class LibTcg {
|
|
public:
|
|
class TranslationBlock {
|
|
private:
|
|
LibTcgInterface &Interface;
|
|
LibTcgContext &Context;
|
|
LibTcgTranslationBlock Block;
|
|
|
|
public:
|
|
TranslationBlock(LibTcgInterface &Interface,
|
|
LibTcgContext &Context,
|
|
LibTcgTranslationBlock Block) :
|
|
Interface(Interface), Context(Context), Block(Block) {}
|
|
|
|
~TranslationBlock() {
|
|
Interface.translation_block_destroy(&Context, Block);
|
|
}
|
|
|
|
public:
|
|
LibTcgTranslationBlock &operator*() { return Block; }
|
|
const LibTcgTranslationBlock &operator*() const { return Block; }
|
|
LibTcgTranslationBlock *operator->() { return &Block; }
|
|
const LibTcgTranslationBlock *operator->() const { return &Block; }
|
|
};
|
|
|
|
private:
|
|
void *LibraryHandle = nullptr;
|
|
LibTcgInterface Interface;
|
|
LibTcgContext *Context = nullptr;
|
|
LibTcgArchInfo ArchInfo;
|
|
std::map<intptr_t, llvm::StringRef> GlobalNames;
|
|
|
|
public:
|
|
~LibTcg();
|
|
|
|
public:
|
|
static LibTcg get(model::Architecture::Values Architecture);
|
|
|
|
public:
|
|
const LibTcgArchInfo &archInfo() const { return ArchInfo; }
|
|
|
|
uint8_t *envPointer() { return Interface.env_ptr(Context); }
|
|
|
|
TranslationBlock translateBlock(const unsigned char *Buffer,
|
|
size_t Size,
|
|
uint64_t VirtualAddress,
|
|
uint32_t TranslateFlags) {
|
|
return TranslationBlock(Interface,
|
|
*Context,
|
|
Interface.translate_block(Context,
|
|
Buffer,
|
|
Size,
|
|
VirtualAddress,
|
|
TranslateFlags));
|
|
}
|
|
|
|
void dumpInstructionToBuffer(LibTcgInstruction *Instruction,
|
|
char *Buffer,
|
|
size_t Size) {
|
|
Interface.dump_instruction_to_buffer(Instruction, Buffer, Size);
|
|
}
|
|
|
|
const char *instructionName(LibTcgOpcode Opcode) {
|
|
return Interface.get_instruction_name(Opcode);
|
|
}
|
|
|
|
LibTcgHelperInfo helperInfo(LibTcgInstruction *InstructionInfo) {
|
|
return Interface.get_helper_info(InstructionInfo);
|
|
}
|
|
|
|
const auto &globalNames() const { return GlobalNames; }
|
|
};
|