Helper function to create the "extern_module" module instance.
| 293 | |
| 294 | // Helper function to create the "extern_module" module instance. |
| 295 | WasmEdge_ModuleInstanceContext *createExternModule() { |
| 296 | WasmEdge_String HostName; |
| 297 | WasmEdge_FunctionTypeContext *HostFType = nullptr; |
| 298 | WasmEdge_FunctionInstanceContext *HostFunc = nullptr; |
| 299 | WasmEdge_ValType P[3], R[1]; |
| 300 | |
| 301 | HostName = WasmEdge_StringCreateByCString("extern_module"); |
| 302 | WasmEdge_ModuleInstanceContext *HostMod = |
| 303 | WasmEdge_ModuleInstanceCreate(HostName); |
| 304 | WasmEdge_StringDelete(HostName); |
| 305 | |
| 306 | // Add host function "functor_square": {externref, i32} -> {i32} |
| 307 | P[0] = WasmEdge_ValTypeGenExternRef(); |
| 308 | P[1] = WasmEdge_ValTypeGenI32(); |
| 309 | R[0] = WasmEdge_ValTypeGenI32(); |
| 310 | HostFType = WasmEdge_FunctionTypeCreate(P, 2, R, 1); |
| 311 | HostFunc = WasmEdge_FunctionInstanceCreate(HostFType, ExternFunctorSquare, |
| 312 | nullptr, 0); |
| 313 | WasmEdge_FunctionTypeDelete(HostFType); |
| 314 | HostName = WasmEdge_StringCreateByCString("functor_square"); |
| 315 | WasmEdge_ModuleInstanceAddFunction(HostMod, HostName, HostFunc); |
| 316 | WasmEdge_StringDelete(HostName); |
| 317 | |
| 318 | // Add host function "class_add": {externref, i32, i32} -> {i32} |
| 319 | P[2] = WasmEdge_ValTypeGenI32(); |
| 320 | HostFType = WasmEdge_FunctionTypeCreate(P, 3, R, 1); |
| 321 | HostFunc = |
| 322 | WasmEdge_FunctionInstanceCreate(HostFType, ExternClassAdd, nullptr, 0); |
| 323 | WasmEdge_FunctionTypeDelete(HostFType); |
| 324 | HostName = WasmEdge_StringCreateByCString("class_add"); |
| 325 | WasmEdge_ModuleInstanceAddFunction(HostMod, HostName, HostFunc); |
| 326 | WasmEdge_StringDelete(HostName); |
| 327 | |
| 328 | // Add host function "func_mul": {externref, i32, i32} -> {i32} |
| 329 | HostFType = WasmEdge_FunctionTypeCreate(P, 3, R, 1); |
| 330 | HostFunc = |
| 331 | WasmEdge_FunctionInstanceCreate(HostFType, ExternFuncMul, nullptr, 0); |
| 332 | WasmEdge_FunctionTypeDelete(HostFType); |
| 333 | HostName = WasmEdge_StringCreateByCString("func_mul"); |
| 334 | WasmEdge_ModuleInstanceAddFunction(HostMod, HostName, HostFunc); |
| 335 | WasmEdge_StringDelete(HostName); |
| 336 | |
| 337 | // Add host function "stl_ostream_str": {externref, externref} -> {} |
| 338 | P[1] = WasmEdge_ValTypeGenExternRef(); |
| 339 | HostFType = WasmEdge_FunctionTypeCreate(P, 2, nullptr, 0); |
| 340 | HostFunc = WasmEdge_FunctionInstanceCreate(HostFType, ExternSTLOStreamStr, |
| 341 | nullptr, 0); |
| 342 | WasmEdge_FunctionTypeDelete(HostFType); |
| 343 | HostName = WasmEdge_StringCreateByCString("stl_ostream_str"); |
| 344 | WasmEdge_ModuleInstanceAddFunction(HostMod, HostName, HostFunc); |
| 345 | WasmEdge_StringDelete(HostName); |
| 346 | |
| 347 | // Add host function "stl_ostream_u32": {externref, i32} -> {} |
| 348 | P[1] = WasmEdge_ValTypeGenI32(); |
| 349 | HostFType = WasmEdge_FunctionTypeCreate(P, 2, nullptr, 0); |
| 350 | HostFunc = WasmEdge_FunctionInstanceCreate(HostFType, ExternSTLOStreamU32, |
| 351 | nullptr, 0); |
| 352 | WasmEdge_FunctionTypeDelete(HostFType); |
no test coverage detected