Skip to content

Commit 0544b87

Browse files
authored
feat: Support .wast extension in --textFile (#1545)
1 parent 34dd7a0 commit 0544b87

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

cli/asc.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -856,19 +856,22 @@ exports.main = function main(argv, options, callback) {
856856

857857
// Write text (also fallback)
858858
if (opts.textFile != null || !hasOutput) {
859-
let wat;
859+
let out;
860860
if (opts.textFile != null && opts.textFile.length) {
861+
// use superset text format when extension is `.wast`.
862+
// Otherwise use official stack IR format (wat).
863+
let watFormat = !opts.textFile.endsWith('.wast');
861864
stats.emitCount++;
862865
stats.emitTime += measure(() => {
863-
wat = module.toText();
866+
out = module.toText(watFormat);
864867
});
865-
writeFile(opts.textFile, wat, baseDir);
868+
writeFile(opts.textFile, out, baseDir);
866869
} else if (!hasStdout) {
867870
stats.emitCount++;
868871
stats.emitTime += measure(() => {
869-
wat = module.toText();
872+
out = module.toText();
870873
});
871-
writeStdout(wat);
874+
writeStdout(out);
872875
}
873876
}
874877

src/glue/binaryen.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ module.exports = binaryen;
99

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

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

2024
Module.prototype.toAsmjs = function toAsmjs() {

src/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1716,7 +1716,7 @@ export class Module {
17161716
return binary;
17171717
}
17181718

1719-
toText(): string {
1719+
toText(watFormat: bool = true): string {
17201720
throw new Error("not implemented"); // JS glue overrides this
17211721
}
17221722

0 commit comments

Comments
 (0)