-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathsanity.js
More file actions
68 lines (50 loc) · 1.78 KB
/
sanity.js
File metadata and controls
68 lines (50 loc) · 1.78 KB
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
61
62
63
64
65
66
67
68
import assert from "assert";
// Basic tests to make sure that we do not push something obviously broken
console.log("importing binaryen");
const binaryen = (await import("../index.js")).default;
assert(binaryen);
console.log("constructing a module");
var mod = new binaryen.Module();
assert(mod);
console.log("creating an expression");
var expr = mod.i32.const(0);
assert(expr);
console.log("creating a statement");
var stmt = mod.return(expr);
assert(stmt);
console.log("adding a function");
var func = mod.addFunction("main", binaryen.none, binaryen.i32, [], stmt);
assert(func);
console.log("creating a multi-value type");
var mvtype = binaryen.createType([ binaryen.i32, binaryen.f64 ]);
assert(mvtype);
console.log("adding a function import");
mod.addFunctionImport("func", "env", "func", mvtype, binaryen.i32);
console.log("adding a function export");
mod.addFunctionExport("main", "main");
console.log("adding a memory import");
mod.addMemoryImport("0", "env", "memory");
console.log("adding a memory export");
mod.addMemoryExport("0", "memory");
console.log("validating the module");
assert(mod.validate());
console.log("emitting text");
var text = mod.emitText();
assert(typeof text === "string" && text.length);
console.log(text);
console.log("optimizing the module");
assert.doesNotThrow(() => mod.optimize());
console.log("emitting text (again)");
text = mod.emitText();
assert(typeof text === "string" && text.length);
console.log(text);
console.log("emitting a binary");
var binary = mod.emitBinary();
assert(binary && binary.length);
console.log(Array.from(binary));
console.log("emitting js");
var js = mod.emitAsmjs();
assert(typeof js === "string" && js.length);
console.log("wrapping an existing module");
var wrapped = binaryen.wrapModule(mod.ptr);
assert(wrapped.getFunction("main"));