srctree

Robin Linden parent 6809b060 236aa498
wasm/example: Print imports

inlinesplit
wasm/wasm_example.cpp added: 17, removed: 1, total 16
@@ -12,6 +12,8 @@
#include <fstream>
#include <iostream>
#include <iterator>
#include <string_view>
#include <variant>
 
namespace wasm {
std::ostream &operator<<(std::ostream &, wasm::ValueType);
@@ -59,6 +61,20 @@ int main(int argc, char **argv) {
}
}
 
if (auto const &import_section = module->import_section) {
struct ImportStringifier {
std::string_view operator()(wasm::TypeIdx) const { return "func"; }
std::string_view operator()(wasm::TableType const &) const { return "table"; }
std::string_view operator()(wasm::MemType const &) const { return "mem"; }
std::string_view operator()(wasm::GlobalType const &) const { return "global"; }
};
 
std::cout << "\n# Imports\n";
for (auto const &i : import_section->imports) {
std::cout << i.module << '.' << i.name << ": " << std::visit(ImportStringifier{}, i.description) << '\n';
}
}
 
if (auto const &function_section = module->function_section) {
std::cout << "\n# Function idx -> type idx\n";
for (std::size_t i = 0; i < function_section->type_indices.size(); ++i) {