-
Notifications
You must be signed in to change notification settings - Fork 3
/
loader.js
43 lines (31 loc) · 908 Bytes
/
loader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const {execFileSync} = require('child_process');
const {unlink, writeFileSync, readFileSync} = require('fs');
const {edit, add} = require("@webassemblyjs/wasm-edit");
const t = require("@webassemblyjs/ast");
function transformWasm(bin) {
// bin = edit(bin, {
// ModuleExport(path) {
// const descr = path.node.descr;
// if (descr.exportType === "Mem") {
// path.remove();
// }
// }
// });
// const moduleImport = t.moduleImport(
// "holycjs", "mem",
// t.memory(t.limit(1))
// );
// bin = add(bin, [moduleImport]);
return bin;
}
module.exports = function(source) {
writeFileSync(".tmp.c", source);
execFileSync("./node_modules/.bin/holyc", [
".tmp.c"
]);
const bin = readFileSync(".tmp.c.wasm", null);
const newBin = transformWasm(bin);
this.callback(null, new Buffer(newBin));
unlink(".tmp.c");
unlink(".tmp.c.wasm");
};