Load binary and decode ValType. See "include/loader/loader.h".
| 121 | |
| 122 | // Load binary and decode ValType. See "include/loader/loader.h". |
| 123 | Expect<ValType> Loader::loadValType(ASTNodeAttr From, bool IsStorageType) { |
| 124 | // Peek the valtype code. |
| 125 | auto B = FMgr.peekByte(); |
| 126 | if (unlikely(!B)) { |
| 127 | return logLoadError(B.error(), FMgr.getLastOffset(), From); |
| 128 | } |
| 129 | |
| 130 | // Check the first byte for value type cases. |
| 131 | TypeCode Code = static_cast<TypeCode>(*B); |
| 132 | switch (Code) { |
| 133 | case TypeCode::V128: |
| 134 | if (!Conf.hasProposal(Proposal::SIMD)) { |
| 135 | return logNeedProposal(ErrCode::Value::MalformedValType, Proposal::SIMD, |
| 136 | FMgr.getLastOffset(), From); |
| 137 | } |
| 138 | [[fallthrough]]; |
| 139 | case TypeCode::I32: |
| 140 | case TypeCode::I64: |
| 141 | case TypeCode::F32: |
| 142 | case TypeCode::F64: |
| 143 | FMgr.readByte(); |
| 144 | return ValType(Code); |
| 145 | case TypeCode::I8: |
| 146 | case TypeCode::I16: |
| 147 | // Packed types are for GC proposal. The proposal checking should be handled |
| 148 | // in the parent scope. |
| 149 | if (!IsStorageType) { |
| 150 | return logLoadError(ErrCode::Value::MalformedValType, FMgr.getOffset(), |
| 151 | From); |
| 152 | } |
| 153 | FMgr.readByte(); |
| 154 | return ValType(Code); |
| 155 | default: |
| 156 | return loadRefType(From); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | Expect<ValMut> Loader::loadMutability(ASTNodeAttr From) { |
| 161 | // Read the mutability byte. |
nothing calls this directly
no test coverage detected