Load component core:module section. See "include/loader/loader.h".
| 8 | |
| 9 | // Load component core:module section. See "include/loader/loader.h". |
| 10 | Expect<void> Loader::loadSection(AST::Component::CoreModuleSection &Sec) { |
| 11 | return loadSectionContent(Sec, [this, &Sec]() -> Expect<void> { |
| 12 | auto ReportError = [](auto E) { |
| 13 | spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Comp_Sec_CoreMod)); |
| 14 | return E; |
| 15 | }; |
| 16 | auto ExpectedSize = Sec.getContentSize(); |
| 17 | auto StartOffset = FMgr.getOffset(); |
| 18 | |
| 19 | EXPECTED_TRY(auto Preamble, Loader::loadPreamble().map_error(ReportError)); |
| 20 | auto &[WasmMagic, Ver] = Preamble; |
| 21 | if (unlikely(Ver != ModuleVersion)) { |
| 22 | return logLoadError(ErrCode::Value::MalformedVersion, |
| 23 | FMgr.getLastOffset(), ASTNodeAttr::Comp_Sec_CoreMod); |
| 24 | } |
| 25 | AST::Module &CoreMod = Sec.getContent(); |
| 26 | CoreMod.getMagic() = WasmMagic; |
| 27 | CoreMod.getVersion() = Ver; |
| 28 | |
| 29 | auto Offset = FMgr.getOffset(); |
| 30 | if (unlikely(ExpectedSize < Offset - StartOffset)) { |
| 31 | return logLoadError(ErrCode::Value::UnexpectedEnd, FMgr.getLastOffset(), |
| 32 | ASTNodeAttr::Comp_Sec_CoreMod); |
| 33 | } |
| 34 | |
| 35 | EXPECTED_TRY(loadModule(CoreMod, ExpectedSize - (Offset - StartOffset)) |
| 36 | .map_error(ReportError)); |
| 37 | return {}; |
| 38 | }); |
| 39 | } |
| 40 | |
| 41 | // Load component core:instance section. See "include/loader/loader.h". |
| 42 | Expect<void> Loader::loadSection(AST::Component::CoreInstanceSection &Sec) { |
nothing calls this directly
no test coverage detected