mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
c050dcb621
Before this commit, SerializeModelPass and SerializeModelWrapperPass had hard dependencies on the passes that load the model from LLVM-IR. This commit makes this dependency optional. When the passes for model serialization are executed, if they see that nobody requested to load the model, they will not try to serialize it. This prevents them from crashing when running in pipelines that only contain passes that ignore the model. This is particularly beneficial because `revng opt` automatically adds `-serialize-model` at the end of each pipeline and, before this commit, this meant that `revng opt` could not be used for unit-testing simple llvm passes that do not use the model. With this commit, `revng opt` can be used for unit-tests, even on LLVM IR with missing model.
34 lines
793 B
C++
34 lines
793 B
C++
#pragma once
|
|
|
|
//
|
|
// This file is distributed under the MIT License. See LICENSE.md for details.
|
|
//
|
|
|
|
#include "llvm/Pass.h"
|
|
|
|
#include "revng/Model/Binary.h"
|
|
#include "revng/Model/LoadModelPass.h"
|
|
|
|
void writeModel(model::Binary &Model, llvm::Module &M);
|
|
|
|
class SerializeModelWrapperPass : public llvm::ModulePass {
|
|
public:
|
|
static char ID;
|
|
|
|
public:
|
|
SerializeModelWrapperPass() : llvm::ModulePass(ID) {}
|
|
void getAnalysisUsage(llvm::AnalysisUsage &AU) const override final {
|
|
AU.setPreservesAll();
|
|
AU.addUsedIfAvailable<LoadModelWrapperPass>();
|
|
}
|
|
|
|
public:
|
|
bool runOnModule(llvm::Module &M) override final;
|
|
};
|
|
|
|
class SerializeModelPass : public llvm::PassInfoMixin<SerializeModelPass> {
|
|
public:
|
|
llvm::PreservedAnalyses
|
|
run(llvm::Module &M, llvm::ModuleAnalysisManager &MAM);
|
|
};
|