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[]) { int stacktop; const char *sourcefile; Parrot_PMC interp; Parrot_PMC bytecodepmc; Parrot_PMC argsarray; int status; int pir_argc; const char **pir_argv; const char *core = "slow"; int run_pbc = 0; Parrot_Init_Args *initargs; Parrot_Int trace = 0; GET_INIT_STRUCT(initargs); /* internationalization setup */ /* setlocale(LC_ALL, ""); */ /* PARROT_BINDTEXTDOMAIN(PACKAGE, LOCALEDIR); */ /* PARROT_TEXTDOMAIN(PACKAGE); */ /* Parse minimal subset of flags */ parseflags_minimal(initargs, argc, argv); if (!(Parrot_api_make_interpreter(NULL, 0, initargs, &interp) && Parrot_set_config_hash(interp) && Parrot_api_set_executable_name(interp, argv[0]))) { fprintf(stderr, "PARROT VM: Could not initialize new interpreter"); show_last_error_and_exit(interp); } /* Parse flags */ sourcefile = parseflags(interp, argc, argv, &pir_argc, &pir_argv, &core, &trace); if (!Parrot_api_set_runcore(interp, core, trace)) show_last_error_and_exit(interp); if (!Parrot_api_wrap_imcc_hack( interp, sourcefile, argc, argv, &bytecodepmc, &run_pbc, imcc_run_api)) show_last_error_and_exit(interp); if (run_pbc) { if (!Parrot_api_pmc_wrap_string_array(interp, pir_argc, pir_argv, &argsarray)) show_last_error_and_exit(interp); if (!Parrot_api_run_bytecode(interp, bytecodepmc, argsarray)) show_last_error_and_exit(interp); } /* Clean-up after ourselves */ Parrot_api_destroy_interpreter(interp); exit(EXIT_SUCCESS); }
int main(int argc, const char *argv[]) { PMC *interp; PMC *pbc; PMC *argsarray; const unsigned char *program_code_addr; Parrot_Init_Args *initargs; GET_INIT_STRUCT(initargs); initargs->gc_system = GCCORE; program_code_addr = (const unsigned char *)get_program_code(); if (!program_code_addr) exit(EXIT_FAILURE); if (!(Parrot_api_make_interpreter(NULL, 0, initargs, &interp) && Parrot_set_config_hash(interp) && Parrot_api_set_executable_name(interp, argv[0]) && Parrot_api_set_runcore(interp, RUNCORE, TRACE))) { fprintf(stderr, "PARROT VM: Could not initialize new interpreter\n"); show_last_error_and_exit(interp); } setup_pir_compregs(interp); if (!Parrot_api_pmc_wrap_string_array(interp, argc, argv, &argsarray)) { fprintf(stderr, "PARROT VM: Could not build args array"); show_last_error_and_exit(interp); } if (!Parrot_api_load_bytecode_bytes(interp, program_code_addr, (Parrot_Int) bytecode_size, &pbc)) { fprintf(stderr, "PARROT VM: Could not load bytecode\n"); show_last_error_and_exit(interp); } if (!Parrot_api_run_bytecode(interp, pbc, argsarray)) { show_last_error_and_exit(interp); } if (!Parrot_api_destroy_interpreter(interp)) { fprintf(stderr, "PARROT VM: Could not destroy interpreter\n"); show_last_error_and_exit(interp); } exit(EXIT_SUCCESS); }
int main(int argc, const char *argv[]) { Parrot_PMC interp, bytecodepmc, sysargs, pirargs; Parrot_Init_Args *initargs; struct init_args_t parsed_flags; GET_INIT_STRUCT(initargs); /* Parse minimal subset of flags */ parseflags_minimal(initargs, argc, argv); if (!Parrot_api_make_interpreter(NULL, 0, initargs, &interp)) { fprintf(stderr, "PARROT VM: Could not allocate new interpreter\n"); if (interp != NULL) show_last_error_and_exit(interp); else fprintf(stderr, "PARROT VM: No interpreter. Cannot get error details\n"); exit(EXIT_FAILURE); } if (!(Parrot_set_config_hash(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); } /* Parse flags */ parseflags(interp, argc, argv, &parsed_flags); if (!Parrot_api_set_runcore(interp, parsed_flags.run_core_name, parsed_flags.trace)) show_last_error_and_exit(interp); Parrot_api_toggle_gc(interp, 0); setup_imcc(interp); if (!parsed_flags.turn_gc_off) Parrot_api_toggle_gc(interp, 1); if (!(Parrot_api_pmc_wrap_string_array(interp, parsed_flags.sysargc, parsed_flags.sysargv, &sysargs) && Parrot_api_pmc_wrap_string_array(interp, parsed_flags.progargc, parsed_flags.progargv, &pirargs) && Parrot_api_load_bytecode_bytes(interp, get_program_code(), get_program_code_size(), &bytecodepmc) && Parrot_api_run_bytecode(interp, bytecodepmc, sysargs, pirargs))) show_last_error_and_exit(interp); /* Clean-up after ourselves */ Parrot_api_destroy_interpreter(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[]) { Parrot_PMC interp, bytecodepmc, args; Parrot_Init_Args *initargs; struct init_args_t parsed_flags; Parrot_PMC compiler = NULL; GET_INIT_STRUCT(initargs); initargs->numthreads = 0; /* Parse minimal subset of flags */ parseflags_minimal(initargs, argc, argv); if (!Parrot_api_make_interpreter(NULL, 0, initargs, &interp)) { fprintf(stderr, "PARROT VM: Could not allocate new interpreter\n"); if (interp != NULL) show_last_error_and_exit(interp); else fprintf(stderr, "PARROT VM: No interpreter. Cannot get error details\n"); exit(EXIT_FAILURE); } if (!(Parrot_set_config_hash(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); } /* Parse flags */ parseflags(interp, argc, argv, &parsed_flags); if (!Parrot_api_set_runcore(interp, parsed_flags.run_core_name, parsed_flags.trace)) show_last_error_and_exit(interp); Parrot_api_toggle_gc(interp, 0); { Parrot_PMC pir_compiler = NULL; Parrot_PMC pasm_compiler = NULL;; if (!(imcc_get_pir_compreg_api(interp, 1, &pir_compiler) && imcc_get_pasm_compreg_api(interp, 1, &pasm_compiler))) show_last_error_and_exit(interp); compiler = parsed_flags.have_pasm_file ? pasm_compiler : pir_compiler; } if (!parsed_flags.turn_gc_off) Parrot_api_toggle_gc(interp, 1); if (parsed_flags.imcc_dflags || parsed_flags.imcc_opts) { if (!imcc_set_flags_api(interp, compiler, parsed_flags.imcc_dflags, parsed_flags.imcc_opts)) exit(EXIT_FAILURE); } if (!(Parrot_api_pmc_wrap_string_array(interp, parsed_flags.argc, parsed_flags.argv, &args) && Parrot_api_load_bytecode_bytes(interp, get_program_code(), get_program_code_size(), &bytecodepmc) && Parrot_api_run_bytecode(interp, bytecodepmc, args))) show_last_error_and_exit(interp); /* Clean-up after ourselves */ Parrot_api_destroy_interpreter(interp); exit(EXIT_SUCCESS); }