39{
40
42 "circle-operator allows users to retrieve operator information from a Circle model file"};
43 arser.add_argument(
"--name").nargs(0).help(
"Dump operators name in circle file");
44 arser.add_argument(
"--code").nargs(0).help(
"Dump operators code in circle file");
45 arser.add_argument(
"--output_path").help(
"Save output to file (default output is console)");
46 arser.add_argument(
"circle").help(
"Circle file to dump");
47
48 try
49 {
50 arser.parse(argc, argv);
51 }
52 catch (const std::runtime_error &err)
53 {
54 std::cerr << err.what() << std::endl;
56 return 255;
57 }
58
62
63 std::ofstream oFstream;
64 std::ostream *oStream = &std::cout;
65 if (
arser[
"--output_path"])
66 {
68 oFstream.open(output_path, std::ofstream::out | std::ofstream::trunc);
69 if (oFstream.fail())
70 {
71 std::cerr <<
"ERROR: Failed to create output to file " <<
output_path << std::endl;
72 return 255;
73 }
74 oStream = &oFstream;
75 }
76
77
78 struct sigaction sa;
79 memset(&sa, 0, sizeof(struct sigaction));
80 sigemptyset(&sa.sa_mask);
82 sa.sa_flags = SA_SIGINFO;
83 sigaction(SIGSEGV, &sa, NULL);
84
85 std::string modelFile =
arser.get<std::string>(
"circle");
86
87 try
88 {
90 std::vector<char> modelData = fileLoader.
load();
91 const circle::Model *circleModel = circle::GetModel(modelData.data());
92 if (circleModel == nullptr)
93 {
94 std::cerr << "ERROR: Failed to load circle '" << modelFile << "'" << std::endl;
95 return 255;
96 }
98 dump.
run(*oStream, circleModel, option);
99 }
100 catch (const std::runtime_error &err)
101 {
102 std::cerr << "ERROR: " << err.what() << std::endl;
103 return 255;
104 }
105
106 if (oFstream.is_open())
107 {
108 oFstream.close();
109 }
110
111 return 0;
112}
void run(std::ostream &os, const circle::Model *model, const DumpOption &option)
DataBuffer load(void) const
void handle_segfault(int signal, siginfo_t *si, void *arg)
void dump(const coco::Op *op, int indent)