@@ -21,8 +21,8 @@ const (
21
21
22
22
// Strings returns the CompilerKind as a string.
23
23
//
24
- // CRANELIFT.String() // "cranelift"
25
- // LLVM.String() // "llvm"
24
+ // CRANELIFT.String() // "cranelift"
25
+ // LLVM.String() // "llvm"
26
26
func (self CompilerKind ) String () string {
27
27
switch self {
28
28
case CRANELIFT :
@@ -40,7 +40,7 @@ func (self CompilerKind) String() string {
40
40
// IsCompilerAvailable checks that the given compiler is available
41
41
// in this current version of `wasmer-go`.
42
42
//
43
- // IsCompilerAvailable(CRANELIFT)
43
+ // IsCompilerAvailable(CRANELIFT)
44
44
func IsCompilerAvailable (compiler CompilerKind ) bool {
45
45
return bool (C .wasmer_is_compiler_available (uint32 (C .wasmer_compiler_t (compiler ))))
46
46
}
@@ -64,8 +64,8 @@ const (
64
64
65
65
// Strings returns the EngineKind as a string.
66
66
//
67
- // JIT.String() // "jit"
68
- // NATIVE.String() // "native"
67
+ // JIT.String() // "jit"
68
+ // NATIVE.String() // "native"
69
69
func (self EngineKind ) String () string {
70
70
switch self {
71
71
case UNIVERSAL :
@@ -80,35 +80,31 @@ func (self EngineKind) String() string {
80
80
// IsEngineAvailable checks that the given engine is available in this
81
81
// current version of `wasmer-go`.
82
82
//
83
- // IsEngineAvailable(UNIVERSAL)
83
+ // IsEngineAvailable(UNIVERSAL)
84
84
func IsEngineAvailable (engine EngineKind ) bool {
85
85
return bool (C .wasmer_is_engine_available (uint32 (C .wasmer_engine_t (engine ))))
86
86
}
87
87
88
88
// Config holds the compiler and the Engine used by the Store.
89
89
type Config struct {
90
- _inner * C.wasm_config_t
90
+ CPtrBase [ * C.wasm_config_t ]
91
91
}
92
92
93
93
// NewConfig instantiates and returns a new Config.
94
94
//
95
- // config := NewConfig()
95
+ // config := NewConfig()
96
96
func NewConfig () * Config {
97
- config := C .wasm_config_new ()
98
-
99
- return & Config {
100
- _inner : config ,
101
- }
97
+ return & Config {CPtrBase : mkPtr (C .wasm_config_new ())}
102
98
}
103
99
104
100
func (self * Config ) inner () * C.wasm_config_t {
105
- return self ._inner
101
+ return self .ptr ()
106
102
}
107
103
108
104
// UseNativeEngine sets the engine to Universal in the configuration.
109
105
//
110
- // config := NewConfig()
111
- // config.UseUniversalEngine()
106
+ // config := NewConfig()
107
+ // config.UseUniversalEngine()
112
108
//
113
109
// This method might fail if the Universal engine isn't
114
110
// available. Check `IsEngineAvailable` to learn more.
@@ -124,8 +120,8 @@ func (self *Config) UseUniversalEngine() *Config {
124
120
125
121
// UseDylibEngine sets the engine to Dylib in the configuration.
126
122
//
127
- // config := NewConfig()
128
- // config.UseDylibEngine()
123
+ // config := NewConfig()
124
+ // config.UseDylibEngine()
129
125
//
130
126
// This method might fail if the Dylib engine isn't available. Check
131
127
// `IsEngineAvailable` to learn more.
@@ -153,8 +149,8 @@ func (self *Config) UseNativeEngine() *Config {
153
149
154
150
// UseCraneliftCompiler sets the compiler to Cranelift in the configuration.
155
151
//
156
- // config := NewConfig()
157
- // config.UseCraneliftCompiler()
152
+ // config := NewConfig()
153
+ // config.UseCraneliftCompiler()
158
154
//
159
155
// This method might fail if the Cranelift compiler isn't
160
156
// available. Check `IsCompilerAvailable` to learn more.
@@ -182,14 +178,17 @@ func metering_delegate(op C.wasmer_parser_operator_t) C.uint64_t {
182
178
}
183
179
184
180
// PushMeteringMiddleware allows the middleware metering to be engaged on a map of opcode to cost
185
- // config := NewConfig()
186
- // opmap := map[uint32]uint32{
187
- // End: 1,
188
- // LocalGet: 1,
189
- // I32Add: 4,
190
- // }
191
- // config.PushMeteringMiddleware(7865444, opmap)
192
- func (self * Config ) PushMeteringMiddleware (maxGasUsageAllowed uint64 , opMap map [Opcode ]uint32 ) * Config {
181
+ //
182
+ // config := NewConfig()
183
+ // opmap := map[uint32]uint32{
184
+ // End: 1,
185
+ // LocalGet: 1,
186
+ // I32Add: 4,
187
+ // }
188
+ // config.PushMeteringMiddleware(7865444, opmap)
189
+ func (self * Config ) PushMeteringMiddleware (
190
+ maxGasUsageAllowed uint64 , opMap map [Opcode ]uint32 ,
191
+ ) * Config {
193
192
if opCodeMap == nil {
194
193
// REVIEW only allowing this to be set once
195
194
opCodeMap = opMap
@@ -200,40 +199,43 @@ func (self *Config) PushMeteringMiddleware(maxGasUsageAllowed uint64, opMap map[
200
199
201
200
// PushMeteringMiddlewarePtr allows the middleware metering to be engaged on an unsafe.Pointer
202
201
// this pointer must be a to C based function with a signature of:
203
- // extern uint64_t cost_delegate_func(enum wasmer_parser_operator_t op);
202
+ //
203
+ // extern uint64_t cost_delegate_func(enum wasmer_parser_operator_t op);
204
+ //
204
205
// package main
205
206
//
206
207
// #include <wasmer.h>
207
208
// extern uint64_t metering_delegate_alt(enum wasmer_parser_operator_t op);
208
209
// import "C"
209
210
// import "unsafe"
210
211
//
211
- // func getInternalCPointer() unsafe.Pointer {
212
- // return unsafe.Pointer(C.metering_delegate_alt)
213
- // }
212
+ // func getInternalCPointer() unsafe.Pointer {
213
+ // return unsafe.Pointer(C.metering_delegate_alt)
214
+ // }
214
215
//
215
216
// //export metering_delegate_alt
216
- // func metering_delegate_alt(op C.wasmer_parser_operator_t) C.uint64_t {
217
- // v, b := opCodeMap[Opcode(op)]
218
- // if !b {
219
- // return 0 // no value means no cost
220
- // }
221
- // return C.uint64_t(v)
222
- // }
223
217
//
224
- // void main(){
225
- // config := NewConfig()
226
- // config.PushMeteringMiddlewarePtr(800000000, getInternalCPointer())
227
- // }
218
+ // func metering_delegate_alt(op C.wasmer_parser_operator_t) C.uint64_t {
219
+ // v, b := opCodeMap[Opcode(op)]
220
+ // if !b {
221
+ // return 0 // no value means no cost
222
+ // }
223
+ // return C.uint64_t(v)
224
+ // }
225
+ //
226
+ // void main(){
227
+ // config := NewConfig()
228
+ // config.PushMeteringMiddlewarePtr(800000000, getInternalCPointer())
229
+ // }
228
230
func (self * Config ) PushMeteringMiddlewarePtr (maxGasUsageAllowed uint64 , p unsafe.Pointer ) * Config {
229
231
C .wasm_config_push_middleware (self .inner (), C .wasmer_metering_as_middleware (C .wasmer_metering_new (getPlatformLong (maxGasUsageAllowed ), (* [0 ]byte )(p ))))
230
232
return self
231
233
}
232
234
233
235
// UseLLVMCompiler sets the compiler to LLVM in the configuration.
234
236
//
235
- // config := NewConfig()
236
- // config.UseLLVMCompiler()
237
+ // config := NewConfig()
238
+ // config.UseLLVMCompiler()
237
239
//
238
240
// This method might fail if the LLVM compiler isn't available. Check
239
241
// `IsCompilerAvailable` to learn more.
@@ -250,8 +252,8 @@ func (self *Config) UseLLVMCompiler() *Config {
250
252
// UseSinglepassCompiler sets the compiler to Singlepass in the
251
253
// configuration.
252
254
//
253
- // config := NewConfig()
254
- // config.UseSinglepassCompiler()
255
+ // config := NewConfig()
256
+ // config.UseSinglepassCompiler()
255
257
//
256
258
// This method might fail if the Singlepass compiler isn't
257
259
// available. Check `IsCompilerAvailable` to learn more.
@@ -267,14 +269,14 @@ func (self *Config) UseSinglepassCompiler() *Config {
267
269
268
270
// Use a specific target for doing cross-compilation.
269
271
//
270
- // triple, _ := NewTriple("aarch64-unknown-linux-gnu")
271
- // cpuFeatures := NewCpuFeatures()
272
- // target := NewTarget(triple, cpuFeatures)
272
+ // triple, _ := NewTriple("aarch64-unknown-linux-gnu")
273
+ // cpuFeatures := NewCpuFeatures()
274
+ // target := NewTarget(triple, cpuFeatures)
273
275
//
274
- // config := NewConfig()
275
- // config.UseTarget(target)
276
+ // config := NewConfig()
277
+ // config.UseTarget(target)
276
278
func (self * Config ) UseTarget (target * Target ) * Config {
277
- C .wasm_config_set_target (self .inner (), target .inner ())
279
+ C .wasm_config_set_target (self .inner (), target .release ())
278
280
279
281
return self
280
282
}
0 commit comments