Skip to content
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

Emit text format before emitting JS #1372

Merged
merged 1 commit into from
Jul 2, 2020
Merged
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
43 changes: 21 additions & 22 deletions cli/asc.js
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,11 @@ exports.main = function main(argv, options, callback) {
// Prepare output
if (!args.noEmit) {
let hasStdout = false;
let hasOutput = false;
let hasOutput = args.textFile != null
|| args.binaryFile != null
|| args.jsFile != null
|| args.tsdFile != null
|| args.idlFile != null;

if (args.outFile != null) {
if (/\.was?t$/.test(args.outFile) && args.textFile == null) {
Expand Down Expand Up @@ -752,7 +756,6 @@ exports.main = function main(argv, options, callback) {
writeStdout(wasm.output);
hasStdout = true;
}
hasOutput = true;

// Post-process source map
if (wasm.sourceMap != null) {
Expand All @@ -776,24 +779,22 @@ exports.main = function main(argv, options, callback) {
}
}

// Write JS
if (args.jsFile != null) {
let js;
if (args.jsFile.length) {
// Write text (also fallback)
if (args.textFile != null || !hasOutput) {
let wat;
if (args.textFile != null && args.textFile.length) {
stats.emitCount++;
stats.emitTime += measure(() => {
js = module.toAsmjs();
wat = module.toText();
});
writeFile(args.jsFile, js, baseDir);
writeFile(args.textFile, wat, baseDir);
} else if (!hasStdout) {
stats.emitCount++;
stats.emitTime += measure(() => {
js = module.toAsmjs();
wat = module.toText();
});
writeStdout(js);
hasStdout = true;
writeStdout(wat);
}
hasOutput = true;
}

// Write WebIDL
Expand All @@ -813,7 +814,6 @@ exports.main = function main(argv, options, callback) {
writeStdout(idl);
hasStdout = true;
}
hasOutput = true;
}

// Write TypeScript definition
Expand All @@ -833,24 +833,23 @@ exports.main = function main(argv, options, callback) {
writeStdout(tsd);
hasStdout = true;
}
hasOutput = true;
}

// Write text (must be last)
if (args.textFile != null || !hasOutput) {
let wat;
if (args.textFile && args.textFile.length) {
// Write JS (modifies the binary, so must be last)
if (args.jsFile != null) {
let js;
if (args.jsFile.length) {
stats.emitCount++;
stats.emitTime += measure(() => {
wat = module.toText();
js = module.toAsmjs();
});
writeFile(args.textFile, wat, baseDir);
writeFile(args.jsFile, js, baseDir);
} else if (!hasStdout) {
stats.emitCount++;
stats.emitTime += measure(() => {
wat = module.toText();
js = module.toAsmjs();
});
writeStdout(wat);
writeStdout(js);
}
}
}
Expand Down