diff --git a/CMakeLists.txt b/CMakeLists.txt index 74de0f6..2ae6114 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.26) project(fdt-viewer VERSION 0.8.1 LANGUAGES CXX) @@ -8,11 +8,11 @@ set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) -set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED ON) -find_package(Qt5 COMPONENTS Widgets) -if (Qt5_FOUND) +find_package(Qt6 COMPONENTS Widgets Core) +if (Qt6_FOUND) add_subdirectory("src") if (UNIX) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d8e9af7..7f4c9b4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,5 +27,5 @@ add_executable(fdt-viewer ../resources.qrc ) -target_link_libraries(fdt-viewer PRIVATE Qt5::Widgets qhexview-lib) +target_link_libraries(fdt-viewer PRIVATE Qt6::Widgets Qt6::Core QHexView) install(TARGETS fdt-viewer RUNTIME DESTINATION bin) diff --git a/src/endian-conversions.hpp b/src/endian-conversions.hpp index 44a2b00..486d202 100644 --- a/src/endian-conversions.hpp +++ b/src/endian-conversions.hpp @@ -5,22 +5,19 @@ #include #include -constexpr u32 u32_be(const char *data) noexcept { - if constexpr (std::endian::native == std::endian::big) - return *reinterpret_cast(data); - - if constexpr (std::endian::native == std::endian::little) - return __builtin_bswap32(*reinterpret_cast(data)); - - return 0; +template +constexpr T byteswap(T value) noexcept { + static_assert(std::has_unique_object_representations_v, + "T may not have padding bits"); + auto value_representation = std::bit_cast>(value); + std::ranges::reverse(value_representation); + return std::bit_cast(value_representation); } -constexpr u32 u32_be(const u32 data) noexcept { - if constexpr (std::endian::native == std::endian::big) - return data; - +template +T convert(const T data) noexcept { if constexpr (std::endian::native == std::endian::little) - return __builtin_bswap32(data); + return byteswap(data); return data; } @@ -31,6 +28,6 @@ constexpr type read_data_32be(input_data *input) noexcept { std::memcpy(reinterpret_cast(&container), reinterpret_cast(input), sizeof(type)); auto *data = reinterpret_cast(&container); for (auto i = 0; i < (sizeof(type) / sizeof(u32)); ++i) - data[i] = u32_be(data[i]); + data[i] = convert(data[i]); return container; } diff --git a/src/fdt/fdt-parser.cpp b/src/fdt/fdt-parser.cpp index 56fbe75..f455165 100644 --- a/src/fdt/fdt-parser.cpp +++ b/src/fdt/fdt-parser.cpp @@ -39,7 +39,7 @@ void fdt_parser::parse(const fdt::header header, iface_fdt_generator &generator) return iter += size; }; - const auto token = static_cast(u32_be(iter)); + const auto token = static_cast(convert(*reinterpret_cast(iter))); seek_and_align(sizeof(token)); if (fdt::token::begin_node == token) { diff --git a/src/fdt/fdt-view.cpp b/src/fdt/fdt-view.cpp index 84acb05..662056d 100644 --- a/src/fdt/fdt-view.cpp +++ b/src/fdt/fdt-view.cpp @@ -47,16 +47,16 @@ string present(const fdt_property &property) { return result_str({data}); if (property_type::number == info.type) - return result(string::number(u32_be(data.data()))); + return result(string::number(convert(*reinterpret_cast(data.data())))); } - const static regexp cells_regexp("^#.*-cells$"); - const static regexp names_regexp("^.*-names"); + const static QRegularExpression cells_regexp("^#.*-cells$"); + const static QRegularExpression names_regexp("^.*-names"); - if (cells_regexp.exactMatch(name)) - return result(string::number(u32_be(data.data()))); + if (cells_regexp.match(name).hasMatch()) + return result(string::number(convert(*reinterpret_cast(data.data())))); - if (names_regexp.exactMatch(name)) { + if (names_regexp.match(name).hasMatch()) { auto lines = data.split(0); lines.removeLast(); diff --git a/src/main-window.cpp b/src/main-window.cpp index 9bc38fa..278a6e7 100644 --- a/src/main-window.cpp +++ b/src/main-window.cpp @@ -16,9 +16,8 @@ #include #include -#include -#include -#include +#include "submodules/qhexview/model/buffer/qmemorybuffer.h" +#include "submodules/qhexview/qhexview.h" using namespace Window; diff --git a/src/submodules/qhexview b/src/submodules/qhexview index b3c0e4a..06136db 160000 --- a/src/submodules/qhexview +++ b/src/submodules/qhexview @@ -1 +1 @@ -Subproject commit b3c0e4a8b7318f3c6ed8a29a75694b376ba16cf1 +Subproject commit 06136db4f20d0ef49d3565587109fd50d092caaa diff --git a/src/types.hpp b/src/types.hpp index 8912007..1bc1d6b 100644 --- a/src/types.hpp +++ b/src/types.hpp @@ -1,6 +1,8 @@ #pragma once #include +#include +#include using i16 = std::int16_t; using i32 = std::int32_t; @@ -21,7 +23,6 @@ class QFile; class QFileInfo; class QRegExp; class QString; -class QStringList; class QTreeWidget; class QTreeWidgetItem; class QWidget; @@ -33,7 +34,6 @@ using byte_array = QByteArray; using dir_iterator = QDirIterator; using file = QFile; using file_info = QFileInfo; -using regexp = QRegExp; using string = QString; using string_list = QStringList; using tree_widget = QTreeWidget;