diff --git a/include/wabt/common.h b/include/wabt/common.h index 2ae1fa1fe9..54aeb91268 100644 --- a/include/wabt/common.h +++ b/include/wabt/common.h @@ -166,7 +166,7 @@ Dst WABT_VECTORCALL Bitcast(Src&& value) { template void ZeroMemory(T& v) { - WABT_STATIC_ASSERT(std::is_pod::value); + WABT_STATIC_ASSERT(std::is_trivial::value); memset(&v, 0, sizeof(v)); } diff --git a/include/wabt/interp/interp-inl.h b/include/wabt/interp/interp-inl.h index 23a70e98d5..0a60ea352a 100644 --- a/include/wabt/interp/interp-inl.h +++ b/include/wabt/interp/interp-inl.h @@ -145,7 +145,7 @@ inline bool FreeList::IsUsed(Index index) const { } template <> -inline FreeList::~FreeList() {} +inline FreeList::~FreeList() {} template <> template @@ -181,7 +181,7 @@ bool FreeList::IsUsed(Index index) const { } template -FreeList::~FreeList() { +FreeList::~FreeList() { for (auto object : list_) { if ((reinterpret_cast(object) & ptrFreeBit) == 0) { delete object; @@ -407,14 +407,37 @@ bool operator!=(const RefPtr& lhs, const RefPtr& rhs) { } //// ValueType //// -inline bool IsReference(ValueType type) { return type.IsRef(); } -template <> inline bool HasType(ValueType type) { return type == ValueType::I32; } -template <> inline bool HasType(ValueType type) { return type == ValueType::I32; } -template <> inline bool HasType(ValueType type) { return type == ValueType::I64; } -template <> inline bool HasType(ValueType type) { return type == ValueType::I64; } -template <> inline bool HasType(ValueType type) { return type == ValueType::F32; } -template <> inline bool HasType(ValueType type) { return type == ValueType::F64; } -template <> inline bool HasType(ValueType type) { return IsReference(type); } +inline bool IsReference(ValueType type) { + return type.IsRef(); +} +template <> +inline bool HasType(ValueType type) { + return type == ValueType::I32; +} +template <> +inline bool HasType(ValueType type) { + return type == ValueType::I32; +} +template <> +inline bool HasType(ValueType type) { + return type == ValueType::I64; +} +template <> +inline bool HasType(ValueType type) { + return type == ValueType::I64; +} +template <> +inline bool HasType(ValueType type) { + return type == ValueType::F32; +} +template <> +inline bool HasType(ValueType type) { + return type == ValueType::F64; +} +template <> +inline bool HasType(ValueType type) { + return IsReference(type); +} template void RequireType(ValueType type) { @@ -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 Value WABT_VECTORCALL Value::Make(Simd val) { Value res; @@ -444,38 +507,158 @@ Value WABT_VECTORCALL Value::Make(Simd val) { return res; } -template <> inline s8 WABT_VECTORCALL Value::Get() const { CheckType(ValueType::I32); return i32_; } -template <> inline u8 WABT_VECTORCALL Value::Get() const { CheckType(ValueType::I32); return i32_; } -template <> inline s16 WABT_VECTORCALL Value::Get() const { CheckType(ValueType::I32); return i32_; } -template <> inline u16 WABT_VECTORCALL Value::Get() const { CheckType(ValueType::I32); return i32_; } -template <> inline s32 WABT_VECTORCALL Value::Get() const { CheckType(ValueType::I32); return i32_; } -template <> inline u32 WABT_VECTORCALL Value::Get() const { CheckType(ValueType::I32); return i32_; } -template <> inline s64 WABT_VECTORCALL Value::Get() const { CheckType(ValueType::I64); return i64_; } -template <> inline u64 WABT_VECTORCALL Value::Get() const { CheckType(ValueType::I64); return i64_; } -template <> inline f32 WABT_VECTORCALL Value::Get() const { CheckType(ValueType::F32); return f32_; } -template <> inline f64 WABT_VECTORCALL Value::Get() const { CheckType(ValueType::F64); return f64_; } -template <> inline v128 WABT_VECTORCALL Value::Get() const { CheckType(ValueType::V128); return v128_; } -template <> inline Ref WABT_VECTORCALL Value::Get() const { CheckType(ValueType::ExternRef); return ref_; } - -template <> inline s8x16 WABT_VECTORCALL Value::Get() const { CheckType(ValueType::V128); return Bitcast(v128_); } -template <> inline u8x16 WABT_VECTORCALL Value::Get() const { CheckType(ValueType::V128); return Bitcast(v128_); } -template <> inline s16x8 WABT_VECTORCALL Value::Get() const { CheckType(ValueType::V128); return Bitcast(v128_); } -template <> inline u16x8 WABT_VECTORCALL Value::Get() const { CheckType(ValueType::V128); return Bitcast(v128_); } -template <> inline s32x4 WABT_VECTORCALL Value::Get() const { CheckType(ValueType::V128); return Bitcast(v128_); } -template <> inline u32x4 WABT_VECTORCALL Value::Get() const { CheckType(ValueType::V128); return Bitcast(v128_); } -template <> inline s64x2 WABT_VECTORCALL Value::Get() const { CheckType(ValueType::V128); return Bitcast(v128_); } -template <> inline u64x2 WABT_VECTORCALL Value::Get() const { CheckType(ValueType::V128); return Bitcast(v128_); } -template <> inline f32x4 WABT_VECTORCALL Value::Get() const { CheckType(ValueType::V128); return Bitcast(v128_); } -template <> inline f64x2 WABT_VECTORCALL Value::Get() const { CheckType(ValueType::V128); return Bitcast(v128_); } - -template <> inline void WABT_VECTORCALL Value::Set(s32 val) { i32_ = val; SetType(ValueType::I32); } -template <> inline void WABT_VECTORCALL Value::Set(u32 val) { i32_ = val; SetType(ValueType::I32); } -template <> inline void WABT_VECTORCALL Value::Set(s64 val) { i64_ = val; SetType(ValueType::I64); } -template <> inline void WABT_VECTORCALL Value::Set(u64 val) { i64_ = val; SetType(ValueType::I64); } -template <> inline void WABT_VECTORCALL Value::Set(f32 val) { f32_ = val; SetType(ValueType::F32); } -template <> inline void WABT_VECTORCALL Value::Set(f64 val) { f64_ = val; SetType(ValueType::F64); } -template <> inline void WABT_VECTORCALL Value::Set(v128 val) { v128_ = val; SetType(ValueType::V128); } -template <> inline void WABT_VECTORCALL Value::Set(Ref val) { ref_ = val; SetType(ValueType::ExternRef); } +template <> +inline s8 WABT_VECTORCALL Value::Get() const { + CheckType(ValueType::I32); + return i32_; +} +template <> +inline u8 WABT_VECTORCALL Value::Get() const { + CheckType(ValueType::I32); + return i32_; +} +template <> +inline s16 WABT_VECTORCALL Value::Get() const { + CheckType(ValueType::I32); + return i32_; +} +template <> +inline u16 WABT_VECTORCALL Value::Get() const { + CheckType(ValueType::I32); + return i32_; +} +template <> +inline s32 WABT_VECTORCALL Value::Get() const { + CheckType(ValueType::I32); + return i32_; +} +template <> +inline u32 WABT_VECTORCALL Value::Get() const { + CheckType(ValueType::I32); + return i32_; +} +template <> +inline s64 WABT_VECTORCALL Value::Get() const { + CheckType(ValueType::I64); + return i64_; +} +template <> +inline u64 WABT_VECTORCALL Value::Get() const { + CheckType(ValueType::I64); + return i64_; +} +template <> +inline f32 WABT_VECTORCALL Value::Get() const { + CheckType(ValueType::F32); + return f32_; +} +template <> +inline f64 WABT_VECTORCALL Value::Get() const { + CheckType(ValueType::F64); + return f64_; +} +template <> +inline v128 WABT_VECTORCALL Value::Get() const { + CheckType(ValueType::V128); + return v128_; +} +template <> +inline Ref WABT_VECTORCALL Value::Get() const { + CheckType(ValueType::ExternRef); + return ref_; +} + +template <> +inline s8x16 WABT_VECTORCALL Value::Get() const { + CheckType(ValueType::V128); + return Bitcast(v128_); +} +template <> +inline u8x16 WABT_VECTORCALL Value::Get() const { + CheckType(ValueType::V128); + return Bitcast(v128_); +} +template <> +inline s16x8 WABT_VECTORCALL Value::Get() const { + CheckType(ValueType::V128); + return Bitcast(v128_); +} +template <> +inline u16x8 WABT_VECTORCALL Value::Get() const { + CheckType(ValueType::V128); + return Bitcast(v128_); +} +template <> +inline s32x4 WABT_VECTORCALL Value::Get() const { + CheckType(ValueType::V128); + return Bitcast(v128_); +} +template <> +inline u32x4 WABT_VECTORCALL Value::Get() const { + CheckType(ValueType::V128); + return Bitcast(v128_); +} +template <> +inline s64x2 WABT_VECTORCALL Value::Get() const { + CheckType(ValueType::V128); + return Bitcast(v128_); +} +template <> +inline u64x2 WABT_VECTORCALL Value::Get() const { + CheckType(ValueType::V128); + return Bitcast(v128_); +} +template <> +inline f32x4 WABT_VECTORCALL Value::Get() const { + CheckType(ValueType::V128); + return Bitcast(v128_); +} +template <> +inline f64x2 WABT_VECTORCALL Value::Get() const { + CheckType(ValueType::V128); + return Bitcast(v128_); +} + +template <> +inline void WABT_VECTORCALL Value::Set(s32 val) { + i32_ = val; + SetType(ValueType::I32); +} +template <> +inline void WABT_VECTORCALL Value::Set(u32 val) { + i32_ = val; + SetType(ValueType::I32); +} +template <> +inline void WABT_VECTORCALL Value::Set(s64 val) { + i64_ = val; + SetType(ValueType::I64); +} +template <> +inline void WABT_VECTORCALL Value::Set(u64 val) { + i64_ = val; + SetType(ValueType::I64); +} +template <> +inline void WABT_VECTORCALL Value::Set(f32 val) { + f32_ = val; + SetType(ValueType::F32); +} +template <> +inline void WABT_VECTORCALL Value::Set(f64 val) { + f64_ = val; + SetType(ValueType::F64); +} +template <> +inline void WABT_VECTORCALL Value::Set(v128 val) { + v128_ = val; + SetType(ValueType::V128); +} +template <> +inline void WABT_VECTORCALL Value::Set(Ref val) { + ref_ = val; + SetType(ValueType::ExternRef); +} //// Store //// inline bool Store::IsValid(Ref ref) const { diff --git a/src/resolve-names.cc b/src/resolve-names.cc index 9f0b3b0269..32ca672deb 100644 --- a/src/resolve-names.cc +++ b/src/resolve-names.cc @@ -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; diff --git a/src/wast-lexer.cc b/src/wast-lexer.cc index 1f89c3ff47..551cfc45ab 100644 --- a/src/wast-lexer.cc +++ b/src/wast-lexer.cc @@ -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(p - line_start_ + 1)); }; return Location(filename_, line_, column(token_start_), column(cursor_));