MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / WasmEdge_ExportTypeGetFunctionType

Function WasmEdge_ExportTypeGetFunctionType

lib/api/wasmedge.cpp:1711–1755  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1709}
1710
1711WASMEDGE_CAPI_EXPORT const WasmEdge_FunctionTypeContext *
1712WasmEdge_ExportTypeGetFunctionType(
1713 const WasmEdge_ASTModuleContext *ASTCxt,
1714 const WasmEdge_ExportTypeContext *Cxt) noexcept {
1715 try {
1716 if (ASTCxt && Cxt &&
1717 fromExpTypeCxt(Cxt)->getExternalType() ==
1718 WasmEdge::ExternalType::Function) {
1719 auto ImpDescs = fromASTModCxt(ASTCxt)->getImportSection().getContent();
1720 auto FuncIdxs = fromASTModCxt(ASTCxt)->getFunctionSection().getContent();
1721 uint32_t ExtIdx = fromExpTypeCxt(Cxt)->getExternalIndex();
1722
1723 // Indexing the import descriptions.
1724 std::vector<uint32_t> ImpFuncs;
1725 ImpFuncs.reserve(ImpDescs.size());
1726 for (uint32_t I = 0; I < ImpDescs.size(); I++) {
1727 if (ImpDescs[I].getExternalType() == WasmEdge::ExternalType::Function) {
1728 ImpFuncs.push_back(I);
1729 }
1730 }
1731 // Get the function type index.
1732 uint32_t TypeIdx = 0;
1733 if (ExtIdx < ImpFuncs.size()) {
1734 // Imported function. Get the function type index from the import desc.
1735 TypeIdx = ImpDescs[ImpFuncs[ExtIdx]].getExternalFuncTypeIdx();
1736 } else if (ExtIdx < ImpFuncs.size() + FuncIdxs.size()) {
1737 // Module owned function. Get the function type index from the section.
1738 TypeIdx = FuncIdxs[ExtIdx - ImpFuncs.size()];
1739 } else {
1740 // Invalid function index.
1741 return nullptr;
1742 }
1743 // Get the function type.
1744 auto SubTypes = fromASTModCxt(ASTCxt)->getTypeSection().getContent();
1745 if (TypeIdx < SubTypes.size() &&
1746 SubTypes[TypeIdx].getCompositeType().isFunc()) {
1747 return toFuncTypeCxt(
1748 &(SubTypes[TypeIdx].getCompositeType().getFuncType()));
1749 }
1750 }
1751 } catch (...) {
1752 handleCAPIError();
1753 }
1754 return nullptr;
1755}
1756
1757WASMEDGE_CAPI_EXPORT const WasmEdge_TableTypeContext *
1758WasmEdge_ExportTypeGetTableType(

Callers 1

TESTFunction · 0.85

Calls 7

handleCAPIErrorFunction · 0.85
getExternalTypeMethod · 0.80
getExternalIndexMethod · 0.80
getContentMethod · 0.45
sizeMethod · 0.45
isFuncMethod · 0.45

Tested by 1

TESTFunction · 0.68