Example #1
0
static void compilefiles(std::ostream &fout, const std::vector<std::string> &files, const std::string &args)
{
    for (unsigned int i = 0; i < files.size(); ++i) {
        fout << objfile(files[i]) << ": " << files[i];
        std::vector<std::string> depfiles;
        getDeps(files[i], depfiles);
        for (unsigned int dep = 0; dep < depfiles.size(); ++dep)
            fout << " " << depfiles[dep];
        fout << "\n\t$(CXX) " << args << " $(CPPFLAGS) $(CFG) $(CXXFLAGS) -std=c++0x -c -o " << objfile(files[i]) << " " << builddir(files[i]) << "\n\n";
    }
}
Example #2
0
// constructor
PythonModule::PythonModule(
    sc_core::sc_module_name mn,
    const char* script_filename,
    int argc,
    char **argv) :
        sc_core::sc_module(mn),
        initialised(false),
        my_namespace(NULL),
        pysc_module(NULL),
        sys_path(NULL),
        name_py(NULL) {

    PYSC_INIT_MODULES();

    // set up interpreter and gs module and context object
    subscribe();
    block_threads();

    PYSC_PREPARE_MODULES();

#ifndef MTI_SYSTEMC
#if PY_MAJOR_VERSION >= 3
    wchar_t *args[argc];
    for(int i = 0; i< argc; i++) {
        args[i] = new wchar_t[strlen(argv[i])+1];
        mbstowcs(args[i], argv[i], strlen(argv[i])+1);
    }
    Py_SetProgramName(args[0]);
    if(script_filename && *script_filename) {
      delete args[0];
      args[0] = new wchar_t[strlen(script_filename)+1];
      mbstowcs(args[0], script_filename, strlen(script_filename)+1);
    }
    PySys_SetArgvEx(argc, args, 0);
#else
    char *args[argc];
    for(int i = 0; i< argc; i++) {
        args[i] = argv[i];
    }
    Py_SetProgramName(args[0]);
    if(script_filename && *script_filename) {
      args[0] = const_cast<char *>(script_filename);
    }
    PySys_SetArgvEx(argc, args, 0);
#endif

#else
    Py_SetProgramName("vsim");
    PySys_SetArgvEx(0, NULL, 0);
#endif

    // get a globals() dict for this PythonModule
    PyObject* main_module = PyImport_AddModule("__main__");  // borrowed ref
    if(!main_module) {
        PyErr_Print();
        unblock_threads();
        return;
    }
    my_namespace = PyModule_GetDict(main_module);  // borrowed ref
    my_namespace = PyDict_Copy(my_namespace);  // new ref

    sys_path = PySys_GetObject(const_cast<char *>("path"));  // new ref
    if(!sys_path) {
        PyErr_Print();
        unblock_threads();
        return;
    }

    initialised = true;

    // Now add the virtual env to the sys.path to load pysc and other socrocket modules
    unblock_threads();
#if defined(MTI_SYSTEMC) || defined(NC_SYSTEMC)
    boost::filesystem::path builddir = findPath("build", __FILE__);
#else
    std::map<std::string, std::string> *wafConfig = getWafConfig(argv[0]);
    std::string outdir = (*wafConfig)["out_dir"];
    outdir.erase(std::remove(outdir.begin(), outdir.end(), '\''), outdir.end());
    boost::filesystem::path builddir(outdir);
#endif
    boost::filesystem::path venvactivate(".conf_check_venv/bin/activate_this.py");
    std::string activate = (builddir/venvactivate).string();
    exec(
        "with open('"+activate+"') as script:\n" +
        "    code = compile(script.read(), '"+activate+"', 'exec')\n" +
        "    exec(code, dict(__file__='"+activate+"'))");
    block_threads();

    // make sure there's a reference to the pysc module available
    pysc_module = PyImport_ImportModuleEx(const_cast<char *>("usi"), my_namespace, my_namespace, NULL);
    if(!pysc_module) {
        PyErr_Print();
        unblock_threads();
        return;
    }

    // if we get to here, we consider ourselves initialised
    // note that:
    // - the namespace has no name, so is impossible to access from another PythonModule
    // - pysc and sys have been imported, but are not added to the namespace

    // tell the Python code it is embedded
    PyObject_SetAttrString(pysc_module, "__standalone__", Py_False);

    // tell the Python code its interpreter name
    name_py = PyString_FromString(name());  // new ref
    set_interpreter_name();
    unblock_threads();
    add_to_pythonpath(".");

    PythonModule::globalInstance = this;

    // run a script if one has been requested
    if (script_filename && *script_filename) {
      load(script_filename);
    }

#ifndef MTI_SYSTEMC
    sr_report_handler::handler = report_handler;
#endif
}
Example #3
0
std::string objfile(std::string cppfile)
{
    cppfile.erase(cppfile.rfind("."));
    return builddir(cppfile + ".o");
}
Example #4
0
static void compilefiles(std::ostream &fout, const std::vector<std::string> &files, const std::string &args)
{
    for (unsigned int i = 0; i < files.size(); ++i) {
        bool external(files[i].compare(0,10,"externals/") == 0);
        fout << objfile(files[i]) << ": " << files[i];
        std::vector<std::string> depfiles;
        depfiles.push_back("lib/cxx11emu.h");
        getDeps(files[i], depfiles);
        for (unsigned int dep = 0; dep < depfiles.size(); ++dep)
            fout << " " << depfiles[dep];
        fout << "\n\t$(CXX) " << args << " $(CPPFLAGS) $(CFG) $(CXXFLAGS)" << (external?" -w":"") << " $(UNDEF_STRICT_ANSI) -c -o " << objfile(files[i]) << " " << builddir(files[i]) << "\n\n";
    }
}