1package util
2
3import (
4 "context"
5
6 "github.com/tetratelabs/wazero"
7 "github.com/tetratelabs/wazero/api"
8)
9
10type funcVI[T0 i32] func(context.Context, api.Module, T0)
11
12func (fn funcVI[T0]) Call(ctx context.Context, mod api.Module, stack []uint64) {
13 fn(ctx, mod, T0(stack[0]))
14}
15
16func ExportFuncVI[T0 i32](mod wazero.HostModuleBuilder, name string, fn func(context.Context, api.Module, T0)) {
17 mod.NewFunctionBuilder().
18 WithGoModuleFunction(funcVI[T0](fn),
19 []api.ValueType{api.ValueTypeI32}, nil).
20 Export(name)
21}
22
23type funcVII[T0, T1 i32] func(context.Context, api.Module, T0, T1)
24
25func (fn funcVII[T0, T1]) Call(ctx context.Context, mod api.Module, stack []uint64) {
26 _ = stack[1] // prevent bounds check on every slice access
27 fn(ctx, mod, T0(stack[0]), T1(stack[1]))
28}
29
30func ExportFuncVII[T0, T1 i32](mod wazero.HostModuleBuilder, name string, fn func(context.Context, api.Module, T0, T1)) {
31 mod.NewFunctionBuilder().
32 WithGoModuleFunction(funcVII[T0, T1](fn),
33 []api.ValueType{api.ValueTypeI32, api.ValueTypeI32}, nil).
34 Export(name)
35}
36
37type funcVIII[T0, T1, T2 i32] func(context.Context, api.Module, T0, T1, T2)
38
39func (fn funcVIII[T0, T1, T2]) Call(ctx context.Context, mod api.Module, stack []uint64) {
40 _ = stack[2] // prevent bounds check on every slice access
41 fn(ctx, mod, T0(stack[0]), T1(stack[1]), T2(stack[2]))
42}
43
44func ExportFuncVIII[T0, T1, T2 i32](mod wazero.HostModuleBuilder, name string, fn func(context.Context, api.Module, T0, T1, T2)) {
45 mod.NewFunctionBuilder().
46 WithGoModuleFunction(funcVIII[T0, T1, T2](fn),
47 []api.ValueType{api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32}, nil).
48 Export(name)
49}
50
51type funcVIIII[T0, T1, T2, T3 i32] func(context.Context, api.Module, T0, T1, T2, T3)
52
53func (fn funcVIIII[T0, T1, T2, T3]) Call(ctx context.Context, mod api.Module, stack []uint64) {
54 _ = stack[3] // prevent bounds check on every slice access
55 fn(ctx, mod, T0(stack[0]), T1(stack[1]), T2(stack[2]), T3(stack[3]))
56}
57
58func ExportFuncVIIII[T0, T1, T2, T3 i32](mod wazero.HostModuleBuilder, name string, fn func(context.Context, api.Module, T0, T1, T2, T3)) {
59 mod.NewFunctionBuilder().
60 WithGoModuleFunction(funcVIIII[T0, T1, T2, T3](fn),
61 []api.ValueType{api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32}, nil).
62 Export(name)
63}
64
65type funcVIIIII[T0, T1, T2, T3, T4 i32] func(context.Context, api.Module, T0, T1, T2, T3, T4)
66
67func (fn funcVIIIII[T0, T1, T2, T3, T4]) Call(ctx context.Context, mod api.Module, stack []uint64) {
68 _ = stack[4] // prevent bounds check on every slice access
69 fn(ctx, mod, T0(stack[0]), T1(stack[1]), T2(stack[2]), T3(stack[3]), T4(stack[4]))
70}
71
72func ExportFuncVIIIII[T0, T1, T2, T3, T4 i32](mod wazero.HostModuleBuilder, name string, fn func(context.Context, api.Module, T0, T1, T2, T3, T4)) {
73 mod.NewFunctionBuilder().
74 WithGoModuleFunction(funcVIIIII[T0, T1, T2, T3, T4](fn),
75 []api.ValueType{api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32}, nil).
76 Export(name)
77}
78
79type funcVIIIIJ[T0, T1, T2, T3 i32, T4 i64] func(context.Context, api.Module, T0, T1, T2, T3, T4)
80
81func (fn funcVIIIIJ[T0, T1, T2, T3, T4]) Call(ctx context.Context, mod api.Module, stack []uint64) {
82 _ = stack[4] // prevent bounds check on every slice access
83 fn(ctx, mod, T0(stack[0]), T1(stack[1]), T2(stack[2]), T3(stack[3]), T4(stack[4]))
84}
85
86func ExportFuncVIIIIJ[T0, T1, T2, T3 i32, T4 i64](mod wazero.HostModuleBuilder, name string, fn func(context.Context, api.Module, T0, T1, T2, T3, T4)) {
87 mod.NewFunctionBuilder().
88 WithGoModuleFunction(funcVIIIIJ[T0, T1, T2, T3, T4](fn),
89 []api.ValueType{api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI64}, nil).
90 Export(name)
91}
92
93type funcII[TR, T0 i32] func(context.Context, api.Module, T0) TR
94
95func (fn funcII[TR, T0]) Call(ctx context.Context, mod api.Module, stack []uint64) {
96 stack[0] = uint64(fn(ctx, mod, T0(stack[0])))
97}
98
99func ExportFuncII[TR, T0 i32](mod wazero.HostModuleBuilder, name string, fn func(context.Context, api.Module, T0) TR) {
100 mod.NewFunctionBuilder().
101 WithGoModuleFunction(funcII[TR, T0](fn),
102 []api.ValueType{api.ValueTypeI32}, []api.ValueType{api.ValueTypeI32}).
103 Export(name)
104}
105
106type funcIII[TR, T0, T1 i32] func(context.Context, api.Module, T0, T1) TR
107
108func (fn funcIII[TR, T0, T1]) Call(ctx context.Context, mod api.Module, stack []uint64) {
109 _ = stack[1] // prevent bounds check on every slice access
110 stack[0] = uint64(fn(ctx, mod, T0(stack[0]), T1(stack[1])))
111}
112
113func ExportFuncIII[TR, T0, T1 i32](mod wazero.HostModuleBuilder, name string, fn func(context.Context, api.Module, T0, T1) TR) {
114 mod.NewFunctionBuilder().
115 WithGoModuleFunction(funcIII[TR, T0, T1](fn),
116 []api.ValueType{api.ValueTypeI32, api.ValueTypeI32}, []api.ValueType{api.ValueTypeI32}).
117 Export(name)
118}
119
120type funcIIII[TR, T0, T1, T2 i32] func(context.Context, api.Module, T0, T1, T2) TR
121
122func (fn funcIIII[TR, T0, T1, T2]) Call(ctx context.Context, mod api.Module, stack []uint64) {
123 _ = stack[2] // prevent bounds check on every slice access
124 stack[0] = uint64(fn(ctx, mod, T0(stack[0]), T1(stack[1]), T2(stack[2])))
125}
126
127func ExportFuncIIII[TR, T0, T1, T2 i32](mod wazero.HostModuleBuilder, name string, fn func(context.Context, api.Module, T0, T1, T2) TR) {
128 mod.NewFunctionBuilder().
129 WithGoModuleFunction(funcIIII[TR, T0, T1, T2](fn),
130 []api.ValueType{api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32}, []api.ValueType{api.ValueTypeI32}).
131 Export(name)
132}
133
134type funcIIIII[TR, T0, T1, T2, T3 i32] func(context.Context, api.Module, T0, T1, T2, T3) TR
135
136func (fn funcIIIII[TR, T0, T1, T2, T3]) Call(ctx context.Context, mod api.Module, stack []uint64) {
137 _ = stack[3] // prevent bounds check on every slice access
138 stack[0] = uint64(fn(ctx, mod, T0(stack[0]), T1(stack[1]), T2(stack[2]), T3(stack[3])))
139}
140
141func ExportFuncIIIII[TR, T0, T1, T2, T3 i32](mod wazero.HostModuleBuilder, name string, fn func(context.Context, api.Module, T0, T1, T2, T3) TR) {
142 mod.NewFunctionBuilder().
143 WithGoModuleFunction(funcIIIII[TR, T0, T1, T2, T3](fn),
144 []api.ValueType{api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32}, []api.ValueType{api.ValueTypeI32}).
145 Export(name)
146}
147
148type funcIIIIII[TR, T0, T1, T2, T3, T4 i32] func(context.Context, api.Module, T0, T1, T2, T3, T4) TR
149
150func (fn funcIIIIII[TR, T0, T1, T2, T3, T4]) Call(ctx context.Context, mod api.Module, stack []uint64) {
151 _ = stack[4] // prevent bounds check on every slice access
152 stack[0] = uint64(fn(ctx, mod, T0(stack[0]), T1(stack[1]), T2(stack[2]), T3(stack[3]), T4(stack[4])))
153}
154
155func ExportFuncIIIIII[TR, T0, T1, T2, T3, T4 i32](mod wazero.HostModuleBuilder, name string, fn func(context.Context, api.Module, T0, T1, T2, T3, T4) TR) {
156 mod.NewFunctionBuilder().
157 WithGoModuleFunction(funcIIIIII[TR, T0, T1, T2, T3, T4](fn),
158 []api.ValueType{api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32}, []api.ValueType{api.ValueTypeI32}).
159 Export(name)
160}
161
162type funcIIIIIII[TR, T0, T1, T2, T3, T4, T5 i32] func(context.Context, api.Module, T0, T1, T2, T3, T4, T5) TR
163
164func (fn funcIIIIIII[TR, T0, T1, T2, T3, T4, T5]) Call(ctx context.Context, mod api.Module, stack []uint64) {
165 _ = stack[5] // prevent bounds check on every slice access
166 stack[0] = uint64(fn(ctx, mod, T0(stack[0]), T1(stack[1]), T2(stack[2]), T3(stack[3]), T4(stack[4]), T5(stack[5])))
167}
168
169func ExportFuncIIIIIII[TR, T0, T1, T2, T3, T4, T5 i32](mod wazero.HostModuleBuilder, name string, fn func(context.Context, api.Module, T0, T1, T2, T3, T4, T5) TR) {
170 mod.NewFunctionBuilder().
171 WithGoModuleFunction(funcIIIIIII[TR, T0, T1, T2, T3, T4, T5](fn),
172 []api.ValueType{api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32}, []api.ValueType{api.ValueTypeI32}).
173 Export(name)
174}
175
176type funcIIIIJ[TR, T0, T1, T2 i32, T3 i64] func(context.Context, api.Module, T0, T1, T2, T3) TR
177
178func (fn funcIIIIJ[TR, T0, T1, T2, T3]) Call(ctx context.Context, mod api.Module, stack []uint64) {
179 _ = stack[3] // prevent bounds check on every slice access
180 stack[0] = uint64(fn(ctx, mod, T0(stack[0]), T1(stack[1]), T2(stack[2]), T3(stack[3])))
181}
182
183func ExportFuncIIIIJ[TR, T0, T1, T2 i32, T3 i64](mod wazero.HostModuleBuilder, name string, fn func(context.Context, api.Module, T0, T1, T2, T3) TR) {
184 mod.NewFunctionBuilder().
185 WithGoModuleFunction(funcIIIIJ[TR, T0, T1, T2, T3](fn),
186 []api.ValueType{api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI64}, []api.ValueType{api.ValueTypeI32}).
187 Export(name)
188}
189
190type funcIIJ[TR, T0 i32, T1 i64] func(context.Context, api.Module, T0, T1) TR
191
192func (fn funcIIJ[TR, T0, T1]) Call(ctx context.Context, mod api.Module, stack []uint64) {
193 _ = stack[1] // prevent bounds check on every slice access
194 stack[0] = uint64(fn(ctx, mod, T0(stack[0]), T1(stack[1])))
195}
196
197func ExportFuncIIJ[TR, T0 i32, T1 i64](mod wazero.HostModuleBuilder, name string, fn func(context.Context, api.Module, T0, T1) TR) {
198 mod.NewFunctionBuilder().
199 WithGoModuleFunction(funcIIJ[TR, T0, T1](fn),
200 []api.ValueType{api.ValueTypeI32, api.ValueTypeI64}, []api.ValueType{api.ValueTypeI32}).
201 Export(name)
202}