Commit 2c149243 authored by nagayama15's avatar nagayama15

Add the function counter

parent 2c9e8b0e
...@@ -23,3 +23,11 @@ add_executable(pisn ...@@ -23,3 +23,11 @@ add_executable(pisn
target_link_libraries(pisn target_link_libraries(pisn
kyut kyut
) )
add_executable(funccnt
funccnt.cpp
)
target_link_libraries(funccnt
kyut
)
#include <algorithm>
#include <fmt/printf.h>
#include <wasm-io.h>
int main(int argc, char *argv[]) {
// Parse command line options
if (argc != 2) {
fmt::print(std::cerr, "{} <input file>\n", argv[0]);
return 1;
}
const std::string inputFile = argv[1];
try {
// Read the input module
wasm::Module module;
wasm::ModuleReader{}.read(inputFile, module);
const auto count = std::count_if(
std::begin(module.functions), std::end(module.functions), [](const auto &f) { return f->body != nullptr; });
fmt::print("{}\n", count);
} catch (const wasm::ParseException &e) {
e.dump(std::cerr);
return 1;
} catch (const std::exception &e) {
fmt::print(std::cerr, "exception: {}\n", e.what());
return 1;
} catch (...) {
fmt::print(std::cerr, "unknown exception\n");
return 1;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment