summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Smith <binjimin@gmail.com>2018-01-07 13:27:03 -0800
committerGitHub <noreply@github.com>2018-01-07 13:27:03 -0800
commit1f735e8f5125f84abba2a91d4f44bc8ee30544a8 (patch)
tree1b4e42e32c9566ed91df9503da4e9b857ff253de
parent2a0b6920d6b41ef7c8190573a5f4a7503c441afd (diff)
downloadwabt-1f735e8f5125f84abba2a91d4f44bc8ee30544a8.tar.gz
wabt-1f735e8f5125f84abba2a91d4f44bc8ee30544a8.tar.bz2
wabt-1f735e8f5125f84abba2a91d4f44bc8ee30544a8.zip
Always write expected action types in .json output (#709)
This is useful to determine what the signature of the action's function was. Without this, it is impossible to tell the difference in function signature between these two functions: (func $f1 (param i32) (result i32) ...) (func $f2 (param i32) ...) Because they have the same parameter list, and the result is discarded: (invoke "f1") (i32.const 1) (invoke "f2") (i32.const 1)
-rw-r--r--src/binary-writer-spec.cc34
-rw-r--r--src/tools/spectest-interp.cc25
2 files changed, 38 insertions, 21 deletions
diff --git a/src/binary-writer-spec.cc b/src/binary-writer-spec.cc
index 334945ba..4efb4394 100644
--- a/src/binary-writer-spec.cc
+++ b/src/binary-writer-spec.cc
@@ -53,13 +53,14 @@ class BinaryWriterSpec {
void WriteConst(const Const& const_);
void WriteConstVector(const ConstVector& consts);
void WriteAction(const Action& action);
- void WriteActionResultType(const Script& script, const Action& action);
+ void WriteActionResultType(const Action& action);
void WriteModule(string_view filename, const Module& module);
void WriteScriptModule(string_view filename,
const ScriptModule& script_module);
void WriteInvalidModule(const ScriptModule& module, string_view text);
- void WriteCommands(const Script& script);
+ void WriteCommands();
+ const Script* script_ = nullptr;
MemoryStream json_stream_;
std::string source_filename_;
std::string module_filename_noext_;
@@ -243,9 +244,8 @@ void BinaryWriterSpec::WriteAction(const Action& action) {
json_stream_.Writef("}");
}
-void BinaryWriterSpec::WriteActionResultType(const Script& script,
- const Action& action) {
- const Module* module = script.GetModule(action.module_var);
+void BinaryWriterSpec::WriteActionResultType(const Action& action) {
+ const Module* module = script_->GetModule(action.module_var);
const Export* export_;
json_stream_.Writef("[");
switch (action.type()) {
@@ -349,13 +349,13 @@ void BinaryWriterSpec::WriteInvalidModule(const ScriptModule& module,
WriteScriptModule(filename, module);
}
-void BinaryWriterSpec::WriteCommands(const Script& script) {
+void BinaryWriterSpec::WriteCommands() {
json_stream_.Writef("{\"source_filename\": ");
WriteEscapedString(source_filename_);
json_stream_.Writef(",\n \"commands\": [\n");
Index last_module_index = kInvalidIndex;
- for (size_t i = 0; i < script.commands.size(); ++i) {
- const Command* command = script.commands[i].get();
+ for (size_t i = 0; i < script_->commands.size(); ++i) {
+ const Command* command = script_->commands[i].get();
if (i != 0) {
WriteSeparator();
@@ -390,6 +390,9 @@ void BinaryWriterSpec::WriteCommands(const Script& script) {
WriteLocation(action.loc);
WriteSeparator();
WriteAction(action);
+ WriteSeparator();
+ WriteKey("expected");
+ WriteActionResultType(action);
break;
}
@@ -466,8 +469,7 @@ void BinaryWriterSpec::WriteCommands(const Script& script) {
WriteAction(*assert_return_canonical_nan_command->action);
WriteSeparator();
WriteKey("expected");
- WriteActionResultType(script,
- *assert_return_canonical_nan_command->action);
+ WriteActionResultType(*assert_return_canonical_nan_command->action);
break;
}
@@ -479,8 +481,7 @@ void BinaryWriterSpec::WriteCommands(const Script& script) {
WriteAction(*assert_return_arithmetic_nan_command->action);
WriteSeparator();
WriteKey("expected");
- WriteActionResultType(script,
- *assert_return_arithmetic_nan_command->action);
+ WriteActionResultType(*assert_return_arithmetic_nan_command->action);
break;
}
@@ -492,6 +493,9 @@ void BinaryWriterSpec::WriteCommands(const Script& script) {
WriteSeparator();
WriteKey("text");
WriteEscapedString(assert_trap_command->text);
+ WriteSeparator();
+ WriteKey("expected");
+ WriteActionResultType(*assert_trap_command->action);
break;
}
@@ -501,6 +505,9 @@ void BinaryWriterSpec::WriteCommands(const Script& script) {
WriteLocation(assert_exhaustion_command->action->loc);
WriteSeparator();
WriteAction(*assert_exhaustion_command->action);
+ WriteSeparator();
+ WriteKey("expected");
+ WriteActionResultType(*assert_exhaustion_command->action);
break;
}
}
@@ -511,7 +518,8 @@ void BinaryWriterSpec::WriteCommands(const Script& script) {
}
Result BinaryWriterSpec::WriteScript(const Script& script) {
- WriteCommands(script);
+ script_ = &script;
+ WriteCommands();
if (spec_options_->json_filename) {
json_stream_.WriteToFile(spec_options_->json_filename);
}
diff --git a/src/tools/spectest-interp.cc b/src/tools/spectest-interp.cc
index c98220e1..17426767 100644
--- a/src/tools/spectest-interp.cc
+++ b/src/tools/spectest-interp.cc
@@ -222,6 +222,7 @@ class JSONParser {
wabt::Result ParseConst(TypedValue* out_value);
wabt::Result ParseConstVector(TypedValues* out_values);
wabt::Result ParseAction(Action* out_action);
+ wabt::Result ParseActionResult();
wabt::Result ParseModuleType(ModuleType* out_type);
std::string CreateModulePath(string_view filename);
@@ -553,6 +554,14 @@ wabt::Result JSONParser::ParseAction(Action* out_action) {
return wabt::Result::Ok;
}
+wabt::Result JSONParser::ParseActionResult() {
+ // Not needed for wabt-interp, but useful for other parsers.
+ EXPECT_KEY("expected");
+ TypeVector expected;
+ CHECK_RESULT(ParseTypeVector(&expected));
+ return wabt::Result::Ok;
+}
+
wabt::Result JSONParser::ParseModuleType(ModuleType* out_type) {
std::string module_type_str;
@@ -628,6 +637,8 @@ wabt::Result JSONParser::ParseCommand(CommandPtr* out_command) {
CHECK_RESULT(ParseLine(&command->line));
EXPECT(",");
CHECK_RESULT(ParseAction(&command->action));
+ EXPECT(",");
+ CHECK_RESULT(ParseActionResult());
*out_command = std::move(command);
} else if (Match("\"register\"")) {
auto command = MakeUnique<RegisterCommand>();
@@ -698,10 +709,7 @@ wabt::Result JSONParser::ParseCommand(CommandPtr* out_command) {
EXPECT(",");
CHECK_RESULT(ParseAction(&command->action));
EXPECT(",");
- // Not needed for wabt-interp, but useful for other parsers.
- EXPECT_KEY("expected");
- TypeVector expected;
- CHECK_RESULT(ParseTypeVector(&expected));
+ CHECK_RESULT(ParseActionResult());
*out_command = std::move(command);
} else if (Match("\"assert_return_arithmetic_nan\"")) {
auto command = MakeUnique<AssertReturnArithmeticNanCommand>();
@@ -710,10 +718,7 @@ wabt::Result JSONParser::ParseCommand(CommandPtr* out_command) {
EXPECT(",");
CHECK_RESULT(ParseAction(&command->action));
EXPECT(",");
- // Not needed for wabt-interp, but useful for other parsers.
- EXPECT_KEY("expected");
- TypeVector expected;
- CHECK_RESULT(ParseTypeVector(&expected));
+ CHECK_RESULT(ParseActionResult());
*out_command = std::move(command);
} else if (Match("\"assert_trap\"")) {
auto command = MakeUnique<AssertTrapCommand>();
@@ -723,6 +728,8 @@ wabt::Result JSONParser::ParseCommand(CommandPtr* out_command) {
CHECK_RESULT(ParseAction(&command->action));
EXPECT(",");
PARSE_KEY_STRING_VALUE("text", &command->text);
+ EXPECT(",");
+ CHECK_RESULT(ParseActionResult());
*out_command = std::move(command);
} else if (Match("\"assert_exhaustion\"")) {
auto command = MakeUnique<AssertExhaustionCommand>();
@@ -730,6 +737,8 @@ wabt::Result JSONParser::ParseCommand(CommandPtr* out_command) {
CHECK_RESULT(ParseLine(&command->line));
EXPECT(",");
CHECK_RESULT(ParseAction(&command->action));
+ EXPECT(",");
+ CHECK_RESULT(ParseActionResult());
*out_command = std::move(command);
} else {
PrintError("unknown command type");