Skip to content

Commit

Permalink
fdt: connect with qt tree generator
Browse files Browse the repository at this point in the history
Signed-off-by: Bartłomiej Burdukiewicz <[email protected]>
  • Loading branch information
dev-0x7C6 committed Jun 28, 2024
1 parent be9a3ee commit b0502dc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/fdt/fdt-parser-v2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ constexpr auto id_of(end) -> u32 { return 0x09; };

} // namespace types

using token = std::variant<types::node_begin, types::node_end, types::property, types::nop, types::end>;
using token = std::variant<types::property, types::node_begin, types::node_end, types::nop, types::end>;
using token_list = std::vector<token>;

struct context {
Expand Down
19 changes: 19 additions & 0 deletions src/fdt/fdt-parser.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "fdt-parser.hpp"
#include "fdt/fdt-header.hpp"
#include <ostream>
#include <string_view>
#include <variant>
Expand Down Expand Up @@ -141,6 +142,11 @@ auto foreach_token_type(std::variant<Ts...>, const u32 token_id, const char *dat
return (conditional_parse(Ts{}) || ...);
}

template <class... Ts>
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;
Expand Down Expand Up @@ -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);
}

0 comments on commit b0502dc

Please sign in to comment.