Skip to content

Commit

Permalink
Add hasArgument helper to pass options. NFC (#5278)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 committed Nov 18, 2022
1 parent b23cedc commit ff32193
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
8 changes: 5 additions & 3 deletions src/pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ struct PassOptions {
bool debugInfo = false;
// Arbitrary string arguments from the commandline, which we forward to
// passes.
std::map<std::string, std::string> arguments;
std::unordered_map<std::string, std::string> arguments;

// Effect info computed for functions. One pass can generate this and then
// other passes later can benefit from it. It is up to the sequence of passes
Expand Down Expand Up @@ -217,15 +217,17 @@ struct PassOptions {
return PassOptions(); // defaults are to not optimize
}

bool hasArgument(std::string key) { return arguments.count(key) > 0; }

std::string getArgument(std::string key, std::string errorTextIfMissing) {
if (arguments.count(key) == 0) {
if (!hasArgument(key)) {
Fatal() << errorTextIfMissing;
}
return arguments[key];
}

std::string getArgumentOrDefault(std::string key, std::string default_) {
if (arguments.count(key) == 0) {
if (!hasArgument(key)) {
return default_;
}
return arguments[key];
Expand Down
12 changes: 5 additions & 7 deletions src/passes/Asyncify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1537,7 +1537,7 @@ struct Asyncify : public Pass {
// canIndirectChangeState is the default. asyncify-ignore-indirect sets it
// to false.
auto canIndirectChangeState =
options.getArgumentOrDefault("asyncify-ignore-indirect", "") == "";
!options.hasArgument("asyncify-ignore-indirect");
std::string removeListInput =
options.getArgumentOrDefault("asyncify-removelist", "");
if (removeListInput.empty()) {
Expand All @@ -1558,12 +1558,10 @@ struct Asyncify : public Pass {
}
String::Split onlyList(
String::trim(read_possible_response_file(onlyListInput)), ",");
auto asserts = options.getArgumentOrDefault("asyncify-asserts", "") != "";
auto verbose = options.getArgumentOrDefault("asyncify-verbose", "") != "";
auto relocatable =
options.getArgumentOrDefault("asyncify-relocatable", "") != "";
auto secondaryMemory =
options.getArgumentOrDefault("asyncify-in-secondary-memory", "") != "";
auto asserts = options.hasArgument("asyncify-asserts");
auto verbose = options.hasArgument("asyncify-verbose");
auto relocatable = options.hasArgument("asyncify-relocatable");
auto secondaryMemory = options.hasArgument("asyncify-in-secondary-memory");

// Ensure there is a memory, as we need it.
if (secondaryMemory) {
Expand Down
3 changes: 1 addition & 2 deletions src/passes/Directize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ struct Directize : public Pass {

// TODO: consider a per-table option here
auto initialContentsImmutable =
getPassOptions().getArgumentOrDefault(
"directize-initial-contents-immutable", "") != "";
getPassOptions().hasArgument("directize-initial-contents-immutable");

// Set up the initial info.
TableInfoMap tables;
Expand Down
8 changes: 2 additions & 6 deletions src/passes/LegalizeJSInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,9 @@ struct LegalizeJSInterface : public Pass {
setTempRet0 = nullptr;
getTempRet0 = nullptr;
auto exportOriginals =
!getPassOptions()
.getArgumentOrDefault("legalize-js-interface-export-originals", "")
.empty();
getPassOptions().hasArgument("legalize-js-interface-export-originals");
exportedHelpers =
!getPassOptions()
.getArgumentOrDefault("legalize-js-interface-exported-helpers", "")
.empty();
getPassOptions().hasArgument("legalize-js-interface-exported-helpers");
// for each illegal export, we must export a legalized stub instead
std::vector<std::unique_ptr<Export>> newExports;
for (auto& ex : module->exports) {
Expand Down

0 comments on commit ff32193

Please sign in to comment.