diff options
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/spectest-interp.cc | 101 | ||||
-rw-r--r-- | src/tools/wasm-interp.cc | 61 |
2 files changed, 80 insertions, 82 deletions
diff --git a/src/tools/spectest-interp.cc b/src/tools/spectest-interp.cc index e6577cc3..3602940a 100644 --- a/src/tools/spectest-interp.cc +++ b/src/tools/spectest-interp.cc @@ -23,12 +23,12 @@ #include <string> #include <vector> -#include "src/binary-reader-interpreter.h" +#include "src/binary-reader-interp.h" #include "src/binary-reader.h" #include "src/cast.h" #include "src/error-handler.h" #include "src/feature.h" -#include "src/interpreter.h" +#include "src/interp.h" #include "src/literal.h" #include "src/option-parser.h" #include "src/resolve-names.h" @@ -38,7 +38,7 @@ #include "src/wast-parser.h" using namespace wabt; -using namespace wabt::interpreter; +using namespace wabt::interp; static int s_verbose; static const char* s_infile; @@ -767,7 +767,7 @@ class CommandRunner { PrintError(uint32_t line_number, const char* format, ...); wabt::Result RunAction(int line_number, const Action* action, - interpreter::Result* out_iresult, + interp::Result* out_iresult, TypedValues* out_results, RunVerbosity verbose); @@ -803,14 +803,13 @@ class CommandRunner { std::string source_filename_; }; -static interpreter::Result DefaultHostCallback( - const HostFunc* func, - const interpreter::FuncSignature* sig, - Index num_args, - TypedValue* args, - Index num_results, - TypedValue* out_results, - void* user_data) { +static interp::Result DefaultHostCallback(const HostFunc* func, + const interp::FuncSignature* sig, + Index num_args, + TypedValue* args, + Index num_results, + TypedValue* out_results, + void* user_data) { memset(out_results, 0, sizeof(TypedValue) * num_results); for (Index i = 0; i < num_results; ++i) out_results[i].type = sig->result_types[i]; @@ -820,8 +819,8 @@ static interpreter::Result DefaultHostCallback( printf("called host "); WriteCall(s_stdout_stream.get(), func->module_name, func->field_name, - vec_args, vec_results, interpreter::Result::Ok); - return interpreter::Result::Ok; + vec_args, vec_results, interp::Result::Ok); + return interp::Result::Ok; } #define PRIimport "\"%s.%s\"" @@ -829,9 +828,9 @@ static interpreter::Result DefaultHostCallback( class SpectestHostImportDelegate : public HostImportDelegate { public: - wabt::Result ImportFunc(interpreter::FuncImport* import, - interpreter::Func* func, - interpreter::FuncSignature* func_sig, + wabt::Result ImportFunc(interp::FuncImport* import, + interp::Func* func, + interp::FuncSignature* func_sig, const ErrorCallback& callback) override { if (import->field_name == "print") { cast<HostFunc>(func)->callback = DefaultHostCallback; @@ -843,8 +842,8 @@ class SpectestHostImportDelegate : public HostImportDelegate { } } - wabt::Result ImportTable(interpreter::TableImport* import, - interpreter::Table* table, + wabt::Result ImportTable(interp::TableImport* import, + interp::Table* table, const ErrorCallback& callback) override { if (import->field_name == "table") { table->limits.has_max = true; @@ -858,8 +857,8 @@ class SpectestHostImportDelegate : public HostImportDelegate { } } - wabt::Result ImportMemory(interpreter::MemoryImport* import, - interpreter::Memory* memory, + wabt::Result ImportMemory(interp::MemoryImport* import, + interp::Memory* memory, const ErrorCallback& callback) override { if (import->field_name == "memory") { memory->page_limits.has_max = true; @@ -874,8 +873,8 @@ class SpectestHostImportDelegate : public HostImportDelegate { } } - wabt::Result ImportGlobal(interpreter::GlobalImport* import, - interpreter::Global* global, + wabt::Result ImportGlobal(interp::GlobalImport* import, + interp::Global* global, const ErrorCallback& callback) override { if (import->field_name == "global") { switch (global->typed_value.type) { @@ -995,30 +994,30 @@ void CommandRunner::PrintError(uint32_t line_number, const char* format, ...) { printf("%s:%u: %s\n", source_filename_.c_str(), line_number, buffer); } -static interpreter::Result GetGlobalExportByName(Thread* thread, - interpreter::Module* module, - string_view name, - TypedValues* out_results) { - interpreter::Export* export_ = module->GetExport(name); +static interp::Result GetGlobalExportByName(Thread* thread, + interp::Module* module, + string_view name, + TypedValues* out_results) { + interp::Export* export_ = module->GetExport(name); if (!export_) - return interpreter::Result::UnknownExport; + return interp::Result::UnknownExport; if (export_->kind != ExternalKind::Global) - return interpreter::Result::ExportKindMismatch; + return interp::Result::ExportKindMismatch; - interpreter::Global* global = thread->env()->GetGlobal(export_->index); + interp::Global* global = thread->env()->GetGlobal(export_->index); out_results->clear(); out_results->push_back(global->typed_value); - return interpreter::Result::Ok; + return interp::Result::Ok; } wabt::Result CommandRunner::RunAction(int line_number, const Action* action, - interpreter::Result* out_iresult, + interp::Result* out_iresult, TypedValues* out_results, RunVerbosity verbose) { out_results->clear(); - interpreter::Module* module; + interp::Module* module; if (!action->module_name.empty()) { module = env_.FindModule(action->module_name); } else { @@ -1082,8 +1081,8 @@ static wabt::Result ReadModule(const char* module_filename, const bool kStopOnFirstError = true; ReadBinaryOptions options(s_features, s_log_stream.get(), kReadDebugNames, kStopOnFirstError); - result = ReadBinaryInterpreter(env, DataOrNull(file_data), file_data.size(), - &options, error_handler, out_module); + result = ReadBinaryInterp(env, DataOrNull(file_data), file_data.size(), + &options, error_handler, out_module); if (Succeeded(result)) { if (s_verbose) @@ -1132,8 +1131,8 @@ wabt::Result CommandRunner::OnModuleCommand(const ModuleCommand* command) { return wabt::Result::Error; } - interpreter::Result iresult = thread_.RunStartFunction(last_module_); - if (iresult != interpreter::Result::Ok) { + interp::Result iresult = thread_.RunStartFunction(last_module_); + if (iresult != interp::Result::Ok) { env_.ResetToMarkPoint(mark); WriteResult(s_stdout_stream.get(), "error running start function", iresult); return wabt::Result::Error; @@ -1149,13 +1148,13 @@ wabt::Result CommandRunner::OnModuleCommand(const ModuleCommand* command) { wabt::Result CommandRunner::OnActionCommand(const ActionCommand* command) { TypedValues results; - interpreter::Result iresult; + interp::Result iresult; total_++; wabt::Result result = RunAction(command->line, &command->action, &iresult, &results, RunVerbosity::Verbose); if (Succeeded(result)) { - if (iresult == interpreter::Result::Ok) { + if (iresult == interp::Result::Ok) { passed_++; } else { PrintError(command->line, "unexpected trap: %s", ResultToString(iresult)); @@ -1256,8 +1255,8 @@ wabt::Result CommandRunner::OnAssertUninstantiableCommand( ReadModule(command->filename.c_str(), &env_, &error_handler, &module); if (Succeeded(result)) { - interpreter::Result iresult = thread_.RunStartFunction(module); - if (iresult == interpreter::Result::Ok) { + interp::Result iresult = thread_.RunStartFunction(module); + if (iresult == interp::Result::Ok) { PrintError(command->line, "expected error running start function: \"%s\"", command->filename.c_str()); result = wabt::Result::Error; @@ -1296,14 +1295,14 @@ static bool TypedValuesAreEqual(const TypedValue* tv1, const TypedValue* tv2) { wabt::Result CommandRunner::OnAssertReturnCommand( const AssertReturnCommand* command) { TypedValues results; - interpreter::Result iresult; + interp::Result iresult; total_++; wabt::Result result = RunAction(command->line, &command->action, &iresult, &results, RunVerbosity::Quiet); if (Succeeded(result)) { - if (iresult == interpreter::Result::Ok) { + if (iresult == interp::Result::Ok) { if (results.size() == command->expected.size()) { for (size_t i = 0; i < results.size(); ++i) { const TypedValue* expected_tv = &command->expected[i]; @@ -1342,13 +1341,13 @@ wabt::Result CommandRunner::OnAssertReturnNanCommand( const bool is_canonical = command->type == CommandType::AssertReturnCanonicalNan; TypedValues results; - interpreter::Result iresult; + interp::Result iresult; total_++; wabt::Result result = RunAction(command->line, &command->action, &iresult, &results, RunVerbosity::Quiet); if (Succeeded(result)) { - if (iresult == interpreter::Result::Ok) { + if (iresult == interp::Result::Ok) { if (results.size() != 1) { PrintError(command->line, "expected one result, got %" PRIzd, results.size()); @@ -1401,13 +1400,13 @@ wabt::Result CommandRunner::OnAssertReturnNanCommand( wabt::Result CommandRunner::OnAssertTrapCommand( const AssertTrapCommand* command) { TypedValues results; - interpreter::Result iresult; + interp::Result iresult; total_++; wabt::Result result = RunAction(command->line, &command->action, &iresult, &results, RunVerbosity::Quiet); if (Succeeded(result)) { - if (iresult != interpreter::Result::Ok) { + if (iresult != interp::Result::Ok) { passed_++; } else { PrintError(command->line, "expected trap: \"%s\"", command->text.c_str()); @@ -1421,14 +1420,14 @@ wabt::Result CommandRunner::OnAssertTrapCommand( wabt::Result CommandRunner::OnAssertExhaustionCommand( const AssertExhaustionCommand* command) { TypedValues results; - interpreter::Result iresult; + interp::Result iresult; total_++; wabt::Result result = RunAction(command->line, &command->action, &iresult, &results, RunVerbosity::Quiet); if (Succeeded(result)) { - if (iresult == interpreter::Result::TrapCallStackExhausted || - iresult == interpreter::Result::TrapValueStackExhausted) { + if (iresult == interp::Result::TrapCallStackExhausted || + iresult == interp::Result::TrapValueStackExhausted) { passed_++; } else { PrintError(command->line, "expected call stack exhaustion"); diff --git a/src/tools/wasm-interp.cc b/src/tools/wasm-interp.cc index 9bd2cc24..af842853 100644 --- a/src/tools/wasm-interp.cc +++ b/src/tools/wasm-interp.cc @@ -23,12 +23,12 @@ #include <string> #include <vector> -#include "src/binary-reader-interpreter.h" +#include "src/binary-reader-interp.h" #include "src/binary-reader.h" #include "src/cast.h" #include "src/error-handler.h" #include "src/feature.h" -#include "src/interpreter.h" +#include "src/interp.h" #include "src/literal.h" #include "src/option-parser.h" #include "src/resolve-names.h" @@ -38,7 +38,7 @@ #include "src/wast-parser.h" using namespace wabt; -using namespace wabt::interpreter; +using namespace wabt::interp; static int s_verbose; static const char* s_infile; @@ -56,7 +56,7 @@ enum class RunVerbosity { }; static const char s_description[] = -R"( read a file in the wasm binary format, and run in it a stack-based + R"( read a file in the wasm binary format, and run in it a stack-based interpreter. examples: @@ -112,13 +112,13 @@ static void ParseOptions(int argc, char** argv) { parser.Parse(argc, argv); } -static void RunAllExports(interpreter::Module* module, +static void RunAllExports(interp::Module* module, Thread* thread, RunVerbosity verbose) { TypedValues args; TypedValues results; - for (const interpreter::Export& export_ : module->exports) { - interpreter::Result iresult = thread->RunExport(&export_, args, &results); + for (const interp::Export& export_ : module->exports) { + interp::Result iresult = thread->RunExport(&export_, args, &results); if (verbose == RunVerbosity::Verbose) { WriteCall(s_stdout_stream.get(), string_view(), export_.name, args, results, iresult); @@ -141,8 +141,8 @@ static wabt::Result ReadModule(const char* module_filename, const bool kStopOnFirstError = true; ReadBinaryOptions options(s_features, s_log_stream.get(), kReadDebugNames, kStopOnFirstError); - result = ReadBinaryInterpreter(env, DataOrNull(file_data), file_data.size(), - &options, error_handler, out_module); + result = ReadBinaryInterp(env, DataOrNull(file_data), file_data.size(), + &options, error_handler, out_module); if (Succeeded(result)) { if (s_verbose) @@ -153,15 +153,15 @@ static wabt::Result ReadModule(const char* module_filename, } #define PRIimport "\"" PRIstringview "." PRIstringview "\"" -#define PRINTF_IMPORT_ARG(x) \ +#define PRINTF_IMPORT_ARG(x) \ WABT_PRINTF_STRING_VIEW_ARG((x).module_name) \ , WABT_PRINTF_STRING_VIEW_ARG((x).field_name) class WasmInterpHostImportDelegate : public HostImportDelegate { public: - wabt::Result ImportFunc(interpreter::FuncImport* import, - interpreter::Func* func, - interpreter::FuncSignature* func_sig, + wabt::Result ImportFunc(interp::FuncImport* import, + interp::Func* func, + interp::FuncSignature* func_sig, const ErrorCallback& callback) override { if (import->field_name == "print") { cast<HostFunc>(func)->callback = PrintCallback; @@ -173,33 +173,32 @@ class WasmInterpHostImportDelegate : public HostImportDelegate { } } - wabt::Result ImportTable(interpreter::TableImport* import, - interpreter::Table* table, + wabt::Result ImportTable(interp::TableImport* import, + interp::Table* table, const ErrorCallback& callback) override { return wabt::Result::Error; } - wabt::Result ImportMemory(interpreter::MemoryImport* import, - interpreter::Memory* memory, + wabt::Result ImportMemory(interp::MemoryImport* import, + interp::Memory* memory, const ErrorCallback& callback) override { return wabt::Result::Error; } - wabt::Result ImportGlobal(interpreter::GlobalImport* import, - interpreter::Global* global, + wabt::Result ImportGlobal(interp::GlobalImport* import, + interp::Global* global, const ErrorCallback& callback) override { return wabt::Result::Error; } private: - static interpreter::Result PrintCallback( - const HostFunc* func, - const interpreter::FuncSignature* sig, - Index num_args, - TypedValue* args, - Index num_results, - TypedValue* out_results, - void* user_data) { + static interp::Result PrintCallback(const HostFunc* func, + const interp::FuncSignature* sig, + Index num_args, + TypedValue* args, + Index num_results, + TypedValue* out_results, + void* user_data) { memset(out_results, 0, sizeof(TypedValue) * num_results); for (Index i = 0; i < num_results; ++i) out_results[i].type = sig->result_types[i]; @@ -209,8 +208,8 @@ class WasmInterpHostImportDelegate : public HostImportDelegate { printf("called host "); WriteCall(s_stdout_stream.get(), func->module_name, func->field_name, - vec_args, vec_results, interpreter::Result::Ok); - return interpreter::Result::Ok; + vec_args, vec_results, interp::Result::Ok); + return interp::Result::Ok; } void PrintError(const ErrorCallback& callback, const char* format, ...) { @@ -236,8 +235,8 @@ static wabt::Result ReadAndRunModule(const char* module_filename) { result = ReadModule(module_filename, &env, &error_handler, &module); if (Succeeded(result)) { Thread thread(&env, s_thread_options); - interpreter::Result iresult = thread.RunStartFunction(module); - if (iresult == interpreter::Result::Ok) { + interp::Result iresult = thread.RunStartFunction(module); + if (iresult == interp::Result::Ok) { if (s_run_all_exports) RunAllExports(module, &thread, RunVerbosity::Verbose); } else { |