-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·61 lines (46 loc) · 1.19 KB
/
cli.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env node
import arg from "arg";
import { readFile, writeFile } from "fs/promises";
import { compile } from "./index.js";
import Wabt from './lib/wabt.js'
const argv = arg({
'--output': String,
'--text': Boolean,
'-o': '--output',
'-t': '--text'
});
const help =
`
Usage: mell <source> -o <destination>
Description:
Compiles mell source file to wasm binary output.
Repository:
https://github.com/audio-lab/mell
Options:
--output, -o Output file path
--text, -t [TODO] Output WASM text instead of binary
Example:
mell input.s -o output.wasm
`
const path = argv._?.[0], outpath = argv['--output']
if (!path || !outpath) {
console.log(help);
process.exit(1); // 1 indicates an error occurred, any non-zero value can be used
}
const code = await readFile(path, 'utf8');
const wabt = await Wabt();
const wasmCode = compile(code);
const wasmModule = wabt.parseWat('inline', wasmCode, {
// simd: true,
// reference_types: true,
// gc: true,
bulk_memory: true,
// function_references: true
})
const binary = wasmModule.toBinary({
log: true,
canonicalize_lebs: true,
relocatable: false,
write_debug_names: false,
})
writeFile(outpath, binary.buffer)