int main(int argc, const char *argv[]) { Parrot_PMC interp; Parrot_PMC pbc; const char *outfile = NULL; int option = 0; int debug = PFOPT_UTILS; struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT; int status; Parrot_Init_Args *initargs; GET_INIT_STRUCT(initargs); if (!(Parrot_api_make_interpreter(NULL, 0, initargs, &interp) && Parrot_api_set_executable_name(interp, argv[0]))) { fprintf(stderr, "PARROT VM: Could not initialize new interpreter"); show_last_error_and_exit(interp); } while ((status = longopt_get(argc, argv, options, &opt)) > 0) { switch (opt.opt_id) { case 'h': option += enum_DIS_HEADER; break; case 'b': option += enum_DIS_BARE; break; case 'o': outfile = opt.opt_arg; break; #if TRACE_PACKFILE case 'D': debug += atoi(opt.opt_arg) << 2; break; #endif case '?': default: help(); break; } } if (status == -1) { help(); } argc -= opt.opt_index; argv += opt.opt_index; /* What to do about this debug flag? */ /* pf = Parrot_pbc_read(interp, argc ? *argv : "-", debug); */ if (!(Parrot_api_load_bytecode_file(interp, argc ? *argv : "-", &pbc) && Parrot_api_disassemble_bytecode(interp, pbc, outfile, option) && Parrot_api_destroy_interpreter(interp))) { fprintf(stderr, "Error during disassembly\n"); show_last_error_and_exit(interp); } exit(EXIT_SUCCESS); }
int main(int argc, const char *argv[]) { const char *outfile = NULL; int option = 0, status = 0, debug = PFOPT_UTILS; struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT; Parrot_PMC interp = NULL, pbc = NULL; Parrot_String filename = NULL; Parrot_Init_Args *initargs = NULL; /* Parse command-line arguments */ while ((status = longopt_get(argc, argv, options, &opt)) > 0) { switch (opt.opt_id) { case 'h': option += enum_DIS_HEADER; break; case 'b': option += enum_DIS_BARE; break; case 'o': outfile = opt.opt_arg; break; case '?': /* Fall through */ default: help(); break; } } /* Check for parse errors */ if (argc == 1 || status == -1) { help(); } /* Set initialization parameters */ GET_INIT_STRUCT(initargs); /* Create new interpreter and set executable name */ if (!(Parrot_api_make_interpreter(NULL, 0, initargs, &interp) && Parrot_api_set_executable_name(interp, argv[0]))) { fprintf(stderr, "PARROT VM: Could not initialize new interpreter\n"); show_last_error_and_exit(interp); } argc -= opt.opt_index; argv += opt.opt_index; /* What to do about this debug flag? */ /* pf = Parrot_pbc_read(interp, argc ? *argv : "-", debug); */ /* Convert native char * to Parrot_String */ if (!Parrot_api_string_import(interp, argc ? *argv : "-", &filename)) { fprintf(stderr, "String transformation failed\n"); show_last_error_and_exit(interp); } /* Disassemble bytecode and destroy interpreter */ if (!(Parrot_api_load_bytecode_file(interp, filename, &pbc) && Parrot_api_disassemble_bytecode(interp, pbc, outfile, option) && Parrot_api_destroy_interpreter(interp))) { fprintf(stderr, "Error during disassembly\n"); show_last_error_and_exit(interp); } return 0; }
int main(int argc, const char **argv) { PackFile *pf; Interp *interp; const char *file = NULL; int terse = 0; int disas = 0; int convert = 0; int nums_only = 0; int options = PFOPT_UTILS; struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT; int status; if (argc < 2) help(); interp = Parrot_new(NULL); /* init and set top of stack */ Parrot_init_stacktop(interp, &status); while ((status = longopt_get(interp, argc, argv, opt_options, &opt)) > 0) { switch (opt.opt_id) { #if TRACE_PACKFILE case 'D': options += atoi(opt.opt_arg) << 2; break; #endif case 'h': options += PFOPT_HEADERONLY; break; case 't': terse = 1; break; case 'd': disas = 1; break; case 'o': file = opt.opt_arg; convert = 1; break; case 'n': nums_only = 1; break; case '?': default: help(); break; } } if (status == -1) help(); argc -= opt.opt_index; argv += opt.opt_index; pf = Parrot_pbc_read(interp, *argv, options); if (!pf) { printf("Can't read PBC\n"); return 1; } Parrot_pbc_load(interp, pf); if (convert) { size_t size = PackFile_pack_size(interp, interp->code->base.pf) * sizeof (opcode_t); opcode_t *pack = (opcode_t *)Parrot_gc_allocate_memory_chunk(interp, size); FILE *fp; if (!pack) { printf("out of mem\n"); exit(EXIT_FAILURE); } PackFile_pack(interp, interp->code->base.pf, pack); if (STREQ(file, "-")) fp = stdout; else if ((fp = fopen(file, "wb")) == 0) { printf("Couldn't open %s\n", file); exit(EXIT_FAILURE); } if ((1 != fwrite(pack, size, 1, fp))) { printf("Couldn't write %s\n", file); exit(EXIT_FAILURE); } fclose(fp); Parrot_gc_free_memory_chunk(interp, pack); Parrot_exit(interp, 0); } if (!nums_only) PackFile_header_dump(interp, pf); if (options & PFOPT_HEADERONLY) Parrot_exit(interp, 0); /* install a dumper function */ if (!terse) { pf->PackFuncs[PF_CONST_SEG].dump = const_dump; } if (disas) pf->PackFuncs[PF_BYTEC_SEG].dump = disas_dump; if (nums_only) { int i; for (i = PF_DIR_SEG + 1; i < PF_MAX_SEG; ++i) pf->PackFuncs[i].dump = null_dump; pf->PackFuncs[PF_DIR_SEG].dump = null_dir_dump; pf->PackFuncs[PF_BYTEC_SEG].dump = nums_dump; } /* do a directory dump, which dumps segs then */ PackFile_Segment_dump(interp, &pf->directory.base); Parrot_exit(interp, 0); }