MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / loadRefType

Method loadRefType

lib/loader/ast/type.cpp:82–120  ·  view source on GitHub ↗

Load binary and decode RefType. See "include/loader/loader.h".

Source from the content-addressed store, hash-verified

80
81// Load binary and decode RefType. See "include/loader/loader.h".
82Expect<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".
123Expect<ValType> Loader::loadValType(ASTNodeAttr From, bool IsStorageType) {

Callers

nothing calls this directly

Calls 7

unlikelyFunction · 0.85
ValTypeClass · 0.85
peekByteMethod · 0.80
getLastOffsetMethod · 0.80
hasProposalMethod · 0.80
readByteMethod · 0.80
getOffsetMethod · 0.45

Tested by

no test coverage detected