/* parts taken from qemu/dyngen.c */ #include #include #include extern char *optarg_test; extern int optind_test; extern int getopt_test (int ___argc, char *const *___argv, const char *__shortopts); enum { OUT_GEN_OP, OUT_CODE, OUT_INDEX_OP, }; /* load an elf object file */ static int load_object(const char *filename) { return 0; } static int gen_file(FILE *outfile, int out_type) { return 0; } static void usage(void) { printf("usage: getopt_hidden [-o outfile] [-c] objfile\n" "Generate a dynamic code generator from an object file\n" "-c output enum of operations\n" "-g output gen_op_xx() functions\n" ); exit(1); } static void __attribute__((noreturn)) __attribute__((format (printf, 1, 2))) error(const char *fmt, ...) { va_list ap; va_start(ap, fmt); fprintf(stderr, "getopt_hidden: "); vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); va_end(ap); exit(1); } int main(int argc, char **argv) { int c, out_type; const char *filename, *outfilename; FILE *outfile; outfilename = "out.c"; out_type = OUT_CODE; for(;;) { c = getopt_test(argc, argv, "ho:cg"); if (c == -1) break; switch(c) { case 'h': usage(); break; case 'o': outfilename = optarg_test; break; case 'c': out_type = OUT_INDEX_OP; break; case 'g': out_type = OUT_GEN_OP; break; } } if (optind_test >= argc) usage(); filename = argv[optind_test]; outfile = fopen(outfilename, "w"); if (!outfile) error("could not open '%s'", outfilename); load_object(filename); gen_file(outfile, out_type); fclose(outfile); return 0; }