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

Method validateCanonLift

lib/validator/component_validator.cpp:1257–1309  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1255}
1256
1257Expect<void>
1258Validator::validateCanonLift(const AST::Component::Canonical &Canon) noexcept {
1259 const uint32_t CoreFuncIdx = Canon.getIndex();
1260 const uint32_t CoreFuncSpaceSize =
1261 CompCtx.getCoreSortIndexSize(AST::Component::Sort::CoreSortType::Func);
1262 // 1. Core func index bounds.
1263 if (CoreFuncIdx >= CoreFuncSpaceSize) {
1264 spdlog::error(ErrCode::Value::InvalidIndex);
1265 spdlog::error(
1266 " canon lift: core func index {} exceeds core func index space size {}"sv,
1267 CoreFuncIdx, CoreFuncSpaceSize);
1268 spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Comp_Canonical));
1269 return Unexpect(ErrCode::Value::InvalidIndex);
1270 }
1271 const uint32_t TypeIdx = Canon.getTargetIndex();
1272 const uint32_t TypeSpaceSize =
1273 CompCtx.getSortIndexSize(AST::Component::Sort::SortType::Type);
1274 // 2. Target type index bounds.
1275 if (TypeIdx >= TypeSpaceSize) {
1276 spdlog::error(ErrCode::Value::InvalidIndex);
1277 spdlog::error(
1278 " canon lift: type index {} exceeds type index space size {}"sv,
1279 TypeIdx, TypeSpaceSize);
1280 spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Comp_Canonical));
1281 return Unexpect(ErrCode::Value::InvalidIndex);
1282 }
1283 // 3. Target type must be a component FuncType.
1284 const auto *DT = CompCtx.getDefType(TypeIdx);
1285 if (DT == nullptr) {
1286 // Unresolved slot: the index was registered by an import or outer alias
1287 // but the concrete definition has not been filled in yet.
1288 spdlog::error(ErrCode::Value::InvalidTypeReference);
1289 spdlog::error(
1290 " canon lift: target type index {} is an unresolved type slot"sv,
1291 TypeIdx);
1292 spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Comp_Canonical));
1293 return Unexpect(ErrCode::Value::InvalidTypeReference);
1294 }
1295 if (!DT->isFuncType()) {
1296 spdlog::error(ErrCode::Value::InvalidTypeReference);
1297 spdlog::error(
1298 " canon lift: target type index {} does not reference a component func type"sv,
1299 TypeIdx);
1300 spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Comp_Canonical));
1301 return Unexpect(ErrCode::Value::InvalidTypeReference);
1302 }
1303 // 4. Validate canonical options (Lift site allows all).
1304 EXPECTED_TRY(validateCanonOptions(Canon.getOpCode(), Canon.getOptions()));
1305 // 5. Allocate component func, binding the resolved FuncType. Full ABI
1306 // signature match (flat_lifted) deferred as GAP-C-1b.
1307 CompCtx.addFunc(&DT->getFuncType());
1308 return {};
1309}
1310
1311Expect<void>
1312Validator::validateCanonLower(const AST::Component::Canonical &Canon) noexcept {

Callers

nothing calls this directly

Calls 13

InfoASTClass · 0.85
UnexpectFunction · 0.85
isFuncTypeMethod · 0.80
getOptionsMethod · 0.80
errorFunction · 0.50
EXPECTED_TRYFunction · 0.50
getIndexMethod · 0.45
getCoreSortIndexSizeMethod · 0.45
getTargetIndexMethod · 0.45
getSortIndexSizeMethod · 0.45
getDefTypeMethod · 0.45
getOpCodeMethod · 0.45

Tested by

no test coverage detected