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

Method compare

test/spec/spectest.cpp:411–699  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

409}
410
411bool SpecTest::compare(const std::pair<std::string, std::string> &Expected,
412 const std::pair<ValVariant, ValType> &Got) const {
413 const auto &TypeStr = Expected.first;
414 const auto &ValStr = Expected.second;
415
416 auto IsRefMatch = [&ValStr](const WasmEdge::RefVariant &R) {
417 if (ValStr == "null"sv) {
418 // If explicitly expected a `null`, the reference must be null.
419 return R.isNull();
420 }
421 if (ValStr == ""sv) {
422 // Opaque expected reference. Always true.
423 return true;
424 }
425 // Explicitly expected the reference value.
426 return static_cast<uint32_t>(reinterpret_cast<uintptr_t>(
427 R.getPtr<void>())) == static_cast<uint32_t>(std::stoul(ValStr));
428 };
429
430 bool IsV128 = (std::string_view(TypeStr).substr(0, 4) == "v128"sv);
431 if (!IsV128 && ValStr.substr(0, 4) == "nan:"sv) {
432 // Handle NaN case
433 // TODO: nan:canonical and nan:arithmetic
434 if (TypeStr == "f32"sv) {
435 if (Got.second.getCode() != TypeCode::F32) {
436 return false;
437 }
438 return std::isnan(Got.first.get<float>());
439 } else if (TypeStr == "f64"sv) {
440 if (Got.second.getCode() != TypeCode::F64) {
441 return false;
442 }
443 return std::isnan(Got.first.get<double>());
444 }
445 } else if (TypeStr == "ref"sv) {
446 // "ref" fits all reference types.
447 if (!Got.second.isRefType()) {
448 return false;
449 }
450 return IsRefMatch(Got.first.get<RefVariant>());
451 } else if (TypeStr == "anyref"sv) {
452 // "anyref" fits all internal reference types.
453 if (!Got.second.isRefType() || Got.second.isExternRefType()) {
454 return false;
455 }
456 return IsRefMatch(Got.first.get<RefVariant>());
457 } else if (TypeStr == "eqref"sv) {
458 // "eqref" fits eqref, structref, arrayref, i31ref, and nullref.
459 if (!Got.second.isRefType()) {
460 return false;
461 }
462 switch (Got.second.getHeapTypeCode()) {
463 case TypeCode::EqRef:
464 case TypeCode::I31Ref:
465 case TypeCode::StructRef:
466 case TypeCode::ArrayRef:
467 case TypeCode::NullRef:
468 break;

Callers 1

isDebuggerActiveFunction · 0.45

Calls 9

isnanFunction · 0.85
isNullMethod · 0.80
substrMethod · 0.80
isRefTypeMethod · 0.80
isExternRefTypeMethod · 0.80
getHeapTypeCodeMethod · 0.80
isFuncRefTypeMethod · 0.80
getCodeMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected