Minor improvements to help asc -h

This commit is contained in:
dcodeIO 2018-01-18 06:55:30 +01:00
parent fc40ed80f7
commit 27a66c1a7a
4 changed files with 54 additions and 43 deletions

View File

@ -164,18 +164,18 @@ else if (args.trapMode !== "allow") {
process.exit(1); process.exit(1);
} }
var optimizeLevel = 0; var defaultOptimizeLevel = 2;
var defaultShrinkLevel = 1;
var optimizeLevel = -1;
var shrinkLevel = 0; var shrinkLevel = 0;
var debugInfo = !args.noDebug; var debugInfo = !args.noDebug;
var runPasses = []; var runPasses = [];
if (args["O"]) { if (args.optimize !== false) {
if (typeof args["O"] === "number") if (typeof args.optimize === "number")
optimizeLevel = args["O"]; optimizeLevel = args.optimize;
else if (args["O"] === true) { else if (args["0"])
optimizeLevel = 2;
shrinkLevel = 1;
} else if (args["0"])
optimizeLevel = 0; optimizeLevel = 0;
else if (args["1"]) else if (args["1"])
optimizeLevel = 1; optimizeLevel = 1;
@ -183,8 +183,11 @@ if (args["O"]) {
optimizeLevel = 2; optimizeLevel = 2;
else if (args["3"]) else if (args["3"])
optimizeLevel = 3; optimizeLevel = 3;
else else if (args.optimize === true) {
optimizeLevel = 2; optimizeLevel = defaultOptimizeLevel;
shrinkLevel = defaultShrinkLevel;
} else
optimizeLevel = 0;
} }
if (args["s"]) if (args["s"])
shrinkLevel = 1; shrinkLevel = 1;
@ -198,8 +201,8 @@ if (typeof args.shrinkLevel === "number")
shrinkLevel = args.shrinkLevel; shrinkLevel = args.shrinkLevel;
// Workaround for inlining not being performed (42.0.0) // Workaround for inlining not being performed (42.0.0)
if ((optimizeLevel >= 2 || shrinkLevel >= 2) && !debugInfo) // if ((optimizeLevel >= 2 || shrinkLevel >= 2) && !debugInfo)
runPasses = [ "inlining", "inlining-optimizing" ]; // runPasses = [ "inlining", "inlining-optimizing" ];
// Check additional passes // Check additional passes
if (args.runPasses) { if (args.runPasses) {
@ -216,7 +219,7 @@ module.setOptimizeLevel(optimizeLevel);
module.setShrinkLevel(shrinkLevel); module.setShrinkLevel(shrinkLevel);
module.setDebugInfo(debugInfo); module.setDebugInfo(debugInfo);
if (optimizeLevel || shrinkLevel) if (optimizeLevel >= 0)
module.optimize(); module.optimize();
if (runPasses.length) if (runPasses.length)
module.runPasses(runPasses.map(pass => pass.trim())); module.runPasses(runPasses.map(pass => pass.trim()));

View File

@ -12,23 +12,25 @@
"optimize": { "optimize": {
"desc": [ "desc": [
"Optimizes the module. Also accepts the optimize level:", "Optimizes the module. Also accepts the optimize level:",
" -O Equivalent to -O2s", "",
" -O0 Runs no optimization passes", " -O Defaults: Equivalent to -O2s",
" -O1 Runs fast optimization passes", " -O0 Equivalent to --optimizeLevel 0",
" -O2 Runs default optimization passes", " -O1 Equivalent to --optimizeLevel 1",
" -O3 Runs all optimization passes", " -O2 Equivalent to --optimizeLevel 2",
" -O2s Specifies optimize level 2 with shrink level 1", " -O2 Equivalent to --optimizeLevel 3",
" -O3z etc." " -Oz Equivalent to -O but with --shrinkLevel 2",
" -O3s Equivalent to -O3 with --shrinkLevel 1 etc.",
""
], ],
"type": "number", "type": "boolean",
"aliases": [ "O" ] "aliases": [ "O" ]
}, },
"optimizeLevel": { "optimizeLevel": {
"desc": "How much to focus on optimizing code.", "desc": "How much to focus on optimizing code. [0-3]",
"type": "number" "type": "number"
}, },
"shrinkLevel": { "shrinkLevel": {
"desc": "How much to focus on shrinking code size.", "desc": "How much to focus on shrinking code size. [0-2]",
"type": "number" "type": "number"
}, },
"validate": { "validate": {
@ -42,17 +44,17 @@
"aliases": [ "o" ] "aliases": [ "o" ]
}, },
"binaryFile": { "binaryFile": {
"desc": "Specifies the binary format output file (.wasm).", "desc": "Specifies the binary output file (.wasm).",
"type": "string", "type": "string",
"aliases": [ "b" ] "aliases": [ "b" ]
}, },
"textFile": { "textFile": {
"desc": "Specifies the text format output file (.wast).", "desc": "Specifies the text output file (.wast).",
"type": "string", "type": "string",
"aliases": [ "t" ] "aliases": [ "t" ]
}, },
"asmjsFile": { "asmjsFile": {
"desc": "Specifies the asm.js format output file (.js).", "desc": "Specifies the asm.js output file (.js).",
"type": "string", "type": "string",
"aliases": [ "a" ] "aliases": [ "a" ]
}, },
@ -79,9 +81,11 @@
"trapMode": { "trapMode": {
"desc": [ "desc": [
"Sets the trap mode to use.", "Sets the trap mode to use.",
"",
" allow Allow trapping operations. This is the default.", " allow Allow trapping operations. This is the default.",
" clamp Replace trapping operations with clamping semantics.", " clamp Replace trapping operations with clamping semantics.",
" js Replace trapping operations with JS semantics." " js Replace trapping operations with JS semantics.",
""
], ],
"type": "string", "type": "string",
"default": "allow" "default": "allow"

View File

@ -88,12 +88,12 @@ class BlockHeader {
} }
/** Tags this block as 'free'. Careful: Does not update adjacent blocks. */ /** Tags this block as 'free'. Careful: Does not update adjacent blocks. */
tagFree(): void { tagAsFree(): void {
this.tagged_size |= BlockHeader.FREE_BIT; this.tagged_size |= BlockHeader.FREE_BIT;
} }
/** Tags this block as 'used'. Careful: Does not update adjacent blocks. */ /** Tags this block as 'used'. Careful: Does not update adjacent blocks. */
tagUsed(): void { tagAsUsed(): void {
this.tagged_size &= ~BlockHeader.FREE_BIT; this.tagged_size &= ~BlockHeader.FREE_BIT;
} }
@ -103,12 +103,12 @@ class BlockHeader {
} }
/** Tags this block as 'prev is free'. Does not update adjacent blocks. */ /** Tags this block as 'prev is free'. Does not update adjacent blocks. */
tagPrevFree(): void { tagAsPrevFree(): void {
this.tagged_size |= BlockHeader.PREV_FREE_BIT; this.tagged_size |= BlockHeader.PREV_FREE_BIT;
} }
/** Tags this block as 'prev is used'. Does not update adjacent blocks. */ /** Tags this block as 'prev is used'. Does not update adjacent blocks. */
tagPrevUsed(): void { tagAsPrevUsed(): void {
this.tagged_size &= ~BlockHeader.PREV_FREE_BIT; this.tagged_size &= ~BlockHeader.PREV_FREE_BIT;
} }
@ -158,15 +158,15 @@ class BlockHeader {
/** Marks this block as being 'free'. */ /** Marks this block as being 'free'. */
markAsFree(): void { markAsFree(): void {
var next = this.linkNext(); // Link the block to the next block, first. var next = this.linkNext(); // Link the block to the next block, first.
next.tagPrevFree(); next.tagAsPrevFree();
this.tagFree(); this.tagAsFree();
} }
/** Marks this block as being 'used'. */ /** Marks this block as being 'used'. */
markAsUsed(): void { markAsUsed(): void {
var next = this.next; var next = this.next;
next.tagPrevUsed(); next.tagAsPrevUsed();
this.tagUsed(); this.tagAsUsed();
} }
/** Tests if this block can be splitted. */ /** Tests if this block can be splitted. */
@ -377,7 +377,7 @@ class Control extends BlockHeader { // Empty lists point here, indicating free
if (block.canSplit(size)) { if (block.canSplit(size)) {
var remaining_block = block.split(size); var remaining_block = block.split(size);
block.linkNext(); block.linkNext();
remaining_block.tagPrevFree(); remaining_block.tagAsPrevFree();
this.insertBlock(remaining_block); this.insertBlock(remaining_block);
} }
} }
@ -393,7 +393,7 @@ class Control extends BlockHeader { // Empty lists point here, indicating free
if (block.canSplit(size)) { if (block.canSplit(size)) {
// If the next block is free, we must coalesce. // If the next block is free, we must coalesce.
var remaining_block = block.split(size); var remaining_block = block.split(size);
remaining_block.tagPrevUsed(); remaining_block.tagAsPrevUsed();
remaining_block = this.mergeNextBlock(remaining_block); remaining_block = this.mergeNextBlock(remaining_block);
this.insertBlock(remaining_block); this.insertBlock(remaining_block);
} }
@ -403,7 +403,7 @@ class Control extends BlockHeader { // Empty lists point here, indicating free
var remaining_block = block; var remaining_block = block;
if (block.canSplit(size)) { if (block.canSplit(size)) {
remaining_block = block.split(size - BlockHeader.OVERHEAD); remaining_block = block.split(size - BlockHeader.OVERHEAD);
remaining_block.tagPrevFree(); remaining_block.tagAsPrevFree();
block.linkNext(); block.linkNext();
this.insertBlock(block); this.insertBlock(block);
} }
@ -481,15 +481,15 @@ class Control extends BlockHeader { // Empty lists point here, indicating free
// it will never be used. // it will never be used.
var block = BlockHeader.fromOffset(mem, -BlockHeader.OVERHEAD); var block = BlockHeader.fromOffset(mem, -BlockHeader.OVERHEAD);
block.size = pool_bytes; block.size = pool_bytes;
block.tagFree(); block.tagAsFree();
block.tagPrevUsed(); block.tagAsPrevUsed();
this.insertBlock(block); this.insertBlock(block);
// Split the block to create a zero-size sentinel block. // Split the block to create a zero-size sentinel block.
var next = block.linkNext(); var next = block.linkNext();
next.size = 0; next.size = 0;
next.tagUsed(); next.tagAsUsed();
next.tagPrevFree(); next.tagAsPrevFree();
} }
} }

View File

@ -98,7 +98,11 @@ class Control {
/** Tests whether the collector is currently paused. */ /** Tests whether the collector is currently paused. */
get paused(): bool { return (this.state & Control.PAUSED_BIT) != 0; } get paused(): bool { return (this.state & Control.PAUSED_BIT) != 0; }
/** Sets whether the collector is currently paused. */ /** Sets whether the collector is currently paused. */
set paused(paused: bool) { this.state = paused ? this.state |= Control.PAUSED_BIT : this.state &= ~Control.PAUSED_BIT; } set paused(paused: bool) {
this.state = paused
? this.state |= Control.PAUSED_BIT
: this.state &= ~Control.PAUSED_BIT;
}
///////////////////////////////// Methods /////////////////////////////////// ///////////////////////////////// Methods ///////////////////////////////////