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.
68 lines
1.7 KiB
C++
68 lines
1.7 KiB
C++
#pragma once
|
|
|
|
//
|
|
// This file is distributed under the MIT License. See LICENSE.md for details.
|
|
//
|
|
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
|
|
#include "revng/Lift/LibTcg.h"
|
|
#include "revng/Model/Binary.h"
|
|
#include "revng/Model/RawBinaryView.h"
|
|
|
|
// Forward declarations
|
|
namespace llvm {
|
|
|
|
class LLVMContext;
|
|
class Function;
|
|
class GlobalVariable;
|
|
class Module;
|
|
class Value;
|
|
class StructDefinition;
|
|
class DataLayout;
|
|
|
|
}; // namespace llvm
|
|
|
|
struct LibTcgInterface;
|
|
|
|
/// Translator from binary code to LLVM IR.
|
|
class CodeGenerator {
|
|
public:
|
|
/// Create a new code generator translating code from an architecture to
|
|
/// another, writing the corresponding LLVM IR and other useful information to
|
|
/// the specified paths.
|
|
CodeGenerator(const RawBinaryView &RawBinary,
|
|
llvm::Module *TheModule,
|
|
const TupleTree<model::Binary> &Model,
|
|
std::string Helpers,
|
|
std::string EarlyLinked,
|
|
model::Architecture::Values TargetArchitecture);
|
|
|
|
~CodeGenerator();
|
|
|
|
/// Creates an LLVM function for the code in the specified memory area.
|
|
///
|
|
/// \param VirtualAddress the address from where the translation should start.
|
|
void translate(LibTcg &LibTcg, std::optional<uint64_t> RawVirtualAddress);
|
|
|
|
private:
|
|
const RawBinaryView &RawBinary;
|
|
llvm::Module *TheModule;
|
|
llvm::LLVMContext &Context;
|
|
std::unique_ptr<llvm::Module> HelpersModule;
|
|
std::unique_ptr<llvm::Module> EarlyLinkedModule;
|
|
const TupleTree<model::Binary> &Model;
|
|
|
|
unsigned LibTcgInstrMDKind;
|
|
|
|
std::string FunctionListPath;
|
|
|
|
std::set<MetaAddress> NoMoreCodeBoundaries;
|
|
|
|
model::Architecture::Values TargetArchitecture;
|
|
};
|