mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
52 lines
1.6 KiB
C++
52 lines
1.6 KiB
C++
#pragma once
|
|
|
|
/*
|
|
* This file is distributed under the MIT License. See LICENSE.md for details.
|
|
*/
|
|
|
|
#include "llvm/IR/LegacyPassManager.h"
|
|
|
|
#include "revng/Model/LoadModelPass.h"
|
|
#include "revng/Pipeline/Context.h"
|
|
#include "revng/Pipeline/LLVMContainer.h"
|
|
#include "revng/Pipes/ModelGlobal.h"
|
|
#include "revng/Support/ResourceFinder.h"
|
|
|
|
namespace revng::pipes {
|
|
|
|
template<typename... Passes>
|
|
class LLVMAnalysisImplementation {
|
|
public:
|
|
void run(const pipeline::Context &Ctx, pipeline::LLVMContainer &Container) {
|
|
llvm::legacy::PassManager Manager;
|
|
registerPasses(Ctx, Manager);
|
|
Manager.run(Container.getModule());
|
|
}
|
|
|
|
void print(const pipeline::Context &Ctx,
|
|
llvm::raw_ostream &OS,
|
|
llvm::ArrayRef<std::string> ContainerNames) const {
|
|
OS << *revng::ResourceFinder.findFile("bin/revng");
|
|
OS << " opt --model-path=model.yml " << ContainerNames[0] << " -o "
|
|
<< ContainerNames[0];
|
|
std::vector<std::string> PassNames;
|
|
(PassNames.push_back(llvm::PassRegistry::getPassRegistry()
|
|
->getPassInfo(&Passes::ID)
|
|
->getPassArgument()
|
|
.str()),
|
|
...);
|
|
for (const auto &Name : PassNames)
|
|
OS << "-" << Name << " ";
|
|
OS << "\n";
|
|
}
|
|
|
|
void registerPasses(const pipeline::Context &Ctx,
|
|
llvm::legacy::PassManager &Manager) const {
|
|
auto Global = llvm::cantFail(Ctx.getGlobal<ModelGlobal>(ModelGlobalName));
|
|
Manager.add(new LoadModelWrapperPass(ModelWrapper(Global->get())));
|
|
(Manager.add(new Passes()), ...);
|
|
};
|
|
};
|
|
|
|
} // namespace revng::pipes
|