static Parrot_PMC loader_get(Parrot_PMC interp_pmc, char * path) { Parrot_String path_str; Parrot_PMC bytecode_pmc; Parrot_api_string_import_ascii(interp_pmc, path, &path_str); if(Parrot_api_load_bytecode_file(interp_pmc, path_str, &bytecode_pmc)) return bytecode_pmc; return NULL; /* crash and crash hard! */ }
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; }