diff options
Diffstat (limited to 'src/tools/execution-results.h')
-rw-r--r-- | src/tools/execution-results.h | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/src/tools/execution-results.h b/src/tools/execution-results.h index 920bb200a..d9fefc44e 100644 --- a/src/tools/execution-results.h +++ b/src/tools/execution-results.h @@ -27,6 +27,7 @@ using Loggings = std::vector<Literal>; // Logs every relevant import call parameter. struct LoggingExternalInterface : public ShellExternalInterface { +private: Loggings& loggings; struct State { @@ -37,30 +38,40 @@ struct LoggingExternalInterface : public ShellExternalInterface { uint32_t tempRet0 = 0; } state; +public: LoggingExternalInterface(Loggings& loggings) : loggings(loggings) {} Literals callImport(Function* import, const Literals& arguments) override { if (import->module == "fuzzing-support") { - std::cout << "[LoggingExternalInterface logging"; - loggings.push_back(Literal()); // buffer with a None between calls - for (auto argument : arguments) { - if (argument.type == Type::i64) { - // To avoid JS legalization changing logging results, treat a logging - // of an i64 as two i32s (which is what legalization would turn us - // into). - auto low = Literal(int32_t(argument.getInteger())); - auto high = Literal(int32_t(argument.getInteger() >> int32_t(32))); - std::cout << ' ' << low; - loggings.push_back(low); - std::cout << ' ' << high; - loggings.push_back(high); - } else { - std::cout << ' ' << argument; - loggings.push_back(argument); + if (import->base.startsWith("log")) { + // This is a logging function like log-i32 or log-f64 + std::cout << "[LoggingExternalInterface logging"; + loggings.push_back(Literal()); // buffer with a None between calls + for (auto argument : arguments) { + if (argument.type == Type::i64) { + // To avoid JS legalization changing logging results, treat a + // logging of an i64 as two i32s (which is what legalization would + // turn us into). + auto low = Literal(int32_t(argument.getInteger())); + auto high = Literal(int32_t(argument.getInteger() >> int32_t(32))); + std::cout << ' ' << low; + loggings.push_back(low); + std::cout << ' ' << high; + loggings.push_back(high); + } else { + std::cout << ' ' << argument; + loggings.push_back(argument); + } } + std::cout << "]\n"; + return {}; + } else if (import->base == "throw") { + // Throw something. We use a (hopefully) private name here. + auto payload = std::make_shared<ExnData>("__private", Literals{}); + throwException(WasmException{Literal(payload)}); + } else { + WASM_UNREACHABLE("unknown fuzzer import"); } - std::cout << "]\n"; - return {}; } else if (import->module == ENV) { if (import->base == "log_execution") { std::cout << "[LoggingExternalInterface log-execution"; |