Files: e729c860b2eaa16901cefd395558a96c683a5cad / tests / wast2wasm.js
923 bytesRaw
1 | const wabt = require('wabt') |
2 | const fs = require('fs') |
3 | const types = require('../customTypes') |
4 | |
5 | function filesWast2wasm () { |
6 | const srcFiles = fs.readdirSync(`${__dirname}/wast`) |
7 | const wastFiles = srcFiles.filter(name => name.split('.').pop() === 'wast') |
8 | for (let file of wastFiles) { |
9 | const wat = fs.readFileSync(`${__dirname}/wast/${file}`).toString() |
10 | file = file.split('.')[0] |
11 | let json |
12 | try { |
13 | json = fs.readFileSync(`${__dirname}/wast/${file}.json`) |
14 | json = JSON.parse(json) |
15 | } catch (e) { |
16 | console.log('no json') |
17 | } |
18 | |
19 | console.log(wat) |
20 | const mod = wabt.parseWat('module.wast', wat) |
21 | let binary = Buffer.from(mod.toBinary({log: true}).buffer) |
22 | if (json) { |
23 | console.log(json) |
24 | const buf = types.encodeJSON(json) |
25 | binary = types.injectCustomSection(buf, binary) |
26 | } |
27 | fs.writeFileSync(`${__dirname}/wasm/${file}.wasm`, binary) |
28 | } |
29 | } |
30 | |
31 | filesWast2wasm() |
32 |
Built with git-ssb-web