Files: 75864bd5ab5d242349cbe42dcc37db22b686e9c5 / tests / wast2wasm.js
768 bytesRaw
1 | const wabt = require('wabt') |
2 | const fs = require('fs') |
3 | |
4 | function filesWast2wasm () { |
5 | const srcFiles = fs.readdirSync(`${__dirname}/wast`) |
6 | const wastFiles = srcFiles.filter(name => name.split('.').pop() === 'wast') |
7 | for (let file of wastFiles) { |
8 | const wat = fs.readFileSync(`${__dirname}/wast/${file}`).toString() |
9 | file = file.split('.')[0] |
10 | |
11 | try { |
12 | const mod = wabt.parseWat('module.wast', wat) |
13 | const r = mod.toBinary({log: true}) |
14 | let binary = Buffer.from(r.buffer) |
15 | if (!WebAssembly.validate(binary)) { |
16 | throw new Error('invalid wasm binary') |
17 | } |
18 | fs.writeFileSync(`${__dirname}/wasm/${file}.wasm`, binary) |
19 | } catch (e) { |
20 | console.log(`failed at ${file}`) |
21 | console.log(e) |
22 | } |
23 | } |
24 | } |
25 | |
26 | filesWast2wasm() |
27 |
Built with git-ssb-web