diff --git a/include/revng-c/Backend/CDecompilationPipe.h b/include/revng-c/Backend/CDecompilationPipe.h index 11d43b1b1..1245318ec 100644 --- a/include/revng-c/Backend/CDecompilationPipe.h +++ b/include/revng-c/Backend/CDecompilationPipe.h @@ -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, diff --git a/include/revng-c/Backend/DecompileFunction.h b/include/revng-c/Backend/DecompileFunction.h index 732c3db4c..efecc9914 100644 --- a/include/revng-c/Backend/DecompileFunction.h +++ b/include/revng-c/Backend/DecompileFunction.h @@ -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); diff --git a/include/revng-c/Backend/DecompiledYAMLToC.h b/include/revng-c/Backend/DecompiledYAMLToC.h index 44e45782c..c0967b2e3 100644 --- a/include/revng-c/Backend/DecompiledYAMLToC.h +++ b/include/revng-c/Backend/DecompiledYAMLToC.h @@ -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 &Targets); diff --git a/include/revng-c/Backend/DecompiledYAMLToCPipe.h b/include/revng-c/Backend/DecompiledYAMLToCPipe.h index e30da76a1..55a9fc722 100644 --- a/include/revng-c/Backend/DecompiledYAMLToCPipe.h +++ b/include/revng-c/Backend/DecompiledYAMLToCPipe.h @@ -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, diff --git a/include/revng-c/HeadersGeneration/HelpersToHeaderPipe.h b/include/revng-c/HeadersGeneration/HelpersToHeaderPipe.h index 5f2d93e48..e7b4f9778 100644 --- a/include/revng-c/HeadersGeneration/HelpersToHeaderPipe.h +++ b/include/revng-c/HeadersGeneration/HelpersToHeaderPipe.h @@ -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, diff --git a/include/revng-c/HeadersGeneration/ModelToHeaderPipe.h b/include/revng-c/HeadersGeneration/ModelToHeaderPipe.h index 54de9a413..769aa6dcf 100644 --- a/include/revng-c/HeadersGeneration/ModelToHeaderPipe.h +++ b/include/revng-c/HeadersGeneration/ModelToHeaderPipe.h @@ -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, diff --git a/lib/Backend/CDecompilationPipe.cpp b/lib/Backend/CDecompilationPipe.cpp index 163099ac4..ee45a654f 100644 --- a/lib/Backend/CDecompilationPipe.cpp +++ b/lib/Backend/CDecompilationPipe.cpp @@ -14,14 +14,13 @@ namespace revng::pipes { -static RegisterFunctionStringMap DecompiledYAML("DecompiledCCodeInYAML", - "application/" - "x.yaml.c.decompiled", - kinds::DecompiledToYAML); +static RegisterFunctionStringMap 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); diff --git a/lib/Backend/DecompileFunction.cpp b/lib/Backend/DecompileFunction.cpp index 42d7d604e..1bb0dd2d0 100644 --- a/lib/Backend/DecompileFunction.cpp +++ b/lib/Backend/DecompileFunction.cpp @@ -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"); diff --git a/lib/Backend/DecompiledYAMLToC.cpp b/lib/Backend/DecompiledYAMLToC.cpp index 3217860ad..c47686a54 100644 --- a/lib/Backend/DecompiledYAMLToC.cpp +++ b/lib/Backend/DecompiledYAMLToC.cpp @@ -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 &Targets) { auto Scope = ptml::Tag(ptml::tags::Div).scope(Out); // Print headers diff --git a/lib/Backend/DecompiledYAMLToCPipe.cpp b/lib/Backend/DecompiledYAMLToCPipe.cpp index 8df77d73a..2f851baff 100644 --- a/lib/Backend/DecompiledYAMLToCPipe.cpp +++ b/lib/Backend/DecompiledYAMLToCPipe.cpp @@ -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 + 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); diff --git a/lib/HeadersGeneration/HelpersToHeaderPipe.cpp b/lib/HeadersGeneration/HelpersToHeaderPipe.cpp index d1d086c45..d2960f0ab 100644 --- a/lib/HeadersGeneration/HelpersToHeaderPipe.cpp +++ b/lib/HeadersGeneration/HelpersToHeaderPipe.cpp @@ -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 + 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(); diff --git a/lib/HeadersGeneration/ModelToHeaderPipe.cpp b/lib/HeadersGeneration/ModelToHeaderPipe.cpp index 3f8d468ec..c6e79558c 100644 --- a/lib/HeadersGeneration/ModelToHeaderPipe.cpp +++ b/lib/HeadersGeneration/ModelToHeaderPipe.cpp @@ -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 + 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); diff --git a/tools/decompile/Main.cpp b/tools/decompile/Main.cpp index 3e172faf9..75040cf37 100644 --- a/tools/decompile/Main.cpp +++ b/tools/decompile/Main.cpp @@ -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); diff --git a/tools/decompiled-yaml-to-c/Main.cpp b/tools/decompiled-yaml-to-c/Main.cpp index 3024b7837..74026838b 100644 --- a/tools/decompiled-yaml-to-c/Main.cpp +++ b/tools/decompiled-yaml-to-c/Main.cpp @@ -78,11 +78,7 @@ int main(int Argc, const char *Argv[]) { using revng::pipes::FunctionStringMap; TupleTree 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));