summaryrefslogtreecommitdiff
path: root/src/preprocessing/preprocessing_pass_registry.cpp
diff options
context:
space:
mode:
authorAndres Noetzli <andres.noetzli@gmail.com>2018-10-01 10:06:38 -0700
committerGitHub <noreply@github.com>2018-10-01 10:06:38 -0700
commit48ea68aa581d492c48fe9e08b54e9ce26f3508b9 (patch)
treeda50b320545331f2b3f7b8e3304c9d16b40c6c13 /src/preprocessing/preprocessing_pass_registry.cpp
parent5a19b4d2d2fce73b0d29ff3d40d52c7ef1f4246b (diff)
Refactor preprocessing pass registration (#2468)
This commit refactors how preprocessing pass registration works, inspired by LLVM's approach [0]. The basic idea is that every preprocessing pass declares a static variable of type `RegisterPass` in its source file that registers the pass with the `PreprocessingPassRegistry` when starting the program. The registry is a singleton that keeps track of all the available passes and allows other code to create instances of the passes (note: previously the registry itself was owning the passes but this is no longer the case). One of the advantages of this solution is that we have a list of available passes directly at the beginning of the program, which is useful for example when parsing options. As a side effect, this commit also fixes the SortInference pass, which was expecting arguments other than the preprocessing pass context in its constructor. This commit is required for fixing dumping pre/post preprocessing passes. It is also the ground work for allowing the user to specify a preprocessing pipeline using command-line arguments. [0] https://llvm.org/docs/WritingAnLLVMPass.html
Diffstat (limited to 'src/preprocessing/preprocessing_pass_registry.cpp')
-rw-r--r--src/preprocessing/preprocessing_pass_registry.cpp47
1 files changed, 30 insertions, 17 deletions
diff --git a/src/preprocessing/preprocessing_pass_registry.cpp b/src/preprocessing/preprocessing_pass_registry.cpp
index 03aaec46a..a50cd2541 100644
--- a/src/preprocessing/preprocessing_pass_registry.cpp
+++ b/src/preprocessing/preprocessing_pass_registry.cpp
@@ -11,11 +11,14 @@
**
** \brief The preprocessing pass registry
**
- ** The preprocessing pass registry.
+ ** This file defines the classes PreprocessingPassRegistry, which keeps track
+ ** of the available preprocessing passes, and RegisterPass, which registers a
+ ** preprocessing pass with the registry.
**/
#include "preprocessing/preprocessing_pass_registry.h"
+#include <algorithm>
#include <utility>
#include "base/cvc4_assert.h"
@@ -25,29 +28,39 @@
namespace CVC4 {
namespace preprocessing {
-void PreprocessingPassRegistry::registerPass(
- const std::string& ppName,
- std::unique_ptr<PreprocessingPass> preprocessingPass) {
- Debug("pp-registry") << "Registering pass " << ppName << std::endl;
- Assert(preprocessingPass != nullptr);
- Assert(!this->hasPass(ppName));
- d_stringToPreprocessingPass[ppName] = std::move(preprocessingPass);
+PreprocessingPassRegistry& PreprocessingPassRegistry::getInstance()
+{
+ static PreprocessingPassRegistry* ppReg = new PreprocessingPassRegistry();
+ return *ppReg;
+}
+
+void PreprocessingPassRegistry::registerPassInfo(
+ const std::string& name,
+ std::function<PreprocessingPass*(PreprocessingPassContext*)> ctor)
+{
+ d_ppInfo[name] = ctor;
}
-bool PreprocessingPassRegistry::hasPass(const std::string& ppName) {
- return d_stringToPreprocessingPass.find(ppName) !=
- d_stringToPreprocessingPass.end();
+PreprocessingPass* PreprocessingPassRegistry::createPass(
+ PreprocessingPassContext* ppCtx, const std::string& name)
+{
+ return d_ppInfo[name](ppCtx);
}
-PreprocessingPass* PreprocessingPassRegistry::getPass(
- const std::string& ppName) {
- Assert(this->hasPass(ppName));
- return d_stringToPreprocessingPass[ppName].get();
+std::vector<std::string> PreprocessingPassRegistry::getAvailablePasses()
+{
+ std::vector<std::string> passes;
+ for (const auto& info : d_ppInfo)
+ {
+ passes.push_back(info.first);
+ }
+ std::sort(passes.begin(), passes.end());
+ return passes;
}
-void PreprocessingPassRegistry::unregisterPasses()
+bool PreprocessingPassRegistry::hasPass(const std::string& name)
{
- d_stringToPreprocessingPass.clear();
+ return d_ppInfo.find(name) != d_ppInfo.end();
}
} // namespace preprocessing
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback