summaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/wasm-as.cpp29
-rw-r--r--src/tools/wasm-dis.cpp16
-rw-r--r--src/tools/wasm-opt.cpp18
3 files changed, 30 insertions, 33 deletions
diff --git a/src/tools/wasm-as.cpp b/src/tools/wasm-as.cpp
index b01bae0e3..46885dec0 100644
--- a/src/tools/wasm-as.cpp
+++ b/src/tools/wasm-as.cpp
@@ -21,8 +21,9 @@
#include "support/colors.h"
#include "support/command-line.h"
#include "support/file.h"
-#include "wasm-binary.h"
+#include "wasm-io.h"
#include "wasm-s-parser.h"
+#include "wasm-validator.h"
#include "tool-utils.h"
@@ -99,26 +100,18 @@ int main(int argc, const char *argv[]) {
}
}
- if (options.debug) std::cerr << "binarification..." << std::endl;
- BufferWithRandomAccess buffer(options.debug);
- WasmBinaryWriter writer(&wasm, buffer, options.debug);
- // if debug info is used, then we want to emit the names section
- writer.setNamesSection(debugInfo);
- std::unique_ptr<std::ofstream> sourceMapStream = nullptr;
+ if (options.debug) std::cerr << "writing..." << std::endl;
+ ModuleWriter writer;
+ writer.setBinary(true);
+ writer.setDebugInfo(debugInfo);
if (sourceMapFilename.size()) {
- sourceMapStream = make_unique<std::ofstream>();
- sourceMapStream->open(sourceMapFilename);
- writer.setSourceMap(sourceMapStream.get(), sourceMapUrl);
+ writer.setSourceMapFilename(sourceMapFilename);
+ writer.setSourceMapUrl(sourceMapUrl);
}
- if (symbolMap.size() > 0) writer.setSymbolMap(symbolMap);
- writer.write();
-
- if (options.debug) std::cerr << "writing to output..." << std::endl;
- Output output(options.extra["output"], Flags::Binary, options.debug ? Flags::Debug : Flags::Release);
- buffer.writeTo(output);
- if (sourceMapStream) {
- sourceMapStream->close();
+ if (symbolMap.size() > 0) {
+ writer.setSymbolMap(symbolMap);
}
+ writer.write(wasm, options.extra["output"]);
if (options.debug) std::cerr << "Done." << std::endl;
}
diff --git a/src/tools/wasm-dis.cpp b/src/tools/wasm-dis.cpp
index da1a56b6b..3ff6819a5 100644
--- a/src/tools/wasm-dis.cpp
+++ b/src/tools/wasm-dis.cpp
@@ -21,7 +21,7 @@
#include "support/colors.h"
#include "support/command-line.h"
#include "support/file.h"
-#include "wasm-binary.h"
+#include "wasm-io.h"
#include "wasm-printing.h"
using namespace cashew;
@@ -45,22 +45,10 @@ int main(int argc, const char *argv[]) {
});
options.parse(argc, argv);
- auto input(read_file<std::vector<char>>(options.extra["infile"], Flags::Binary, options.debug ? Flags::Debug : Flags::Release));
-
if (options.debug) std::cerr << "parsing binary..." << std::endl;
Module wasm;
try {
- std::unique_ptr<std::ifstream> sourceMapStream;
- WasmBinaryBuilder parser(wasm, input, options.debug);
- if (sourceMapFilename.size()) {
- sourceMapStream = make_unique<std::ifstream>();
- sourceMapStream->open(sourceMapFilename);
- parser.setDebugLocations(sourceMapStream.get());
- }
- parser.read();
- if (sourceMapStream) {
- sourceMapStream->close();
- }
+ ModuleReader().readBinary(options.extra["infile"], wasm, sourceMapFilename);
} catch (ParseException& p) {
p.dump(std::cerr);
std::cerr << '\n';
diff --git a/src/tools/wasm-opt.cpp b/src/tools/wasm-opt.cpp
index 7d7d44b2b..43496b34e 100644
--- a/src/tools/wasm-opt.cpp
+++ b/src/tools/wasm-opt.cpp
@@ -72,6 +72,9 @@ int main(int argc, const char* argv[]) {
bool fuzzPasses = false;
std::string emitJSWrapper;
std::string emitSpecWrapper;
+ std::string inputSourceMapFilename;
+ std::string outputSourceMapFilename;
+ std::string outputSourceMapUrl;
OptimizationOptions options("wasm-opt", "Read, write, and optimize files");
options
@@ -111,6 +114,15 @@ int main(int argc, const char* argv[]) {
.add("--emit-spec-wrapper", "-esw", "Emit a wasm spec interpreter wrapper file that can run the wasm with some test values, useful for fuzzing",
Options::Arguments::One,
[&](Options *o, const std::string& arguments) { emitSpecWrapper = arguments; })
+ .add("--input-source-map", "-ism", "Consume source map from the specified file",
+ Options::Arguments::One,
+ [&inputSourceMapFilename](Options *o, const std::string& argument) { inputSourceMapFilename = argument; })
+ .add("--output-source-map", "-osm", "Emit source map to the specified file",
+ Options::Arguments::One,
+ [&outputSourceMapFilename](Options *o, const std::string& argument) { outputSourceMapFilename = argument; })
+ .add("--output-source-map-url", "-osu", "Emit specified string as source map URL",
+ Options::Arguments::One,
+ [&outputSourceMapUrl](Options *o, const std::string& argument) { outputSourceMapUrl = argument; })
.add_positional("INFILE", Options::Arguments::One,
[](Options* o, const std::string& argument) {
o->extra["infile"] = argument;
@@ -128,7 +140,7 @@ int main(int argc, const char* argv[]) {
ModuleReader reader;
reader.setDebug(options.debug);
try {
- reader.read(options.extra["infile"], wasm);
+ reader.read(options.extra["infile"], wasm, inputSourceMapFilename);
} catch (ParseException& p) {
p.dump(std::cerr);
std::cerr << '\n';
@@ -256,6 +268,10 @@ int main(int argc, const char* argv[]) {
writer.setDebug(options.debug);
writer.setBinary(emitBinary);
writer.setDebugInfo(debugInfo);
+ if (outputSourceMapFilename.size()) {
+ writer.setSourceMapFilename(outputSourceMapFilename);
+ writer.setSourceMapUrl(outputSourceMapUrl);
+ }
writer.write(*curr, options.extra["output"]);
if (extraFuzzCommand.size() > 0) {