| 7 | namespace Loader { |
| 8 | |
| 9 | Expect<void> Loader::loadDesc(AST::Component::CoreImportDesc &Desc) { |
| 10 | auto ReportError = [this](auto E) { |
| 11 | return logLoadError(E, FMgr.getLastOffset(), |
| 12 | ASTNodeAttr::Comp_Desc_CoreImport); |
| 13 | }; |
| 14 | // core:importdesc ::= 0x00 x:typeidx => (func i) |
| 15 | // | 0x01 tt:tabletype => (table tt) |
| 16 | // | 0x02 mt:memtype => (mem mt) |
| 17 | // | 0x03 gt:globaltype => (global gt) |
| 18 | // | 0x04 tt:tagtype => (tag tt) |
| 19 | |
| 20 | EXPECTED_TRY(uint8_t Flag, FMgr.readByte().map_error(ReportError)); |
| 21 | switch (static_cast<ExternalType>(Flag)) { |
| 22 | case ExternalType::Function: { |
| 23 | // Read the function type index. |
| 24 | EXPECTED_TRY(FMgr.readU32().map_error(ReportError).map([&](uint32_t Idx) { |
| 25 | Desc.setTypeIndex(Idx); |
| 26 | })); |
| 27 | return {}; |
| 28 | } |
| 29 | case ExternalType::Table: { |
| 30 | AST::TableType TT; |
| 31 | EXPECTED_TRY(loadType(TT).map_error(ReportError)); |
| 32 | Desc.setTableType(std::move(TT)); |
| 33 | return {}; |
| 34 | } |
| 35 | case ExternalType::Memory: { |
| 36 | AST::MemoryType MT; |
| 37 | EXPECTED_TRY(loadType(MT).map_error(ReportError)); |
| 38 | Desc.setMemoryType(std::move(MT)); |
| 39 | return {}; |
| 40 | } |
| 41 | case ExternalType::Global: { |
| 42 | AST::GlobalType GT; |
| 43 | EXPECTED_TRY(loadType(GT).map_error(ReportError)); |
| 44 | Desc.setGlobalType(std::move(GT)); |
| 45 | return {}; |
| 46 | } |
| 47 | case ExternalType::Tag: { |
| 48 | AST::TagType TT; |
| 49 | EXPECTED_TRY(loadType(TT).map_error(ReportError)); |
| 50 | Desc.setTagType(std::move(TT)); |
| 51 | return {}; |
| 52 | } |
| 53 | default: |
| 54 | return ReportError(ErrCode::Value::IllegalGrammar); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | Expect<void> Loader::loadDesc(AST::Component::ExternDesc &Desc) { |
| 59 | auto ReportError = [this](auto E) { |
nothing calls this directly
no test coverage detected