Load binary of TableSegment node. See "include/loader/loader.h".
| 8 | |
| 9 | // Load binary of TableSegment node. See "include/loader/loader.h". |
| 10 | Expect<void> Loader::loadSegment(AST::TableSegment &TabSeg) { |
| 11 | // Check whether the first byte is the reftype in table type. |
| 12 | EXPECTED_TRY(uint8_t CheckByte, FMgr.peekByte().map_error([this](auto E) { |
| 13 | return logLoadError(E, FMgr.getLastOffset(), ASTNodeAttr::Seg_Table); |
| 14 | })); |
| 15 | |
| 16 | if (CheckByte == 0x40U) { |
| 17 | // Table segment case is for FunctionReferences proposal. |
| 18 | if (!Conf.hasProposal(Proposal::FunctionReferences)) { |
| 19 | return logNeedProposal(ErrCode::Value::MalformedTable, |
| 20 | Proposal::FunctionReferences, FMgr.getLastOffset(), |
| 21 | ASTNodeAttr::Seg_Table); |
| 22 | } |
| 23 | FMgr.readByte(); |
| 24 | |
| 25 | // Check the second byte. |
| 26 | EXPECTED_TRY(uint8_t B, FMgr.readByte().map_error([this](auto E) { |
| 27 | return logLoadError(E, FMgr.getLastOffset(), ASTNodeAttr::Seg_Table); |
| 28 | })); |
| 29 | if (B != 0x00U) { |
| 30 | return logLoadError(ErrCode::Value::MalformedTable, FMgr.getLastOffset(), |
| 31 | ASTNodeAttr::Seg_Table); |
| 32 | } |
| 33 | |
| 34 | // Read the table type. |
| 35 | EXPECTED_TRY(loadType(TabSeg.getTableType()).map_error([](auto E) { |
| 36 | spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Seg_Table)); |
| 37 | return E; |
| 38 | })); |
| 39 | |
| 40 | // Read the expression. |
| 41 | EXPECTED_TRY(loadExpression(TabSeg.getExpr()).map_error([](auto E) { |
| 42 | spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Seg_Table)); |
| 43 | return E; |
| 44 | })); |
| 45 | } else { |
| 46 | // The table type case. |
| 47 | EXPECTED_TRY(loadType(TabSeg.getTableType()).map_error([](auto E) { |
| 48 | spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Seg_Table)); |
| 49 | return E; |
| 50 | })); |
| 51 | } |
| 52 | |
| 53 | return {}; |
| 54 | } |
| 55 | |
| 56 | // Load binary of GlobalSegment node. See "include/loader/loader.h". |
| 57 | Expect<void> Loader::loadSegment(AST::GlobalSegment &GlobSeg) { |
nothing calls this directly
no test coverage detected