Esempio n. 1
0
void main_repl(int argc, char **argv) {
    if (!net_repl_connect()) {

    }

    net_repl_packet_t packet;
    char *line;

    mp_init();
    setup_sys(argc, argv);

    for (; ;) {
        // non-blocking
        net_repl_recv(&packet);
        switch (packet.type) {
            case REPL_QUIT:
                return;
            case REPL_WAIT:
                continue;
            default:
                break;
        }
        if (packet.type == REPL_QUIT) {
            return;
        }

        line = strdup(packet.line);

        while (mp_repl_continue_with_input(line)) {
            net_repl_send(REPL_CONTINUE, NULL, false);
            net_repl_recv(&packet);

            if (packet.type == REPL_QUIT) {
                free(line);
                return;
            } else if (packet.line_len == 0) {
                break;
            }

            char *joined = strjoin(line, '\n', packet.line);
            free(line);

            line = joined;
        }

        mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, line, strlen(line), false);
        int ret = execute_from_lexer(lex, MP_PARSE_SINGLE_INPUT, true);

        free(line);
        if (ret == ERR_SYS_EXIT) {
            return;
        }
    }
}
Esempio n. 2
0
STATIC int run_file(const char *filename, int argc, char **argv, bool return_result) {
    mp_init();
    setup_sys(argc, argv);

    int ret = do_file(filename);
    if (!return_result && ret && ret != ERR_SYS_EXIT) {
        fatal_error(false);
    }

    mp_deinit();

    mod_citrus_exit_all();

    return ret;
}
Esempio n. 3
0
int
plugin_init (struct plugin_name_args *plugin_info,
             struct plugin_gcc_version *version)
{
    LOG("plugin_init started");

    if (!plugin_default_version_check (version, &gcc_version)) {
        return 1;
    }

#if PY_MAJOR_VERSION >= 3
    /*
      Python 3 added internal buffering to sys.stdout and sys.stderr, but this
      leads to unpredictable interleavings of messages from gcc, such as from calling
      gcc.warning() vs those from python scripts, such as from print() and
      sys.stdout.write()

      Suppress the buffering, to better support mixed gcc/python output:
    */
    Py_UnbufferedStdioFlag = 1;
#endif

    PyImport_AppendInittab("gcc", PyInit_gcc);

    LOG("calling Py_Initialize...");

    Py_Initialize();

    LOG("Py_Initialize finished");

    gcc_python_globals.module = PyImport_ImportModule("gcc");

    PyEval_InitThreads();
  
    if (!gcc_python_init_gcc_module(plugin_info)) {
        return 1;
    }

    if (!setup_sys(plugin_info)) {
        return 1;
    }

    /* Init other modules */
    gcc_python_wrapper_init();

    /* FIXME: properly integrate them within the module hierarchy */

    gcc_python_version_init(version);

    autogenerated_callgraph_init_types();  /* FIXME: error checking! */
    autogenerated_cfg_init_types();  /* FIXME: error checking! */
    autogenerated_function_init_types();  /* FIXME: error checking! */
    autogenerated_gimple_init_types();  /* FIXME: error checking! */
    autogenerated_location_init_types();  /* FIXME: error checking! */
    autogenerated_option_init_types();  /* FIXME: error checking! */
    autogenerated_parameter_init_types();  /* FIXME: error checking! */
    autogenerated_pass_init_types();  /* FIXME: error checking! */
    autogenerated_pretty_printer_init_types();  /* FIXME: error checking! */
    autogenerated_rtl_init_types(); /* FIXME: error checking! */
    autogenerated_tree_init_types(); /* FIXME: error checking! */
    autogenerated_variable_init_types(); /* FIXME: error checking! */



    autogenerated_callgraph_add_types(gcc_python_globals.module);
    autogenerated_cfg_add_types(gcc_python_globals.module);
    autogenerated_function_add_types(gcc_python_globals.module);
    autogenerated_gimple_add_types(gcc_python_globals.module);
    autogenerated_location_add_types(gcc_python_globals.module);
    autogenerated_option_add_types(gcc_python_globals.module);
    autogenerated_parameter_add_types(gcc_python_globals.module);
    autogenerated_pass_add_types(gcc_python_globals.module);
    autogenerated_pretty_printer_add_types(gcc_python_globals.module);
    autogenerated_rtl_add_types(gcc_python_globals.module);
    autogenerated_tree_add_types(gcc_python_globals.module);
    autogenerated_variable_add_types(gcc_python_globals.module);


    /* Register at-exit finalization for the plugin: */
    register_callback(plugin_info->base_name, PLUGIN_FINISH,
                      on_plugin_finish, NULL);

    gcc_python_run_any_command();
    gcc_python_run_any_script();

    //printf("%s:%i:got here\n", __FILE__, __LINE__);

#if GCC_PYTHON_TRACE_ALL_EVENTS
#define DEFEVENT(NAME) \
    if (NAME != PLUGIN_PASS_MANAGER_SETUP &&         \
        NAME != PLUGIN_INFO &&                       \
	NAME != PLUGIN_REGISTER_GGC_ROOTS &&         \
	NAME != PLUGIN_REGISTER_GGC_CACHES) {        \
    register_callback(plugin_info->base_name, NAME,  \
		      trace_callback_for_##NAME, NULL); \
    }
# include "plugin.def"
# undef DEFEVENT
#endif /* GCC_PYTHON_TRACE_ALL_EVENTS */

    LOG("init_plugin finished");

    return 0;
}
Esempio n. 4
0
File: mcc.c Progetto: JamesLinus/mcc
int main(int argc, char **argv)
{
    int ret = EXIT_SUCCESS;
    const char *tmpdir;
    size_t fails = 0;

    progname = argv[0];
    setup_sys();
    init_env();
    parse_opts(argc, argv);

    bool partial = opts.E || opts.ast_dump || opts.ir_dump || opts.S || opts.c;

    if (argc == 1) {
        usage();
        return EXIT_SUCCESS;
    } else if (vec_len(inputs) == 0) {
        fprintf(stderr, "no input file.\n");
        return EXIT_FAILURE;
    } else if (output && vec_len(inputs) > 1 && partial) {
        fprintf(stderr,
                "mcc: cannot specify -o when generating multiple output files\n");
        return EXIT_FAILURE;
    }

    if (!(tmpdir = mktmpdir()))
        die("Can't make temporary directory.");

    struct vector *objects = vec_new();

    for (int i = 0; i < vec_len(inputs); i++) {
        const char *ifile = vec_at(inputs, i);
        const char *iname = basename(xstrdup(ifile));
        const char *ofile = NULL;
        int ret;
        if (opts.E || opts.ast_dump || opts.ir_dump) {
            if (output)
                ofile = output;
            ret = translate(ifile, ofile);
        } else if (opts.S) {
            if (output)
                ofile = output;
            else
                ofile = replace_suffix(iname, "s");
            ret = translate(ifile, ofile);
        } else if (opts.c) {
            if (output)
                ofile = output;
            else
                ofile = replace_suffix(iname, "o");
            const char *sfile =
                tempname(tmpdir, replace_suffix(ifile, "s"));
            ret = translate(ifile, sfile);
            if (ret == 0)
                ret = assemble(sfile, ofile);
        } else {
            const char *sfile =
                tempname(tmpdir, replace_suffix(ifile, "s"));
            ret = translate(ifile, sfile);
            if (ret == 0) {
                ofile =
                    tempname(tmpdir,
                             replace_suffix(ifile, "o"));
                ret = assemble(sfile, ofile);
                vec_push(objects, (char *)ofile);
            }
        }
        if (ret == EXIT_FAILURE)
            fails++;
    }

    if (fails) {
        ret = EXIT_FAILURE;
        fprintf(stderr, "%lu succeed, %lu failed.\n",
                vec_len(inputs) - fails, fails);
    } else if (!partial) {
        // link
        ret = link(objects, output, opts.ld_options);
    }

    if (tmpdir)
        rmdir(tmpdir);
    return ret;
}