Skip to content

Support .wast extention for --textFile #1545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions cli/asc.js
Original file line number Diff line number Diff line change
Expand Up @@ -856,19 +856,22 @@ exports.main = function main(argv, options, callback) {

// Write text (also fallback)
if (opts.textFile != null || !hasOutput) {
let wat;
let out;
if (opts.textFile != null && opts.textFile.length) {
// use superset text format when extension is `.wast`.
// Otherwise use official stack IR format (wat).
let watFormat = !opts.textFile.endsWith('.wast');
stats.emitCount++;
stats.emitTime += measure(() => {
wat = module.toText();
out = module.toText(watFormat);
});
writeFile(opts.textFile, wat, baseDir);
writeFile(opts.textFile, out, baseDir);
} else if (!hasStdout) {
stats.emitCount++;
stats.emitTime += measure(() => {
wat = module.toText();
out = module.toText();
});
writeStdout(wat);
writeStdout(out);
}
}

Expand Down
16 changes: 10 additions & 6 deletions src/glue/binaryen.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ module.exports = binaryen;

const { Module } = require("../module");

Module.prototype.toText = function toText() {
// NOTE: Conversion to StackIR can yield conversion artifacts like sequences
// of unreachable statements not actually emitted by the compiler. Optimizing
// StackIR removes these again, but may also suppress useless code emitted by
// the compiler that's then no longer visible in tests. Both not ideal.
return binaryen.wrapModule(this.ref).emitStackIR(/* optimize-stack-ir */ true);
Module.prototype.toText = function toText(watFormat = true) {
if (watFormat) {
// NOTE: Conversion to StackIR can yield conversion artifacts like sequences
// of unreachable statements not actually emitted by the compiler. Optimizing
// StackIR removes these again, but may also suppress useless code emitted by
// the compiler that's then no longer visible in tests. Both not ideal.
return binaryen.wrapModule(this.ref).emitStackIR(/* optimize-stack-ir */ true);
} else {
return binaryen.wrapModule(this.ref).emitText();
}
};

Module.prototype.toAsmjs = function toAsmjs() {
Expand Down
2 changes: 1 addition & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1705,7 +1705,7 @@ export class Module {
return binary;
}

toText(): string {
toText(watFormat: bool = true): string {
throw new Error("not implemented"); // JS glue overrides this
}

Expand Down