summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2020-08-17 17:09:45 -0700
committerGitHub <noreply@github.com>2020-08-17 17:09:45 -0700
commitf5a8bfd25c83dc05d48cbc525c5e8ec2deb246b3 (patch)
treeb60ba1ba7c528ed081ab2f9c0cb107e44683947e /src
parent8139c9d99d4639a2173e51828a6e7bbae397fc2c (diff)
downloadbinaryen-f5a8bfd25c83dc05d48cbc525c5e8ec2deb246b3.tar.gz
binaryen-f5a8bfd25c83dc05d48cbc525c5e8ec2deb246b3.tar.bz2
binaryen-f5a8bfd25c83dc05d48cbc525c5e8ec2deb246b3.zip
Make wasm-emscripten-finalize's output optional (#3055)
This helps towards the goal of allowing emscripten to not always modify the wasm during link. Until now wasm-emscripten-finalize always wrote an output, while with this PR it only does so if it was asked to, either by giving it an output filename, or asking for text output. The only noticeable change from this should be to make what was an error before (not specify an output or ask for text) into a non-error (run and print metadata, but do not write the wasm).
Diffstat (limited to 'src')
-rw-r--r--src/tools/wasm-emscripten-finalize.cpp40
1 files changed, 22 insertions, 18 deletions
diff --git a/src/tools/wasm-emscripten-finalize.cpp b/src/tools/wasm-emscripten-finalize.cpp
index 7bb8ed310..ce1da4c9e 100644
--- a/src/tools/wasm-emscripten-finalize.cpp
+++ b/src/tools/wasm-emscripten-finalize.cpp
@@ -80,7 +80,8 @@ int main(int argc, const char* argv[]) {
[&DWARF](Options*, const std::string&) { DWARF = true; })
.add("--emit-text",
"-S",
- "Emit text instead of binary for the output file",
+ "Emit text instead of binary for the output file. "
+ "In this mode if no output file is specified, we write to stdout.",
Options::Arguments::Zero,
[&emitBinary](Options*, const std::string&) { emitBinary = false; })
.add("--global-base",
@@ -172,9 +173,6 @@ int main(int argc, const char* argv[]) {
if (infile == "") {
Fatal() << "Need to specify an infile\n";
}
- if (outfile == "" && emitBinary) {
- Fatal() << "Need to specify an outfile, or use text output\n";
- }
Module wasm;
ModuleReader reader;
@@ -335,23 +333,29 @@ int main(int argc, const char* argv[]) {
BYN_DEBUG_WITH_TYPE("emscripten-dump",
WasmPrinter::printModule(&wasm, std::cerr));
- Output output(outfile, emitBinary ? Flags::Binary : Flags::Text);
- ModuleWriter writer;
- writer.setDebugInfo(debugInfo);
- // writer.setSymbolMap(symbolMap);
- writer.setBinary(emitBinary);
- if (outputSourceMapFilename.size()) {
- writer.setSourceMapFilename(outputSourceMapFilename);
- writer.setSourceMapUrl(outputSourceMapUrl);
+ // Write the modified wasm if the user asked us to, either by specifying an
+ // output file, or requesting text output (which goes to stdout by default).
+ if (outfile.size() > 0 || !emitBinary) {
+ Output output(outfile, emitBinary ? Flags::Binary : Flags::Text);
+ ModuleWriter writer;
+ writer.setDebugInfo(debugInfo);
+ // writer.setSymbolMap(symbolMap);
+ writer.setBinary(emitBinary);
+ if (outputSourceMapFilename.size()) {
+ writer.setSourceMapFilename(outputSourceMapFilename);
+ writer.setSourceMapUrl(outputSourceMapUrl);
+ }
+ writer.write(wasm, output);
+ if (!emitBinary) {
+ output << "(;\n";
+ output << "--BEGIN METADATA --\n" << metadata << "-- END METADATA --\n";
+ output << ";)\n";
+ }
}
- writer.write(wasm, output);
+ // If we emit text then we emitted the metadata together with that text
+ // earlier. Otherwise emit it to stdout.
if (emitBinary) {
std::cout << metadata;
- } else {
- output << "(;\n";
- output << "--BEGIN METADATA --\n" << metadata << "-- END METADATA --\n";
- output << ";)\n";
}
-
return 0;
}