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

Method loadSection

lib/loader/ast/section.cpp:17–40  ·  view source on GitHub ↗

Load content of custom section. See "include/loader/loader.h".

Source from the content-addressed store, hash-verified

15
16// Load content of custom section. See "include/loader/loader.h".
17Expect<void> Loader::loadSection(AST::CustomSection &Sec) {
18 return loadSectionContent(Sec, [this, &Sec]() -> Expect<void> {
19 auto ReportError = [this](auto E) {
20 return logLoadError(E, FMgr.getLastOffset(), ASTNodeAttr::Sec_Custom);
21 };
22
23 // Read name.
24 auto StartOffset = FMgr.getOffset();
25 EXPECTED_TRY(std::string Name, FMgr.readName().map_error(ReportError));
26 Sec.setName(Name);
27 auto ReadSize = FMgr.getOffset() - StartOffset;
28
29 // Check for overread first, then read the remaining bytes.
30 if (unlikely(Sec.getContentSize() < ReadSize)) {
31 return logLoadError(ErrCode::Value::UnexpectedEnd, FMgr.getLastOffset(),
32 ASTNodeAttr::Sec_Custom);
33 }
34 EXPECTED_TRY(
35 std::vector<uint8_t> Bytes,
36 FMgr.readBytes(Sec.getContentSize() - ReadSize).map_error(ReportError));
37 Sec.getContent().insert(Sec.getContent().end(), Bytes.begin(), Bytes.end());
38 return {};
39 });
40}
41
42// Load vector of type section. See "include/loader/loader.h".
43Expect<void> Loader::loadSection(AST::TypeSection &Sec) {

Callers

nothing calls this directly

Calls 15

unlikelyFunction · 0.85
InfoASTClass · 0.85
getLastOffsetMethod · 0.80
setNameMethod · 0.80
getContentSizeMethod · 0.80
insertMethod · 0.80
hasProposalMethod · 0.80
readByteMethod · 0.80
backMethod · 0.80
setRecursiveInfoMethod · 0.80
EXPECTED_TRYFunction · 0.70
errorFunction · 0.50

Tested by

no test coverage detected