/// \file DropRoot.cpp /// \brief // // This file is distributed under the MIT License. See LICENSE.md for details. // #include "llvm/Pass.h" #include "revng/Pipeline/AllRegistries.h" #include "revng/Pipeline/Contract.h" #include "revng/Pipes/Kinds.h" #include "revng/Pipes/RootKind.h" #include "revng/Pipes/TaggedFunctionKind.h" class DropRootPass : public llvm::ModulePass { public: static char ID; public: DropRootPass() : ModulePass(ID) {} bool runOnModule(llvm::Module &M) override { using namespace llvm; for (Function &F : FunctionTags::Root.functions(&M)) F.deleteBody(); return true; } void getAnalysisUsage(llvm::AnalysisUsage &AU) const override {} }; char DropRootPass::ID = 0; using Register = llvm::RegisterPass; static Register X("drop-root", "Drop Root Pass", true, true); struct DropRootPipe { static constexpr auto Name = "drop-root"; std::vector getContract() const { using namespace pipeline; using namespace ::revng::pipes; return { ContractGroup::transformOnlyArgument(Root, Exactness::DerivedFrom, Kind::deadKind<&RootRank>(), InputPreservation::Erase) }; } void registerPasses(llvm::legacy::PassManager &Manager) { Manager.add(new DropRootPass()); } };