diff --git a/.gitmodules b/.gitmodules index e5266cfc..6acba23c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,18 +1,12 @@ [submodule "third_party/gtest"] path = third_party/gtest url = https://github.com/google/googletest -[submodule "third_party/fmt"] - path = third_party/fmt - url = https://github.com/fmtlib/fmt -[submodule "third_party/span-lite"] - path = third_party/span-lite - url = https://github.com/martinmoene/span-lite -[submodule "third_party/parallel-hashmap"] - path = third_party/parallel-hashmap - url = https://github.com/greg7mdp/parallel-hashmap [submodule "third_party/gdtoa"] path = third_party/gdtoa url = https://github.com/jwiegley/gdtoa [submodule "third_party/testsuite"] path = third_party/testsuite url = https://github.com/WebAssembly/testsuite +[submodule "third_party/abseil"] + path = third_party/abseil + url = https://github.com/abseil/abseil-cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 9cf4b0ee..ef2206b3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,6 @@ else () set(warning_flags -W3) endif () - add_subdirectory(src/base) add_subdirectory(src/binary) add_subdirectory(src/valid) diff --git a/include/wasp/base/absl_hash_value_macros.h b/include/wasp/base/absl_hash_value_macros.h new file mode 100644 index 00000000..ef03840d --- /dev/null +++ b/include/wasp/base/absl_hash_value_macros.h @@ -0,0 +1,65 @@ +// +// Copyright 2020 WebAssembly Community Group participants +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#ifndef WASP_BASE_ABSL_HASH_VALUE_MACROS_H_ +#define WASP_BASE_ABSL_HASH_VALUE_MACROS_H_ + +#define WASP_ABSL_HASH_VALUE_VARGS(Name, Count, ...) \ + WASP_ABSL_HASH_VALUE_##Count(Name, __VA_ARGS__) + +#define WASP_ABSL_HASH_VALUE_0(Name, ...) \ + template \ + H AbslHashValue(H h, const ::wasp::Name&) { \ + return h; \ + } + +#define WASP_ABSL_HASH_VALUE_1(Name, f1) \ + template \ + H AbslHashValue(H h, const ::wasp::Name& v) { \ + return H::combine(std::move(h), v.f1); \ + } + +#define WASP_ABSL_HASH_VALUE_2(Name, f1, f2) \ + template \ + H AbslHashValue(H h, const ::wasp::Name& v) { \ + return H::combine(std::move(h), v.f1, v.f2); \ + } + +#define WASP_ABSL_HASH_VALUE_3(Name, f1, f2, f3) \ + template \ + H AbslHashValue(H h, const ::wasp::Name& v) { \ + return H::combine(std::move(h), v.f1, v.f2, v.f3); \ + } + +#define WASP_ABSL_HASH_VALUE_4(Name, f1, f2, f3, f4) \ + template \ + H AbslHashValue(H h, const ::wasp::Name& v) { \ + return H::combine(std::move(h), v.f1, v.f2, v.f3, v.f4); \ + } + +#define WASP_ABSL_HASH_VALUE_5(Name, f1, f2, f3, f4, f5) \ + template \ + H AbslHashValue(H h, const ::wasp::Name& v) { \ + return H::combine(std::move(h), v.f1, v.f2, v.f3, v.f4, v.f5); \ + } + +#define WASP_ABSL_HASH_VALUE_CONTAINER(Name) \ + template \ + H AbslHashValue(H h, const ::wasp::Name& v) { \ + return H::combine(std::move(h), v); \ + } + +#endif // WASP_BASE_ABSL_HASH_VALUE_MACROS_H_ diff --git a/include/wasp/base/features.h b/include/wasp/base/features.h index f9af48f5..d38e2fbc 100644 --- a/include/wasp/base/features.h +++ b/include/wasp/base/features.h @@ -17,8 +17,7 @@ #ifndef WASP_BASE_FEATURES_H_ #define WASP_BASE_FEATURES_H_ -#include // for std::hash - +#include "wasp/base/hash.h" #include "wasp/base/types.h" namespace wasp { @@ -73,6 +72,11 @@ class Features { friend bool operator==(const Features& lhs, const Features& rhs); friend bool operator!=(const Features& lhs, const Features& rhs); + template + friend H AbslHashValue(H h, const Features& f) { + return H::combine(std::move(h), f.bits_); + } + private: void UpdateDependencies(); @@ -82,11 +86,4 @@ class Features { } // namespace wasp -namespace std { -template <> -struct hash<::wasp::Features> { - size_t operator()(const ::wasp::Features&) const; -}; -} // namespace std - #endif // WASP_BASE_FEATURES_H_ diff --git a/include/wasp/base/formatters-inl.h b/include/wasp/base/formatters-inl.h index 8d815e6d..7211a057 100644 --- a/include/wasp/base/formatters-inl.h +++ b/include/wasp/base/formatters-inl.h @@ -71,7 +71,7 @@ std::ostream& operator<<(std::ostream& os, const ::std::array& self) { template std::ostream& operator<<(std::ostream& os, const ::std::vector& self) { - return os << ::wasp::span{self}; + return os << ::wasp::MakeSpan(self); } template diff --git a/include/wasp/base/hash.h b/include/wasp/base/hash.h index 702a1271..34ed7798 100644 --- a/include/wasp/base/hash.h +++ b/include/wasp/base/hash.h @@ -19,25 +19,11 @@ #include -#include "parallel_hashmap/phmap_utils.h" +#include "absl/hash/hash.h" namespace wasp { -using phmap::HashState; - -template -size_t HashRange(T1 begin, T2 end) { - size_t state = 0; - for (auto it = begin; it != end; ++it) { - state = HashState::combine(state, *it); - } - return state; -} - -template -size_t HashContainer(const C& c) { - return HashRange(std::begin(c), std::end(c)); -} +using absl::HashState; } // namespace wasp diff --git a/include/wasp/base/hashmap.h b/include/wasp/base/hashmap.h index efd4dfa9..dcfb1b18 100644 --- a/include/wasp/base/hashmap.h +++ b/include/wasp/base/hashmap.h @@ -17,14 +17,17 @@ #ifndef WASP_BASE_HASHMAP_H_ #define WASP_BASE_HASHMAP_H_ -#include "parallel_hashmap/phmap.h" +#include "absl/container/flat_hash_map.h" +#include "absl/container/flat_hash_set.h" +#include "absl/container/node_hash_map.h" +#include "absl/container/node_hash_set.h" namespace wasp { -using phmap::flat_hash_map; -using phmap::flat_hash_set; -using phmap::node_hash_map; -using phmap::node_hash_set; +using absl::flat_hash_map; +using absl::flat_hash_set; +using absl::node_hash_map; +using absl::node_hash_set; } // namespace wasp diff --git a/include/wasp/base/span.h b/include/wasp/base/span.h index 0dd7d1c5..ab7af8f9 100644 --- a/include/wasp/base/span.h +++ b/include/wasp/base/span.h @@ -21,29 +21,25 @@ #include -#include "nonstd/span.hpp" +#include "absl/types/span.h" #include "wasp/base/string_view.h" #include "wasp/base/types.h" namespace wasp { -using nonstd::span; +template +using span = absl::Span; -using nonstd::operator==; -using nonstd::operator!=; -using nonstd::operator<; -using nonstd::operator<=; -using nonstd::operator>; -using nonstd::operator>=; +using absl::operator==; +using absl::operator!=; +using absl::operator<; +using absl::operator<=; +using absl::operator>; +using absl::operator>=; -using span_extent_t = nonstd::span_lite::extent_t; +using absl::MakeSpan; -constexpr span_extent_t dynamic_extent = -1; - -template -void remove_prefix(span* s, span_extent_t offset) { - *s = s->subspan(offset); -} +using span_extent_t = size_t; using SpanU8 = span; using Location = SpanU8; @@ -61,13 +57,4 @@ inline string_view ToStringView(SpanU8 span) { } // namespace wasp -namespace std { - -template <> -struct hash<::wasp::SpanU8> { - size_t operator()(::wasp::SpanU8) const; -}; - -} - #endif // WASP_BASE_SPAN_H_ diff --git a/include/wasp/base/std_hash_macros.h b/include/wasp/base/std_hash_macros.h deleted file mode 100644 index 45130f9d..00000000 --- a/include/wasp/base/std_hash_macros.h +++ /dev/null @@ -1,80 +0,0 @@ -// -// Copyright 2019 WebAssembly Community Group participants -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#ifndef WASP_BASE_STD_HASH_MACROS_H_ -#define WASP_BASE_STD_HASH_MACROS_H_ - -#define WASP_DECLARE_STD_HASH(Name, ...) \ - namespace std { \ - template <> \ - struct hash<::wasp::Name> { \ - size_t operator()(const ::wasp::Name&) const; \ - }; \ - } - -#define WASP_STD_HASH_VARGS(Name, Count, ...) \ - WASP_STD_HASH_##Count(Name, __VA_ARGS__) - -#define WASP_STD_HASH_0(Name, ...) \ - namespace std { \ - size_t hash<::wasp::Name>::operator()(const ::wasp::Name& v) const { \ - return 0; \ - } \ - } - -#define WASP_STD_HASH_1(Name, f1) \ - namespace std { \ - size_t hash<::wasp::Name>::operator()(const ::wasp::Name& v) const { \ - return ::wasp::HashState::combine(0, v.f1); \ - } \ - } - -#define WASP_STD_HASH_2(Name, f1, f2) \ - namespace std { \ - size_t hash<::wasp::Name>::operator()(const ::wasp::Name& v) const { \ - return ::wasp::HashState::combine(0, v.f1, v.f2); \ - } \ - } - -#define WASP_STD_HASH_3(Name, f1, f2, f3) \ - namespace std { \ - size_t hash<::wasp::Name>::operator()(const ::wasp::Name& v) const { \ - return ::wasp::HashState::combine(0, v.f1, v.f2, v.f3); \ - } \ - } - -#define WASP_STD_HASH_4(Name, f1, f2, f3, f4) \ - namespace std { \ - size_t hash<::wasp::Name>::operator()(const ::wasp::Name& v) const { \ - return ::wasp::HashState::combine(0, v.f1, v.f2, v.f3, v.f4); \ - } \ - } - -#define WASP_STD_HASH_5(Name, f1, f2, f3, f4, f5) \ - namespace std { \ - size_t hash<::wasp::Name>::operator()(const ::wasp::Name& v) const { \ - return ::wasp::HashState::combine(0, v.f1, v.f2, v.f3, v.f4, v.f5); \ - } \ - } - -#define WASP_STD_HASH_CONTAINER(Name) \ - namespace std { \ - size_t hash<::wasp::Name>::operator()(const ::wasp::Name& v) const { \ - return ::wasp::HashContainer(v); \ - } \ - } - -#endif // WASP_BASE_STD_HASH_MACROS_H_ diff --git a/include/wasp/base/v128.h b/include/wasp/base/v128.h index cb8fc3b3..7d76c4d6 100644 --- a/include/wasp/base/v128.h +++ b/include/wasp/base/v128.h @@ -81,21 +81,18 @@ class v128 { friend bool operator==(const v128&, const v128&); friend bool operator!=(const v128&, const v128&); + template + friend H AbslHashValue(H h, const v128& f) { + auto u = f.as<::wasp::u64x2>(); + return H::combine(std::move(h), u[0], u[1]); + } + private: u8x16 data_; }; } // namespace wasp -namespace std { - -template <> -struct hash<::wasp::v128> { - size_t operator()(const ::wasp::v128&) const; -}; - -} // namespace std - #include "wasp/base/v128-inl.h" #endif // WASP_BASE_V128_H_ diff --git a/include/wasp/base/wasm_types.h b/include/wasp/base/wasm_types.h index e7663d0d..883a8ac2 100644 --- a/include/wasp/base/wasm_types.h +++ b/include/wasp/base/wasm_types.h @@ -20,9 +20,9 @@ #include #include +#include "wasp/base/absl_hash_value_macros.h" #include "wasp/base/at.h" #include "wasp/base/operator_eq_ne_macros.h" -#include "wasp/base/std_hash_macros.h" #include "wasp/base/types.h" namespace wasp { @@ -144,9 +144,9 @@ using ShuffleImmediate = std::array; WASP_BASE_WASM_STRUCTS(WASP_DECLARE_OPERATOR_EQ_NE) WASP_BASE_WASM_CONTAINERS(WASP_DECLARE_OPERATOR_EQ_NE) -} // namespace wasp +WASP_BASE_WASM_STRUCTS(WASP_ABSL_HASH_VALUE_VARGS) +WASP_BASE_WASM_CONTAINERS(WASP_ABSL_HASH_VALUE_CONTAINER) -WASP_BASE_WASM_STRUCTS(WASP_DECLARE_STD_HASH) -WASP_BASE_WASM_CONTAINERS(WASP_DECLARE_STD_HASH) +} // namespace wasp #endif // WASP_BASE_WASM_TYPES_H_ diff --git a/include/wasp/binary/lazy_sequence-inl.h b/include/wasp/binary/lazy_sequence-inl.h index 415a3709..b5590aeb 100644 --- a/include/wasp/binary/lazy_sequence-inl.h +++ b/include/wasp/binary/lazy_sequence-inl.h @@ -27,7 +27,7 @@ void LazySequence::NotifyRead(const u8* pos, bool ok) { } else if (expected_count_ && count_ != *expected_count_) { // Reached the end, but there was a mismatch. LazySequenceBase::OnCountError(context_.errors, - SpanU8{last_pos_, data_.end()}, name_, + MakeSpan(last_pos_, data_.end()), name_, *expected_count_, count_); } } diff --git a/include/wasp/binary/linking_section/types.h b/include/wasp/binary/linking_section/types.h index 1969affd..ad71e2a3 100644 --- a/include/wasp/binary/linking_section/types.h +++ b/include/wasp/binary/linking_section/types.h @@ -19,11 +19,11 @@ #include +#include "wasp/base/absl_hash_value_macros.h" #include "wasp/base/at.h" #include "wasp/base/operator_eq_ne_macros.h" #include "wasp/base/optional.h" #include "wasp/base/span.h" -#include "wasp/base/std_hash_macros.h" #include "wasp/base/string_view.h" #include "wasp/base/types.h" #include "wasp/base/variant.h" @@ -196,9 +196,9 @@ struct SymbolInfo { WASP_BINARY_LINKING_STRUCTS(WASP_DECLARE_OPERATOR_EQ_NE) WASP_BINARY_LINKING_CONTAINERS(WASP_DECLARE_OPERATOR_EQ_NE) -} // namespace wasp::binary +WASP_BINARY_LINKING_STRUCTS(WASP_ABSL_HASH_VALUE_VARGS) +WASP_BINARY_LINKING_CONTAINERS(WASP_ABSL_HASH_VALUE_CONTAINER) -WASP_BINARY_LINKING_STRUCTS(WASP_DECLARE_STD_HASH) -WASP_BINARY_LINKING_CONTAINERS(WASP_DECLARE_STD_HASH) +} // namespace wasp::binary #endif // WASP_BINARY_LINKING_SECTION_TYPES_H_ diff --git a/include/wasp/binary/name_section/types.h b/include/wasp/binary/name_section/types.h index b58334ca..2e8ef146 100644 --- a/include/wasp/binary/name_section/types.h +++ b/include/wasp/binary/name_section/types.h @@ -19,10 +19,10 @@ #include +#include "wasp/base/absl_hash_value_macros.h" #include "wasp/base/at.h" #include "wasp/base/operator_eq_ne_macros.h" #include "wasp/base/span.h" -#include "wasp/base/std_hash_macros.h" #include "wasp/base/string_view.h" #include "wasp/base/types.h" @@ -65,9 +65,9 @@ struct IndirectNameAssoc { WASP_BINARY_NAME_STRUCTS(WASP_DECLARE_OPERATOR_EQ_NE) WASP_BINARY_NAME_CONTAINERS(WASP_DECLARE_OPERATOR_EQ_NE) -} // namespace wasp::binary +WASP_BINARY_NAME_STRUCTS(WASP_ABSL_HASH_VALUE_VARGS) +WASP_BINARY_NAME_CONTAINERS(WASP_ABSL_HASH_VALUE_CONTAINER) -WASP_BINARY_NAME_STRUCTS(WASP_DECLARE_STD_HASH) -WASP_BINARY_NAME_CONTAINERS(WASP_DECLARE_STD_HASH) +} // namespace wasp::binary #endif // WASP_BINARY_NAME_SECTION_TYPES_H_ diff --git a/include/wasp/binary/read/location_guard.h b/include/wasp/binary/read/location_guard.h index a6f06b05..3e4964c0 100644 --- a/include/wasp/binary/read/location_guard.h +++ b/include/wasp/binary/read/location_guard.h @@ -26,7 +26,7 @@ class LocationGuard { public: explicit LocationGuard(SpanU8* data) : start_{data->begin()} {} - Location range(SpanU8* end) const { return Location{start_, end->begin()}; } + Location range(SpanU8* end) const { return MakeSpan(start_, end->begin()); } private: const u8* start_; diff --git a/include/wasp/binary/types.h b/include/wasp/binary/types.h index 97a45a68..0dfc79aa 100644 --- a/include/wasp/binary/types.h +++ b/include/wasp/binary/types.h @@ -21,11 +21,11 @@ #include #include +#include "wasp/base/absl_hash_value_macros.h" #include "wasp/base/at.h" #include "wasp/base/operator_eq_ne_macros.h" #include "wasp/base/optional.h" #include "wasp/base/span.h" -#include "wasp/base/std_hash_macros.h" #include "wasp/base/string_view.h" #include "wasp/base/types.h" #include "wasp/base/v128.h" @@ -763,9 +763,9 @@ WASP_BINARY_CONTAINERS(WASP_DECLARE_OPERATOR_EQ_NE) WASP_DECLARE_OPERATOR_EQ_NE(binary::Module) -} // namespace wasp::binary +WASP_BINARY_STRUCTS_CUSTOM_FORMAT(WASP_ABSL_HASH_VALUE_VARGS) +WASP_BINARY_CONTAINERS(WASP_ABSL_HASH_VALUE_CONTAINER) -WASP_BINARY_STRUCTS_CUSTOM_FORMAT(WASP_DECLARE_STD_HASH) -WASP_BINARY_CONTAINERS(WASP_DECLARE_STD_HASH) +} // namespace wasp::binary #endif // WASP_BINARY_TYPES_H_ diff --git a/include/wasp/text/numeric-inl.h b/include/wasp/text/numeric-inl.h index 6abab963..6eaefe53 100644 --- a/include/wasp/text/numeric-inl.h +++ b/include/wasp/text/numeric-inl.h @@ -91,7 +91,7 @@ auto StrToNat(LiteralInfo info, SpanU8 span) -> optional { inline void RemoveSign(SpanU8& span, Sign sign) { if (sign != Sign::None) { - remove_prefix(&span, 1); // Remove + or -. + span.remove_prefix(1); // Remove + or -. } } diff --git a/include/wasp/text/read/location_guard.h b/include/wasp/text/read/location_guard.h index 7f89c9a8..b3b2bc3c 100644 --- a/include/wasp/text/read/location_guard.h +++ b/include/wasp/text/read/location_guard.h @@ -28,7 +28,7 @@ class LocationGuard { Location loc() const { auto* end = tokenizer_.Previous().loc.end(); - return Location{start_, start_ <= end ? end : start_}; + return MakeSpan(start_, start_ <= end ? end : start_); } private: diff --git a/include/wasp/text/types.h b/include/wasp/text/types.h index 5908d3d9..2bfa0065 100644 --- a/include/wasp/text/types.h +++ b/include/wasp/text/types.h @@ -20,10 +20,10 @@ #include #include +#include "wasp/base/absl_hash_value_macros.h" #include "wasp/base/at.h" #include "wasp/base/operator_eq_ne_macros.h" #include "wasp/base/optional.h" -#include "wasp/base/std_hash_macros.h" #include "wasp/base/string_view.h" #include "wasp/base/v128.h" #include "wasp/base/variant.h" @@ -1112,10 +1112,10 @@ bool operator==(const ValueTypeList& lhs, const BoundValueTypeList& rhs); bool operator!=(const BoundValueTypeList& lhs, const ValueTypeList& rhs); bool operator!=(const ValueTypeList& lhs, const BoundValueTypeList& rhs); -} // namespace wasp::text +WASP_TEXT_STRUCTS(WASP_ABSL_HASH_VALUE_VARGS) +WASP_TEXT_STRUCTS_CUSTOM_FORMAT(WASP_ABSL_HASH_VALUE_VARGS) +WASP_TEXT_CONTAINERS(WASP_ABSL_HASH_VALUE_CONTAINER) -WASP_TEXT_STRUCTS(WASP_DECLARE_STD_HASH) -WASP_TEXT_STRUCTS_CUSTOM_FORMAT(WASP_DECLARE_STD_HASH) -WASP_TEXT_CONTAINERS(WASP_DECLARE_STD_HASH) +} // namespace wasp::text #endif // WASP_TEXT_TYPES_H_ diff --git a/include/wasp/valid/types.h b/include/wasp/valid/types.h index 1c5d984a..1c1ba4e5 100644 --- a/include/wasp/valid/types.h +++ b/include/wasp/valid/types.h @@ -98,9 +98,9 @@ auto AsNonNullableType(StackType) -> StackType; WASP_VALID_STRUCTS_CUSTOM_FORMAT(WASP_DECLARE_OPERATOR_EQ_NE) WASP_VALID_CONTAINERS(WASP_DECLARE_OPERATOR_EQ_NE) -} // namespace wasp::valid +WASP_VALID_STRUCTS_CUSTOM_FORMAT(WASP_ABSL_HASH_VALUE_VARGS) +WASP_VALID_CONTAINERS(WASP_ABSL_HASH_VALUE_CONTAINER) -WASP_VALID_STRUCTS_CUSTOM_FORMAT(WASP_DECLARE_STD_HASH) -WASP_VALID_CONTAINERS(WASP_DECLARE_STD_HASH) +} // namespace wasp::valid #endif // WASP_VALID_TYPES_H_ diff --git a/src/base/CMakeLists.txt b/src/base/CMakeLists.txt index 16e0761e..7d936197 100644 --- a/src/base/CMakeLists.txt +++ b/src/base/CMakeLists.txt @@ -15,6 +15,7 @@ # add_library(libwasp_base + ../../include/wasp/base/absl_hash_value_macros.h ../../include/wasp/base/at.h ../../include/wasp/base/bitcast.h ../../include/wasp/base/buffer.h @@ -36,7 +37,6 @@ add_library(libwasp_base ../../include/wasp/base/operator_eq_ne_macros.h ../../include/wasp/base/optional.h ../../include/wasp/base/span.h - ../../include/wasp/base/std_hash_macros.h ../../include/wasp/base/str_to_u32.h ../../include/wasp/base/string_view.h ../../include/wasp/base/types.h @@ -65,6 +65,10 @@ target_compile_options(libwasp_base target_include_directories(libwasp_base PUBLIC ${wasp_SOURCE_DIR}/include - ${wasp_SOURCE_DIR}/third_party/span-lite/include - ${wasp_SOURCE_DIR}/third_party/parallel-hashmap +) + +target_link_libraries(libwasp_base + absl::base + absl::container + absl::hash ) diff --git a/src/base/features.cc b/src/base/features.cc index a1289129..f1f4c7a8 100644 --- a/src/base/features.cc +++ b/src/base/features.cc @@ -17,7 +17,6 @@ #include "wasp/base/features.h" #include "wasp/base/hash.h" -#include "wasp/base/std_hash_macros.h" namespace wasp { @@ -59,9 +58,3 @@ bool operator!=(const Features& lhs, const Features& rhs) { } } // namespace wasp - -namespace std { -size_t hash<::wasp::Features>::operator()(const ::wasp::Features& v) const { - return ::wasp::HashState::combine(0, v.bits()); -} -} // namespace std diff --git a/src/base/span.cc b/src/base/span.cc index e74cd286..aec00f94 100644 --- a/src/base/span.cc +++ b/src/base/span.cc @@ -17,11 +17,3 @@ #include "wasp/base/span.h" #include "wasp/base/hash.h" - -namespace std { - -size_t hash<::wasp::SpanU8>::operator()(::wasp::SpanU8 v) const { - return ::wasp::HashContainer(v); -} - -} // namespace std diff --git a/src/base/v128.cc b/src/base/v128.cc index 36dd59b2..8d4b88bf 100644 --- a/src/base/v128.cc +++ b/src/base/v128.cc @@ -134,12 +134,3 @@ v128::v128(u8x16 other) { WASP_OPERATOR_EQ_NE_1(v128, data_) } // namespace wasp - -namespace std { - -size_t hash<::wasp::v128>::operator()(const ::wasp::v128& v) const { - auto u = v.as<::wasp::u64x2>(); - return ::wasp::HashState::combine(0, u[0], u[1]); -} - -} // namespace std diff --git a/src/base/wasm_types.cc b/src/base/wasm_types.cc index 3dc29fc4..ca018171 100644 --- a/src/base/wasm_types.cc +++ b/src/base/wasm_types.cc @@ -18,7 +18,6 @@ #include "wasp/base/hash.h" #include "wasp/base/operator_eq_ne_macros.h" -#include "wasp/base/std_hash_macros.h" namespace wasp { @@ -34,6 +33,3 @@ WASP_BASE_WASM_STRUCTS(WASP_OPERATOR_EQ_NE_VARGS) WASP_BASE_WASM_CONTAINERS(WASP_OPERATOR_EQ_NE_CONTAINER) } // namespace wasp - -WASP_BASE_WASM_STRUCTS(WASP_STD_HASH_VARGS) -WASP_BASE_WASM_CONTAINERS(WASP_STD_HASH_CONTAINER) diff --git a/src/binary/linking_section/types.cc b/src/binary/linking_section/types.cc index 13336034..c460d4d3 100644 --- a/src/binary/linking_section/types.cc +++ b/src/binary/linking_section/types.cc @@ -21,7 +21,6 @@ #include "wasp/base/hash.h" #include "wasp/base/macros.h" #include "wasp/base/operator_eq_ne_macros.h" -#include "wasp/base/std_hash_macros.h" namespace wasp::binary { @@ -101,6 +100,3 @@ WASP_BINARY_LINKING_STRUCTS(WASP_OPERATOR_EQ_NE_VARGS) WASP_BINARY_LINKING_CONTAINERS(WASP_OPERATOR_EQ_NE_CONTAINER) } // namespace wasp::binary - -WASP_BINARY_LINKING_STRUCTS(WASP_STD_HASH_VARGS) -WASP_BINARY_LINKING_CONTAINERS(WASP_STD_HASH_CONTAINER) diff --git a/src/binary/name_section/types.cc b/src/binary/name_section/types.cc index c3658ad4..fc27ca81 100644 --- a/src/binary/name_section/types.cc +++ b/src/binary/name_section/types.cc @@ -18,7 +18,6 @@ #include "wasp/base/hash.h" #include "wasp/base/operator_eq_ne_macros.h" -#include "wasp/base/std_hash_macros.h" namespace wasp::binary { @@ -26,6 +25,3 @@ WASP_BINARY_NAME_STRUCTS(WASP_OPERATOR_EQ_NE_VARGS) WASP_BINARY_NAME_CONTAINERS(WASP_OPERATOR_EQ_NE_CONTAINER) } // namespace wasp::binary - -WASP_BINARY_NAME_STRUCTS(WASP_STD_HASH_VARGS) -WASP_BINARY_NAME_CONTAINERS(WASP_STD_HASH_CONTAINER) diff --git a/src/binary/read.cc b/src/binary/read.cc index ec96c754..9ec3dcec 100644 --- a/src/binary/read.cc +++ b/src/binary/read.cc @@ -56,7 +56,7 @@ OptAt Read(SpanU8* data, Context& context, Tag) { context.features); return decoded; } else if (encoding::BlockType::IsBare(val)) { - remove_prefix(data, 1); + data->remove_prefix(1); WASP_TRY_DECODE_FEATURES(decoded, val, BlockType, "block type", context.features); return decoded; @@ -104,7 +104,7 @@ OptAt ReadBytes(SpanU8* data, span_extent_t N, Context& context) { } SpanU8 result{data->begin(), N}; - remove_prefix(data, N); + data->remove_prefix(N); return At{result, result}; } @@ -360,7 +360,7 @@ OptAt Read(SpanU8* data, Context& context, Tag) { WASP_TRY_READ(ref_type, Read(data, context)); return At{ref_type.loc(), ReferenceType{ref_type}}; } else { - remove_prefix(data, 1); + data->remove_prefix(1); WASP_TRY_DECODE_FEATURES(decoded, val, ReferenceKind, "reference type", context.features); return At{decoded.loc(), ReferenceType{decoded}}; @@ -497,7 +497,7 @@ OptAt Read(SpanU8* data, Context& context, Tag) { ErrorsContextGuard error_guard{context.errors, *data, "heap type"}; WASP_TRY_READ(val, PeekU8(data, context)); if (encoding::HeapKind::Is(val)) { - remove_prefix(data, 1); + data->remove_prefix(1); WASP_TRY_DECODE_FEATURES(decoded, val, HeapKind, "heap kind", context.features); return At{decoded.loc(), HeapType{decoded}}; @@ -1470,7 +1470,7 @@ auto Read(SpanU8* data, Context& context, Tag) WASP_TRY_READ(val, PeekU8(data, context)); if (encoding::PackedType::Is(val)) { - remove_prefix(data, 1); + data->remove_prefix(1); WASP_TRY_DECODE_FEATURES(decoded, val, PackedType, "packed type", context.features); return At{decoded.loc(), StorageType{decoded}}; @@ -1505,7 +1505,7 @@ OptAt ReadString(SpanU8* data, LocationGuard guard{data}; WASP_TRY_READ(len, ReadLength(data, context)); string_view result{reinterpret_cast(data->data()), len}; - remove_prefix(data, len); + data->remove_prefix(len); return At{guard.range(data), result}; } @@ -1552,7 +1552,7 @@ auto PeekU8(SpanU8* data, Context& context) -> OptAt { OptAt Read(SpanU8* data, Context& context, Tag) { auto result_opt = PeekU8(data, context); if (result_opt) { - remove_prefix(data, 1); + data->remove_prefix(1); } return result_opt; } @@ -1572,7 +1572,7 @@ OptAt Read(SpanU8* data, Context& context, Tag) { WASP_TRY_READ(val, PeekU8(data, context)); if (encoding::NumericType::Is(val)) { - remove_prefix(data, 1); + data->remove_prefix(1); WASP_TRY_DECODE_FEATURES(decoded, val, NumericType, "value type", context.features); return At{decoded.loc(), ValueType{decoded}}; diff --git a/src/binary/types.cc b/src/binary/types.cc index cfe82282..9b1120ae 100644 --- a/src/binary/types.cc +++ b/src/binary/types.cc @@ -19,7 +19,6 @@ #include "wasp/base/hash.h" #include "wasp/base/macros.h" #include "wasp/base/operator_eq_ne_macros.h" -#include "wasp/base/std_hash_macros.h" namespace wasp::binary { @@ -918,6 +917,3 @@ bool operator==(const Module& lhs, const Module& rhs) { bool operator!=(const Module& lhs, const Module& rhs) { return !(lhs == rhs); } } // namespace wasp::binary - -WASP_BINARY_STRUCTS_CUSTOM_FORMAT(WASP_STD_HASH_VARGS) -WASP_BINARY_CONTAINERS(WASP_STD_HASH_CONTAINER) diff --git a/src/text/lex.cc b/src/text/lex.cc index 948e333e..f33ddce0 100644 --- a/src/text/lex.cc +++ b/src/text/lex.cc @@ -28,7 +28,7 @@ struct MatchGuard { SpanU8* Reset() { *data_ = orig; return data_; } void ResetUnless(bool b) { if (!b) { Reset(); } } - Location loc() const { return Location(orig.begin(), data_->begin()); } + Location loc() const { return MakeSpan(orig.begin(), data_->begin()); } SpanU8* data_; SpanU8 orig; @@ -79,7 +79,7 @@ auto PeekChar(SpanU8* data, span_extent_t offset = 0) -> int { void SkipChar(SpanU8* data) { assert(!data->empty()); - remove_prefix(data, 1); + data->remove_prefix(1); } int ReadReservedChars(SpanU8* data) { diff --git a/src/text/types.cc b/src/text/types.cc index b3164e55..8fc6d781 100644 --- a/src/text/types.cc +++ b/src/text/types.cc @@ -21,7 +21,6 @@ #include "wasp/base/hash.h" #include "wasp/base/operator_eq_ne_macros.h" -#include "wasp/base/std_hash_macros.h" namespace wasp::text { @@ -1307,7 +1306,3 @@ bool operator!=(const BoundValueTypeList& lhs, const ValueTypeList& rhs) { } } // namespace wasp::text - -WASP_TEXT_STRUCTS(WASP_STD_HASH_VARGS) -WASP_TEXT_STRUCTS_CUSTOM_FORMAT(WASP_STD_HASH_VARGS) -WASP_TEXT_CONTAINERS(WASP_STD_HASH_CONTAINER) diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt index 4f23dcb0..6dc58ce8 100644 --- a/src/tools/CMakeLists.txt +++ b/src/tools/CMakeLists.txt @@ -66,7 +66,8 @@ target_link_libraries(wasp_tool libwasp_text libwasp_binary libwasp_base - libfmt + absl::raw_hash_set + absl::str_format ${filesystem_lib} ) diff --git a/src/tools/argparser.cc b/src/tools/argparser.cc index 4e659bcb..a0383576 100644 --- a/src/tools/argparser.cc +++ b/src/tools/argparser.cc @@ -19,12 +19,12 @@ #include #include -#include "fmt/format.h" -#include "fmt/ostream.h" +#include "absl/strings/str_format.h" namespace wasp::tools { -using namespace fmt; +using absl::StrFormat; +using absl::Format; ArgParser::Option::Option(LongName long_name, Help help, FlagCallback cb) : Option{kInvalidShortName, long_name, help, cb} {} @@ -83,7 +83,7 @@ ArgParser& ArgParser::AddFeatureFlags(Features& features) { return *this; } -void ArgParser::Parse(span args) { +void ArgParser::Parse(span args) { ArgsGuard guard{*this, args}; for (index_ = 0; index_ < args.size(); ++index_) { @@ -94,7 +94,7 @@ void ArgParser::Parse(span args) { if (index_ + 1 < args.size()) { get(option.callback)(args[++index_]); } else { - print(std::cerr, "Argument `{}` requires parameter\n.", arg); + Format(&std::cerr, "Argument `%s` requires parameter\n.", arg); } return true; } else { @@ -107,16 +107,16 @@ void ArgParser::Parse(span args) { if (auto option = FindLongOption(arg)) { call(*option); } else { - print(std::cerr, "Unknown long argument `{}`.\n", arg); + Format(&std::cerr, "Unknown long argument `%s`.\n", arg); } } else if (arg[0] == '-') { optional prev_arg_with_param; for (auto c : arg.substr(1)) { if (prev_arg_with_param) { - print(std::cerr, - "Argument `-{}` ignored since it follows `-{}` which has a " - "parameter.\n", - c, *prev_arg_with_param); + Format(&std::cerr, + "Argument `-%c` ignored since it follows `-%c` which has a " + "parameter.\n", + c, *prev_arg_with_param); continue; } @@ -127,7 +127,7 @@ void ArgParser::Parse(span args) { prev_arg_with_param = c; } } else { - print(std::cerr, "Unknown short argument `-{}`.\n", c); + Format(&std::cerr, "Unknown short argument `-%c`.\n", c); } } } else { @@ -135,24 +135,24 @@ void ArgParser::Parse(span args) { --index_; // Back up so call reads arg as the parameter. call(*option); } else { - print(std::cerr, "Unexpected bare argument `{}`.\n", arg); + Format(&std::cerr, "Unexpected bare argument `%s`.\n", arg); } } } } -span ArgParser::RestOfArgs() { +span ArgParser::RestOfArgs() { return args_.subspan(index_ + 1); } std::string ArgParser::GetHelpString() const { std::string result; - result += format("usage: {}", program_); + result += StrFormat("usage: %s", program_); if (!options_.empty()) { result += " [options]"; } if (auto bare = FindBare()) { - result += format(" {}", bare->metavar); + result += StrFormat(" %s", bare->metavar); } if (!options_.empty()) { @@ -173,26 +173,26 @@ std::string ArgParser::GetHelpString() const { } if (option.short_name != kInvalidShortName) { - result += format(" -{}, ", option.short_name); + result += StrFormat(" -%c, ", option.short_name); } else { result += " "; } - result += format("{:<{}} {}\n", - format("{} {}", option.long_name, option.metavar), width, - option.help); + result += StrFormat("%-*s %s\n", width, + StrFormat("%s %s", option.long_name, option.metavar), + option.help); } result += "\npositional:\n"; if (auto option = FindBare()) { result += - format(" {:<{}} {}\n", option->metavar, width, option->help); + StrFormat(" %-*s %s\n", width, option->metavar, option->help); } } return result; } void ArgParser::PrintHelpAndExit(int errcode) { - print(std::cerr, GetHelpString()); + Format(&std::cerr, "%s", GetHelpString()); exit(errcode); } @@ -217,7 +217,7 @@ auto ArgParser::FindBare() const -> optional