| 144 | } |
| 145 | |
| 146 | Expect<void> Executor::proxyCallIndirect(Runtime::StackManager &StackMgr, |
| 147 | const uint32_t TableIdx, |
| 148 | const uint32_t FuncTypeIdx, |
| 149 | const uint32_t FuncIdx, |
| 150 | const ValVariant *Args, |
| 151 | ValVariant *Rets) noexcept { |
| 152 | const auto *TabInst = getTabInstByIdx(StackMgr, TableIdx); |
| 153 | assuming(TabInst); |
| 154 | |
| 155 | if (unlikely(FuncIdx >= TabInst->getSize())) { |
| 156 | return Unexpect(ErrCode::Value::UndefinedElement); |
| 157 | } |
| 158 | |
| 159 | auto Ref = TabInst->getRefAddr(FuncIdx); |
| 160 | assuming(Ref); |
| 161 | if (unlikely(Ref->isNull())) { |
| 162 | return Unexpect(ErrCode::Value::UninitializedElement); |
| 163 | } |
| 164 | |
| 165 | const auto *ModInst = StackMgr.getModule(); |
| 166 | assuming(ModInst); |
| 167 | const auto &ExpDefType = **ModInst->getType(FuncTypeIdx); |
| 168 | const auto *FuncInst = retrieveFuncRef(*Ref); |
| 169 | assuming(FuncInst); |
| 170 | bool IsMatch = false; |
| 171 | if (FuncInst->getModule()) { |
| 172 | IsMatch = AST::TypeMatcher::matchType( |
| 173 | ModInst->getTypeList(), *ExpDefType.getTypeIndex(), |
| 174 | FuncInst->getModule()->getTypeList(), FuncInst->getTypeIndex()); |
| 175 | } else { |
| 176 | // Independent host module instance case. Matching the composite type |
| 177 | // directly. |
| 178 | IsMatch = AST::TypeMatcher::matchType( |
| 179 | ModInst->getTypeList(), ExpDefType.getCompositeType(), |
| 180 | FuncInst->getHostFunc().getDefinedType().getCompositeType()); |
| 181 | } |
| 182 | if (!IsMatch) { |
| 183 | return Unexpect(ErrCode::Value::IndirectCallTypeMismatch); |
| 184 | } |
| 185 | |
| 186 | const auto &FuncType = FuncInst->getFuncType(); |
| 187 | const uint32_t ParamsSize = |
| 188 | static_cast<uint32_t>(FuncType.getParamTypes().size()); |
| 189 | const uint32_t ReturnsSize = |
| 190 | static_cast<uint32_t>(FuncType.getReturnTypes().size()); |
| 191 | |
| 192 | for (uint32_t I = 0; I < ParamsSize; ++I) { |
| 193 | StackMgr.push(Args[I]); |
| 194 | } |
| 195 | |
| 196 | auto Instrs = FuncInst->getInstrs(); |
| 197 | EXPECTED_TRY(auto StartIt, enterFunction(StackMgr, *FuncInst, Instrs.end())); |
| 198 | EXPECTED_TRY(execute(StackMgr, StartIt, Instrs.end())); |
| 199 | |
| 200 | for (uint32_t I = 0; I < ReturnsSize; ++I) { |
| 201 | Rets[ReturnsSize - 1 - I] = StackMgr.pop(); |
| 202 | } |
| 203 | return {}; |
nothing calls this directly
no test coverage detected