Skip to content

Commit

Permalink
C++20 compatibility fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
shravanrn committed Jun 20, 2023
1 parent 5edb241 commit b23f203
Show file tree
Hide file tree
Showing 4 changed files with 241 additions and 58 deletions.
2 changes: 1 addition & 1 deletion include/wabt/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ Dst WABT_VECTORCALL Bitcast(Src&& value) {

template <typename T>
void ZeroMemory(T& v) {
WABT_STATIC_ASSERT(std::is_pod<T>::value);
WABT_STATIC_ASSERT(std::is_trivial<T>::value);
memset(&v, 0, sizeof(v));
}

Expand Down
283 changes: 233 additions & 50 deletions include/wabt/interp/interp-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ inline bool FreeList<Ref>::IsUsed(Index index) const {
}

template <>
inline FreeList<Ref>::~FreeList<Ref>() {}
inline FreeList<Ref>::~FreeList() {}

template <>
template <typename... Args>
Expand Down Expand Up @@ -181,7 +181,7 @@ bool FreeList<T>::IsUsed(Index index) const {
}

template <typename T>
FreeList<T>::~FreeList<T>() {
FreeList<T>::~FreeList() {
for (auto object : list_) {
if ((reinterpret_cast<uintptr_t>(object) & ptrFreeBit) == 0) {
delete object;
Expand Down Expand Up @@ -407,14 +407,37 @@ bool operator!=(const RefPtr<U>& lhs, const RefPtr<V>& rhs) {
}

//// ValueType ////
inline bool IsReference(ValueType type) { return type.IsRef(); }
template <> inline bool HasType<s32>(ValueType type) { return type == ValueType::I32; }
template <> inline bool HasType<u32>(ValueType type) { return type == ValueType::I32; }
template <> inline bool HasType<s64>(ValueType type) { return type == ValueType::I64; }
template <> inline bool HasType<u64>(ValueType type) { return type == ValueType::I64; }
template <> inline bool HasType<f32>(ValueType type) { return type == ValueType::F32; }
template <> inline bool HasType<f64>(ValueType type) { return type == ValueType::F64; }
template <> inline bool HasType<Ref>(ValueType type) { return IsReference(type); }
inline bool IsReference(ValueType type) {
return type.IsRef();
}
template <>
inline bool HasType<s32>(ValueType type) {
return type == ValueType::I32;
}
template <>
inline bool HasType<u32>(ValueType type) {
return type == ValueType::I32;
}
template <>
inline bool HasType<s64>(ValueType type) {
return type == ValueType::I64;
}
template <>
inline bool HasType<u64>(ValueType type) {
return type == ValueType::I64;
}
template <>
inline bool HasType<f32>(ValueType type) {
return type == ValueType::F32;
}
template <>
inline bool HasType<f64>(ValueType type) {
return type == ValueType::F64;
}
template <>
inline bool HasType<Ref>(ValueType type) {
return IsReference(type);
}

template <typename T>
void RequireType(ValueType type) {
Expand All @@ -428,14 +451,54 @@ inline bool TypesMatch(ValueType expected, ValueType actual) {
}

//// Value ////
inline Value WABT_VECTORCALL Value::Make(s32 val) { Value res; res.i32_ = val; res.SetType(ValueType::I32); return res; }
inline Value WABT_VECTORCALL Value::Make(u32 val) { Value res; res.i32_ = val; res.SetType(ValueType::I32); return res; }
inline Value WABT_VECTORCALL Value::Make(s64 val) { Value res; res.i64_ = val; res.SetType(ValueType::I64); return res; }
inline Value WABT_VECTORCALL Value::Make(u64 val) { Value res; res.i64_ = val; res.SetType(ValueType::I64); return res; }
inline Value WABT_VECTORCALL Value::Make(f32 val) { Value res; res.f32_ = val; res.SetType(ValueType::F32); return res; }
inline Value WABT_VECTORCALL Value::Make(f64 val) { Value res; res.f64_ = val; res.SetType(ValueType::F64); return res; }
inline Value WABT_VECTORCALL Value::Make(v128 val) { Value res; res.v128_ = val; res.SetType(ValueType::V128); return res; }
inline Value WABT_VECTORCALL Value::Make(Ref val) { Value res; res.ref_ = val; res.SetType(ValueType::ExternRef); return res; }
inline Value WABT_VECTORCALL Value::Make(s32 val) {
Value res;
res.i32_ = val;
res.SetType(ValueType::I32);
return res;
}
inline Value WABT_VECTORCALL Value::Make(u32 val) {
Value res;
res.i32_ = val;
res.SetType(ValueType::I32);
return res;
}
inline Value WABT_VECTORCALL Value::Make(s64 val) {
Value res;
res.i64_ = val;
res.SetType(ValueType::I64);
return res;
}
inline Value WABT_VECTORCALL Value::Make(u64 val) {
Value res;
res.i64_ = val;
res.SetType(ValueType::I64);
return res;
}
inline Value WABT_VECTORCALL Value::Make(f32 val) {
Value res;
res.f32_ = val;
res.SetType(ValueType::F32);
return res;
}
inline Value WABT_VECTORCALL Value::Make(f64 val) {
Value res;
res.f64_ = val;
res.SetType(ValueType::F64);
return res;
}
inline Value WABT_VECTORCALL Value::Make(v128 val) {
Value res;
res.v128_ = val;
res.SetType(ValueType::V128);
return res;
}
inline Value WABT_VECTORCALL Value::Make(Ref val) {
Value res;
res.ref_ = val;
res.SetType(ValueType::ExternRef);
return res;
}
template <typename T, u8 L>
Value WABT_VECTORCALL Value::Make(Simd<T, L> val) {
Value res;
Expand All @@ -444,38 +507,158 @@ Value WABT_VECTORCALL Value::Make(Simd<T, L> val) {
return res;
}

template <> inline s8 WABT_VECTORCALL Value::Get<s8>() const { CheckType(ValueType::I32); return i32_; }
template <> inline u8 WABT_VECTORCALL Value::Get<u8>() const { CheckType(ValueType::I32); return i32_; }
template <> inline s16 WABT_VECTORCALL Value::Get<s16>() const { CheckType(ValueType::I32); return i32_; }
template <> inline u16 WABT_VECTORCALL Value::Get<u16>() const { CheckType(ValueType::I32); return i32_; }
template <> inline s32 WABT_VECTORCALL Value::Get<s32>() const { CheckType(ValueType::I32); return i32_; }
template <> inline u32 WABT_VECTORCALL Value::Get<u32>() const { CheckType(ValueType::I32); return i32_; }
template <> inline s64 WABT_VECTORCALL Value::Get<s64>() const { CheckType(ValueType::I64); return i64_; }
template <> inline u64 WABT_VECTORCALL Value::Get<u64>() const { CheckType(ValueType::I64); return i64_; }
template <> inline f32 WABT_VECTORCALL Value::Get<f32>() const { CheckType(ValueType::F32); return f32_; }
template <> inline f64 WABT_VECTORCALL Value::Get<f64>() const { CheckType(ValueType::F64); return f64_; }
template <> inline v128 WABT_VECTORCALL Value::Get<v128>() const { CheckType(ValueType::V128); return v128_; }
template <> inline Ref WABT_VECTORCALL Value::Get<Ref>() const { CheckType(ValueType::ExternRef); return ref_; }

template <> inline s8x16 WABT_VECTORCALL Value::Get<s8x16>() const { CheckType(ValueType::V128); return Bitcast<s8x16>(v128_); }
template <> inline u8x16 WABT_VECTORCALL Value::Get<u8x16>() const { CheckType(ValueType::V128); return Bitcast<u8x16>(v128_); }
template <> inline s16x8 WABT_VECTORCALL Value::Get<s16x8>() const { CheckType(ValueType::V128); return Bitcast<s16x8>(v128_); }
template <> inline u16x8 WABT_VECTORCALL Value::Get<u16x8>() const { CheckType(ValueType::V128); return Bitcast<u16x8>(v128_); }
template <> inline s32x4 WABT_VECTORCALL Value::Get<s32x4>() const { CheckType(ValueType::V128); return Bitcast<s32x4>(v128_); }
template <> inline u32x4 WABT_VECTORCALL Value::Get<u32x4>() const { CheckType(ValueType::V128); return Bitcast<u32x4>(v128_); }
template <> inline s64x2 WABT_VECTORCALL Value::Get<s64x2>() const { CheckType(ValueType::V128); return Bitcast<s64x2>(v128_); }
template <> inline u64x2 WABT_VECTORCALL Value::Get<u64x2>() const { CheckType(ValueType::V128); return Bitcast<u64x2>(v128_); }
template <> inline f32x4 WABT_VECTORCALL Value::Get<f32x4>() const { CheckType(ValueType::V128); return Bitcast<f32x4>(v128_); }
template <> inline f64x2 WABT_VECTORCALL Value::Get<f64x2>() const { CheckType(ValueType::V128); return Bitcast<f64x2>(v128_); }

template <> inline void WABT_VECTORCALL Value::Set<s32>(s32 val) { i32_ = val; SetType(ValueType::I32); }
template <> inline void WABT_VECTORCALL Value::Set<u32>(u32 val) { i32_ = val; SetType(ValueType::I32); }
template <> inline void WABT_VECTORCALL Value::Set<s64>(s64 val) { i64_ = val; SetType(ValueType::I64); }
template <> inline void WABT_VECTORCALL Value::Set<u64>(u64 val) { i64_ = val; SetType(ValueType::I64); }
template <> inline void WABT_VECTORCALL Value::Set<f32>(f32 val) { f32_ = val; SetType(ValueType::F32); }
template <> inline void WABT_VECTORCALL Value::Set<f64>(f64 val) { f64_ = val; SetType(ValueType::F64); }
template <> inline void WABT_VECTORCALL Value::Set<v128>(v128 val) { v128_ = val; SetType(ValueType::V128); }
template <> inline void WABT_VECTORCALL Value::Set<Ref>(Ref val) { ref_ = val; SetType(ValueType::ExternRef); }
template <>
inline s8 WABT_VECTORCALL Value::Get<s8>() const {
CheckType(ValueType::I32);
return i32_;
}
template <>
inline u8 WABT_VECTORCALL Value::Get<u8>() const {
CheckType(ValueType::I32);
return i32_;
}
template <>
inline s16 WABT_VECTORCALL Value::Get<s16>() const {
CheckType(ValueType::I32);
return i32_;
}
template <>
inline u16 WABT_VECTORCALL Value::Get<u16>() const {
CheckType(ValueType::I32);
return i32_;
}
template <>
inline s32 WABT_VECTORCALL Value::Get<s32>() const {
CheckType(ValueType::I32);
return i32_;
}
template <>
inline u32 WABT_VECTORCALL Value::Get<u32>() const {
CheckType(ValueType::I32);
return i32_;
}
template <>
inline s64 WABT_VECTORCALL Value::Get<s64>() const {
CheckType(ValueType::I64);
return i64_;
}
template <>
inline u64 WABT_VECTORCALL Value::Get<u64>() const {
CheckType(ValueType::I64);
return i64_;
}
template <>
inline f32 WABT_VECTORCALL Value::Get<f32>() const {
CheckType(ValueType::F32);
return f32_;
}
template <>
inline f64 WABT_VECTORCALL Value::Get<f64>() const {
CheckType(ValueType::F64);
return f64_;
}
template <>
inline v128 WABT_VECTORCALL Value::Get<v128>() const {
CheckType(ValueType::V128);
return v128_;
}
template <>
inline Ref WABT_VECTORCALL Value::Get<Ref>() const {
CheckType(ValueType::ExternRef);
return ref_;
}

template <>
inline s8x16 WABT_VECTORCALL Value::Get<s8x16>() const {
CheckType(ValueType::V128);
return Bitcast<s8x16>(v128_);
}
template <>
inline u8x16 WABT_VECTORCALL Value::Get<u8x16>() const {
CheckType(ValueType::V128);
return Bitcast<u8x16>(v128_);
}
template <>
inline s16x8 WABT_VECTORCALL Value::Get<s16x8>() const {
CheckType(ValueType::V128);
return Bitcast<s16x8>(v128_);
}
template <>
inline u16x8 WABT_VECTORCALL Value::Get<u16x8>() const {
CheckType(ValueType::V128);
return Bitcast<u16x8>(v128_);
}
template <>
inline s32x4 WABT_VECTORCALL Value::Get<s32x4>() const {
CheckType(ValueType::V128);
return Bitcast<s32x4>(v128_);
}
template <>
inline u32x4 WABT_VECTORCALL Value::Get<u32x4>() const {
CheckType(ValueType::V128);
return Bitcast<u32x4>(v128_);
}
template <>
inline s64x2 WABT_VECTORCALL Value::Get<s64x2>() const {
CheckType(ValueType::V128);
return Bitcast<s64x2>(v128_);
}
template <>
inline u64x2 WABT_VECTORCALL Value::Get<u64x2>() const {
CheckType(ValueType::V128);
return Bitcast<u64x2>(v128_);
}
template <>
inline f32x4 WABT_VECTORCALL Value::Get<f32x4>() const {
CheckType(ValueType::V128);
return Bitcast<f32x4>(v128_);
}
template <>
inline f64x2 WABT_VECTORCALL Value::Get<f64x2>() const {
CheckType(ValueType::V128);
return Bitcast<f64x2>(v128_);
}

template <>
inline void WABT_VECTORCALL Value::Set<s32>(s32 val) {
i32_ = val;
SetType(ValueType::I32);
}
template <>
inline void WABT_VECTORCALL Value::Set<u32>(u32 val) {
i32_ = val;
SetType(ValueType::I32);
}
template <>
inline void WABT_VECTORCALL Value::Set<s64>(s64 val) {
i64_ = val;
SetType(ValueType::I64);
}
template <>
inline void WABT_VECTORCALL Value::Set<u64>(u64 val) {
i64_ = val;
SetType(ValueType::I64);
}
template <>
inline void WABT_VECTORCALL Value::Set<f32>(f32 val) {
f32_ = val;
SetType(ValueType::F32);
}
template <>
inline void WABT_VECTORCALL Value::Set<f64>(f64 val) {
f64_ = val;
SetType(ValueType::F64);
}
template <>
inline void WABT_VECTORCALL Value::Set<v128>(v128 val) {
v128_ = val;
SetType(ValueType::V128);
}
template <>
inline void WABT_VECTORCALL Value::Set<Ref>(Ref val) {
ref_ = val;
SetType(ValueType::ExternRef);
}

//// Store ////
inline bool Store::IsValid(Ref ref) const {
Expand Down
12 changes: 6 additions & 6 deletions src/resolve-names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -488,12 +488,12 @@ void NameResolver::VisitFunc(Func* func) {
ResolveFuncTypeVar(&func->decl.type_var);
}

func->bindings.FindDuplicates(
[=](const BindingHash::value_type& a, const BindingHash::value_type& b) {
const char* desc =
(a.second.index < func->GetNumParams()) ? "parameter" : "local";
PrintDuplicateBindingsError(a, b, desc);
});
func->bindings.FindDuplicates([=, this](const BindingHash::value_type& a,
const BindingHash::value_type& b) {
const char* desc =
(a.second.index < func->GetNumParams()) ? "parameter" : "local";
PrintDuplicateBindingsError(a, b, desc);
});

visitor_.VisitFunc(func);
current_func_ = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/wast-lexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ Token WastLexer::GetToken() {
}

Location WastLexer::GetLocation() {
auto column = [=](const char* p) {
auto column = [=, this](const char* p) {
return std::max(1, static_cast<int>(p - line_start_ + 1));
};
return Location(filename_, line_, column(token_start_), column(cursor_));
Expand Down

0 comments on commit b23f203

Please sign in to comment.