From 27a66c1a7a6b2d378f488ef17633e4ad59a21bd3 Mon Sep 17 00:00:00 2001 From: dcodeIO Date: Thu, 18 Jan 2018 06:55:30 +0100 Subject: [PATCH] Minor improvements to help asc -h --- bin/asc.js | 29 ++++++++++++++++------------- bin/asc.json | 32 ++++++++++++++++++-------------- examples/tlsf/assembly/tlsf.ts | 30 +++++++++++++++--------------- examples/ugc/assembly/ugc.ts | 6 +++++- 4 files changed, 54 insertions(+), 43 deletions(-) diff --git a/bin/asc.js b/bin/asc.js index 6ab7a97c..36fb353d 100644 --- a/bin/asc.js +++ b/bin/asc.js @@ -164,18 +164,18 @@ else if (args.trapMode !== "allow") { process.exit(1); } -var optimizeLevel = 0; +var defaultOptimizeLevel = 2; +var defaultShrinkLevel = 1; + +var optimizeLevel = -1; var shrinkLevel = 0; var debugInfo = !args.noDebug; var runPasses = []; -if (args["O"]) { - if (typeof args["O"] === "number") - optimizeLevel = args["O"]; - else if (args["O"] === true) { - optimizeLevel = 2; - shrinkLevel = 1; - } else if (args["0"]) +if (args.optimize !== false) { + if (typeof args.optimize === "number") + optimizeLevel = args.optimize; + else if (args["0"]) optimizeLevel = 0; else if (args["1"]) optimizeLevel = 1; @@ -183,8 +183,11 @@ if (args["O"]) { optimizeLevel = 2; else if (args["3"]) optimizeLevel = 3; - else - optimizeLevel = 2; + else if (args.optimize === true) { + optimizeLevel = defaultOptimizeLevel; + shrinkLevel = defaultShrinkLevel; + } else + optimizeLevel = 0; } if (args["s"]) shrinkLevel = 1; @@ -198,8 +201,8 @@ if (typeof args.shrinkLevel === "number") shrinkLevel = args.shrinkLevel; // Workaround for inlining not being performed (42.0.0) -if ((optimizeLevel >= 2 || shrinkLevel >= 2) && !debugInfo) - runPasses = [ "inlining", "inlining-optimizing" ]; +// if ((optimizeLevel >= 2 || shrinkLevel >= 2) && !debugInfo) +// runPasses = [ "inlining", "inlining-optimizing" ]; // Check additional passes if (args.runPasses) { @@ -216,7 +219,7 @@ module.setOptimizeLevel(optimizeLevel); module.setShrinkLevel(shrinkLevel); module.setDebugInfo(debugInfo); -if (optimizeLevel || shrinkLevel) +if (optimizeLevel >= 0) module.optimize(); if (runPasses.length) module.runPasses(runPasses.map(pass => pass.trim())); diff --git a/bin/asc.json b/bin/asc.json index 236c1f5c..f79a2fe6 100644 --- a/bin/asc.json +++ b/bin/asc.json @@ -12,23 +12,25 @@ "optimize": { "desc": [ "Optimizes the module. Also accepts the optimize level:", - " -O Equivalent to -O2s", - " -O0 Runs no optimization passes", - " -O1 Runs fast optimization passes", - " -O2 Runs default optimization passes", - " -O3 Runs all optimization passes", - " -O2s Specifies optimize level 2 with shrink level 1", - " -O3z etc." + "", + " -O Defaults: Equivalent to -O2s", + " -O0 Equivalent to --optimizeLevel 0", + " -O1 Equivalent to --optimizeLevel 1", + " -O2 Equivalent to --optimizeLevel 2", + " -O2 Equivalent to --optimizeLevel 3", + " -Oz Equivalent to -O but with --shrinkLevel 2", + " -O3s Equivalent to -O3 with --shrinkLevel 1 etc.", + "" ], - "type": "number", + "type": "boolean", "aliases": [ "O" ] }, "optimizeLevel": { - "desc": "How much to focus on optimizing code.", + "desc": "How much to focus on optimizing code. [0-3]", "type": "number" }, "shrinkLevel": { - "desc": "How much to focus on shrinking code size.", + "desc": "How much to focus on shrinking code size. [0-2]", "type": "number" }, "validate": { @@ -42,17 +44,17 @@ "aliases": [ "o" ] }, "binaryFile": { - "desc": "Specifies the binary format output file (.wasm).", + "desc": "Specifies the binary output file (.wasm).", "type": "string", "aliases": [ "b" ] }, "textFile": { - "desc": "Specifies the text format output file (.wast).", + "desc": "Specifies the text output file (.wast).", "type": "string", "aliases": [ "t" ] }, "asmjsFile": { - "desc": "Specifies the asm.js format output file (.js).", + "desc": "Specifies the asm.js output file (.js).", "type": "string", "aliases": [ "a" ] }, @@ -79,9 +81,11 @@ "trapMode": { "desc": [ "Sets the trap mode to use.", + "", " allow Allow trapping operations. This is the default.", " clamp Replace trapping operations with clamping semantics.", - " js Replace trapping operations with JS semantics." + " js Replace trapping operations with JS semantics.", + "" ], "type": "string", "default": "allow" diff --git a/examples/tlsf/assembly/tlsf.ts b/examples/tlsf/assembly/tlsf.ts index 16b2a412..ef1672cb 100644 --- a/examples/tlsf/assembly/tlsf.ts +++ b/examples/tlsf/assembly/tlsf.ts @@ -88,12 +88,12 @@ class BlockHeader { } /** Tags this block as 'free'. Careful: Does not update adjacent blocks. */ - tagFree(): void { + tagAsFree(): void { this.tagged_size |= BlockHeader.FREE_BIT; } /** Tags this block as 'used'. Careful: Does not update adjacent blocks. */ - tagUsed(): void { + tagAsUsed(): void { this.tagged_size &= ~BlockHeader.FREE_BIT; } @@ -103,12 +103,12 @@ class BlockHeader { } /** Tags this block as 'prev is free'. Does not update adjacent blocks. */ - tagPrevFree(): void { + tagAsPrevFree(): void { this.tagged_size |= BlockHeader.PREV_FREE_BIT; } /** Tags this block as 'prev is used'. Does not update adjacent blocks. */ - tagPrevUsed(): void { + tagAsPrevUsed(): void { this.tagged_size &= ~BlockHeader.PREV_FREE_BIT; } @@ -158,15 +158,15 @@ class BlockHeader { /** Marks this block as being 'free'. */ markAsFree(): void { var next = this.linkNext(); // Link the block to the next block, first. - next.tagPrevFree(); - this.tagFree(); + next.tagAsPrevFree(); + this.tagAsFree(); } /** Marks this block as being 'used'. */ markAsUsed(): void { var next = this.next; - next.tagPrevUsed(); - this.tagUsed(); + next.tagAsPrevUsed(); + this.tagAsUsed(); } /** 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)) { var remaining_block = block.split(size); block.linkNext(); - remaining_block.tagPrevFree(); + remaining_block.tagAsPrevFree(); this.insertBlock(remaining_block); } } @@ -393,7 +393,7 @@ class Control extends BlockHeader { // Empty lists point here, indicating free if (block.canSplit(size)) { // If the next block is free, we must coalesce. var remaining_block = block.split(size); - remaining_block.tagPrevUsed(); + remaining_block.tagAsPrevUsed(); remaining_block = this.mergeNextBlock(remaining_block); this.insertBlock(remaining_block); } @@ -403,7 +403,7 @@ class Control extends BlockHeader { // Empty lists point here, indicating free var remaining_block = block; if (block.canSplit(size)) { remaining_block = block.split(size - BlockHeader.OVERHEAD); - remaining_block.tagPrevFree(); + remaining_block.tagAsPrevFree(); block.linkNext(); this.insertBlock(block); } @@ -481,15 +481,15 @@ class Control extends BlockHeader { // Empty lists point here, indicating free // it will never be used. var block = BlockHeader.fromOffset(mem, -BlockHeader.OVERHEAD); block.size = pool_bytes; - block.tagFree(); - block.tagPrevUsed(); + block.tagAsFree(); + block.tagAsPrevUsed(); this.insertBlock(block); // Split the block to create a zero-size sentinel block. var next = block.linkNext(); next.size = 0; - next.tagUsed(); - next.tagPrevFree(); + next.tagAsUsed(); + next.tagAsPrevFree(); } } diff --git a/examples/ugc/assembly/ugc.ts b/examples/ugc/assembly/ugc.ts index ee4ed065..821016c4 100644 --- a/examples/ugc/assembly/ugc.ts +++ b/examples/ugc/assembly/ugc.ts @@ -98,7 +98,11 @@ class Control { /** Tests whether the collector is currently paused. */ get paused(): bool { return (this.state & Control.PAUSED_BIT) != 0; } /** 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 ///////////////////////////////////