| #include <cstdio> |
| #include <cstdlib> |
| #include <cstring> |
| #include <vector> |
|
|
| #include <executorch/runtime/executor/program.h> |
| #include <executorch/runtime/core/data_loader.h> |
| #include <executorch/extension/data_loader/buffer_data_loader.h> |
| #include <executorch/runtime/platform/runtime.h> |
|
|
| using executorch::runtime::Program; |
| using executorch::runtime::Result; |
| using executorch::runtime::Error; |
| using executorch::extension::BufferDataLoader; |
|
|
| static std::vector<uint8_t> read_file(const char* path) { |
| FILE* f = fopen(path, "rb"); |
| if (!f) { perror("fopen"); exit(2); } |
| fseek(f, 0, SEEK_END); long n = ftell(f); fseek(f, 0, SEEK_SET); |
| std::vector<uint8_t> buf(n); |
| if (fread(buf.data(), 1, n, f) != (size_t)n) { perror("fread"); exit(2); } |
| fclose(f); |
| return buf; |
| } |
|
|
| int main(int argc, char** argv) { |
| if (argc < 2) { fprintf(stderr, "usage: %s <file.pte> [ic]\n", argv[0]); return 2; } |
| executorch::runtime::runtime_init(); |
|
|
| std::vector<uint8_t> data = read_file(argv[1]); |
| printf("loaded %zu bytes from %s\n", data.size(), argv[1]); |
|
|
| BufferDataLoader loader(data.data(), data.size()); |
|
|
| Program::Verification mode = Program::Verification::Minimal; |
| if (argc >= 3 && strcmp(argv[2], "ic") == 0) { |
| mode = Program::Verification::InternalConsistency; |
| printf("verification = InternalConsistency\n"); |
| } else { |
| printf("verification = Minimal (default)\n"); |
| } |
|
|
| Result<Program> program = Program::load(&loader, mode); |
| if (!program.ok()) { |
| printf("load failed: 0x%x\n", (unsigned)program.error()); |
| return 1; |
| } |
| printf("load OK\n"); |
|
|
| size_t n = program->num_methods(); |
| printf("num_methods=%zu\n", n); |
| for (size_t i = 0; i < n; ++i) { |
| Result<const char*> name = program->get_method_name(i); |
| if (name.ok()) { |
|
|
| printf("method[%zu]=%s\n", i, name.get()); |
| } else { |
| printf("method[%zu]=<err 0x%x>\n", i, (unsigned)name.error()); |
| } |
| } |
| printf("DONE clean\n"); |
| return 0; |
| } |
|
|