Skip to content

Commit 90d558e

Browse files
authored
Merge pull request #23 from GoogleChromeLabs/update-wabt
2 parents 980ebe7 + 69e8428 commit 90d558e

File tree

14 files changed

+31
-25
lines changed

14 files changed

+31
-25
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ The _other_ reason is that you _should_ be using `WebAssembly.compile`, `WebAsse
6565

6666
## Contributing
6767

68-
If you want to contribute a new feature test, all you need to do is create a new folder in `src/detectors` and it will be automatically picked up. The folder must contain a `module.wat` file, which will be compiled using [`wat2wasm`][wat2wasm].
68+
If you want to contribute a new feature test, all you need to do is create a new folder in `src/detectors` and it will be automatically picked up. The folder must contain a `module.wat` file, which will be compiled using [`wabt.js`](https://github.com/AssemblyScript/wabt.js).
6969

7070
```wat
7171
;; Name: <Name of the feature for the README>
7272
;; Proposal: <Link to the proposal’s explainer/repo>
73-
;; Flags: <CLI flags for `wat2wasm`>
73+
;; Features: <Space-separated list of WasmFeatures from wabt.js>
7474
7575
(module
7676
;; More WAT code here

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"markdown-it": "^10.0.0",
2525
"prettier": "^1.18.2",
2626
"rollup": "^1.20.3",
27-
"rollup-plugin-terser": "^5.1.1"
27+
"rollup-plugin-terser": "^5.1.1",
28+
"wabt": "^1.0.13-nightly.20200430"
2829
}
2930
}

rollup-plugins/helpers.mjs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,19 @@
1111
* limitations under the License.
1212
*/
1313

14-
import { exec } from "child_process";
15-
import { promisify } from "util";
14+
import initWabt from "wabt";
1615
import { promises as fsp } from "fs";
1716

18-
const execP = promisify(exec);
17+
const wabt = initWabt();
1918

20-
export async function compileWat(watPath, flags = []) {
21-
const { stdout } = await execP(`wat2wasm -d ${flags.join(" ")} ${watPath}`);
22-
const hex = stdout
23-
.split("\n")
24-
.filter(line => line.length > 0)
25-
.map(line => line.split(":")[1].replace(/\s+/g, ""))
26-
.join("");
27-
return Buffer.from(hex, "hex");
19+
export async function compileWat(watPath, features = []) {
20+
const watSource = await fsp.readFile(watPath, "utf-8");
21+
const module = wabt.parseWat(
22+
watPath,
23+
watSource,
24+
Object.fromEntries(features.map(flag => [flag, true]))
25+
);
26+
return module.toBinary({ canonicalize_lebs: true }).buffer;
2827
}
2928

3029
export async function fileExists(path) {

rollup-plugins/index-generator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ export default function({ indexPath, pluginFolder, format }) {
3737
`./src/${pluginFolder}/${plugin}/module.wat`,
3838
"utf8"
3939
);
40-
const flags = (/;;\s*Flags:\s*(.+)$/im.exec(source) || [
40+
const features = (/;;\s*Features:\s*(.+)$/im.exec(source) || [
4141
"",
4242
""
4343
])[1].split(" ");
4444
const moduleBytes = JSON.stringify([
4545
...(await compileWat(
4646
`./src/${pluginFolder}/${plugin}/module.wat`,
47-
flags
47+
features
4848
))
4949
]);
5050
const pluginName = camelCaseify(plugin);

src/detectors/bulk-memory/module.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
;; Name: Bulk memory operations
22
;; Proposal: https://github.com/webassembly/bulk-memory-operations
3-
;; Flags: --enable-bulk-memory
3+
;; Features: bulk_memory
44

55
(module
66
(memory 1)

src/detectors/exceptions/module.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
;; Name: Exception handling
22
;; Proposal: https://github.com/WebAssembly/exception-handling
3-
;; Flags: --enable-exceptions
3+
;; Features: exceptions
44

55
(module
66
(func

src/detectors/multi-value/module.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
;; Name: Multi-value
22
;; Proposal: https://github.com/WebAssembly/multi-value
3-
;; Flags: --enable-multi-value
3+
;; Features: multi_value
44

55
(module
66
(func (result i32 i32)

src/detectors/reference-types/module.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
;; Name: Reference Types
22
;; Proposal: https://github.com/WebAssembly/reference-types
3-
;; Flags: --enable-reference-types
3+
;; Features: reference_types
44

55
(module
66
(func

src/detectors/saturated-float-to-int/module.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
;; Name: Non-trapping float-to-int conversions
22
;; Proposal: https://github.com/WebAssembly/nontrapping-float-to-int-conversions
3-
;; Flags: --enable-saturating-float-to-int
3+
;; Features: sat_float_to_int
44

55
(module
66
(func

src/detectors/sign-extensions/module.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
;; Name: Sign-extension operators
22
;; Proposal: https://github.com/WebAssembly/sign-extension-ops
3-
;; Flags: --enable-sign-extension
3+
;; Features: sign_extension
44

55
(module
66
(func

src/detectors/simd/module.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
;; Name: Fixed-Width SIMD
22
;; Proposal: https://github.com/webassembly/simd
3-
;; Flags: --enable-simd
3+
;; Features: simd
44

55
(module
66
(func

src/detectors/tail-call/module.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
;; Name: Tail call
22
;; Proposal: https://github.com/webassembly/tail-call
3-
;; Flags: --enable-tail-call
3+
;; Features: tail_call
44

55
(module
66
(func

src/detectors/threads/module.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
;; Name: Threads
22
;; Proposal: https://github.com/webassembly/threads
3-
;; Flags: --enable-threads
3+
;; Features: threads
44

55
(module
66
(memory 1 1 shared)

0 commit comments

Comments
 (0)