Serialize import description. See "include/loader/serialize.h".
| 8 | |
| 9 | // Serialize import description. See "include/loader/serialize.h". |
| 10 | Expect<void> |
| 11 | Serializer::serializeDesc(const AST::ImportDesc &Desc, |
| 12 | std::vector<uint8_t> &OutVec) const noexcept { |
| 13 | // Import description: modname:vec(byte) + extname:vec(byte) + importdesc |
| 14 | // Module name: vec(byte). |
| 15 | serializeU32(static_cast<uint32_t>(Desc.getModuleName().size()), OutVec); |
| 16 | OutVec.insert(OutVec.end(), Desc.getModuleName().begin(), |
| 17 | Desc.getModuleName().end()); |
| 18 | // External name: vec(byte). |
| 19 | serializeU32(static_cast<uint32_t>(Desc.getExternalName().size()), OutVec); |
| 20 | OutVec.insert(OutVec.end(), Desc.getExternalName().begin(), |
| 21 | Desc.getExternalName().end()); |
| 22 | |
| 23 | // Import Desc: extern_type:byte + content:idx|tabletype|memorytype|globaltype |
| 24 | OutVec.push_back(static_cast<uint8_t>(Desc.getExternalType())); |
| 25 | switch (Desc.getExternalType()) { |
| 26 | case ExternalType::Function: |
| 27 | serializeU32(Desc.getExternalFuncTypeIdx(), OutVec); |
| 28 | break; |
| 29 | case ExternalType::Table: |
| 30 | return serializeType(Desc.getExternalTableType(), OutVec); |
| 31 | case ExternalType::Memory: |
| 32 | return serializeType(Desc.getExternalMemoryType(), OutVec); |
| 33 | case ExternalType::Global: |
| 34 | if (Desc.getExternalGlobalType().getValMut() == ValMut::Var && |
| 35 | unlikely(!Conf.hasProposal(Proposal::ImportExportMutGlobals))) { |
| 36 | return logNeedProposal(ErrCode::Value::InvalidMut, |
| 37 | Proposal::ImportExportMutGlobals, |
| 38 | ASTNodeAttr::Desc_Import); |
| 39 | } |
| 40 | return serializeType(Desc.getExternalGlobalType(), OutVec); |
| 41 | case ExternalType::Tag: |
| 42 | if (!Conf.hasProposal(Proposal::ExceptionHandling)) { |
| 43 | return logNeedProposal(ErrCode::Value::MalformedImportKind, |
| 44 | Proposal::ExceptionHandling, ASTNodeAttr::Module); |
| 45 | } |
| 46 | return serializeType(Desc.getExternalTagType(), OutVec); |
| 47 | default: |
| 48 | return logSerializeError(ErrCode::Value::Unreachable, |
| 49 | ASTNodeAttr::Desc_Import); |
| 50 | } |
| 51 | return {}; |
| 52 | } |
| 53 | |
| 54 | // Serialize export description. See "include/loader/serialize.h". |
| 55 | Expect<void> |
nothing calls this directly
no test coverage detected