mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-05-28 15:11:25 +00:00
More options for asc; asm.js output
This commit is contained in:
parent
64516eecfb
commit
bbc71ebe81
23
README.md
23
README.md
@ -29,7 +29,7 @@ Side effects:
|
||||
How does it work?
|
||||
-----------------
|
||||
|
||||
AssemblyScript NEXT compiles a subset (or variant) of TypeScript to Binaryen IR. The resulting module can then be optimized, emitted in text or binary format, or even be converted to asm.js as a polyfill.
|
||||
AssemblyScript NEXT compiles a subset (or variant) of TypeScript to [Binaryen](https://github.com/WebAssembly/binaryen) IR. The resulting module can then be optimized, emitted in text or binary format or converted to [asm.js](http://asmjs.org) as a polyfill.
|
||||
|
||||
Getting started
|
||||
---------------
|
||||
@ -59,3 +59,24 @@ Development status
|
||||
------------------
|
||||
|
||||
For now, see the [compiler tests](https://github.com/AssemblyScript/next/tree/master/tests/compiler) for an overview of what's supposed to be working already.
|
||||
|
||||
Using the CLI
|
||||
-------------
|
||||
|
||||
```
|
||||
Syntax: asc [options] [file ...]
|
||||
|
||||
Examples: asc hello.ts
|
||||
|
||||
Options:
|
||||
-v, --version Prints the compiler's version.
|
||||
-h, --help Prints this message.
|
||||
-O, --optimize Optimizes the module.
|
||||
-c, --validate Validates the module.
|
||||
-o, --outFile Specifies the output file.
|
||||
-b, --binaryFile Specifies the binary format output file.
|
||||
-t, --textFile Specifies the text format output file.
|
||||
-a, --asmjsFile Specifies the asm.js format output file.
|
||||
--noTreeShaking Disables tree-shaking.
|
||||
--noDebug Disables assertions.
|
||||
```
|
||||
|
30
bin/asc.js
30
bin/asc.js
@ -45,10 +45,10 @@ if (args.help || args._.length < 1) {
|
||||
Object.keys(conf).forEach(name => {
|
||||
var option = conf[name];
|
||||
var text = " ";
|
||||
if (option.aliases)
|
||||
if (option.aliases && option.aliases[0].length === 1)
|
||||
text += "-" + option.aliases[0] + ", ";
|
||||
text += "--" + name;
|
||||
while (text.length < 20)
|
||||
while (text.length < 24)
|
||||
text += " ";
|
||||
options.push(text + option.desc);
|
||||
});
|
||||
@ -141,14 +141,32 @@ if (args.optimize)
|
||||
var hasOutput = false;
|
||||
|
||||
if (args.outFile != null) {
|
||||
fs.writeFileSync(args.outFile, module.toBinary());
|
||||
if (/\.wast$/.test(args.outFile) && args.textFile == null)
|
||||
args.textFile = args.outFile;
|
||||
else if (/\.js$/.test(args.outFile) && args.asmjsFile == null)
|
||||
args.asmjsFile = args.outFile;
|
||||
else if (args.binaryFile == null)
|
||||
args.binaryFile = args.outFile;
|
||||
}
|
||||
if (args.binaryFile != null && args.binaryFile.length) {
|
||||
fs.writeFileSync(args.binaryFile, module.toBinary());
|
||||
hasOutput = true;
|
||||
}
|
||||
if (args.textFile != null) {
|
||||
if (args.textFile != null && args.textFile.length) {
|
||||
fs.writeFileSync(args.textFile, module.toText(), { encoding: "utf8" });
|
||||
hasOutput = true;
|
||||
}
|
||||
if (!hasOutput)
|
||||
module.print();
|
||||
if (args.asmjsFile != null && args.asmjsFile.length) {
|
||||
fs.writeFileSync(args.asmjsFile, module.toAsmjs(), { encoding: "utf8" });
|
||||
hasOutput = true;
|
||||
}
|
||||
if (!hasOutput) {
|
||||
if (args.binaryFile === "")
|
||||
process.stdout.write(Buffer.from(module.toBinary()));
|
||||
else if (args.asmjsFile === "")
|
||||
module.printAsmjs();
|
||||
else
|
||||
module.print();
|
||||
}
|
||||
|
||||
module.dispose();
|
||||
|
27
bin/asc.json
27
bin/asc.json
@ -16,22 +16,35 @@
|
||||
},
|
||||
"validate": {
|
||||
"desc": "Validates the module.",
|
||||
"type": "boolean"
|
||||
"type": "boolean",
|
||||
"aliases": [ "c", "check" ]
|
||||
},
|
||||
"outFile": {
|
||||
"desc": "Specifies the output file (binary format).",
|
||||
"type": "string"
|
||||
"desc": "Specifies the output file.",
|
||||
"type": "string",
|
||||
"aliases": [ "o" ]
|
||||
},
|
||||
"binaryFile": {
|
||||
"desc": "Specifies the binary format output file.",
|
||||
"type": "string",
|
||||
"aliases": [ "b" ]
|
||||
},
|
||||
"textFile": {
|
||||
"desc": "Specifies the output file (text format).",
|
||||
"type": "string"
|
||||
"desc": "Specifies the text format output file.",
|
||||
"type": "string",
|
||||
"aliases": [ "t" ]
|
||||
},
|
||||
"asmjsFile": {
|
||||
"desc": "Specifies the asm.js format output file.",
|
||||
"type": "string",
|
||||
"aliases": [ "a" ]
|
||||
},
|
||||
"noTreeShaking": {
|
||||
"desc": "Disables built-in tree-shaking.",
|
||||
"desc": "Disables tree-shaking.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"noDebug": {
|
||||
"desc": "Replaces assertions with nops.",
|
||||
"desc": "Disables assertions.",
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
|
@ -40,3 +40,12 @@ Module.prototype.toText = function toText() {
|
||||
binaryen.print = previousPrint;
|
||||
return ret;
|
||||
}
|
||||
|
||||
Module.prototype.toAsmjs = function toAsmjs() {
|
||||
var previousPrint = binaryen.print;
|
||||
var ret = "";
|
||||
binaryen.print = function print(x) { ret += x + "\n" };
|
||||
this.printAsmjs();
|
||||
binaryen.print = previousPrint;
|
||||
return ret;
|
||||
}
|
||||
|
@ -743,6 +743,10 @@ export class Module {
|
||||
return _BinaryenModulePrint(this.ref);
|
||||
}
|
||||
|
||||
printAsmjs(): void {
|
||||
return _BinaryenModulePrintAsmjs(this.ref);
|
||||
}
|
||||
|
||||
toBinary(bufferSize: usize = 1048576): Uint8Array {
|
||||
// FIXME: target specific / JS glue overrides this
|
||||
throw new Error("not implemented");
|
||||
|
Loading…
x
Reference in New Issue
Block a user