-
Notifications
You must be signed in to change notification settings - Fork 4
/
wasm.go
48 lines (38 loc) · 910 Bytes
/
wasm.go
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
package trealla
import (
"context"
_ "embed"
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/api"
"github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
)
//go:embed libtpl.wasm
var tplWASM []byte
type wasmFunc = api.Function
var wasmEngine wazero.Runtime
var wasmModule wazero.CompiledModule
func init() {
ctx := context.Background()
wasmEngine = wazero.NewRuntime(ctx)
wasi_snapshot_preview1.MustInstantiate(ctx, wasmEngine)
_, err := wasmEngine.NewHostModuleBuilder("trealla").
NewFunctionBuilder().WithFunc(hostCall).Export("host-call").
NewFunctionBuilder().WithFunc(hostResume).Export("host-resume").
Instantiate(ctx)
if err != nil {
panic(err)
}
wasmModule, err = wasmEngine.CompileModule(ctx, tplWASM)
if err != nil {
panic(err)
}
}
var (
wasmFalse uint32 = 0
wasmTrue uint32 = 1
)
const (
ptrSize = 4
align = 1
pageSize = 64 * 1024
)