File size: 1,942 Bytes
2fc4a7e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#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;
}