| 52 | } |
| 53 | |
| 54 | static WasmEdge_ModuleInstanceContext * |
| 55 | CreateTestModule(const struct WasmEdge_ModuleDescriptor *Desc) { |
| 56 | /* Allocate and initialize a host data. */ |
| 57 | printf("Allocate host data\n"); |
| 58 | int32_t *Accumulate = (int32_t *)malloc(sizeof(int32_t)); |
| 59 | *Accumulate = 0; |
| 60 | |
| 61 | /* Create the module instance. */ |
| 62 | WasmEdge_String ModuleName = WasmEdge_StringCreateByCString(Desc->Name); |
| 63 | WasmEdge_ModuleInstanceContext *Mod = |
| 64 | WasmEdge_ModuleInstanceCreateWithData(ModuleName, Accumulate, Finalizer); |
| 65 | WasmEdge_StringDelete(ModuleName); |
| 66 | |
| 67 | WasmEdge_String FuncName; |
| 68 | WasmEdge_FunctionTypeContext *FType; |
| 69 | WasmEdge_FunctionInstanceContext *FuncCxt; |
| 70 | WasmEdge_ValType ParamTypes[2], ReturnTypes[1]; |
| 71 | ParamTypes[0] = WasmEdge_ValTypeGenI32(); |
| 72 | ParamTypes[1] = WasmEdge_ValTypeGenI32(); |
| 73 | ReturnTypes[0] = WasmEdge_ValTypeGenI32(); |
| 74 | |
| 75 | /* Create the "add" function and add it to the module instance. */ |
| 76 | FType = WasmEdge_FunctionTypeCreate(ParamTypes, 2, ReturnTypes, 1); |
| 77 | FuncName = WasmEdge_StringCreateByCString("add"); |
| 78 | FuncCxt = WasmEdge_FunctionInstanceCreate(FType, HostFuncAdd, Accumulate, 0); |
| 79 | WasmEdge_ModuleInstanceAddFunction(Mod, FuncName, FuncCxt); |
| 80 | WasmEdge_StringDelete(FuncName); |
| 81 | /* Create the "sub" function and add it to the module instance. */ |
| 82 | FuncName = WasmEdge_StringCreateByCString("sub"); |
| 83 | FuncCxt = WasmEdge_FunctionInstanceCreate(FType, HostFuncSub, Accumulate, 0); |
| 84 | WasmEdge_ModuleInstanceAddFunction(Mod, FuncName, FuncCxt); |
| 85 | WasmEdge_StringDelete(FuncName); |
| 86 | WasmEdge_FunctionTypeDelete(FType); |
| 87 | |
| 88 | return Mod; |
| 89 | } |
| 90 | |
| 91 | static WasmEdge_ProgramOption PODesc[] = {{ |
| 92 | .Name = "name", |
nothing calls this directly
no test coverage detected