wat4wasm 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/clean.js CHANGED
@@ -26,58 +26,54 @@ function FUNC_WAT4WASM_START_CALLS(wat) {
26
26
  }
27
27
 
28
28
  export default function (wat) {
29
+ console.log("")
29
30
  let block, $name;
30
-
31
31
  block = FUNC_WAT4WASM_BLOCK_ONEXTERNREADY(wat);
32
32
  if (!block.hasAnyBlock) { wat = block.removedRaw(); }
33
-
34
33
  block = FUNC_WAT4WASM_BLOCK_ONTEXTREADY(wat);
35
34
  if (!block.hasAnyBlock) { wat = block.removedRaw(); }
36
-
37
35
  block = FUNC_WAT4WASM_BLOCK_ONINIT(wat);
38
36
  if (!block.hasAnyBlock) {
39
-
40
37
  wat = block.removedRaw();
41
-
42
38
  let $starts = FUNC_WAT4WASM_START_CALLS(wat);
43
39
  if ($starts.length === 1) {
44
- wat = wat.replace(`(start $wat4wasm)`, `(start ${$starts.pop()})`);
40
+ const $start = $starts.pop();
41
+ wat = wat.replace(`(start $wat4wasm)`, `(start ${$start})`);
42
+ console.log(`⚠️ replaced --> \x1b[34m(start \x1b[35m$wat4wasm\x1b[0m --> \x1b[35m${$start}\x1b[0m)\x1b[0m`);
45
43
  }
46
-
47
44
  let $func = FUNC_WAT4WASM(wat);
48
45
  if ($func) {
46
+ console.log(`⚠️ removing --> \x1b[34m(func \x1b[35m$wat4wasm\x1b[0m ...)\x1b[0m`);
49
47
  wat = $func.removedRaw();
50
48
  }
51
-
52
49
  block = ELEM_WAT4WASM(wat);
53
- if (block.isInitial) { wat = block.removedRaw(); }
54
-
55
- block = TABLE_WAT4WASM(wat);
56
- if (block.isInitial) { wat = block.removedRaw(); }
57
-
50
+ if (block.isInitial) {
51
+ console.log(`⚠️ removing --> \x1b[34m(elem \x1b[35m$wat4wasm\x1b[0m ...)\x1b[0m`);
52
+ wat = block.removedRaw();
53
+ }
58
54
  block = DATA_WAT4WASM(wat);
59
- if (block.isInitial) { wat = block.removedRaw(); }
60
-
55
+ if (block.isInitial) {
56
+ console.log(`⚠️ removing --> \x1b[34m(data \x1b[35m$wat4wasm\x1b[0m ...)\x1b[0m`);
57
+ wat = block.removedRaw();
58
+ }
59
+ block = TABLE_WAT4WASM(wat);
60
+ if (block.isInitial) {
61
+ console.log(`⚠️ removing --> \x1b[34m(table \x1b[35m$wat4wasm\x1b[0m ...)\x1b[0m`);
62
+ wat = block.removedRaw();
63
+ }
61
64
  if (false === helpers.hasBlock(wat, "global.get", { $name: "$wat4wasm" }) &&
62
65
  false === helpers.hasBlock(wat, "global.set", { $name: "$wat4wasm" })) {
66
+ console.log(`⚠️ removing --> \x1b[34m(global \x1b[35m$wat4wasm\x1b[0m ...)\x1b[0m`);
63
67
  wat = GLOBAL_WAT4WASM(wat).removedRaw();
64
68
  }
65
-
66
- block = MEMORY_WAT4WASM(wat);
67
- if (block && (helpers.containsMemoryOperation(wat) === false)) {
68
- wat = block.removedRaw();
69
- }
70
69
  }
71
-
72
70
  const maskSet = new helpers.MaskSet(wat);
73
71
  const imports = new Array();
74
-
75
72
  while (block = maskSet.lastBlockOf("import")) {
76
73
  block.$name = helpers.parseFirstBlock(block).$name;
77
74
  imports.push(block);
78
75
  maskSet.remove(block);
79
76
  }
80
-
81
77
  wat = maskSet.restore();
82
78
  wat = helpers.prepend(wat,
83
79
  imports
@@ -86,32 +82,33 @@ export default function (wat) {
86
82
  .map(b => b.toString())
87
83
  .join("\n")
88
84
  );
89
-
90
-
91
85
  const funcMask = new helpers.MaskSet(wat);
92
86
  const unusedCalls = new Set();
93
-
94
87
  funcMask.maskAll("import");
95
88
  funcMask.maskComments();
96
-
97
89
  while (block = funcMask.lastBlockOf("func")) {
98
90
  funcMask.mask(block);
99
91
  if (($name = block.$name)) {
100
92
  if (wat.match(new RegExp(`\\\((call|start|ref\\.func)\\s+\\${$name}(\\s|\\\))`))) {
101
93
  continue;
102
94
  }
103
-
104
95
  if (unusedCalls.has($name) === false) {
105
96
  unusedCalls.add($name);
106
97
  }
107
98
  }
108
99
  }
109
-
110
100
  unusedCalls.forEach($name => {
111
101
  const begin = wat.lastIndexOf(`(func ${$name}`);
112
102
  const block = helpers.parseBlockAt(wat, begin);
103
+ $name = $name.replace(".prototype.", ":")
104
+ console.log(`⚠️ removing unused --> \x1b[34m(func \x1b[32m${$name}\x1b[0m ...)\x1b[0m`);
113
105
  if (block) { wat = block.removedRaw() }
114
106
  });
115
-
107
+ const nonWat4WasmMemory = wat.replace(WAT4WASM_BLOCKS.memory, "");
108
+ if (nonWat4WasmMemory.match(/\(memory\s+(\$|\d)/)) {
109
+ console.log(`⚠️ removing --> \x1b[34m(memory \x1b[35m$wat4wasm\x1b[0m ...)\x1b[0m`);
110
+ wat = nonWat4WasmMemory;
111
+ }
112
+ console.log("")
116
113
  return wat;
117
114
  }
package/lib/index.js CHANGED
@@ -68,12 +68,12 @@ processCLI(async wat4 => {
68
68
  const netChange = outLines.length - inLines.length;
69
69
 
70
70
  const stat = [
71
- `\x1b[32m+${addedLines}\x1b[0m`.padStart(15, " "),
72
- `\x1b[34m-${removedLines}\x1b[0m`.padStart(15, " "),
73
- `\x1b[${netChange && 36 || 33}m\u0394\x1b[0m`.padStart(12, " "),
74
- `\x1b[${netChange && 36 || 33}m${netChange}\x1b[0m`.padStart(12, " "),
71
+ `\x1b[32m+${addedLines}\x1b[0m`.padStart(16, " "),
72
+ `\x1b[34m-${removedLines}\x1b[0m`.padStart(16, " "),
73
+ `\x1b[${netChange && 36 || 33}m\u0394\x1b[0m`.padStart(14, " "),
74
+ `\x1b[${netChange && 36 || 33}m${netChange}\x1b[0m`.padStart(14, " "),
75
75
  ` byte(\u03B4) :`,
76
- `\x1b[33m${wat2.length}\x1b[0m`.padStart(14, " "),
76
+ `\x1b[33m${wat2.length}\x1b[0m`.padStart(16, " "),
77
77
  `-->`,
78
78
  `\x1b[33m${wat4.length}\x1b[0m`,
79
79
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wat4wasm",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/central-network/wat4wasm#readme",
6
6
  "bugs": {
package/wat4wasm CHANGED
@@ -1693,6 +1693,7 @@ function W4W (wat) {
1693
1693
  return calls;
1694
1694
  }
1695
1695
  function clean (wat) {
1696
+ console.log("")
1696
1697
  let block, $name;
1697
1698
  block = FUNC_WAT4WASM_BLOCK_ONEXTERNREADY(wat);
1698
1699
  if (!block.hasAnyBlock) { wat = block.removedRaw(); }
@@ -1703,26 +1704,35 @@ function clean (wat) {
1703
1704
  wat = block.removedRaw();
1704
1705
  let $starts = FUNC_WAT4WASM_START_CALLS(wat);
1705
1706
  if ($starts.length === 1) {
1706
- wat = wat.replace(`(start $wat4wasm)`, `(start ${$starts.pop()})`);
1707
+ const $start = $starts.pop();
1708
+ wat = wat.replace(`(start $wat4wasm)`, `(start ${$start})`);
1709
+ console.log(`⚠️ replaced --> \x1b[34m(start \x1b[35m$wat4wasm\x1b[0m --> \x1b[35m${$start}\x1b[0m)\x1b[0m`);
1707
1710
  }
1708
1711
  let $func = FUNC_WAT4WASM(wat);
1709
1712
  if ($func) {
1713
+ console.log(`⚠️ removing --> \x1b[34m(func \x1b[35m$wat4wasm\x1b[0m ...)\x1b[0m`);
1710
1714
  wat = $func.removedRaw();
1711
1715
  }
1712
1716
  block = ELEM_WAT4WASM(wat);
1713
- if (block.isInitial) { wat = block.removedRaw(); }
1714
- block = TABLE_WAT4WASM(wat);
1715
- if (block.isInitial) { wat = block.removedRaw(); }
1717
+ if (block.isInitial) {
1718
+ console.log(`⚠️ removing --> \x1b[34m(elem \x1b[35m$wat4wasm\x1b[0m ...)\x1b[0m`);
1719
+ wat = block.removedRaw();
1720
+ }
1716
1721
  block = DATA_WAT4WASM(wat);
1717
- if (block.isInitial) { wat = block.removedRaw(); }
1722
+ if (block.isInitial) {
1723
+ console.log(`⚠️ removing --> \x1b[34m(data \x1b[35m$wat4wasm\x1b[0m ...)\x1b[0m`);
1724
+ wat = block.removedRaw();
1725
+ }
1726
+ block = TABLE_WAT4WASM(wat);
1727
+ if (block.isInitial) {
1728
+ console.log(`⚠️ removing --> \x1b[34m(table \x1b[35m$wat4wasm\x1b[0m ...)\x1b[0m`);
1729
+ wat = block.removedRaw();
1730
+ }
1718
1731
  if (false === helpers.hasBlock(wat, "global.get", { $name: "$wat4wasm" }) &&
1719
1732
  false === helpers.hasBlock(wat, "global.set", { $name: "$wat4wasm" })) {
1733
+ console.log(`⚠️ removing --> \x1b[34m(global \x1b[35m$wat4wasm\x1b[0m ...)\x1b[0m`);
1720
1734
  wat = GLOBAL_WAT4WASM(wat).removedRaw();
1721
1735
  }
1722
- block = MEMORY_WAT4WASM(wat);
1723
- if (block && (helpers.containsMemoryOperation(wat) === false)) {
1724
- wat = block.removedRaw();
1725
- }
1726
1736
  }
1727
1737
  const maskSet = new helpers.MaskSet(wat);
1728
1738
  const imports = new Array();
@@ -1757,8 +1767,16 @@ function clean (wat) {
1757
1767
  unusedCalls.forEach($name => {
1758
1768
  const begin = wat.lastIndexOf(`(func ${$name}`);
1759
1769
  const block = helpers.parseBlockAt(wat, begin);
1770
+ $name = $name.replace(".prototype.", ":")
1771
+ console.log(`⚠️ removing unused --> \x1b[34m(func \x1b[32m${$name}\x1b[0m ...)\x1b[0m`);
1760
1772
  if (block) { wat = block.removedRaw() }
1761
1773
  });
1774
+ const nonWat4WasmMemory = wat.replace(WAT4WASM_BLOCKS.memory, "");
1775
+ if (nonWat4WasmMemory.match(/\(memory\s+(\$|\d)/)) {
1776
+ console.log(`⚠️ removing --> \x1b[34m(memory \x1b[35m$wat4wasm\x1b[0m ...)\x1b[0m`);
1777
+ wat = nonWat4WasmMemory;
1778
+ }
1779
+ console.log("")
1762
1780
  return wat;
1763
1781
  }
1764
1782
 
@@ -2057,12 +2075,12 @@ processCLI(async wat4 => {
2057
2075
  const addedLines = outLines.length - commonLines;
2058
2076
  const netChange = outLines.length - inLines.length;
2059
2077
  const stat = [
2060
- `\x1b[32m+${addedLines}\x1b[0m`.padStart(15, " "),
2061
- `\x1b[34m-${removedLines}\x1b[0m`.padStart(15, " "),
2062
- `\x1b[${netChange && 36 || 33}m\u0394\x1b[0m`.padStart(12, " "),
2063
- `\x1b[${netChange && 36 || 33}m${netChange}\x1b[0m`.padStart(12, " "),
2078
+ `\x1b[32m+${addedLines}\x1b[0m`.padStart(16, " "),
2079
+ `\x1b[34m-${removedLines}\x1b[0m`.padStart(16, " "),
2080
+ `\x1b[${netChange && 36 || 33}m\u0394\x1b[0m`.padStart(14, " "),
2081
+ `\x1b[${netChange && 36 || 33}m${netChange}\x1b[0m`.padStart(14, " "),
2064
2082
  ` byte(\u03B4) :`,
2065
- `\x1b[33m${wat2.length}\x1b[0m`.padStart(14, " "),
2083
+ `\x1b[33m${wat2.length}\x1b[0m`.padStart(16, " "),
2066
2084
  `-->`,
2067
2085
  `\x1b[33m${wat4.length}\x1b[0m`,
2068
2086
  ];