summaryrefslogtreecommitdiff
path: root/src/tools/wast2json.cc
diff options
context:
space:
mode:
authorBen Smith <binji@chromium.org>2020-02-20 14:06:20 -0800
committerGitHub <noreply@github.com>2020-02-20 14:06:19 -0800
commit94ad3e84817c546b1313e161da565d181b1a470c (patch)
tree77b94ab9dd8a06fbad94e2931e489950eecd2155 /src/tools/wast2json.cc
parent09d712be32398d2ab4174f36228dcac5fbb5f672 (diff)
downloadwabt-94ad3e84817c546b1313e161da565d181b1a470c.tar.gz
wabt-94ad3e84817c546b1313e161da565d181b1a470c.tar.bz2
wabt-94ad3e84817c546b1313e161da565d181b1a470c.zip
Always run ResolveNames after parsing .wast/.wat (#1337)
Resolving names (i.e. remapping variable names to indexes) is meant to be part of the parsing process. The spec even considers an unmapped variable name to be "malformed" text. This PR moves in that direction, by always running ResolveNames after parsing text. The next step would be to integrate this more closely with the parser itself.
Diffstat (limited to 'src/tools/wast2json.cc')
-rw-r--r--src/tools/wast2json.cc40
1 files changed, 18 insertions, 22 deletions
diff --git a/src/tools/wast2json.cc b/src/tools/wast2json.cc
index 1ed8367d..62548084 100644
--- a/src/tools/wast2json.cc
+++ b/src/tools/wast2json.cc
@@ -115,34 +115,30 @@ int ProgramMain(int argc, char** argv) {
WastParseOptions parse_wast_options(s_features);
result = ParseWastScript(lexer.get(), &script, &errors, &parse_wast_options);
- if (Succeeded(result)) {
- result = ResolveNamesScript(script.get(), &errors);
+ if (Succeeded(result) && s_validate) {
+ ValidateOptions options(s_features);
+ result = ValidateScript(script.get(), &errors, options);
+ }
- if (Succeeded(result) && s_validate) {
- ValidateOptions options(s_features);
- result = ValidateScript(script.get(), &errors, options);
+ if (Succeeded(result)) {
+ if (s_outfile.empty()) {
+ s_outfile = DefaultOuputName(s_infile);
}
- if (Succeeded(result)) {
- if (s_outfile.empty()) {
- s_outfile = DefaultOuputName(s_infile);
- }
-
- std::vector<FilenameMemoryStreamPair> module_streams;
- MemoryStream json_stream;
+ std::vector<FilenameMemoryStreamPair> module_streams;
+ MemoryStream json_stream;
- std::string output_basename = StripExtension(s_outfile).to_string();
- s_write_binary_options.features = s_features;
- result = WriteBinarySpecScript(
- &json_stream, script.get(), s_infile, output_basename,
- s_write_binary_options, &module_streams, s_log_stream.get());
+ std::string output_basename = StripExtension(s_outfile).to_string();
+ s_write_binary_options.features = s_features;
+ result = WriteBinarySpecScript(&json_stream, script.get(), s_infile,
+ output_basename, s_write_binary_options,
+ &module_streams, s_log_stream.get());
- json_stream.WriteToFile(s_outfile);
+ json_stream.WriteToFile(s_outfile);
- for (auto iter = module_streams.begin(); iter != module_streams.end();
- ++iter) {
- iter->stream->WriteToFile(iter->filename);
- }
+ for (auto iter = module_streams.begin(); iter != module_streams.end();
+ ++iter) {
+ iter->stream->WriteToFile(iter->filename);
}
}