From 86e45461a09cc653ee450be73760bfd1edda82fd Mon Sep 17 00:00:00 2001 From: Massimo Fioravanti Date: Fri, 24 Nov 2023 17:37:41 +0100 Subject: [PATCH] Introduce pipeline execution context --- include/revng-c/Backend/CDecompilationPipe.h | 2 +- include/revng-c/Backend/DecompiledYAMLToCPipe.h | 2 +- .../revng-c/HeadersGeneration/HelpersToHeaderPipe.h | 2 +- include/revng-c/HeadersGeneration/ModelToHeaderPipe.h | 2 +- lib/Backend/CDecompilationPipe.cpp | 2 +- lib/Backend/DecompiledYAMLToCPipe.cpp | 2 +- lib/DataLayoutAnalysis/DLAPass.cpp | 6 +++--- lib/HeadersGeneration/HelpersToHeaderPipe.cpp | 5 +++-- lib/HeadersGeneration/ModelToHeaderPipe.cpp | 2 +- lib/ImportModelFromC/ImportModelFromCAnalysis.cpp | 5 +++-- lib/PromoteStackPointer/DetectStackSizePass.cpp | 10 +++++----- lib/RemoveLiftingArtifacts/MakeSegmentRefPipe.cpp | 4 ++-- lib/mlir/Pipes/MLIRPipe.cpp | 2 +- 13 files changed, 24 insertions(+), 22 deletions(-) diff --git a/include/revng-c/Backend/CDecompilationPipe.h b/include/revng-c/Backend/CDecompilationPipe.h index 9fed3c1ad..bc7d9ae55 100644 --- a/include/revng-c/Backend/CDecompilationPipe.h +++ b/include/revng-c/Backend/CDecompilationPipe.h @@ -44,7 +44,7 @@ public: InputPreservation::Preserve) }) }; } - void run(const pipeline::Context &Ctx, + void run(const pipeline::ExecutionContext &Ctx, pipeline::LLVMContainer &IRContainer, DecompiledCCodeInYAMLStringMap &DecompiledFunctionsContainer); diff --git a/include/revng-c/Backend/DecompiledYAMLToCPipe.h b/include/revng-c/Backend/DecompiledYAMLToCPipe.h index fb00b1614..74c80e554 100644 --- a/include/revng-c/Backend/DecompiledYAMLToCPipe.h +++ b/include/revng-c/Backend/DecompiledYAMLToCPipe.h @@ -44,7 +44,7 @@ public: InputPreservation::Preserve) }) }; } - void run(const pipeline::Context &Ctx, + void run(const pipeline::ExecutionContext &Ctx, const DecompiledCCodeInYAMLStringMap &DecompiledFunctionsContainer, DecompiledFileContainer &OutCFile); diff --git a/include/revng-c/HeadersGeneration/HelpersToHeaderPipe.h b/include/revng-c/HeadersGeneration/HelpersToHeaderPipe.h index 40e032d98..bf9099a64 100644 --- a/include/revng-c/HeadersGeneration/HelpersToHeaderPipe.h +++ b/include/revng-c/HeadersGeneration/HelpersToHeaderPipe.h @@ -42,7 +42,7 @@ public: InputPreservation::Preserve) } }; } - void run(const pipeline::Context &Ctx, + void run(const pipeline::ExecutionContext &Ctx, pipeline::LLVMContainer &IRContainer, HelpersHeaderFileContainer &HeaderFile); diff --git a/include/revng-c/HeadersGeneration/ModelToHeaderPipe.h b/include/revng-c/HeadersGeneration/ModelToHeaderPipe.h index ff8bdd6ee..dd236e8d8 100644 --- a/include/revng-c/HeadersGeneration/ModelToHeaderPipe.h +++ b/include/revng-c/HeadersGeneration/ModelToHeaderPipe.h @@ -39,7 +39,7 @@ public: return { ContractGroup({ C1 }) }; } - void run(const pipeline::Context &Ctx, + void run(const pipeline::ExecutionContext &Ctx, const BinaryFileContainer &BinaryFile, ModelHeaderFileContainer &HeaderFile); diff --git a/lib/Backend/CDecompilationPipe.cpp b/lib/Backend/CDecompilationPipe.cpp index 33ed0181f..4be8c099e 100644 --- a/lib/Backend/CDecompilationPipe.cpp +++ b/lib/Backend/CDecompilationPipe.cpp @@ -16,7 +16,7 @@ namespace revng::pipes { static RegisterFunctionStringMap Reg; -void CDecompilation::run(const pipeline::Context &Ctx, +void CDecompilation::run(const pipeline::ExecutionContext &Ctx, pipeline::LLVMContainer &IRContainer, DecompiledCCodeInYAMLStringMap &DecompiledFunctions) { diff --git a/lib/Backend/DecompiledYAMLToCPipe.cpp b/lib/Backend/DecompiledYAMLToCPipe.cpp index 9d01ef51d..662255c37 100644 --- a/lib/Backend/DecompiledYAMLToCPipe.cpp +++ b/lib/Backend/DecompiledYAMLToCPipe.cpp @@ -19,7 +19,7 @@ static pipeline::RegisterDefaultConstructibleContainer Reg; using Container = DecompiledCCodeInYAMLStringMap; -void DecompiledYAMLToC::run(const pipeline::Context &Ctx, +void DecompiledYAMLToC::run(const pipeline::ExecutionContext &Ctx, const Container &DecompiledFunctions, DecompiledFileContainer &OutCFile) { diff --git a/lib/DataLayoutAnalysis/DLAPass.cpp b/lib/DataLayoutAnalysis/DLAPass.cpp index f00062a96..921b15a97 100644 --- a/lib/DataLayoutAnalysis/DLAPass.cpp +++ b/lib/DataLayoutAnalysis/DLAPass.cpp @@ -115,12 +115,12 @@ public: { &revng::kinds::StackAccessesSegregated } }; - void run(pipeline::Context &Ctx, pipeline::LLVMContainer &Module) { + void run(pipeline::ExecutionContext &Ctx, pipeline::LLVMContainer &Module) { using namespace revng; llvm::legacy::PassManager Manager; - auto Global = llvm::cantFail(Ctx.getGlobal(ModelGlobalName)); - Manager.add(new LoadModelWrapperPass(ModelWrapper(Global->get()))); + auto &Global = getWritableModelFromContext(Ctx); + Manager.add(new LoadModelWrapperPass(ModelWrapper(Global))); Manager.add(new DLAPass()); Manager.run(Module.getModule()); } diff --git a/lib/HeadersGeneration/HelpersToHeaderPipe.cpp b/lib/HeadersGeneration/HelpersToHeaderPipe.cpp index c853d4729..d6442f7c1 100644 --- a/lib/HeadersGeneration/HelpersToHeaderPipe.cpp +++ b/lib/HeadersGeneration/HelpersToHeaderPipe.cpp @@ -15,12 +15,13 @@ namespace revng::pipes { using namespace pipeline; static RegisterDefaultConstructibleContainer Reg; -void HelpersToHeader::run(const pipeline::Context &Ctx, +void HelpersToHeader::run(const pipeline::ExecutionContext &Ctx, pipeline::LLVMContainer &IRContainer, HelpersHeaderFileContainer &HeaderFile) { auto Enumeration = IRContainer.enumerate(); - if (not Enumeration.contains(kinds::StackAccessesSegregated.allTargets(Ctx))) + auto Targets = kinds::StackAccessesSegregated.allTargets(Ctx.getContext()); + if (not Enumeration.contains(Targets)) return; std::error_code EC; diff --git a/lib/HeadersGeneration/ModelToHeaderPipe.cpp b/lib/HeadersGeneration/ModelToHeaderPipe.cpp index a6268e9e5..39ad4b997 100644 --- a/lib/HeadersGeneration/ModelToHeaderPipe.cpp +++ b/lib/HeadersGeneration/ModelToHeaderPipe.cpp @@ -21,7 +21,7 @@ static pipeline::RegisterDefaultConstructibleContainer // At the moment revng-pipeline does not support pipes with no inputs, so we // had to resort to this trick. Whenever pipes with no inputs are supported // BinaryFile can be dropped. -void ModelToHeader::run(const pipeline::Context &Ctx, +void ModelToHeader::run(const pipeline::ExecutionContext &Ctx, const BinaryFileContainer &BinaryFile, ModelHeaderFileContainer &HeaderFile) { diff --git a/lib/ImportModelFromC/ImportModelFromCAnalysis.cpp b/lib/ImportModelFromC/ImportModelFromCAnalysis.cpp index 7036863ee..65128770d 100644 --- a/lib/ImportModelFromC/ImportModelFromCAnalysis.cpp +++ b/lib/ImportModelFromC/ImportModelFromCAnalysis.cpp @@ -82,8 +82,9 @@ struct ImportModelFromCAnalysis { std::vector> AcceptedKinds = {}; - llvm::Error - run(pipeline::Context &Ctx, std::string LocationToEdit, std::string CCode) { + llvm::Error run(pipeline::ExecutionContext &Ctx, + std::string LocationToEdit, + std::string CCode) { enum ImportModelFromCOption TheOption; auto &Model = revng::getWritableModelFromContext(Ctx); diff --git a/lib/PromoteStackPointer/DetectStackSizePass.cpp b/lib/PromoteStackPointer/DetectStackSizePass.cpp index 7f3e40e0f..3b449ad7b 100644 --- a/lib/PromoteStackPointer/DetectStackSizePass.cpp +++ b/lib/PromoteStackPointer/DetectStackSizePass.cpp @@ -355,20 +355,20 @@ public: { &revng::kinds::StackPointerPromoted } }; - llvm::Error run(pipeline::Context &Ctx, pipeline::LLVMContainer &Module) { + llvm::Error run(pipeline::ExecutionContext &Ctx, + pipeline::LLVMContainer &Module) { using namespace revng; llvm::legacy::PassManager Manager; - auto Global = llvm::cantFail(Ctx.getGlobal(ModelGlobalName)); + auto &Global = getWritableModelFromContext(Ctx); - const TupleTree &Model = Global->get(); - if (Model->Architecture() == model::Architecture::Invalid) { + if (Global->Architecture() == model::Architecture::Invalid) { return createStringError(inconvertibleErrorCode(), "DetectStackSize analysis require a valid" " Architecture"); } - Manager.add(new LoadModelWrapperPass(ModelWrapper(Global->get()))); + Manager.add(new LoadModelWrapperPass(ModelWrapper(Global))); Manager.add(new DetectStackSizePass()); Manager.run(Module.getModule()); diff --git a/lib/RemoveLiftingArtifacts/MakeSegmentRefPipe.cpp b/lib/RemoveLiftingArtifacts/MakeSegmentRefPipe.cpp index 11f4c5cf7..b8f955129 100644 --- a/lib/RemoveLiftingArtifacts/MakeSegmentRefPipe.cpp +++ b/lib/RemoveLiftingArtifacts/MakeSegmentRefPipe.cpp @@ -32,7 +32,7 @@ public: return { pipeline::ContractGroup({ BinaryPart, FunctionsPart }) }; } - void run(pipeline::Context &Ctx, + void run(pipeline::ExecutionContext &Ctx, const BinaryFileContainer &SourceBinary, pipeline::LLVMContainer &Output); @@ -48,7 +48,7 @@ public: } }; -void MakeSegmentRefs::run(pipeline::Context &Ctx, +void MakeSegmentRefs::run(pipeline::ExecutionContext &Ctx, const BinaryFileContainer &SourceBinary, pipeline::LLVMContainer &TargetsList) { if (not SourceBinary.exists()) diff --git a/lib/mlir/Pipes/MLIRPipe.cpp b/lib/mlir/Pipes/MLIRPipe.cpp index ac7dc574c..71ec5e32a 100644 --- a/lib/mlir/Pipes/MLIRPipe.cpp +++ b/lib/mlir/Pipes/MLIRPipe.cpp @@ -51,7 +51,7 @@ public: InputPreservation::Preserve) }) }; } - void run(const pipeline::Context &Ctx, + void run(const pipeline::ExecutionContext &Ctx, pipeline::LLVMContainer &IRContainer, MLIRFileContainer &DecompiledFunctionsContainer) { mlir::MLIRContext Context;