5#ifndef V8_WASM_WASM_VALUE_H_
6#define V8_WASM_WASM_VALUE_H_
8#if !V8_ENABLE_WEBASSEMBLY
9#error This header should only be included if WebAssembly is enabled.
17#include "third_party/fp16/src/include/fp16.h"
30#define FOREACH_PRIMITIVE_WASMVAL_TYPE(V) \
31 V(i8, kWasmI8, int8_t) \
32 V(i16, kWasmI16, int16_t) \
33 V(i32, kWasmI32, int32_t) \
34 V(u32, kWasmI32, uint32_t) \
35 V(i64, kWasmI64, int64_t) \
36 V(u64, kWasmI64, uint64_t) \
37 V(f16, kWasmF16, uint16_t) \
38 V(f32, kWasmF32, float) \
39 V(f32_boxed, kWasmF32, Float32) \
40 V(f64, kWasmF64, double) \
41 V(f64_boxed, kWasmF64, Float64) \
42 V(s128, kWasmS128, Simd128)
51#define DEFINE_TYPE_SPECIFIC_METHODS(name, localtype, ctype) \
52 explicit WasmValue(ctype v) : type_(localtype), bit_pattern_{} { \
53 static_assert(sizeof(ctype) <= sizeof(bit_pattern_), \
54 "size too big for WasmValue"); \
55 base::WriteUnalignedValue<ctype>(reinterpret_cast<Address>(bit_pattern_), \
58 ctype to_##name() const { \
59 DCHECK_EQ(localtype, type_); \
60 return to_##name##_unchecked(); \
62 ctype to_##name##_unchecked() const { \
63 return base::ReadUnalignedValue<ctype>( \
64 reinterpret_cast<Address>(bit_pattern_)); \
68#undef DEFINE_TYPE_SPECIFIC_METHODS
79 "bit_pattern_ must be large enough to fit a Handle");
80 DCHECK(type.is_reference());
97 return type_ == other.type_ &&
104 static_assert(
sizeof(float) ==
sizeof(
Float32));
105 static_assert(
sizeof(double) ==
sizeof(
Float64));
115 return WasmValue(
static_cast<int8_t
>(to_i32()));
119 return WasmValue(
static_cast<int16_t
>(to_i32()));
124 template <
typename T>
127 template <
typename T>
132 std::conditional<kSystemPointerSize == 8, uint64_t, uint32_t>::type;
139 return std::to_string(to_i8());
141 return std::to_string(to_i16());
143 return std::to_string(to_i32());
145 return std::to_string(to_i64());
147 return std::to_string(fp16_ieee_to_fp32_value(to_f16()));
149 return std::to_string(to_f32());
151 return std::to_string(to_f64());
153 std::stringstream stream;
154 stream <<
"0x" << std::hex;
156 if (!(uint8_t & 0xf0)) stream <<
'0';
163 return "DirectHandle [" + std::to_string(
to_ref().address()) +
"]";
174 return static_cast<uint32_t
>(std::count(
184#define DECLARE_CAST(name, localtype, ctype, ...) \
186 inline ctype WasmValue::to_unchecked() const { \
187 return to_##name##_unchecked(); \
190 inline ctype WasmValue::to() const { \
191 return to_##name(); \
#define DECLARE_CAST(CamelName)
constexpr int value_kind_size() const
constexpr ValueKind kind() const
constexpr bool is_reference() const
constexpr bool is_numeric() const
const WasmModule * module_
DirectHandle< Object > to_ref() const
void CopyTo(uint8_t *to) const
bool zero_byte_representation()
bool operator==(const WasmValue &other) const
std::string to_string() const
static WasmValue ForUintPtr(uintptr_t value)
WasmValue Packed(ValueType packed_type) const
WasmValue(const uint8_t *raw_bytes, CanonicalValueType type)
WasmValue(DirectHandle< Object > ref, CanonicalValueType type)
const WasmModule * module() const
CanonicalValueType type() const
static V ReadUnalignedValue(Address p)
static void WriteUnalignedValue(Address p, V value)
FloatWithBits< 32 > Float32
FloatWithBits< 64 > Float64
constexpr IndependentValueType kWasmI8
constexpr IndependentValueType kWasmI32
constexpr IndependentHeapType kWasmVoid
constexpr IndependentValueType kWasmI16
wasm::WasmModule WasmModule
#define DCHECK(condition)
#define DCHECK_EQ(v1, v2)
#define ASSERT_TRIVIALLY_COPYABLE(T)
#define DEFINE_TYPE_SPECIFIC_METHODS(name, localtype, ctype)
#define FOREACH_PRIMITIVE_WASMVAL_TYPE(V)