1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 07:27:45 +00:00

LibWasm: Implement reference instructions (ref.{null,func,is_null})

This commit is contained in:
Ali Mohammad Pur 2021-06-01 09:48:36 +04:30 committed by Ali Mohammad Pur
parent 7fb458b7c9
commit 56bf80251c
8 changed files with 73 additions and 9 deletions

View file

@ -45,7 +45,11 @@ public:
{
}
using AnyValueType = Variant<i32, i64, float, double, FunctionAddress, ExternAddress>;
struct Null {
ValueType type;
};
using AnyValueType = Variant<i32, i64, float, double, FunctionAddress, ExternAddress, Null>;
explicit Value(AnyValueType value)
: m_value(move(value))
, m_type(ValueType::I32)
@ -62,6 +66,8 @@ public:
m_type = ValueType { ValueType::FunctionReference };
else if (m_value.has<ExternAddress>())
m_type = ValueType { ValueType::ExternReference };
else if (m_value.has<Null>())
m_type = ValueType { m_value.get<Null>().type.kind() == ValueType::ExternReference ? ValueType::NullExternReference : ValueType::NullFunctionReference };
else
VERIFY_NOT_REACHED();
}
@ -90,6 +96,14 @@ public:
case ValueType::Kind::F64:
m_value = bit_cast<double>(raw_value);
break;
case ValueType::Kind::NullFunctionReference:
VERIFY(raw_value == 0);
m_value = Null { ValueType(ValueType::Kind::FunctionReference) };
break;
case ValueType::Kind::NullExternReference:
VERIFY(raw_value == 0);
m_value = Null { ValueType(ValueType::Kind::ExternReference) };
break;
default:
VERIFY_NOT_REACHED();
}
@ -139,6 +153,10 @@ public:
[&](const ExternAddress& address) {
if constexpr (IsSame<T, ExternAddress>)
result = address;
},
[&](const Null& null) {
if constexpr (IsSame<T, Null>)
result = null;
});
return result;
}