From 749ea81552d7e4defadebd32661dc337a8154867 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sat, 24 Dec 2022 02:01:58 +0100 Subject: [PATCH 01/22] ci: Add release-windows build --- circle.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/circle.yml b/circle.yml index affd23dc8..342f11c75 100644 --- a/circle.yml +++ b/circle.yml @@ -1,4 +1,6 @@ version: 2.1 +orbs: + win: circleci/windows@5.0 parameters: benchmark: @@ -400,6 +402,34 @@ jobs: cmake_options: -DNATIVE=ON - test + release-windows: + executor: win/server-2022 + environment: + CMAKE_BUILD_TYPE: Release + steps: + - checkout + - run: + name: "Setup environment (bash)" + shell: bash + command: | + echo 'export PATH=$PATH:"/c/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin"' >> $BASH_ENV + - run: + name: 'Configure' + shell: powershell + command: | + $ErrorActionPreference = "Stop" + & 'C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\Launch-VsDevShell.ps1' -Arch amd64 + which cmake + cmake -S . -B ~/build -G Ninja -DCMAKE_INSTALL_PREFIX=C:\install + - run: + name: 'Build' + shell: powershell + command: | + $ErrorActionPreference = "Stop" + & 'C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\Launch-VsDevShell.ps1' -Arch amd64 + cmake --build ~/build + - test + coverage-clang: executor: linux-clang-latest steps: @@ -789,6 +819,7 @@ workflows: - release-native-linux - release-macos - release-native-macos + - release-windows - coverage-gcc: requires: - fetch-spectests From a58cb9679ec2d0de960232d4d88d0ef8c2912857 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sat, 24 Dec 2022 02:05:27 +0100 Subject: [PATCH 02/22] move for win --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fb3ea7b28..e2f7a23e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,10 +39,10 @@ endif() cable_configure_compiler() cable_add_compile_options( + IF_SUPPORTED -Wcast-qual -Wcast-align -Wmissing-declarations - IF_SUPPORTED -Wextra-semi -Wold-style-cast -Wfinal-dtor-non-final-class From 5d4391745e75597e1d34fe3508e08cb90a8071c6 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sat, 24 Dec 2022 02:07:52 +0100 Subject: [PATCH 03/22] f --- lib/fizzy/capi.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/fizzy/capi.cpp b/lib/fizzy/capi.cpp index e06e6f3a9..3dd1af374 100644 --- a/lib/fizzy/capi.cpp +++ b/lib/fizzy/capi.cpp @@ -8,6 +8,7 @@ #include "instantiate.hpp" #include "parser.hpp" #include +#include #include #include From 92ba7d14277fd21c6c2230a6f1c2d7bc1dec10bc Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 29 Dec 2022 14:12:10 +0100 Subject: [PATCH 04/22] Disable sanitizer on windows --- lib/fizzy/execute.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/fizzy/execute.cpp b/lib/fizzy/execute.cpp index 10a21a261..c4b59626f 100644 --- a/lib/fizzy/execute.cpp +++ b/lib/fizzy/execute.cpp @@ -459,7 +459,10 @@ T fnearest(T value) noexcept } template -__attribute__((no_sanitize("float-divide-by-zero"))) inline constexpr T fdiv(T a, T b) noexcept +#indef _MSC_VER +__attribute__((no_sanitize("float-divide-by-zero"))) +#endif +inline constexpr T fdiv(T a, T b) noexcept { static_assert(std::is_floating_point_v); static_assert(std::numeric_limits::is_iec559); @@ -494,8 +497,10 @@ inline T fmax(T a, T b) noexcept return a < b ? b : a; } - -__attribute__((no_sanitize("float-cast-overflow"))) inline constexpr float demote( +#ifndef _MSC_VER +__attribute__((no_sanitize("float-cast-overflow"))) +#endif +inline constexpr float demote( double value) noexcept { // The float-cast-overflow UBSan check disabled for this conversion. In older clang versions From c00a2f2dd2c9a8bd6a4dc8daaeb9431e67f96154 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 29 Dec 2022 16:11:45 +0100 Subject: [PATCH 05/22] require c++20 for windows --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 342f11c75..229c9e573 100644 --- a/circle.yml +++ b/circle.yml @@ -420,7 +420,7 @@ jobs: $ErrorActionPreference = "Stop" & 'C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\Launch-VsDevShell.ps1' -Arch amd64 which cmake - cmake -S . -B ~/build -G Ninja -DCMAKE_INSTALL_PREFIX=C:\install + cmake -S . -B ~/build -G Ninja -DCMAKE_INSTALL_PREFIX=C:\install -DCMAKE_CXX_STANDARD=20 - run: name: 'Build' shell: powershell From a256b9e26b52d413ac6a12598eda88fc0b02df97 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 29 Dec 2022 16:17:48 +0100 Subject: [PATCH 06/22] Add missing include for iterator --- lib/fizzy/capi.cpp | 1 + lib/fizzy/parser.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/fizzy/capi.cpp b/lib/fizzy/capi.cpp index 3dd1af374..ddf1c7660 100644 --- a/lib/fizzy/capi.cpp +++ b/lib/fizzy/capi.cpp @@ -9,6 +9,7 @@ #include "parser.hpp" #include #include +#include #include #include diff --git a/lib/fizzy/parser.cpp b/lib/fizzy/parser.cpp index 20413d0dd..29948715f 100644 --- a/lib/fizzy/parser.cpp +++ b/lib/fizzy/parser.cpp @@ -9,6 +9,7 @@ #include "types.hpp" #include "utf8.hpp" #include +#include #include namespace fizzy From 4c19ac869b3a0205bd0cba18a785d9d64688ec6c Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 29 Dec 2022 16:18:03 +0100 Subject: [PATCH 07/22] fix ifndef --- lib/fizzy/execute.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fizzy/execute.cpp b/lib/fizzy/execute.cpp index c4b59626f..b9c377007 100644 --- a/lib/fizzy/execute.cpp +++ b/lib/fizzy/execute.cpp @@ -459,7 +459,7 @@ T fnearest(T value) noexcept } template -#indef _MSC_VER +#ifndef _MSC_VER __attribute__((no_sanitize("float-divide-by-zero"))) #endif inline constexpr T fdiv(T a, T b) noexcept From 7e13ff459cd15527cd20881bd9c1ee060d632c27 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 29 Dec 2022 18:17:19 +0100 Subject: [PATCH 08/22] quick hack for msvc --- lib/fizzy/execute.cpp | 6 +++--- lib/fizzy/parser.hpp | 2 +- lib/fizzy/parser_expr.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/fizzy/execute.cpp b/lib/fizzy/execute.cpp index b9c377007..7e2912df0 100644 --- a/lib/fizzy/execute.cpp +++ b/lib/fizzy/execute.cpp @@ -31,7 +31,7 @@ template inline T read(const uint8_t*& input) noexcept { T ret; - __builtin_memcpy(&ret, input, sizeof(ret)); + memcpy(&ret, input, sizeof(ret)); input += sizeof(ret); return ret; } @@ -39,14 +39,14 @@ inline T read(const uint8_t*& input) noexcept template inline void store(bytes& input, size_t offset, T value) noexcept { - __builtin_memcpy(input.data() + offset, &value, sizeof(value)); + memcpy(input.data() + offset, &value, sizeof(value)); } template inline T load(bytes_view input, size_t offset) noexcept { T ret; - __builtin_memcpy(&ret, input.data() + offset, sizeof(ret)); + memcpy(&ret, input.data() + offset, sizeof(ret)); return ret; } diff --git a/lib/fizzy/parser.hpp b/lib/fizzy/parser.hpp index b2db86fde..bdc878bc3 100644 --- a/lib/fizzy/parser.hpp +++ b/lib/fizzy/parser.hpp @@ -40,7 +40,7 @@ inline parser_result parse_value(const uint8_t* pos, const uint8_t* end) throw parser_error{"unexpected EOF"}; T value; - __builtin_memcpy(&value, pos, size); + memcpy(&value, pos, size); return {value, pos + size}; } diff --git a/lib/fizzy/parser_expr.cpp b/lib/fizzy/parser_expr.cpp index f75f2b4e9..3e66a1b49 100644 --- a/lib/fizzy/parser_expr.cpp +++ b/lib/fizzy/parser_expr.cpp @@ -16,7 +16,7 @@ namespace template inline void store(uint8_t* dst, T value) noexcept { - __builtin_memcpy(dst, &value, sizeof(value)); + memcpy(dst, &value, sizeof(value)); } template From c3863691990d33ac5528949ea4c6b75c5ee43646 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 29 Dec 2022 18:19:27 +0100 Subject: [PATCH 09/22] hack for windows --- lib/fizzy/bytes.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fizzy/bytes.hpp b/lib/fizzy/bytes.hpp index 07dd80695..623e740f6 100644 --- a/lib/fizzy/bytes.hpp +++ b/lib/fizzy/bytes.hpp @@ -10,6 +10,6 @@ namespace fizzy { using bytes = std::basic_string; -using bytes_view = std::basic_string_view; +using bytes_view = std::basic_string; } // namespace fizzy From f79ddb382a916ec8b650c01361699a08a9d02035 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 30 Dec 2022 01:56:29 +0100 Subject: [PATCH 10/22] add dumb basic_string_view --- lib/fizzy/bytes.hpp | 127 ++++++++++++++++++++++++++++++++++++++++++- lib/fizzy/parser.cpp | 4 +- 2 files changed, 128 insertions(+), 3 deletions(-) diff --git a/lib/fizzy/bytes.hpp b/lib/fizzy/bytes.hpp index 623e740f6..d86e44d0e 100644 --- a/lib/fizzy/bytes.hpp +++ b/lib/fizzy/bytes.hpp @@ -7,9 +7,134 @@ #include #include +#include + namespace fizzy { + +template > +class basic_string_view { + +// static_assert(!is_array_v); +// static_assert(is_trivial_v<_CharT> && is_standard_layout_v<_CharT>); +// static_assert(is_same_v<_CharT, typename _Traits::char_type>); + +public: + // Types. + using traits_type = Traits; + using value_type = CharT; + using const_pointer = const value_type*; + using const_reference = const value_type&; + using const_iterator = const value_type*; + using size_type = size_t; + static constexpr size_type npos = size_type(-1); + + // Construction. + constexpr basic_string_view() noexcept : data_(nullptr), len_(0) {} +// constexpr basic_string_view(const basic_string_view& other) noexcept = +// default; + constexpr basic_string_view(const_pointer str) + : data_(str), len_(internal_strlen(str)) {} + constexpr basic_string_view(const_pointer str, size_type len) + : data_(str), len_(len) {} +// basic_string_view(const std::string& str) +// : data_(str.data()), len_(str.size()) {} + constexpr basic_string_view(std::basic_string /*str*/) : data_(nullptr), len_(0) {} + +// basic_string_view& operator=(const basic_string_view&) noexcept = default; + +// constexpr basic_string_view() noexcept : data_(nullptr), len_(0) {} +// constexpr basic_string_view(const_pointer str, size_type len) +// : data_(str), len_(len) {} +// constexpr basic_string_view(const_pointer str) +// : data_(str), len_(internal_strlen(str)) {} +// basic_string_view(const std::string& str) +// : data_(str.data()), len_(str.size()) {} +// template +// constexpr basic_string_view(It first, End last) {} +// template< class R > +// explicit constexpr basic_string_view( R&& r ) {} + + // Iterator support. + constexpr const_iterator begin() const noexcept { return data_; } + constexpr const_iterator end() const noexcept { return data_ + len_; } + + // Element access. + constexpr const_pointer data() const noexcept { return data_; } + + // Capacity. + constexpr size_type size() const noexcept { return len_; } + + constexpr const_reference operator[](size_type pos) const { + return data_[pos]; + } + + // Modifiers. + void remove_prefix(size_type n) { + data_ = data_ + n; + len_ -= n; + } + + // Operations. + + // Returns a view of the substring [pos, pos + rcount), where rcount is the + // smaller of count and size() - pos. + constexpr basic_string_view substr(size_type pos = 0, size_type count = npos) const { + if (pos > len_) { + throw std::out_of_range("Out of range"); + } + + const size_type rcount = std::min(count, len_ - pos); + if (rcount > 0) { + return basic_string_view(data_ + pos, rcount); + } + return basic_string_view(); + } + + // Compares two character sequences. + constexpr int compare(basic_string_view s) const noexcept { + const size_t rlen = std::min(len_, s.len_); + const int comparison = traits_type::compare(data_, s.data_, rlen); + if (comparison != 0) return comparison; + if (len_ == s.len_) return 0; + return len_ < s.len_ ? -1 : 1; + } + // Compare substring(pos1, count1) with s. + constexpr int compare(size_type pos1, size_type count1, basic_string_view s) const { + return substr(pos1, count1).compare(s); + } + // Compare substring(pos1, count1) with s.substring(pos2, count2). + constexpr int compare(size_type pos1, size_type count1, basic_string_view s, + size_type pos2, size_type count2) const { + return substr(pos1, count1).compare(s.substr(pos2, count2)); + } + constexpr int compare(const_pointer s) const { return compare(basic_string_view(s)); } + constexpr int compare(size_type pos1, size_type count1, const_pointer s) const { + return substr(pos1, count1).compare(basic_string_view(s)); + } + constexpr int compare(size_type pos1, size_type count1, const_pointer s, + size_type count2) const { + return substr(pos1, count1).compare(basic_string_view(s, count2)); + } + +// operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, + +// constexpr bool operator!=(basic_string_view x, const std::basic_string y) const { +// return true; +// } + +private: + constexpr static size_type internal_strlen(const_pointer str) { + return str ? traits_type::length(str) : 0; + } + + const_pointer data_; + size_type len_; +}; + +using bytes_view = basic_string_view; + using bytes = std::basic_string; -using bytes_view = std::basic_string; +//using bytes_view = std::basic_string_view; } // namespace fizzy diff --git a/lib/fizzy/parser.cpp b/lib/fizzy/parser.cpp index 29948715f..030b253a1 100644 --- a/lib/fizzy/parser.cpp +++ b/lib/fizzy/parser.cpp @@ -456,8 +456,8 @@ inline parser_result parse(const uint8_t* pos, const uint8_t* end) std::unique_ptr parse(bytes_view input) { - if (input.substr(0, wasm_prefix.size()) != wasm_prefix) - throw parser_error{"invalid wasm module prefix"}; +// if (input.substr(0, wasm_prefix.size()) != wasm_prefix) +// throw parser_error{"invalid wasm module prefix"}; input.remove_prefix(wasm_prefix.size()); From 5fb7c2bfdbf033677a0ab4dca426131715be9a38 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 30 Dec 2022 02:02:50 +0100 Subject: [PATCH 11/22] turn on test build --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 229c9e573..32a070768 100644 --- a/circle.yml +++ b/circle.yml @@ -420,7 +420,7 @@ jobs: $ErrorActionPreference = "Stop" & 'C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\Launch-VsDevShell.ps1' -Arch amd64 which cmake - cmake -S . -B ~/build -G Ninja -DCMAKE_INSTALL_PREFIX=C:\install -DCMAKE_CXX_STANDARD=20 + cmake -S . -B ~/build -G Ninja -DCMAKE_INSTALL_PREFIX=C:\install -DCMAKE_CXX_STANDARD=20 -DFIZZY_TESTING=ON - run: name: 'Build' shell: powershell From 32cab31fa1cd3ad16b1463aad9d1eb96a31b0593 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 5 Jan 2023 21:38:56 +0100 Subject: [PATCH 12/22] cmake: Update Hunter --- cmake/Hunter/init.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/Hunter/init.cmake b/cmake/Hunter/init.cmake index 4ccf3bedf..3f2e74019 100644 --- a/cmake/Hunter/init.cmake +++ b/cmake/Hunter/init.cmake @@ -4,8 +4,8 @@ include(FetchContent) FetchContent_Declare( huntergate - URL https://github.com/cpp-pm/gate/archive/v0.9.2.tar.gz - URL_HASH SHA256=edef54e8cec019a7b4e6b1e1d9e76346c431a6b64d0717422ec903dcd62b3dad + URL https://github.com/cpp-pm/hunter/archive/v0.23.297.tar.gz + URL_HASH SHA256=077e5d33db470dd5af3afef1f436539e050a84f5daffe80cbea7c3e16a931d8e ) FetchContent_GetProperties(huntergate) From 36a02c8d671accfdb61a6e62ac0659b78e594b00 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 5 Jan 2023 22:22:15 +0100 Subject: [PATCH 13/22] hunter --- cmake/Hunter/init.cmake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmake/Hunter/init.cmake b/cmake/Hunter/init.cmake index 3f2e74019..119b1cd73 100644 --- a/cmake/Hunter/init.cmake +++ b/cmake/Hunter/init.cmake @@ -4,8 +4,8 @@ include(FetchContent) FetchContent_Declare( huntergate - URL https://github.com/cpp-pm/hunter/archive/v0.23.297.tar.gz - URL_HASH SHA256=077e5d33db470dd5af3afef1f436539e050a84f5daffe80cbea7c3e16a931d8e + URL https://github.com/cpp-pm/gate/archive/v0.9.2.tar.gz + URL_HASH SHA256=edef54e8cec019a7b4e6b1e1d9e76346c431a6b64d0717422ec903dcd62b3dad ) FetchContent_GetProperties(huntergate) @@ -25,7 +25,7 @@ if(NOT CMAKE_CONFIGURATION_TYPES) endif() HunterGate( - URL https://github.com/cpp-pm/hunter/archive/v0.23.294.tar.gz - SHA1 0dd1ee8723d54a15822519c17a877c1f281fce39 + URL https://github.com/cpp-pm/hunter/archive/v0.23.297.tar.gz + SHA1 3319fe6a3b08090df7df98dee75134d68e2ef5a3 LOCAL ) From edd4d7c4294230e6577285e7525b32e03f1db9e7 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 5 Jan 2023 22:57:17 +0100 Subject: [PATCH 14/22] hunter (needed for msvc2022 support) --- cmake/Hunter/init.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/Hunter/init.cmake b/cmake/Hunter/init.cmake index 119b1cd73..6412569a7 100644 --- a/cmake/Hunter/init.cmake +++ b/cmake/Hunter/init.cmake @@ -25,7 +25,7 @@ if(NOT CMAKE_CONFIGURATION_TYPES) endif() HunterGate( - URL https://github.com/cpp-pm/hunter/archive/v0.23.297.tar.gz - SHA1 3319fe6a3b08090df7df98dee75134d68e2ef5a3 + URL https://github.com/cpp-pm/hunter/archive/v0.24.13.tar.gz + SHA1 2bc7384b2bf27db5b3847739a6a5361fa04075e7 LOCAL ) From dd390d7ae53f3eff82d3e0069c57e3da196ae05c Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 5 Jan 2023 22:59:30 +0100 Subject: [PATCH 15/22] hunter update (gtest already present) --- cmake/Hunter/config.cmake | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cmake/Hunter/config.cmake b/cmake/Hunter/config.cmake index 8ced70a0a..ad93b11df 100644 --- a/cmake/Hunter/config.cmake +++ b/cmake/Hunter/config.cmake @@ -1,14 +1,14 @@ # Hunter local configuration. -hunter_config( - GTest - VERSION 1.11.0 - URL https://github.com/google/googletest/archive/release-1.11.0.tar.gz - SHA1 7b100bb68db8df1060e178c495f3cbe941c9b058 - CMAKE_ARGS - HUNTER_INSTALL_LICENSE_FILES=LICENSE - gtest_force_shared_crt=TRUE -) +#hunter_config( +# GTest +# VERSION 1.11.0 +# URL https://github.com/google/googletest/archive/release-1.11.0.tar.gz +# SHA1 7b100bb68db8df1060e178c495f3cbe941c9b058 +# CMAKE_ARGS +# HUNTER_INSTALL_LICENSE_FILES=LICENSE +# gtest_force_shared_crt=TRUE +#) hunter_config( benchmark From a11237549de9fa60aad09ff6fac85a8174e8eb4d Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 6 Jan 2023 00:12:03 +0100 Subject: [PATCH 16/22] cmake: Link ws2_#2 on windows for uvwasi --- cmake/ProjectUVWASI.cmake | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmake/ProjectUVWASI.cmake b/cmake/ProjectUVWASI.cmake index 74c29cbe9..4347d9ab8 100644 --- a/cmake/ProjectUVWASI.cmake +++ b/cmake/ProjectUVWASI.cmake @@ -12,6 +12,14 @@ set(include_dir ${source_dir}/include) set(uvwasi_library ${binary_dir}/${CMAKE_STATIC_LIBRARY_PREFIX}uvwasi_a${CMAKE_STATIC_LIBRARY_SUFFIX}) set(uv_library ${binary_dir}/_deps/libuv-build/${CMAKE_STATIC_LIBRARY_PREFIX}uv_a${CMAKE_STATIC_LIBRARY_SUFFIX}) +# This is hack. Should fix proper uvwasi.cmake integration. +if(WIN32) + list(APPEND uv_library iphlpapi) + list(APPEND uv_library userenv) + list(APPEND uv_library psapi) + list(APPEND uv_library ws2_32) +endif() + if(UNIX AND NOT APPLE) set(system_libs "pthread;dl;rt") endif() From ca348bed132e5fbcf15ff4de54a0d809b3c5016c Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 6 Jan 2023 00:27:33 +0100 Subject: [PATCH 17/22] missing header --- test/utils/wasm_engine.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/utils/wasm_engine.hpp b/test/utils/wasm_engine.hpp index aaacd96f3..3bb0e98d6 100644 --- a/test/utils/wasm_engine.hpp +++ b/test/utils/wasm_engine.hpp @@ -7,6 +7,7 @@ #include "bytes.hpp" #include #include +#include #include #include #include From 5df6ae7de2d2bc9e8faa113ae5d6329842d9e4f2 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 6 Jan 2023 00:33:40 +0100 Subject: [PATCH 18/22] This is not noexcept in wabt --- test/utils/wabt_engine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/utils/wabt_engine.cpp b/test/utils/wabt_engine.cpp index 3c1fc93a3..4f37c38cd 100644 --- a/test/utils/wabt_engine.cpp +++ b/test/utils/wabt_engine.cpp @@ -16,7 +16,7 @@ namespace fizzy::test class WabtEngine final : public WasmEngine { // mutable because getting RefPtr from Ref requires non-const Store - mutable wabt::interp::Store m_store{([]() constexpr noexcept { + mutable wabt::interp::Store m_store{([]() noexcept { wabt::Features features; features.disable_multi_value(); features.disable_sat_float_to_int(); From 6de90b5af2855c05f1a8e5dac18d79a7fb87ca0f Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 3 Mar 2023 19:10:59 +0100 Subject: [PATCH 19/22] bytes_string clang-format --- lib/fizzy/bytes.hpp | 228 +++++++++++++++++++++++--------------------- 1 file changed, 118 insertions(+), 110 deletions(-) diff --git a/lib/fizzy/bytes.hpp b/lib/fizzy/bytes.hpp index d86e44d0e..f602185d3 100644 --- a/lib/fizzy/bytes.hpp +++ b/lib/fizzy/bytes.hpp @@ -13,128 +13,136 @@ namespace fizzy { template > -class basic_string_view { - -// static_assert(!is_array_v); -// static_assert(is_trivial_v<_CharT> && is_standard_layout_v<_CharT>); -// static_assert(is_same_v<_CharT, typename _Traits::char_type>); +class basic_string_view +{ + // static_assert(!is_array_v); + // static_assert(is_trivial_v<_CharT> && is_standard_layout_v<_CharT>); + // static_assert(is_same_v<_CharT, typename _Traits::char_type>); public: - // Types. - using traits_type = Traits; - using value_type = CharT; - using const_pointer = const value_type*; - using const_reference = const value_type&; - using const_iterator = const value_type*; - using size_type = size_t; - static constexpr size_type npos = size_type(-1); - - // Construction. - constexpr basic_string_view() noexcept : data_(nullptr), len_(0) {} -// constexpr basic_string_view(const basic_string_view& other) noexcept = -// default; - constexpr basic_string_view(const_pointer str) - : data_(str), len_(internal_strlen(str)) {} - constexpr basic_string_view(const_pointer str, size_type len) - : data_(str), len_(len) {} -// basic_string_view(const std::string& str) -// : data_(str.data()), len_(str.size()) {} - constexpr basic_string_view(std::basic_string /*str*/) : data_(nullptr), len_(0) {} - -// basic_string_view& operator=(const basic_string_view&) noexcept = default; - -// constexpr basic_string_view() noexcept : data_(nullptr), len_(0) {} -// constexpr basic_string_view(const_pointer str, size_type len) -// : data_(str), len_(len) {} -// constexpr basic_string_view(const_pointer str) -// : data_(str), len_(internal_strlen(str)) {} -// basic_string_view(const std::string& str) -// : data_(str.data()), len_(str.size()) {} -// template -// constexpr basic_string_view(It first, End last) {} -// template< class R > -// explicit constexpr basic_string_view( R&& r ) {} - - // Iterator support. - constexpr const_iterator begin() const noexcept { return data_; } - constexpr const_iterator end() const noexcept { return data_ + len_; } - - // Element access. - constexpr const_pointer data() const noexcept { return data_; } - - // Capacity. - constexpr size_type size() const noexcept { return len_; } - - constexpr const_reference operator[](size_type pos) const { - return data_[pos]; - } - - // Modifiers. - void remove_prefix(size_type n) { - data_ = data_ + n; - len_ -= n; - } - - // Operations. - - // Returns a view of the substring [pos, pos + rcount), where rcount is the - // smaller of count and size() - pos. - constexpr basic_string_view substr(size_type pos = 0, size_type count = npos) const { - if (pos > len_) { - throw std::out_of_range("Out of range"); + // Types. + using traits_type = Traits; + using value_type = CharT; + using const_pointer = const value_type*; + using const_reference = const value_type&; + using const_iterator = const value_type*; + using size_type = size_t; + static constexpr size_type npos = size_type(-1); + + // Construction. + constexpr basic_string_view() noexcept : data_(nullptr), len_(0) {} + // constexpr basic_string_view(const basic_string_view& other) noexcept = + // default; + constexpr basic_string_view(const_pointer str) : data_(str), len_(internal_strlen(str)) {} + constexpr basic_string_view(const_pointer str, size_type len) : data_(str), len_(len) {} + // basic_string_view(const std::string& str) + // : data_(str.data()), len_(str.size()) {} + constexpr basic_string_view(std::basic_string /*str*/) : data_(nullptr), len_(0) {} + + // basic_string_view& operator=(const basic_string_view&) noexcept = default; + + // constexpr basic_string_view() noexcept : data_(nullptr), len_(0) {} + // constexpr basic_string_view(const_pointer str, size_type len) + // : data_(str), len_(len) {} + // constexpr basic_string_view(const_pointer str) + // : data_(str), len_(internal_strlen(str)) {} + // basic_string_view(const std::string& str) + // : data_(str.data()), len_(str.size()) {} + // template + // constexpr basic_string_view(It first, End last) {} + // template< class R > + // explicit constexpr basic_string_view( R&& r ) {} + + // Iterator support. + constexpr const_iterator begin() const noexcept { return data_; } + constexpr const_iterator end() const noexcept { return data_ + len_; } + + // Element access. + constexpr const_pointer data() const noexcept { return data_; } + + // Capacity. + constexpr size_type size() const noexcept { return len_; } + + constexpr const_reference operator[](size_type pos) const { return data_[pos]; } + + // Modifiers. + void remove_prefix(size_type n) + { + data_ = data_ + n; + len_ -= n; } - const size_type rcount = std::min(count, len_ - pos); - if (rcount > 0) { - return basic_string_view(data_ + pos, rcount); + // Operations. + + // Returns a view of the substring [pos, pos + rcount), where rcount is the + // smaller of count and size() - pos. + constexpr basic_string_view substr(size_type pos = 0, size_type count = npos) const + { + if (pos > len_) + { + throw std::out_of_range("Out of range"); + } + + const size_type rcount = std::min(count, len_ - pos); + if (rcount > 0) + { + return basic_string_view(data_ + pos, rcount); + } + return basic_string_view(); } - return basic_string_view(); - } - - // Compares two character sequences. - constexpr int compare(basic_string_view s) const noexcept { - const size_t rlen = std::min(len_, s.len_); - const int comparison = traits_type::compare(data_, s.data_, rlen); - if (comparison != 0) return comparison; - if (len_ == s.len_) return 0; - return len_ < s.len_ ? -1 : 1; - } - // Compare substring(pos1, count1) with s. - constexpr int compare(size_type pos1, size_type count1, basic_string_view s) const { - return substr(pos1, count1).compare(s); - } - // Compare substring(pos1, count1) with s.substring(pos2, count2). - constexpr int compare(size_type pos1, size_type count1, basic_string_view s, - size_type pos2, size_type count2) const { - return substr(pos1, count1).compare(s.substr(pos2, count2)); - } - constexpr int compare(const_pointer s) const { return compare(basic_string_view(s)); } - constexpr int compare(size_type pos1, size_type count1, const_pointer s) const { - return substr(pos1, count1).compare(basic_string_view(s)); - } - constexpr int compare(size_type pos1, size_type count1, const_pointer s, - size_type count2) const { - return substr(pos1, count1).compare(basic_string_view(s, count2)); - } - -// operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, - -// constexpr bool operator!=(basic_string_view x, const std::basic_string y) const { -// return true; -// } + + // Compares two character sequences. + constexpr int compare(basic_string_view s) const noexcept + { + const size_t rlen = std::min(len_, s.len_); + const int comparison = traits_type::compare(data_, s.data_, rlen); + if (comparison != 0) + return comparison; + if (len_ == s.len_) + return 0; + return len_ < s.len_ ? -1 : 1; + } + // Compare substring(pos1, count1) with s. + constexpr int compare(size_type pos1, size_type count1, basic_string_view s) const + { + return substr(pos1, count1).compare(s); + } + // Compare substring(pos1, count1) with s.substring(pos2, count2). + constexpr int compare(size_type pos1, size_type count1, basic_string_view s, size_type pos2, + size_type count2) const + { + return substr(pos1, count1).compare(s.substr(pos2, count2)); + } + constexpr int compare(const_pointer s) const { return compare(basic_string_view(s)); } + constexpr int compare(size_type pos1, size_type count1, const_pointer s) const + { + return substr(pos1, count1).compare(basic_string_view(s)); + } + constexpr int compare(size_type pos1, size_type count1, const_pointer s, size_type count2) const + { + return substr(pos1, count1).compare(basic_string_view(s, count2)); + } + + // operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, + + // constexpr bool operator!=(basic_string_view x, const std::basic_string y) + // const { + // return true; + // } private: - constexpr static size_type internal_strlen(const_pointer str) { - return str ? traits_type::length(str) : 0; - } + constexpr static size_type internal_strlen(const_pointer str) + { + return str ? traits_type::length(str) : 0; + } - const_pointer data_; - size_type len_; + const_pointer data_; + size_type len_; }; using bytes_view = basic_string_view; using bytes = std::basic_string; -//using bytes_view = std::basic_string_view; +// using bytes_view = std::basic_string_view; } // namespace fizzy From e380b3ff24871c9f4e951b39d028d3d072cde82c Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 3 Mar 2023 19:11:35 +0100 Subject: [PATCH 20/22] clang-format --- lib/fizzy/capi.cpp | 2 +- lib/fizzy/execute.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/fizzy/capi.cpp b/lib/fizzy/capi.cpp index ddf1c7660..d831b6640 100644 --- a/lib/fizzy/capi.cpp +++ b/lib/fizzy/capi.cpp @@ -9,8 +9,8 @@ #include "parser.hpp" #include #include -#include #include +#include #include namespace diff --git a/lib/fizzy/execute.cpp b/lib/fizzy/execute.cpp index 7e2912df0..b099b5156 100644 --- a/lib/fizzy/execute.cpp +++ b/lib/fizzy/execute.cpp @@ -462,7 +462,8 @@ template #ifndef _MSC_VER __attribute__((no_sanitize("float-divide-by-zero"))) #endif -inline constexpr T fdiv(T a, T b) noexcept +inline constexpr T +fdiv(T a, T b) noexcept { static_assert(std::is_floating_point_v); static_assert(std::numeric_limits::is_iec559); @@ -500,8 +501,8 @@ inline T fmax(T a, T b) noexcept #ifndef _MSC_VER __attribute__((no_sanitize("float-cast-overflow"))) #endif -inline constexpr float demote( - double value) noexcept +inline constexpr float +demote(double value) noexcept { // The float-cast-overflow UBSan check disabled for this conversion. In older clang versions // (up to 8.0) it reports a failure when non-infinity f64 value is converted to f32 infinity. From 0629be8ccd7e695b7f11c8d422a6ad5d6954d0a3 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sun, 19 Mar 2023 12:36:35 +0100 Subject: [PATCH 21/22] header include for memcpy --- lib/fizzy/parser.hpp | 1 + lib/fizzy/parser_expr.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/fizzy/parser.hpp b/lib/fizzy/parser.hpp index bdc878bc3..2026d507c 100644 --- a/lib/fizzy/parser.hpp +++ b/lib/fizzy/parser.hpp @@ -7,6 +7,7 @@ #include "exceptions.hpp" #include "leb128.hpp" #include "module.hpp" +#include #include namespace fizzy diff --git a/lib/fizzy/parser_expr.cpp b/lib/fizzy/parser_expr.cpp index 3e66a1b49..7764a315e 100644 --- a/lib/fizzy/parser_expr.cpp +++ b/lib/fizzy/parser_expr.cpp @@ -8,6 +8,7 @@ #include "parser.hpp" #include "stack.hpp" #include +#include namespace fizzy { From ceb39b695e770fa68cfd47751b3ab3b9c99f687c Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sun, 19 Mar 2023 12:38:02 +0100 Subject: [PATCH 22/22] linter --- lib/fizzy/parser.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/fizzy/parser.cpp b/lib/fizzy/parser.cpp index 030b253a1..75ad76b55 100644 --- a/lib/fizzy/parser.cpp +++ b/lib/fizzy/parser.cpp @@ -456,8 +456,8 @@ inline parser_result parse(const uint8_t* pos, const uint8_t* end) std::unique_ptr parse(bytes_view input) { -// if (input.substr(0, wasm_prefix.size()) != wasm_prefix) -// throw parser_error{"invalid wasm module prefix"}; + // if (input.substr(0, wasm_prefix.size()) != wasm_prefix) + // throw parser_error{"invalid wasm module prefix"}; input.remove_prefix(wasm_prefix.size());