Skip to content

Commit ff32193

Browse files
authored
Add hasArgument helper to pass options. NFC (#5278)
1 parent b23cedc commit ff32193

File tree

4 files changed

+13
-18
lines changed

4 files changed

+13
-18
lines changed

src/pass.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ struct PassOptions {
188188
bool debugInfo = false;
189189
// Arbitrary string arguments from the commandline, which we forward to
190190
// passes.
191-
std::map<std::string, std::string> arguments;
191+
std::unordered_map<std::string, std::string> arguments;
192192

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

220+
bool hasArgument(std::string key) { return arguments.count(key) > 0; }
221+
220222
std::string getArgument(std::string key, std::string errorTextIfMissing) {
221-
if (arguments.count(key) == 0) {
223+
if (!hasArgument(key)) {
222224
Fatal() << errorTextIfMissing;
223225
}
224226
return arguments[key];
225227
}
226228

227229
std::string getArgumentOrDefault(std::string key, std::string default_) {
228-
if (arguments.count(key) == 0) {
230+
if (!hasArgument(key)) {
229231
return default_;
230232
}
231233
return arguments[key];

src/passes/Asyncify.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,7 @@ struct Asyncify : public Pass {
15371537
// canIndirectChangeState is the default. asyncify-ignore-indirect sets it
15381538
// to false.
15391539
auto canIndirectChangeState =
1540-
options.getArgumentOrDefault("asyncify-ignore-indirect", "") == "";
1540+
!options.hasArgument("asyncify-ignore-indirect");
15411541
std::string removeListInput =
15421542
options.getArgumentOrDefault("asyncify-removelist", "");
15431543
if (removeListInput.empty()) {
@@ -1558,12 +1558,10 @@ struct Asyncify : public Pass {
15581558
}
15591559
String::Split onlyList(
15601560
String::trim(read_possible_response_file(onlyListInput)), ",");
1561-
auto asserts = options.getArgumentOrDefault("asyncify-asserts", "") != "";
1562-
auto verbose = options.getArgumentOrDefault("asyncify-verbose", "") != "";
1563-
auto relocatable =
1564-
options.getArgumentOrDefault("asyncify-relocatable", "") != "";
1565-
auto secondaryMemory =
1566-
options.getArgumentOrDefault("asyncify-in-secondary-memory", "") != "";
1561+
auto asserts = options.hasArgument("asyncify-asserts");
1562+
auto verbose = options.hasArgument("asyncify-verbose");
1563+
auto relocatable = options.hasArgument("asyncify-relocatable");
1564+
auto secondaryMemory = options.hasArgument("asyncify-in-secondary-memory");
15671565

15681566
// Ensure there is a memory, as we need it.
15691567
if (secondaryMemory) {

src/passes/Directize.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,7 @@ struct Directize : public Pass {
208208

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

214213
// Set up the initial info.
215214
TableInfoMap tables;

src/passes/LegalizeJSInterface.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,9 @@ struct LegalizeJSInterface : public Pass {
6262
setTempRet0 = nullptr;
6363
getTempRet0 = nullptr;
6464
auto exportOriginals =
65-
!getPassOptions()
66-
.getArgumentOrDefault("legalize-js-interface-export-originals", "")
67-
.empty();
65+
getPassOptions().hasArgument("legalize-js-interface-export-originals");
6866
exportedHelpers =
69-
!getPassOptions()
70-
.getArgumentOrDefault("legalize-js-interface-exported-helpers", "")
71-
.empty();
67+
getPassOptions().hasArgument("legalize-js-interface-exported-helpers");
7268
// for each illegal export, we must export a legalized stub instead
7369
std::vector<std::unique_ptr<Export>> newExports;
7470
for (auto& ex : module->exports) {

0 commit comments

Comments
 (0)