diff options
Diffstat (limited to 'src/passes/pass.cpp')
-rw-r--r-- | src/passes/pass.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp index b226d6ec9..ec6077941 100644 --- a/src/passes/pass.cpp +++ b/src/passes/pass.cpp @@ -73,6 +73,10 @@ std::vector<std::string> PassRegistry::getRegisteredNames() { return ret; } +bool PassRegistry::containsPass(const std::string& name) { + return passInfos.count(name) > 0; +} + std::string PassRegistry::getPassDescription(std::string name) { assert(passInfos.find(name) != passInfos.end()); return passInfos[name].description; @@ -715,6 +719,15 @@ void PassRunner::addDefaultGlobalOptimizationPrePasses() { // which can lead to more opportunities for global effects to matter. } +void PassRunner::add(std::string passName, std::optional<std::string> passArg) { + auto pass = PassRegistry::get()->createPass(passName); + if (passArg) { + pass->setPassArg(*passArg); + } + + doAdd(std::move(pass)); +} + void PassRunner::addDefaultGlobalOptimizationPostPasses() { if (options.optimizeLevel >= 2 || options.shrinkLevel >= 1) { addIfNoDWARFIssues("dae-optimizing"); @@ -1025,4 +1038,29 @@ bool PassRunner::shouldPreserveDWARF() { return true; } +bool Pass::hasArgument(const std::string& key) { + // An argument with the name of the pass is stored on the instance. Other + // arguments are in the global storage. + return key == name ? passArg.has_value() : getPassOptions().hasArgument(key); +} + +std::string Pass::getArgument(const std::string& key, + const std::string& errorTextIfMissing) { + if (!hasArgument(key)) { + Fatal() << errorTextIfMissing; + } + + return (key == name) ? *passArg + : getPassOptions().getArgument(key, errorTextIfMissing); +} + +std::string Pass::getArgumentOrDefault(const std::string& key, + const std::string& defaultValue) { + if (key == name) { + return passArg.value_or(defaultValue); + } + + return getPassOptions().getArgumentOrDefault(key, defaultValue); +} + } // namespace wasm |