Load binary and decode RefType. See "include/loader/loader.h".
| 80 | |
| 81 | // Load binary and decode RefType. See "include/loader/loader.h". |
| 82 | Expect<ValType> Loader::loadRefType(ASTNodeAttr From) { |
| 83 | // Peek the reftype code. |
| 84 | auto B = FMgr.peekByte(); |
| 85 | if (unlikely(!B)) { |
| 86 | return logLoadError(B.error(), FMgr.getLastOffset(), From); |
| 87 | } |
| 88 | |
| 89 | // The error code is different when the reference-types proposal is disabled. |
| 90 | ErrCode::Value FailCode = Conf.hasProposal(Proposal::ReferenceTypes) |
| 91 | ? ErrCode::Value::MalformedRefType |
| 92 | : ErrCode::Value::MalformedElemType; |
| 93 | |
| 94 | // Check the first byte for reference type cases. |
| 95 | TypeCode Code = static_cast<TypeCode>(*B); |
| 96 | switch (Code) { |
| 97 | case TypeCode::ExternRef: |
| 98 | if (!Conf.hasProposal(Proposal::ReferenceTypes)) { |
| 99 | return logNeedProposal(FailCode, Proposal::ReferenceTypes, |
| 100 | FMgr.getOffset(), From); |
| 101 | } |
| 102 | [[fallthrough]]; |
| 103 | case TypeCode::FuncRef: |
| 104 | // The FuncRef (0x70) is always allowed in the RefType even if the |
| 105 | // reference-types proposal not enabled. |
| 106 | FMgr.readByte(); |
| 107 | return ValType(Code); |
| 108 | case TypeCode::Ref: |
| 109 | case TypeCode::RefNull: { |
| 110 | if (!Conf.hasProposal(Proposal::FunctionReferences)) { |
| 111 | return logNeedProposal(FailCode, Proposal::FunctionReferences, |
| 112 | FMgr.getOffset(), From); |
| 113 | } |
| 114 | FMgr.readByte(); |
| 115 | return loadHeapType(Code, From); |
| 116 | } |
| 117 | default: |
| 118 | return loadHeapType(TypeCode::RefNull, From); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | // Load binary and decode ValType. See "include/loader/loader.h". |
| 123 | Expect<ValType> Loader::loadValType(ASTNodeAttr From, bool IsStorageType) { |
nothing calls this directly
no test coverage detected