| 1855 | } |
| 1856 | |
| 1857 | WASMEDGE_CAPI_EXPORT const WasmEdge_GlobalTypeContext * |
| 1858 | WasmEdge_ExportTypeGetGlobalType( |
| 1859 | const WasmEdge_ASTModuleContext *ASTCxt, |
| 1860 | const WasmEdge_ExportTypeContext *Cxt) noexcept { |
| 1861 | try { |
| 1862 | if (ASTCxt && Cxt && |
| 1863 | fromExpTypeCxt(Cxt)->getExternalType() == |
| 1864 | WasmEdge::ExternalType::Global) { |
| 1865 | auto ImpDescs = fromASTModCxt(ASTCxt)->getImportSection().getContent(); |
| 1866 | auto GlobDescs = fromASTModCxt(ASTCxt)->getGlobalSection().getContent(); |
| 1867 | uint32_t ExtIdx = fromExpTypeCxt(Cxt)->getExternalIndex(); |
| 1868 | |
| 1869 | // Indexing the import descriptions. |
| 1870 | std::vector<uint32_t> ImpGlobs; |
| 1871 | ImpGlobs.reserve(ImpDescs.size()); |
| 1872 | for (uint32_t I = 0; I < ImpDescs.size(); I++) { |
| 1873 | if (ImpDescs[I].getExternalType() == WasmEdge::ExternalType::Global) { |
| 1874 | ImpGlobs.push_back(I); |
| 1875 | } |
| 1876 | } |
| 1877 | // Get the global type. |
| 1878 | if (ExtIdx < ImpGlobs.size()) { |
| 1879 | // Imported global. Get the global type from the import desc. |
| 1880 | return toGlobTypeCxt( |
| 1881 | &ImpDescs[ImpGlobs[ExtIdx]].getExternalGlobalType()); |
| 1882 | } else if (ExtIdx < ImpGlobs.size() + GlobDescs.size()) { |
| 1883 | // Module owned global. Get the global type from the section. |
| 1884 | return toGlobTypeCxt( |
| 1885 | &GlobDescs[ExtIdx - ImpGlobs.size()].getGlobalType()); |
| 1886 | } else { |
| 1887 | // Invalid global type index. |
| 1888 | return nullptr; |
| 1889 | } |
| 1890 | } |
| 1891 | } catch (...) { |
| 1892 | handleCAPIError(); |
| 1893 | } |
| 1894 | return nullptr; |
| 1895 | } |
| 1896 | |
| 1897 | // <<<<<<<< WasmEdge export type functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
| 1898 | |