Load content of custom section. See "include/loader/loader.h".
| 15 | |
| 16 | // Load content of custom section. See "include/loader/loader.h". |
| 17 | Expect<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". |
| 43 | Expect<void> Loader::loadSection(AST::TypeSection &Sec) { |
nothing calls this directly
no test coverage detected