mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
Pipeline: reworked cpp container types
This commit is contained in:
committed by
massimofioravanti
parent
48104c404b
commit
f1852166ab
@@ -20,6 +20,11 @@
|
||||
|
||||
namespace revng::pipes {
|
||||
|
||||
inline char DecompiledCCodeInYAMLMimeType[] = "application/x.yaml.c.decompiled";
|
||||
using DecompiledCCodeInYAMLStringMap = FunctionStringMap<
|
||||
&kinds::DecompiledToYAML,
|
||||
DecompiledCCodeInYAMLMimeType>;
|
||||
|
||||
class CDecompilation {
|
||||
public:
|
||||
static constexpr auto Name = "CDecompilation";
|
||||
@@ -38,7 +43,7 @@ public:
|
||||
|
||||
void run(const pipeline::Context &Ctx,
|
||||
pipeline::LLVMContainer &IRContainer,
|
||||
FunctionStringMap &DecompiledFunctionsContainer);
|
||||
DecompiledCCodeInYAMLStringMap &DecompiledFunctionsContainer);
|
||||
|
||||
void print(const pipeline::Context &Ctx,
|
||||
llvm::raw_ostream &OS,
|
||||
|
||||
@@ -9,6 +9,12 @@
|
||||
#include "revng/Model/Binary.h"
|
||||
#include "revng/Pipes/FunctionStringMap.h"
|
||||
|
||||
#include "revng-c/Backend/CDecompilationPipe.h"
|
||||
|
||||
namespace detail {
|
||||
using Container = revng::pipes::DecompiledCCodeInYAMLStringMap;
|
||||
}
|
||||
|
||||
void decompile(llvm::Module &M,
|
||||
const model::Binary &Model,
|
||||
revng::pipes::FunctionStringMap &DecompiledFunctions);
|
||||
detail::Container &DecompiledFunctions);
|
||||
|
||||
@@ -9,6 +9,12 @@
|
||||
#include "revng/Pipes/FunctionStringMap.h"
|
||||
#include "revng/Support/MetaAddress.h"
|
||||
|
||||
#include "revng-c/Backend/CDecompilationPipe.h"
|
||||
|
||||
namespace detail {
|
||||
using DecompiledStringMap = revng::pipes::DecompiledCCodeInYAMLStringMap;
|
||||
}
|
||||
|
||||
void printSingleCFile(llvm::raw_ostream &Out,
|
||||
const revng::pipes::FunctionStringMap &Functions,
|
||||
const detail::DecompiledStringMap &Functions,
|
||||
const std::set<MetaAddress> &Targets);
|
||||
|
||||
@@ -20,6 +20,12 @@
|
||||
|
||||
namespace revng::pipes {
|
||||
|
||||
inline constexpr char DecompiledMIMEType[] = "text/ptml.c";
|
||||
inline constexpr char DecompiledMIMESuffix[] = "";
|
||||
using DecompiledFileContainer = FileContainer<&kinds::DecompiledToC,
|
||||
DecompiledMIMEType,
|
||||
DecompiledMIMESuffix>;
|
||||
|
||||
class DecompiledYAMLToC {
|
||||
public:
|
||||
static constexpr auto Name = "DecompiledYAMLToC";
|
||||
@@ -37,8 +43,8 @@ public:
|
||||
}
|
||||
|
||||
void run(const pipeline::Context &Ctx,
|
||||
const FunctionStringMap &DecompiledFunctionsContainer,
|
||||
FileContainer &OutCFile);
|
||||
const DecompiledCCodeInYAMLStringMap &DecompiledFunctionsContainer,
|
||||
DecompiledFileContainer &OutCFile);
|
||||
|
||||
void print(const pipeline::Context &Ctx,
|
||||
llvm::raw_ostream &OS,
|
||||
|
||||
@@ -19,6 +19,12 @@
|
||||
|
||||
namespace revng::pipes {
|
||||
|
||||
inline char HelpersHeaderFactoryMIMEType[] = "text/plain";
|
||||
inline char HelpersHeaderFactorySuffix[] = ".h";
|
||||
using HelpersHeaderFileContainer = FileContainer<&kinds::HelpersHeader,
|
||||
HelpersHeaderFactoryMIMEType,
|
||||
HelpersHeaderFactorySuffix>;
|
||||
|
||||
class HelpersToHeader {
|
||||
public:
|
||||
static constexpr auto Name = "HelpersToHeader";
|
||||
@@ -37,7 +43,7 @@ public:
|
||||
|
||||
void run(const pipeline::Context &Ctx,
|
||||
pipeline::LLVMContainer &IRContainer,
|
||||
FileContainer &HeaderFile);
|
||||
HelpersHeaderFileContainer &HeaderFile);
|
||||
|
||||
void print(const pipeline::Context &Ctx,
|
||||
llvm::raw_ostream &OS,
|
||||
|
||||
@@ -19,6 +19,13 @@
|
||||
|
||||
namespace revng::pipes {
|
||||
|
||||
inline char ModelHeaderFileContainerMIMEType[] = "text/plain";
|
||||
inline char ModelHeaderFileContainerSuffix[] = ".h";
|
||||
|
||||
using ModelHeaderFileContainer = FileContainer<&kinds::ModelHeader,
|
||||
ModelHeaderFileContainerMIMEType,
|
||||
ModelHeaderFileContainerSuffix>;
|
||||
|
||||
class ModelToHeader {
|
||||
public:
|
||||
static constexpr auto Name = "ModelToHeader";
|
||||
@@ -36,8 +43,8 @@ public:
|
||||
}
|
||||
|
||||
void run(const pipeline::Context &Ctx,
|
||||
const FileContainer &BinaryFile,
|
||||
FileContainer &HeaderFile);
|
||||
const BinaryFileContainer &BinaryFile,
|
||||
ModelHeaderFileContainer &HeaderFile);
|
||||
|
||||
void print(const pipeline::Context &Ctx,
|
||||
llvm::raw_ostream &OS,
|
||||
|
||||
@@ -14,14 +14,13 @@
|
||||
|
||||
namespace revng::pipes {
|
||||
|
||||
static RegisterFunctionStringMap DecompiledYAML("DecompiledCCodeInYAML",
|
||||
"application/"
|
||||
"x.yaml.c.decompiled",
|
||||
kinds::DecompiledToYAML);
|
||||
static RegisterFunctionStringMap<DecompiledCCodeInYAMLStringMap> Reg("Decompile"
|
||||
"dCCodeInY"
|
||||
"AML");
|
||||
|
||||
void CDecompilation::run(const pipeline::Context &Ctx,
|
||||
pipeline::LLVMContainer &IRContainer,
|
||||
FunctionStringMap &DecompiledFunctions) {
|
||||
DecompiledCCodeInYAMLStringMap &DecompiledFunctions) {
|
||||
|
||||
llvm::Module &Module = IRContainer.getModule();
|
||||
const model::Binary &Model = *getModelFromContext(Ctx);
|
||||
|
||||
@@ -1768,9 +1768,10 @@ static std::string decompileFunction(const llvm::Function &LLVMFunc,
|
||||
return Result;
|
||||
}
|
||||
|
||||
using Container = revng::pipes::DecompiledCCodeInYAMLStringMap;
|
||||
void decompile(llvm::Module &Module,
|
||||
const model::Binary &Model,
|
||||
revng::pipes::FunctionStringMap &DecompiledFunctions) {
|
||||
Container &DecompiledFunctions) {
|
||||
|
||||
if (Log.isEnabled())
|
||||
writeToFile(Model.toString(), "model-during-c-codegen.yaml");
|
||||
|
||||
@@ -7,8 +7,10 @@
|
||||
#include "revng-c/Backend/DecompiledYAMLToC.h"
|
||||
#include "revng-c/Support/PTMLC.h"
|
||||
|
||||
using namespace revng::pipes;
|
||||
|
||||
void printSingleCFile(llvm::raw_ostream &Out,
|
||||
const revng::pipes::FunctionStringMap &Functions,
|
||||
const DecompiledCCodeInYAMLStringMap &Functions,
|
||||
const std::set<MetaAddress> &Targets) {
|
||||
auto Scope = ptml::Tag(ptml::tags::Div).scope(Out);
|
||||
// Print headers
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
//
|
||||
|
||||
#include "revng/Pipeline/AllRegistries.h"
|
||||
#include "revng/Pipeline/RegisterContainerFactory.h"
|
||||
#include "revng/Pipes/FileContainer.h"
|
||||
#include "revng/Pipes/Kinds.h"
|
||||
|
||||
#include "revng-c/Backend/DecompiledYAMLToC.h"
|
||||
@@ -13,15 +15,13 @@ using namespace revng::kinds;
|
||||
|
||||
namespace revng::pipes {
|
||||
|
||||
using RegFactory = pipeline::RegisterContainerFactory;
|
||||
static RegFactory DecompiledCFactory("DecompiledCCode",
|
||||
makeFileContainerFactory(DecompiledToC,
|
||||
"text/ptml",
|
||||
".c"));
|
||||
static pipeline::RegisterDefaultConstructibleContainer<DecompiledFileContainer>
|
||||
Reg("DecompiledCCode");
|
||||
|
||||
using Container = DecompiledCCodeInYAMLStringMap;
|
||||
void DecompiledYAMLToC::run(const pipeline::Context &Ctx,
|
||||
const FunctionStringMap &DecompiledFunctions,
|
||||
FileContainer &OutCFile) {
|
||||
const Container &DecompiledFunctions,
|
||||
DecompiledFileContainer &OutCFile) {
|
||||
|
||||
std::error_code EC;
|
||||
llvm::raw_fd_ostream Out(OutCFile.getOrCreatePath(), EC);
|
||||
|
||||
@@ -3,20 +3,22 @@
|
||||
//
|
||||
|
||||
#include "revng/Pipeline/AllRegistries.h"
|
||||
#include "revng/Pipeline/RegisterContainerFactory.h"
|
||||
#include "revng/Pipes/FileContainer.h"
|
||||
|
||||
#include "revng-c/HeadersGeneration/HelpersToHeader.h"
|
||||
#include "revng-c/HeadersGeneration/HelpersToHeaderPipe.h"
|
||||
#include "revng-c/Pipes/Kinds.h"
|
||||
|
||||
namespace revng::pipes {
|
||||
|
||||
inline auto &makeFCF = makeFileContainerFactory;
|
||||
static pipeline::RegisterContainerFactory
|
||||
HelpersHeaderFactory("HelpersHeader",
|
||||
makeFCF(kinds::HelpersHeader, "text/plain", ".h"));
|
||||
using namespace pipeline;
|
||||
static RegisterDefaultConstructibleContainer<HelpersHeaderFileContainer>
|
||||
Reg("HelpersHeader");
|
||||
|
||||
void HelpersToHeader::run(const pipeline::Context &Ctx,
|
||||
pipeline::LLVMContainer &IRContainer,
|
||||
FileContainer &HeaderFile) {
|
||||
HelpersHeaderFileContainer &HeaderFile) {
|
||||
auto HasAllFunctions = [](const pipeline::Target &Target) {
|
||||
return &Target.getKind() == &kinds::StackAccessesSegregated
|
||||
and Target.getPathComponents().back().isAll();
|
||||
|
||||
@@ -3,17 +3,18 @@
|
||||
//
|
||||
|
||||
#include "revng/Pipeline/AllRegistries.h"
|
||||
#include "revng/Pipeline/RegisterContainerFactory.h"
|
||||
#include "revng/Pipes/FileContainer.h"
|
||||
#include "revng/Pipes/ModelGlobal.h"
|
||||
|
||||
#include "revng-c/HeadersGeneration/ModelToHeader.h"
|
||||
#include "revng-c/HeadersGeneration/ModelToHeaderPipe.h"
|
||||
#include "revng-c/Pipes/Kinds.h"
|
||||
|
||||
namespace revng::pipes {
|
||||
|
||||
inline auto &makeFCF = makeFileContainerFactory;
|
||||
static pipeline::RegisterContainerFactory
|
||||
ModelHeaderFactory("ModelHeader",
|
||||
makeFCF(kinds::ModelHeader, "text/plain", ".h"));
|
||||
static pipeline::RegisterDefaultConstructibleContainer<ModelHeaderFileContainer>
|
||||
Reg("ModelHeader");
|
||||
|
||||
// TODO: BinaryFile here is a placeholder. In principle this pipe has no real
|
||||
// input container. It just juses the model in Ctx to generated HeaderFile.
|
||||
@@ -21,8 +22,8 @@ static pipeline::RegisterContainerFactory
|
||||
// had to resort to this trick. Whenever pipes with no inputs are supported
|
||||
// BinaryFile can be dropped.
|
||||
void ModelToHeader::run(const pipeline::Context &Ctx,
|
||||
const FileContainer &BinaryFile,
|
||||
FileContainer &HeaderFile) {
|
||||
const BinaryFileContainer &BinaryFile,
|
||||
ModelHeaderFileContainer &HeaderFile) {
|
||||
|
||||
std::error_code EC;
|
||||
llvm::raw_fd_ostream Header(HeaderFile.getOrCreatePath(), EC);
|
||||
|
||||
@@ -128,11 +128,8 @@ int main(int Argc, const char *Argv[]) {
|
||||
}
|
||||
|
||||
using revng::pipes::FunctionStringMap;
|
||||
FunctionStringMap DecompiledFunctions("" /*Name*/,
|
||||
"application/"
|
||||
"x.yaml.c.decompiled",
|
||||
revng::kinds::DecompiledToYAML,
|
||||
Model);
|
||||
revng::pipes::DecompiledCCodeInYAMLStringMap DecompiledFunctions("" /*Name*/,
|
||||
&Model);
|
||||
|
||||
decompile(*Module, *Model, DecompiledFunctions);
|
||||
|
||||
|
||||
@@ -78,11 +78,7 @@ int main(int Argc, const char *Argv[]) {
|
||||
using revng::pipes::FunctionStringMap;
|
||||
TupleTree<model::Binary> Model;
|
||||
|
||||
FunctionStringMap Functions("" /*Name*/,
|
||||
"application/"
|
||||
"x.yaml.c.decompiled",
|
||||
revng::kinds::DecompiledToYAML,
|
||||
Model);
|
||||
revng::pipes::DecompiledCCodeInYAMLStringMap Functions("" /*Name*/, &Model);
|
||||
|
||||
// Deserialize the map
|
||||
llvm::cantFail(Functions.deserialize(**InputBuffer));
|
||||
|
||||
Reference in New Issue
Block a user