summaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/s2wasm.cpp23
-rw-r--r--src/tools/wasm-as.cpp31
2 files changed, 40 insertions, 14 deletions
diff --git a/src/tools/s2wasm.cpp b/src/tools/s2wasm.cpp
index 54404c478..2ee094af4 100644
--- a/src/tools/s2wasm.cpp
+++ b/src/tools/s2wasm.cpp
@@ -32,10 +32,10 @@ using namespace wasm;
int main(int argc, const char *argv[]) {
bool ignoreUnknownSymbols = false;
bool generateEmscriptenGlue = false;
- bool validateOutput = true;
std::string startFunction;
std::vector<std::string> archiveLibraries;
Options options("s2wasm", "Link .s file into .wast");
+ options.extra["validate"] = "wasm";
options
.add("--output", "-o", "Output file (stdout if not specified)",
Options::Arguments::One,
@@ -83,10 +83,14 @@ int main(int argc, const char *argv[]) {
[&archiveLibraries](Options *o, const std::string &argument) {
archiveLibraries.push_back(argument);
})
- .add("--no-validate", "", "Disable validation of the output module",
- Options::Arguments::Zero,
- [&validateOutput](Options *, const std::string &) {
- validateOutput = false;
+ .add("--validate", "-v", "Control validation of the output module",
+ Options::Arguments::One,
+ [](Options *o, const std::string &argument) {
+ if (argument != "web" && argument != "none" && argument != "wasm") {
+ std::cerr << "Valid arguments for --validate flag are 'wasm', 'web' and 'none'.\n";
+ exit(1);
+ }
+ o->extra["validate"] = argument;
})
.add_positional("INFILE", Options::Arguments::One,
[](Options *o, const std::string &argument) {
@@ -138,9 +142,12 @@ int main(int argc, const char *argv[]) {
linker.emscriptenGlue(meta);
}
- if (options.debug) std::cerr << "Validating..." << std::endl;
- if (validateOutput && !wasm::WasmValidator().validate(linker.getOutput().wasm)) {
- Fatal() << "Error: linked module is not valid.\n";
+ if (options.extra["validate"] != "none") {
+ if (options.debug) std::cerr << "Validating..." << std::endl;
+ if (!wasm::WasmValidator().validate(linker.getOutput().wasm,
+ options.extra["validate"] == "web")) {
+ Fatal() << "Error: linked module is not valid.\n";
+ }
}
if (options.debug) std::cerr << "Printing..." << std::endl;
diff --git a/src/tools/wasm-as.cpp b/src/tools/wasm-as.cpp
index e5f5af085..e2425b24a 100644
--- a/src/tools/wasm-as.cpp
+++ b/src/tools/wasm-as.cpp
@@ -29,12 +29,23 @@ using namespace wasm;
int main(int argc, const char *argv[]) {
Options options("wasm-as", "Assemble a .wast (WebAssembly text format) into a .wasm (WebAssembly binary format)");
- options.add("--output", "-o", "Output file (stdout if not specified)",
- Options::Arguments::One,
- [](Options *o, const std::string &argument) {
- o->extra["output"] = argument;
- Colors::disable();
- })
+ options.extra["validate"] = "wasm";
+ options
+ .add("--output", "-o", "Output file (stdout if not specified)",
+ Options::Arguments::One,
+ [](Options *o, const std::string &argument) {
+ o->extra["output"] = argument;
+ Colors::disable();
+ })
+ .add("--validate", "-v", "Control validation of the output module",
+ Options::Arguments::One,
+ [](Options *o, const std::string &argument) {
+ if (argument != "web" && argument != "none" && argument != "wasm") {
+ std::cerr << "Valid arguments for --validate flag are 'wasm', 'web', and 'none'.\n";
+ exit(1);
+ }
+ o->extra["validate"] = argument;
+ })
.add_positional("INFILE", Options::Arguments::One,
[](Options *o, const std::string &argument) {
o->extra["infile"] = argument;
@@ -56,6 +67,14 @@ int main(int argc, const char *argv[]) {
Fatal() << "error in parsing input";
}
+ if (options.extra["validate"] != "none") {
+ if (options.debug) std::cerr << "Validating..." << std::endl;
+ if (!wasm::WasmValidator().validate(wasm,
+ options.extra["validate"] == "web")) {
+ Fatal() << "Error: input module is not valid.\n";
+ }
+ }
+
if (options.debug) std::cerr << "binarification..." << std::endl;
BufferWithRandomAccess buffer(options.debug);
WasmBinaryWriter writer(&wasm, buffer, options.debug);