diff options
author | Alon Zakai <azakai@google.com> | 2019-05-01 14:48:41 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-01 14:48:41 -0700 |
commit | 2bd3758a22131cfd6925b3fd995657b211095c90 (patch) | |
tree | 2a38a48ab68c00ed1b55e885f86014bbdda92ff2 /src/tools | |
parent | 73709b4da08d285c2237c8c23a54ba53274c0c7f (diff) | |
download | binaryen-2bd3758a22131cfd6925b3fd995657b211095c90.tar.gz binaryen-2bd3758a22131cfd6925b3fd995657b211095c90.tar.bz2 binaryen-2bd3758a22131cfd6925b3fd995657b211095c90.zip |
clang-tidy braces changes (#2075)
Applies the changes in #2065, and temprarily disables the hook since it's too slow to run on a change this large. We should re-enable it in a later commit.
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/asm2wasm.cpp | 12 | ||||
-rw-r--r-- | src/tools/execution-results.h | 3 | ||||
-rw-r--r-- | src/tools/fuzzing.h | 153 | ||||
-rw-r--r-- | src/tools/js-wrapper.h | 3 | ||||
-rw-r--r-- | src/tools/optimization-options.h | 3 | ||||
-rw-r--r-- | src/tools/spec-wrapper.h | 3 | ||||
-rw-r--r-- | src/tools/wasm-as.cpp | 15 | ||||
-rw-r--r-- | src/tools/wasm-ctor-eval.cpp | 6 | ||||
-rw-r--r-- | src/tools/wasm-dis.cpp | 9 | ||||
-rw-r--r-- | src/tools/wasm-emscripten-finalize.cpp | 6 | ||||
-rw-r--r-- | src/tools/wasm-metadce.cpp | 6 | ||||
-rw-r--r-- | src/tools/wasm-opt.cpp | 18 | ||||
-rw-r--r-- | src/tools/wasm-reduce.cpp | 120 | ||||
-rw-r--r-- | src/tools/wasm-shell.cpp | 12 | ||||
-rw-r--r-- | src/tools/wasm2js.cpp | 15 |
15 files changed, 256 insertions, 128 deletions
diff --git a/src/tools/asm2wasm.cpp b/src/tools/asm2wasm.cpp index 843106ffd..b1196850b 100644 --- a/src/tools/asm2wasm.cpp +++ b/src/tools/asm2wasm.cpp @@ -212,13 +212,15 @@ int main(int argc, const char* argv[]) { : Flags::Release)); char* start = pre.process(input.data()); - if (options.debug) + if (options.debug) { std::cerr << "parsing..." << std::endl; + } cashew::Parser<Ref, DotZeroValueBuilder> builder; Ref asmjs = builder.parseToplevel(start); - if (options.debug) + if (options.debug) { std::cerr << "wasming..." << std::endl; + } Module wasm; // set up memory @@ -294,8 +296,9 @@ int main(int argc, const char* argv[]) { } } - if (options.debug) + if (options.debug) { std::cerr << "emitting..." << std::endl; + } ModuleWriter writer; writer.setDebug(options.debug); writer.setDebugInfo(options.passOptions.debugInfo); @@ -307,6 +310,7 @@ int main(int argc, const char* argv[]) { } writer.write(wasm, options.extra["output"]); - if (options.debug) + if (options.debug) { std::cerr << "done." << std::endl; + } } diff --git a/src/tools/execution-results.h b/src/tools/execution-results.h index 2a42b941b..13771a69d 100644 --- a/src/tools/execution-results.h +++ b/src/tools/execution-results.h @@ -62,8 +62,9 @@ struct ExecutionResults { // execute all exported methods (that are therefore preserved through // opts) for (auto& exp : wasm.exports) { - if (exp->kind != ExternalKind::Function) + if (exp->kind != ExternalKind::Function) { continue; + } std::cout << "[fuzz-exec] calling " << exp->name << "\n"; auto* func = wasm.getFunction(exp->value); if (func->result != none) { diff --git a/src/tools/fuzzing.h b/src/tools/fuzzing.h index f5b548ec6..16b04fe02 100644 --- a/src/tools/fuzzing.h +++ b/src/tools/fuzzing.h @@ -463,8 +463,9 @@ private: } Expression* makeDeNanOp(Expression* expr) { - if (allowNaNs) + if (allowNaNs) { return expr; + } if (expr->type == f32) { return builder.makeCall("deNan32", {expr}, f32); } else if (expr->type == f64) { @@ -566,8 +567,9 @@ private: void recombine(Function* func) { // Don't always do this. - if (oneIn(2)) + if (oneIn(2)) { return; + } // First, scan and group all expressions by type. struct Scanner : public PostWalker<Scanner, UnifiedExpressionVisitor<Scanner>> { @@ -583,8 +585,9 @@ private: // Potentially trim the list of possible picks, so replacements are more // likely to collide. for (auto& pair : scanner.exprsByType) { - if (oneIn(2)) + if (oneIn(2)) { continue; + } auto& list = pair.second; std::vector<Expression*> trimmed; size_t num = upToSquared(list.size()); @@ -630,8 +633,9 @@ private: void mutate(Function* func) { // Don't always do this. - if (oneIn(2)) + if (oneIn(2)) { return; + } struct Modder : public PostWalker<Modder, UnifiedExpressionVisitor<Modder>> { Module& wasm; @@ -688,8 +692,9 @@ private: void visitSwitch(Switch* curr) { for (auto name : curr->targets) { - if (replaceIfInvalid(name)) + if (replaceIfInvalid(name)) { return; + } } replaceIfInvalid(curr->default_); } @@ -708,23 +713,27 @@ private: void replace() { replaceCurrent(parent.makeTrivial(getCurrent()->type)); } bool hasBreakTarget(Name name) { - if (controlFlowStack.empty()) + if (controlFlowStack.empty()) { return false; + } Index i = controlFlowStack.size() - 1; while (1) { auto* curr = controlFlowStack[i]; if (Block* block = curr->template dynCast<Block>()) { - if (name == block->name) + if (name == block->name) { return true; + } } else if (Loop* loop = curr->template dynCast<Loop>()) { - if (name == loop->name) + if (name == loop->name) { return true; + } } else { // an if, ignorable assert(curr->template is<If>()); } - if (i == 0) + if (i == 0) { return false; + } i--; } } @@ -754,8 +763,9 @@ private: invocations.push_back(makeMemoryHashLogging()); } } - if (invocations.empty()) + if (invocations.empty()) { return; + } auto* invoker = new Function; invoker->name = func->name.str + std::string("_invoker"); invoker->result = none; @@ -821,20 +831,27 @@ private: Expression* _makeConcrete(Type type) { auto choice = upTo(100); - if (choice < 10) + if (choice < 10) { return makeConst(type); - if (choice < 30) + } + if (choice < 30) { return makeSetLocal(type); - if (choice < 50) + } + if (choice < 50) { return makeGetLocal(type); - if (choice < 60) + } + if (choice < 60) { return makeBlock(type); - if (choice < 70) + } + if (choice < 70) { return makeIf(type); - if (choice < 80) + } + if (choice < 80) { return makeLoop(type); - if (choice < 90) + } + if (choice < 90) { return makeBreak(type); + } using Self = TranslateToFuzzReader; auto options = FeatureOptions<Expression* (Self::*)(Type)>() .add(FeatureSet::MVP, @@ -869,16 +886,21 @@ private: } } choice = upTo(100); - if (choice < 50) + if (choice < 50) { return makeSetLocal(none); - if (choice < 60) + } + if (choice < 60) { return makeBlock(none); - if (choice < 70) + } + if (choice < 70) { return makeIf(none); - if (choice < 80) + } + if (choice < 80) { return makeLoop(none); - if (choice < 90) + } + if (choice < 90) { return makeBreak(none); + } using Self = TranslateToFuzzReader; auto options = FeatureOptions<Expression* (Self::*)(Type)>() .add(FeatureSet::MVP, @@ -1056,8 +1078,9 @@ private: } Expression* makeBreak(Type type) { - if (breakableStack.empty()) + if (breakableStack.empty()) { return makeTrivial(type); + } Expression* condition = nullptr; if (type != unreachable) { hangStack.push_back(nullptr); @@ -1110,18 +1133,21 @@ private: } switch (conditions) { case 0: { - if (!oneIn(4)) + if (!oneIn(4)) { continue; + } break; } case 1: { - if (!oneIn(2)) + if (!oneIn(2)) { continue; + } break; } default: { - if (oneIn(conditions + 1)) + if (oneIn(conditions + 1)) { continue; + } } } return builder.makeBreak(name); @@ -1142,8 +1168,9 @@ private: if (!wasm.functions.empty() && !oneIn(wasm.functions.size())) { target = vectorPick(wasm.functions).get(); } - if (target->result != type) + if (target->result != type) { continue; + } // we found one! std::vector<Expression*> args; for (auto argType : target->params) { @@ -1157,8 +1184,9 @@ private: Expression* makeCallIndirect(Type type) { auto& data = wasm.table.segments[0].data; - if (data.empty()) + if (data.empty()) { return make(type); + } // look for a call target with the right type Index start = upTo(data.size()); Index i = start; @@ -1170,10 +1198,12 @@ private: break; } i++; - if (i == data.size()) + if (i == data.size()) { i = 0; - if (i == start) + } + if (i == start) { return make(type); + } } // with high probability, make sure the type is valid otherwise, most are // going to trap @@ -1193,8 +1223,9 @@ private: Expression* makeGetLocal(Type type) { auto& locals = typeLocals[type]; - if (locals.empty()) + if (locals.empty()) { return makeConst(type); + } return builder.makeGetLocal(vectorPick(locals), type); } @@ -1207,8 +1238,9 @@ private: valueType = getConcreteType(); } auto& locals = typeLocals[valueType]; - if (locals.empty()) + if (locals.empty()) { return makeTrivial(type); + } auto* value = make(valueType); if (tee) { return builder.makeTeeLocal(vectorPick(locals), value); @@ -1219,8 +1251,9 @@ private: Expression* makeGetGlobal(Type type) { auto& globals = globalsByType[type]; - if (globals.empty()) + if (globals.empty()) { return makeConst(type); + } return builder.makeGetGlobal(vectorPick(globals), type); } @@ -1228,8 +1261,9 @@ private: assert(type == none); type = getConcreteType(); auto& globals = globalsByType[type]; - if (globals.empty()) + if (globals.empty()) { return makeTrivial(none); + } auto* value = make(type); return builder.makeSetGlobal(vectorPick(globals), value); } @@ -1300,13 +1334,16 @@ private: } Expression* makeLoad(Type type) { - if (!allowMemory) + if (!allowMemory) { return makeTrivial(type); + } auto* ret = makeNonAtomicLoad(type); - if (type != i32 && type != i64) + if (type != i32 && type != i64) { return ret; - if (!wasm.features.hasAtomics() || oneIn(2)) + } + if (!wasm.features.hasAtomics() || oneIn(2)) { return ret; + } // make it atomic auto* load = ret->cast<Load>(); wasm.memory.shared = true; @@ -1321,8 +1358,9 @@ private: // make a normal store, then make it unreachable auto* ret = makeNonAtomicStore(getConcreteType()); auto* store = ret->dynCast<Store>(); - if (!store) + if (!store) { return ret; + } switch (upTo(3)) { case 0: store->ptr = make(unreachable); @@ -1395,16 +1433,20 @@ private: } Expression* makeStore(Type type) { - if (!allowMemory) + if (!allowMemory) { return makeTrivial(type); + } auto* ret = makeNonAtomicStore(type); auto* store = ret->dynCast<Store>(); - if (!store) + if (!store) { return ret; - if (store->value->type != i32 && store->value->type != i64) + } + if (store->value->type != i32 && store->value->type != i64) { return store; - if (!wasm.features.hasAtomics() || oneIn(2)) + } + if (!wasm.features.hasAtomics() || oneIn(2)) { return store; + } // make it atomic wasm.memory.shared = true; store->isAtomic = true; @@ -2051,8 +2093,9 @@ private: Expression* makeSwitch(Type type) { assert(type == unreachable); - if (breakableStack.empty()) + if (breakableStack.empty()) { return make(type); + } // we need to find proper targets to break to; try a bunch int tries = TRIES; std::vector<Name> names; @@ -2103,8 +2146,9 @@ private: Expression* makeAtomic(Type type) { assert(wasm.features.hasAtomics()); - if (!allowMemory) + if (!allowMemory) { return makeTrivial(type); + } wasm.memory.shared = true; if (type == i32 && oneIn(2)) { if (ATOMIC_WAITS && oneIn(2)) { @@ -2330,8 +2374,9 @@ private: } Expression* makeBulkMemory(Type type) { - if (!allowMemory) + if (!allowMemory) { return makeTrivial(type); + } assert(wasm.features.hasBulkMemory()); assert(type == none); switch (upTo(4)) { @@ -2348,8 +2393,9 @@ private: } Expression* makeMemoryInit() { - if (!allowMemory) + if (!allowMemory) { return makeTrivial(none); + } uint32_t segment = upTo(wasm.memory.segments.size()); size_t totalSize = wasm.memory.segments[segment].data.size(); size_t offsetVal = upTo(totalSize); @@ -2361,14 +2407,16 @@ private: } Expression* makeDataDrop() { - if (!allowMemory) + if (!allowMemory) { return makeTrivial(none); + } return builder.makeDataDrop(upTo(wasm.memory.segments.size())); } Expression* makeMemoryCopy() { - if (!allowMemory) + if (!allowMemory) { return makeTrivial(none); + } Expression* dest = makePointer(); Expression* source = makePointer(); Expression* size = make(i32); @@ -2376,8 +2424,9 @@ private: } Expression* makeMemoryFill() { - if (!allowMemory) + if (!allowMemory) { return makeTrivial(none); + } Expression* dest = makePointer(); Expression* value = makePointer(); Expression* size = make(i32); @@ -2428,8 +2477,9 @@ private: // this isn't a perfectly uniform distribution, but it's fast // and reasonable Index upTo(Index x) { - if (x == 0) + if (x == 0) { return 0; + } Index raw; if (x <= 255) { raw = get(); @@ -2486,8 +2536,9 @@ private: template<typename T, typename... Args> T pickGivenNum(size_t num, T first, Args... args) { - if (num == 0) + if (num == 0) { return first; + } return pickGivenNum<T>(num - 1, args...); } diff --git a/src/tools/js-wrapper.h b/src/tools/js-wrapper.h index e39a015d6..32b46affa 100644 --- a/src/tools/js-wrapper.h +++ b/src/tools/js-wrapper.h @@ -83,8 +83,9 @@ static std::string generateJSWrapper(Module& wasm) { "});\n"; for (auto& exp : wasm.exports) { auto* func = wasm.getFunctionOrNull(exp->value); - if (!func) + if (!func) { continue; // something exported other than a function + } ret += "if (instance.exports.hangLimitInitializer) " "instance.exports.hangLimitInitializer();\n"; ret += "try {\n"; diff --git a/src/tools/optimization-options.h b/src/tools/optimization-options.h index 6fa9aac36..30f59f04d 100644 --- a/src/tools/optimization-options.h +++ b/src/tools/optimization-options.h @@ -177,8 +177,9 @@ struct OptimizationOptions : public ToolOptions { void runPasses(Module& wasm) { PassRunner passRunner(&wasm, passOptions); - if (debug) + if (debug) { passRunner.setDebug(true); + } for (auto& pass : passes) { if (pass == DEFAULT_OPT_PASSES) { passRunner.addDefaultOptimizationPasses(); diff --git a/src/tools/spec-wrapper.h b/src/tools/spec-wrapper.h index 516ce17a9..d481f0fa8 100644 --- a/src/tools/spec-wrapper.h +++ b/src/tools/spec-wrapper.h @@ -25,8 +25,9 @@ static std::string generateSpecWrapper(Module& wasm) { std::string ret; for (auto& exp : wasm.exports) { auto* func = wasm.getFunctionOrNull(exp->value); - if (!func) + if (!func) { continue; // something exported other than a function + } ret += std::string("(invoke \"hangLimitInitializer\") (invoke \"") + exp->name.str + "\" "; for (Type param : func->params) { diff --git a/src/tools/wasm-as.cpp b/src/tools/wasm-as.cpp index 253a93b3b..d45f10f81 100644 --- a/src/tools/wasm-as.cpp +++ b/src/tools/wasm-as.cpp @@ -105,12 +105,14 @@ int main(int argc, const char* argv[]) { Module wasm; try { - if (options.debug) + if (options.debug) { std::cerr << "s-parsing..." << std::endl; + } SExpressionParser parser(const_cast<char*>(input.c_str())); Element& root = *parser.root; - if (options.debug) + if (options.debug) { std::cerr << "w-parsing..." << std::endl; + } SExpressionWasmBuilder builder(wasm, *root[0]); } catch (ParseException& p) { p.dump(std::cerr); @@ -120,8 +122,9 @@ int main(int argc, const char* argv[]) { options.applyFeatures(wasm); if (options.extra["validate"] != "none") { - if (options.debug) + if (options.debug) { std::cerr << "Validating..." << std::endl; + } if (!wasm::WasmValidator().validate( wasm, WasmValidator::Globally | @@ -131,8 +134,9 @@ int main(int argc, const char* argv[]) { } } - if (options.debug) + if (options.debug) { std::cerr << "writing..." << std::endl; + } ModuleWriter writer; writer.setBinary(true); writer.setDebugInfo(debugInfo); @@ -145,6 +149,7 @@ int main(int argc, const char* argv[]) { } writer.write(wasm, options.extra["output"]); - if (options.debug) + if (options.debug) { std::cerr << "Done." << std::endl; + } } diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp index 2050b3ebc..6a967ece7 100644 --- a/src/tools/wasm-ctor-eval.cpp +++ b/src/tools/wasm-ctor-eval.cpp @@ -441,8 +441,9 @@ int main(int argc, const char* argv[]) { Module wasm; { - if (options.debug) + if (options.debug) { std::cerr << "reading...\n"; + } ModuleReader reader; reader.setDebug(options.debug); @@ -483,8 +484,9 @@ int main(int argc, const char* argv[]) { } if (options.extra.count("output") > 0) { - if (options.debug) + if (options.debug) { std::cerr << "writing..." << std::endl; + } ModuleWriter writer; writer.setDebug(options.debug); writer.setBinary(emitBinary); diff --git a/src/tools/wasm-dis.cpp b/src/tools/wasm-dis.cpp index 5b9cb9804..1dbe97656 100644 --- a/src/tools/wasm-dis.cpp +++ b/src/tools/wasm-dis.cpp @@ -56,8 +56,9 @@ int main(int argc, const char* argv[]) { }); options.parse(argc, argv); - if (options.debug) + if (options.debug) { std::cerr << "parsing binary..." << std::endl; + } Module wasm; try { ModuleReader().readBinary(options.extra["infile"], wasm, sourceMapFilename); @@ -71,14 +72,16 @@ int main(int argc, const char* argv[]) { Fatal() << "error in parsing wasm source mapping"; } - if (options.debug) + if (options.debug) { std::cerr << "Printing..." << std::endl; + } Output output(options.extra["output"], Flags::Text, options.debug ? Flags::Debug : Flags::Release); WasmPrinter::printModule(&wasm, output.getStream()); output << '\n'; - if (options.debug) + if (options.debug) { std::cerr << "Done." << std::endl; + } } diff --git a/src/tools/wasm-emscripten-finalize.cpp b/src/tools/wasm-emscripten-finalize.cpp index a23ba1c5a..e524e4732 100644 --- a/src/tools/wasm-emscripten-finalize.cpp +++ b/src/tools/wasm-emscripten-finalize.cpp @@ -193,12 +193,14 @@ int main(int argc, const char* argv[]) { std::vector<Name> initializerFunctions; if (wasm.table.imported()) { - if (wasm.table.base != "table") + if (wasm.table.base != "table") { wasm.table.base = Name("table"); + } } if (wasm.memory.imported()) { - if (wasm.table.base != "memory") + if (wasm.table.base != "memory") { wasm.memory.base = Name("memory"); + } } wasm.updateMaps(); diff --git a/src/tools/wasm-metadce.cpp b/src/tools/wasm-metadce.cpp index a6f5bb012..c87da8c9a 100644 --- a/src/tools/wasm-metadce.cpp +++ b/src/tools/wasm-metadce.cpp @@ -230,8 +230,9 @@ struct MetaDCEGraph { MetaDCEGraph* parent; void handleGlobal(Name name) { - if (!getFunction()) + if (!getFunction()) { return; // non-function stuff (initializers) are handled separately + } Name dceName; if (!getModule()->getGlobal(name)->imported()) { // its a global @@ -465,8 +466,9 @@ int main(int argc, const char* argv[]) { Module wasm; { - if (options.debug) + if (options.debug) { std::cerr << "reading...\n"; + } ModuleReader reader; reader.setDebug(options.debug); diff --git a/src/tools/wasm-opt.cpp b/src/tools/wasm-opt.cpp index e9f369d22..f7e8b5918 100644 --- a/src/tools/wasm-opt.cpp +++ b/src/tools/wasm-opt.cpp @@ -203,8 +203,9 @@ int main(int argc, const char* argv[]) { Module wasm; - if (options.debug) + if (options.debug) { std::cerr << "reading...\n"; + } if (!translateToFuzz) { ModuleReader reader; @@ -280,9 +281,10 @@ int main(int argc, const char* argv[]) { std::string firstOutput; if (extraFuzzCommand.size() > 0 && options.extra.count("output") > 0) { - if (options.debug) + if (options.debug) { std::cerr << "writing binary before opts, for extra fuzz command..." << std::endl; + } ModuleWriter writer; writer.setDebug(options.debug); writer.setBinary(emitBinary); @@ -316,8 +318,9 @@ int main(int argc, const char* argv[]) { } if (options.runningPasses()) { - if (options.debug) + if (options.debug) { std::cerr << "running passes...\n"; + } auto runPasses = [&]() { options.runPasses(*curr); if (options.passOptions.validate) { @@ -340,13 +343,15 @@ int main(int argc, const char* argv[]) { }; auto lastSize = getSize(); while (1) { - if (options.debug) + if (options.debug) { std::cerr << "running iteration for convergence (" << lastSize << ")...\n"; + } runPasses(); auto currSize = getSize(); - if (currSize >= lastSize) + if (currSize >= lastSize) { break; + } lastSize = currSize; } } @@ -359,8 +364,9 @@ int main(int argc, const char* argv[]) { if (options.extra.count("output") == 0) { std::cerr << "(no output file specified, not emitting output)\n"; } else { - if (options.debug) + if (options.debug) { std::cerr << "writing..." << std::endl; + } ModuleWriter writer; writer.setDebug(options.debug); writer.setBinary(emitBinary); diff --git a/src/tools/wasm-reduce.cpp b/src/tools/wasm-reduce.cpp index 87f64c1ae..54a915ec0 100644 --- a/src/tools/wasm-reduce.cpp +++ b/src/tools/wasm-reduce.cpp @@ -285,10 +285,12 @@ struct Reducer // TODO(tlively): -all should be replaced with an option to use the // existing feature set, once implemented. currCommand += working + " -all -o " + test + " " + pass; - if (debugInfo) + if (debugInfo) { currCommand += " -g "; - if (verbose) + } + if (verbose) { std::cerr << "| trying pass command: " << currCommand << "\n"; + } if (!ProgramResult(currCommand).failed()) { auto newSize = file_size(test); if (newSize < oldSize) { @@ -306,8 +308,9 @@ struct Reducer } } } - if (verbose) + if (verbose) { std::cerr << "| done with passes for now\n"; + } } // does one pass of slow and destructive reduction. returns whether it @@ -400,10 +403,12 @@ struct Reducer } auto* curr = getCurrent(); // std::cerr << "try " << curr << " => " << with << '\n'; - if (curr->type != with->type) + if (curr->type != with->type) { return false; - if (!shouldTryToReduce()) + } + if (!shouldTryToReduce()) { return false; + } replaceCurrent(with); if (!writeAndTestReduction()) { replaceCurrent(curr); @@ -425,10 +430,12 @@ struct Reducer if (!isOkReplacement(with)) { return false; } - if (child->type != with->type) + if (child->type != with->type) { return false; - if (!shouldTryToReduce()) + } + if (!shouldTryToReduce()) { return false; + } auto* before = child; child = with; if (!writeAndTestReduction()) { @@ -443,8 +450,9 @@ struct Reducer } std::string getLocation() { - if (getFunction()) + if (getFunction()) { return getFunction()->name.str; + } return "(non-function context)"; } @@ -455,15 +463,18 @@ struct Reducer void visitExpression(Expression* curr) { // type-based reductions if (curr->type == none) { - if (tryToReduceCurrentToNop()) + if (tryToReduceCurrentToNop()) { return; + } } else if (isConcreteType(curr->type)) { - if (tryToReduceCurrentToConst()) + if (tryToReduceCurrentToConst()) { return; + } } else { assert(curr->type == unreachable); - if (tryToReduceCurrentToUnreachable()) + if (tryToReduceCurrentToUnreachable()) { return; + } } // specific reductions if (auto* iff = curr->dynCast<If>()) { @@ -500,14 +511,16 @@ struct Reducer } } } else if (auto* block = curr->dynCast<Block>()) { - if (!shouldTryToReduce()) + if (!shouldTryToReduce()) { return; + } // replace a singleton auto& list = block->list; if (list.size() == 1 && !BranchUtils::BranchSeeker::hasNamed(block, block->name)) { - if (tryToReplaceCurrent(block->list[0])) + if (tryToReplaceCurrent(block->list[0])) { return; + } } // try to get rid of nops Index i = 0; @@ -544,21 +557,25 @@ struct Reducer // Finally, try to replace with a child. for (auto* child : ChildIterator(curr)) { if (isConcreteType(child->type) && curr->type == none) { - if (tryToReplaceCurrent(builder->makeDrop(child))) + if (tryToReplaceCurrent(builder->makeDrop(child))) { return; + } } else { - if (tryToReplaceCurrent(child)) + if (tryToReplaceCurrent(child)) { return; + } } } // If that didn't work, try to replace with a child + a unary conversion if (isConcreteType(curr->type) && !curr->is<Unary>()) { // but not if it's already unary for (auto* child : ChildIterator(curr)) { - if (child->type == curr->type) + if (child->type == curr->type) { continue; // already tried - if (!isConcreteType(child->type)) + } + if (!isConcreteType(child->type)) { continue; // no conversion + } Expression* fixed = nullptr; switch (curr->type) { case i32: { @@ -652,8 +669,9 @@ struct Reducer WASM_UNREACHABLE(); } assert(fixed->type == curr->type); - if (tryToReplaceCurrent(fixed)) + if (tryToReplaceCurrent(fixed)) { return; + } } } } @@ -684,8 +702,9 @@ struct Reducer first = item; break; } - if (!first.isNull()) + if (!first.isNull()) { break; + } } visitSegmented(curr, first, 100); } @@ -706,12 +725,14 @@ struct Reducer // when we succeed, try to shrink by more and more, similar to bisection size_t skip = 1; for (size_t i = 0; i < data.size() && !data.empty(); i++) { - if (!justShrank && !shouldTryToReduce(bonus)) + if (!justShrank && !shouldTryToReduce(bonus)) { continue; + } auto save = data; for (size_t j = 0; j < skip; j++) { - if (!data.empty()) + if (!data.empty()) { data.pop_back(); + } } auto justShrank = writeAndTestReduction(); if (justShrank) { @@ -727,13 +748,16 @@ struct Reducer } // the "opposite" of shrinking: copy a 'zero' element for (auto& segment : curr->segments) { - if (segment.data.empty()) + if (segment.data.empty()) { continue; + } for (auto& item : segment.data) { - if (!shouldTryToReduce(bonus)) + if (!shouldTryToReduce(bonus)) { continue; - if (item == zero) + } + if (item == zero) { continue; + } auto save = item; item = zero; if (writeAndTestReduction()) { @@ -766,8 +790,9 @@ struct Reducer for (size_t i = 0; i < functionNames.size(); i++) { if (!justRemoved && functionsWeTriedToRemove.count(functionNames[i]) == 1 && - !shouldTryToReduce(std::max((factor / 100) + 1, 1000))) + !shouldTryToReduce(std::max((factor / 100) + 1, 1000))) { continue; + } std::vector<Name> names; for (size_t j = 0; names.size() < skip && i + j < functionNames.size(); j++) { @@ -777,8 +802,9 @@ struct Reducer functionsWeTriedToRemove.insert(name); } } - if (names.size() == 0) + if (names.size() == 0) { continue; + } std::cout << "| try to remove " << names.size() << " functions (skip: " << skip << ")\n"; justRemoved = tryToRemoveFunctions(names); @@ -798,8 +824,9 @@ struct Reducer } skip = 1; for (size_t i = 0; i < exports.size(); i++) { - if (!shouldTryToReduce(std::max((factor / 100) + 1, 1000))) + if (!shouldTryToReduce(std::max((factor / 100) + 1, 1000))) { continue; + } std::vector<Export> currExports; for (size_t j = 0; currExports.size() < skip && i + j < exports.size(); j++) { @@ -891,11 +918,13 @@ struct Reducer break; } } - if (!other.isNull()) + if (!other.isNull()) { break; + } } - if (other.isNull()) + if (other.isNull()) { return; // we failed to find a replacement + } for (auto& segment : curr->segments) { for (auto& name : segment.data) { if (names.count(name)) { @@ -929,10 +958,12 @@ struct Reducer // try to replace condition with always true and always false void handleCondition(Expression*& condition) { - if (!condition) + if (!condition) { return; - if (condition->is<Const>()) + } + if (condition->is<Const>()) { return; + } auto* c = builder->makeConst(Literal(int32_t(0))); if (!tryToReplaceChild(condition, c)) { c->value = Literal(int32_t(1)); @@ -942,8 +973,9 @@ struct Reducer bool tryToReduceCurrentToNop() { auto* curr = getCurrent(); - if (curr->is<Nop>()) + if (curr->is<Nop>()) { return false; + } // try to replace with a trivial value Nop nop; if (tryToReplaceCurrent(&nop)) { @@ -956,12 +988,14 @@ struct Reducer // try to replace a concrete value with a trivial constant bool tryToReduceCurrentToConst() { auto* curr = getCurrent(); - if (curr->is<Const>()) + if (curr->is<Const>()) { return false; + } // try to replace with a trivial value Const* c = builder->makeConst(Literal(int32_t(0))); - if (tryToReplaceCurrent(c)) + if (tryToReplaceCurrent(c)) { return true; + } c->value = Literal::makeFromInt32(1, curr->type); c->type = curr->type; return tryToReplaceCurrent(c); @@ -969,8 +1003,9 @@ struct Reducer bool tryToReduceCurrentToUnreachable() { auto* curr = getCurrent(); - if (curr->is<Unreachable>()) + if (curr->is<Unreachable>()) { return false; + } // try to replace with a trivial value Unreachable un; if (tryToReplaceCurrent(&un)) { @@ -1065,10 +1100,12 @@ int main(int argc, const char* argv[]) { [&](Options* o, const std::string& argument) { input = argument; }); options.parse(argc, argv); - if (test.size() == 0) + if (test.size() == 0) { Fatal() << "test file not provided\n"; - if (working.size() == 0) + } + if (working.size() == 0) { Fatal() << "working file not provided\n"; + } if (!binary) { Colors::disable(); @@ -1124,8 +1161,9 @@ int main(int argc, const char* argv[]) { // feature set, once implemented. auto cmd = Path::getBinaryenBinaryTool("wasm-opt") + " " + input + " -all -o " + test; - if (!binary) + if (!binary) { cmd += " -S"; + } ProgramResult readWrite(cmd); if (readWrite.failed()) { stopIfNotForced("failed to read and write the binary", readWrite); @@ -1166,8 +1204,9 @@ int main(int argc, const char* argv[]) { std::cerr << "| after pass reduction: " << newSize << "\n"; // always stop after a pass reduction attempt, for final cleanup - if (stopping) + if (stopping) { break; + } // check if the full cycle (destructive/passes) has helped or not if (lastPostPassesSize && newSize >= lastPostPassesSize) { @@ -1208,8 +1247,9 @@ int main(int argc, const char* argv[]) { while (1) { std::cerr << "| reduce destructively... (factor: " << factor << ")\n"; lastDestructiveReductions = reducer.reduceDestructively(factor); - if (lastDestructiveReductions > 0) + if (lastDestructiveReductions > 0) { break; + } // we failed to reduce destructively if (factor == 1) { stopping = true; diff --git a/src/tools/wasm-shell.cpp b/src/tools/wasm-shell.cpp index 6141b1a37..652b3a352 100644 --- a/src/tools/wasm-shell.cpp +++ b/src/tools/wasm-shell.cpp @@ -125,8 +125,9 @@ static void run_asserts(Name moduleName, while (*i < root->size()) { Element& curr = *(*root)[*i]; IString id = curr[0]->str(); - if (id == MODULE) + if (id == MODULE) { break; + } *checked = true; Colors::red(std::cerr); std::cerr << *i << '/' << (root->size() - 1); @@ -228,8 +229,9 @@ static void run_asserts(Name moduleName, } } } - if (id == ASSERT_TRAP) + if (id == ASSERT_TRAP) { assert(trapped); + } } *i += 1; } @@ -281,8 +283,9 @@ int main(int argc, const char* argv[]) { bool checked = false; try { - if (options.debug) + if (options.debug) { std::cerr << "parsing text to s-expressions...\n"; + } SExpressionParser parser(input.data()); Element& root = *parser.root; @@ -299,8 +302,9 @@ int main(int argc, const char* argv[]) { } IString id = curr[0]->str(); if (id == MODULE) { - if (options.debug) + if (options.debug) { std::cerr << "parsing s-expressions to wasm...\n"; + } Colors::green(std::cerr); std::cerr << "BUILDING MODULE [line: " << curr.line << "]\n"; Colors::normal(std::cerr); diff --git a/src/tools/wasm2js.cpp b/src/tools/wasm2js.cpp index 6e4656878..823ab7f96 100644 --- a/src/tools/wasm2js.cpp +++ b/src/tools/wasm2js.cpp @@ -694,8 +694,9 @@ int main(int argc, const char* argv[]) { o->extra["infile"] = argument; }); options.parse(argc, argv); - if (options.debug) + if (options.debug) { flags.debug = true; + } Element* root = nullptr; Module wasm; @@ -728,13 +729,15 @@ int main(int argc, const char* argv[]) { Flags::Text, options.debug ? Flags::Debug : Flags::Release)); - if (options.debug) + if (options.debug) { std::cerr << "s-parsing..." << std::endl; + } sexprParser = make_unique<SExpressionParser>(input.data()); root = sexprParser->root; - if (options.debug) + if (options.debug) { std::cerr << "w-parsing..." << std::endl; + } sexprBuilder = make_unique<SExpressionWasmBuilder>(wasm, *(*root)[0]); } } catch (ParseException& p) { @@ -752,8 +755,9 @@ int main(int argc, const char* argv[]) { } } - if (options.debug) + if (options.debug) { std::cerr << "j-printing..." << std::endl; + } Output output(options.extra["output"], Flags::Text, options.debug ? Flags::Debug : Flags::Release); @@ -764,6 +768,7 @@ int main(int argc, const char* argv[]) { emitWasm(wasm, output, flags, options.passOptions, "asmFunc"); } - if (options.debug) + if (options.debug) { std::cerr << "done." << std::endl; + } } |