blob: 34142941c1d1a32f91c413a628ce85374e2aef6b (
plain)
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
|
var module = new Binaryen.Module();
var signature = module.addFunctionType("i", Binaryen.i32, []);
var func = module.addFunction("a-function", signature, [],
module.i32.add(
module.i32.const(1),
module.i32.const(2)
)
);
console.log("GetFunction is equal: " + (func === module.getFunction("a-function")));
module.runPassesOnFunction(func, ["precompute"]);
var body = Binaryen.getFunctionBody(func);
console.log("ExpressionId=" + Binaryen.getExpressionId(body));
console.log("ExpressionType=" + Binaryen.getExpressionType(body));
console.log(Binaryen.emitText(body));
module.removeFunction("a-function");
module.addGlobal("a-global", Binaryen.i32, false, body);
module.validate();
console.log(module.emitText());
|