Files: a9764e4cea10db92064ace79bfa09f6e01704fb4 / tests / wast2wasm.js
1042 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 for ${file}`) |
17 | } |
18 | |
19 | try { |
20 | const mod = wabt.parseWat('module.wast', wat) |
21 | const r = mod.toBinary({log: true}) |
22 | let binary = Buffer.from(r.buffer) |
23 | if (json) { |
24 | console.log(json) |
25 | const buf = types.encodeJSON(json) |
26 | binary = types.injectCustomSection(buf, binary) |
27 | } |
28 | fs.writeFileSync(`${__dirname}/wasm/${file}.wasm`, binary) |
29 | } catch (e) { |
30 | console.log(`failed at ${file}`) |
31 | console.log(e) |
32 | } |
33 | } |
34 | } |
35 | |
36 | filesWast2wasm() |
37 |
Built with git-ssb-web