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

Method loadSegment

lib/loader/ast/segment.cpp:10–54  ·  view source on GitHub ↗

Load binary of TableSegment node. See "include/loader/loader.h".

Source from the content-addressed store, hash-verified

8
9// Load binary of TableSegment node. See "include/loader/loader.h".
10Expect<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".
57Expect<void> Loader::loadSegment(AST::GlobalSegment &GlobSeg) {

Callers

nothing calls this directly

Calls 15

InfoASTClass · 0.85
unlikelyFunction · 0.85
UnexpectFunction · 0.85
ValTypeClass · 0.85
hasProposalMethod · 0.80
getLastOffsetMethod · 0.80
readByteMethod · 0.80
readU32Method · 0.80
getInitExprsMethod · 0.80
backMethod · 0.80
setSegSizeMethod · 0.80
getSegSizeMethod · 0.80

Tested by

no test coverage detected