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

Method loadType

lib/loader/ast/component/component_valtype.cpp:22–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20}
21
22Expect<void> Loader::loadType(ComponentValType &Ty) {
23 // valtype ::= i:<typeidx> => i
24 // | pvt:<primvaltype> => pvt
25
26 EXPECTED_TRY(int64_t Val, FMgr.readS33().map_error([this](auto E) {
27 return logLoadError(E, FMgr.getLastOffset(), ASTNodeAttr::Comp_ValueType);
28 }));
29 if (Val < 0) {
30 // PrimValType case.
31 if (Val < -64) {
32 // Check for an invalid s33 value larger than 1 byte.
33 return logLoadError(ErrCode::Value::MalformedValType,
34 FMgr.getLastOffset(), ASTNodeAttr::Comp_ValueType);
35 }
36 AST::Component::PrimValType PVT = static_cast<AST::Component::PrimValType>(
37 static_cast<uint8_t>(Val & INT64_C(0x7F)));
38 switch (PVT) {
39 case AST::Component::PrimValType::Bool:
40 case AST::Component::PrimValType::S8:
41 case AST::Component::PrimValType::U8:
42 case AST::Component::PrimValType::S16:
43 case AST::Component::PrimValType::U16:
44 case AST::Component::PrimValType::S32:
45 case AST::Component::PrimValType::U32:
46 case AST::Component::PrimValType::S64:
47 case AST::Component::PrimValType::U64:
48 case AST::Component::PrimValType::F32:
49 case AST::Component::PrimValType::F64:
50 case AST::Component::PrimValType::Char:
51 case AST::Component::PrimValType::String:
52 case AST::Component::PrimValType::ErrorContext:
53 Ty.setCode(static_cast<ComponentTypeCode>(PVT));
54 break;
55 default:
56 return logLoadError(ErrCode::Value::MalformedValType,
57 FMgr.getLastOffset(), ASTNodeAttr::Comp_ValueType);
58 }
59 } else {
60 // Type index case.
61 Ty.setTypeIndex(static_cast<uint32_t>(Val));
62 }
63 return {};
64}
65
66Expect<void> Loader::loadType(AST::Component::LabelValType &Ty) {
67 // labelvaltype ::= l:<label'> t:<valtype>

Callers

nothing calls this directly

Calls 6

getLastOffsetMethod · 0.80
setLabelMethod · 0.80
EXPECTED_TRYFunction · 0.70
setCodeMethod · 0.45
setTypeIndexMethod · 0.45
setValTypeMethod · 0.45

Tested by

no test coverage detected