summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/tools/spectest-interp.cc4
-rw-r--r--src/tools/wasm-validate.cc3
-rw-r--r--src/tools/wasm2wat.cc3
-rw-r--r--src/tools/wast2json.cc7
-rw-r--r--src/tools/wat2wasm.cc7
-rw-r--r--src/validator.cc34
-rw-r--r--src/validator.h23
7 files changed, 60 insertions, 21 deletions
diff --git a/src/tools/spectest-interp.cc b/src/tools/spectest-interp.cc
index a1603198..ab4c7774 100644
--- a/src/tools/spectest-interp.cc
+++ b/src/tools/spectest-interp.cc
@@ -1059,8 +1059,10 @@ wabt::Result CommandRunner::ReadInvalidTextModule(string_view module_filename,
wabt::Module* module = script->GetFirstModule();
result = ResolveNamesModule(lexer.get(), module, error_handler);
if (Succeeded(result)) {
+ ValidateOptions options(s_features);
// Don't do a full validation, just validate the function signatures.
- result = ValidateFuncSignatures(lexer.get(), module, error_handler);
+ result =
+ ValidateFuncSignatures(lexer.get(), module, error_handler, &options);
}
}
return result;
diff --git a/src/tools/wasm-validate.cc b/src/tools/wasm-validate.cc
index 761d3c16..021aa461 100644
--- a/src/tools/wasm-validate.cc
+++ b/src/tools/wasm-validate.cc
@@ -81,7 +81,8 @@ int ProgramMain(int argc, char** argv) {
file_data.size(), &options, &error_handler, &module);
if (Succeeded(result)) {
WastLexer* lexer = nullptr;
- result = ValidateModule(lexer, &module, &error_handler);
+ ValidateOptions options(s_features);
+ result = ValidateModule(lexer, &module, &error_handler, &options);
}
}
return result != Result::Ok;
diff --git a/src/tools/wasm2wat.cc b/src/tools/wasm2wat.cc
index 96fe5240..2358ce7c 100644
--- a/src/tools/wasm2wat.cc
+++ b/src/tools/wasm2wat.cc
@@ -111,7 +111,8 @@ int ProgramMain(int argc, char** argv) {
if (Succeeded(result)) {
if (Succeeded(result) && s_validate) {
WastLexer* lexer = nullptr;
- result = ValidateModule(lexer, &module, &error_handler);
+ ValidateOptions options(s_features);
+ result = ValidateModule(lexer, &module, &error_handler, &options);
}
if (s_generate_names)
diff --git a/src/tools/wast2json.cc b/src/tools/wast2json.cc
index c13221dd..0243775a 100644
--- a/src/tools/wast2json.cc
+++ b/src/tools/wast2json.cc
@@ -107,8 +107,11 @@ int ProgramMain(int argc, char** argv) {
if (Succeeded(result)) {
result = ResolveNamesScript(lexer.get(), script.get(), &error_handler);
- if (Succeeded(result) && s_validate)
- result = ValidateScript(lexer.get(), script.get(), &error_handler);
+ if (Succeeded(result) && s_validate) {
+ ValidateOptions options(s_features);
+ result =
+ ValidateScript(lexer.get(), script.get(), &error_handler, &options);
+ }
if (Succeeded(result)) {
WriteBinarySpecOptions write_binary_spec_options;
diff --git a/src/tools/wat2wasm.cc b/src/tools/wat2wasm.cc
index 90c6ccb5..e852c5b4 100644
--- a/src/tools/wat2wasm.cc
+++ b/src/tools/wat2wasm.cc
@@ -138,8 +138,11 @@ int ProgramMain(int argc, char** argv) {
if (Succeeded(result)) {
result = ResolveNamesModule(lexer.get(), module.get(), &error_handler);
- if (Succeeded(result) && s_validate)
- result = ValidateModule(lexer.get(), module.get(), &error_handler);
+ if (Succeeded(result) && s_validate) {
+ ValidateOptions options(s_features);
+ result =
+ ValidateModule(lexer.get(), module.get(), &error_handler, &options);
+ }
if (Succeeded(result)) {
MemoryStream stream(s_log_stream.get());
diff --git a/src/validator.cc b/src/validator.cc
index 5d6f3bca..46c8c9e9 100644
--- a/src/validator.cc
+++ b/src/validator.cc
@@ -38,7 +38,10 @@ namespace {
class Validator {
public:
WABT_DISALLOW_COPY_AND_ASSIGN(Validator);
- Validator(ErrorHandler*, WastLexer*, const Script*);
+ Validator(ErrorHandler*,
+ WastLexer*,
+ const Script*,
+ const ValidateOptions* options);
Result CheckModule(const Module* module);
Result CheckScript(const Script* script);
@@ -146,6 +149,7 @@ class Validator {
void CheckExcept(const Location* loc, const Exception* Except);
Result CheckExceptVar(const Var* var, const Exception** out_except);
+ const ValidateOptions* options_ = nullptr;
ErrorHandler* error_handler_ = nullptr;
WastLexer* lexer_ = nullptr;
const Script* script_ = nullptr;
@@ -164,8 +168,12 @@ class Validator {
Validator::Validator(ErrorHandler* error_handler,
WastLexer* lexer,
- const Script* script)
- : error_handler_(error_handler), lexer_(lexer), script_(script) {
+ const Script* script,
+ const ValidateOptions* options)
+ : options_(options),
+ error_handler_(error_handler),
+ lexer_(lexer),
+ script_(script) {
typechecker_.set_error_callback(
[this](const char* msg) { OnTypecheckerError(msg); });
}
@@ -865,7 +873,8 @@ void Validator::CheckImport(const Location* loc, const Import* import) {
case ExternalKind::Global: {
auto* global_import = cast<GlobalImport>(import);
- if (global_import->global.mutable_) {
+ if (global_import->global.mutable_ &&
+ !options_->features.threads_enabled()) {
PrintError(loc, "mutable globals cannot be imported");
}
++num_imported_globals_;
@@ -892,7 +901,7 @@ void Validator::CheckExport(const Location* loc, const Export* export_) {
case ExternalKind::Global: {
const Global* global;
if (Succeeded(CheckGlobalVar(&export_->var, &global, nullptr))) {
- if (global->mutable_) {
+ if (global->mutable_ && !options_->features.threads_enabled()) {
PrintError(&export_->var.loc, "mutable globals cannot be exported");
}
}
@@ -1238,24 +1247,27 @@ Result Validator::CheckAllFuncSignatures(const Module* module) {
Result ValidateScript(WastLexer* lexer,
const Script* script,
- ErrorHandler* error_handler) {
- Validator validator(error_handler, lexer, script);
+ ErrorHandler* error_handler,
+ const ValidateOptions* options) {
+ Validator validator(error_handler, lexer, script, options);
return validator.CheckScript(script);
}
Result ValidateModule(WastLexer* lexer,
const Module* module,
- ErrorHandler* error_handler) {
- Validator validator(error_handler, lexer, nullptr);
+ ErrorHandler* error_handler,
+ const ValidateOptions* options) {
+ Validator validator(error_handler, lexer, nullptr, options);
return validator.CheckModule(module);
}
Result ValidateFuncSignatures(WastLexer* lexer,
const Module* module,
- ErrorHandler* error_handler) {
- Validator validator(error_handler, lexer, nullptr);
+ ErrorHandler* error_handler,
+ const ValidateOptions* options) {
+ Validator validator(error_handler, lexer, nullptr, options);
return validator.CheckAllFuncSignatures(module);
}
diff --git a/src/validator.h b/src/validator.h
index aa5c0c20..6250aa94 100644
--- a/src/validator.h
+++ b/src/validator.h
@@ -17,6 +17,7 @@
#ifndef WABT_VALIDATOR_H_
#define WABT_VALIDATOR_H_
+#include "src/feature.h"
#include "src/wast-lexer.h"
namespace wabt {
@@ -25,10 +26,23 @@ struct Module;
struct Script;
class ErrorHandler;
+struct ValidateOptions {
+ ValidateOptions() = default;
+ ValidateOptions(const Features& features) : features(features) {}
+
+ Features features;
+};
+
// Perform all checks on the script. It is valid if and only if this function
// succeeds.
-Result ValidateScript(WastLexer*, const Script*, ErrorHandler*);
-Result ValidateModule(WastLexer*, const Module*, ErrorHandler*);
+Result ValidateScript(WastLexer*,
+ const Script*,
+ ErrorHandler*,
+ const ValidateOptions*);
+Result ValidateModule(WastLexer*,
+ const Module*,
+ ErrorHandler*,
+ const ValidateOptions*);
// Validate that all functions that have an explicit function signature and a
// function type use match.
@@ -37,7 +51,10 @@ Result ValidateModule(WastLexer*, const Module*, ErrorHandler*);
// be malformed text, not a validation error. We can't handle that error in the
// parser because the parser doesn't resolve names to indexes, which is
// required to perform this check.
-Result ValidateFuncSignatures(WastLexer*, const Module*, ErrorHandler*);
+Result ValidateFuncSignatures(WastLexer*,
+ const Module*,
+ ErrorHandler*,
+ const ValidateOptions*);
} // namespace wabt