From b0502dccf53bc130d06244b9e340286890fe2f5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Burdukiewicz?= Date: Fri, 28 Jun 2024 23:54:12 +0200 Subject: [PATCH] fdt: connect with qt tree generator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bartłomiej Burdukiewicz --- src/fdt/fdt-parser-v2.hpp | 2 +- src/fdt/fdt-parser.cpp | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/fdt/fdt-parser-v2.hpp b/src/fdt/fdt-parser-v2.hpp index 1c0a221..ea4d60e 100644 --- a/src/fdt/fdt-parser-v2.hpp +++ b/src/fdt/fdt-parser-v2.hpp @@ -30,7 +30,7 @@ constexpr auto id_of(end) -> u32 { return 0x09; }; } // namespace types -using token = std::variant; +using token = std::variant; using token_list = std::vector; struct context { diff --git a/src/fdt/fdt-parser.cpp b/src/fdt/fdt-parser.cpp index 47cc315..ed65669 100644 --- a/src/fdt/fdt-parser.cpp +++ b/src/fdt/fdt-parser.cpp @@ -1,4 +1,5 @@ #include "fdt-parser.hpp" +#include "fdt/fdt-header.hpp" #include #include #include @@ -141,6 +142,11 @@ auto foreach_token_type(std::variant, const u32 token_id, const char *dat return (conditional_parse(Ts{}) || ...); } +template +struct overloaded : Ts... { + using Ts::operator()...; +}; + void fdt_parser::parse(const fdt::header header, iface_fdt_generator &generator) { const auto dt_struct = m_data + header.off_dt_struct; const auto dt_strings = m_data + header.off_dt_strings; @@ -192,4 +198,17 @@ void fdt_parser::parse(const fdt::header header, iface_fdt_generator &generator) std::cout << "property count: " << property_count << std::endl; std::cout << "nop count: " << nop_count << std::endl; std::cout << "end count: " << end_count << std::endl; + + for (auto &&token : ctx.tokens) + std::visit(overloaded{ + [&](node_begin &arg) { generator.begin_node(QString::fromUtf8(arg.name.data(), arg.name.size())); }, + [&](node_end &arg) { generator.end_node(); }, + [&](property &arg) { generator.insert_property(fdt_property{ + .name = QString::fromUtf8(arg.name.data(), arg.name.size()), + .data = QByteArray(arg.data.data(), arg.data.size()), + }); }, + [&](nop &) {}, + [&](types::end &) {}, + }, + token); }