Expose abc and data paths as globals

This commit is contained in:
Miodrag Milanovic 2020-11-06 14:17:15 +01:00
parent e7f36d01e4
commit 829b5cca60
4 changed files with 63 additions and 43 deletions

View File

@ -89,6 +89,12 @@ bool memhasher_active = false;
uint32_t memhasher_rng = 123456; uint32_t memhasher_rng = 123456;
std::vector<void*> memhasher_store; std::vector<void*> memhasher_store;
std::string yosys_share_dirname;
std::string yosys_abc_executable;
void init_share_dirname();
void init_abc_executable_name();
void memhasher_on() void memhasher_on()
{ {
#if defined(__linux__) || defined(__FreeBSD__) #if defined(__linux__) || defined(__FreeBSD__)
@ -523,6 +529,8 @@ void yosys_setup()
if(already_setup) if(already_setup)
return; return;
already_setup = true; already_setup = true;
init_share_dirname();
init_abc_executable_name();
#define X(_id) RTLIL::ID::_id = "\\" # _id; #define X(_id) RTLIL::ID::_id = "\\" # _id;
#include "kernel/constids.inc" #include "kernel/constids.inc"
@ -825,38 +833,74 @@ std::string proc_self_dirname()
#endif #endif
#if defined(EMSCRIPTEN) || defined(__wasm) #if defined(EMSCRIPTEN) || defined(__wasm)
std::string proc_share_dirname() void init_share_dirname()
{ {
return "/share/"; yosys_share_dirname = "/share/";
} }
#else #else
std::string proc_share_dirname() void init_share_dirname()
{ {
std::string proc_self_path = proc_self_dirname(); std::string proc_self_path = proc_self_dirname();
# if defined(_WIN32) && !defined(YOSYS_WIN32_UNIX_DIR) # if defined(_WIN32) && !defined(YOSYS_WIN32_UNIX_DIR)
std::string proc_share_path = proc_self_path + "share\\"; std::string proc_share_path = proc_self_path + "share\\";
if (check_file_exists(proc_share_path, true)) if (check_file_exists(proc_share_path, true)) {
return proc_share_path; yosys_share_dirname = proc_share_path;
return;
}
proc_share_path = proc_self_path + "..\\share\\"; proc_share_path = proc_self_path + "..\\share\\";
if (check_file_exists(proc_share_path, true)) if (check_file_exists(proc_share_path, true)) {
return proc_share_path; yosys_share_dirname = proc_share_path;
return;
}
# else # else
std::string proc_share_path = proc_self_path + "share/"; std::string proc_share_path = proc_self_path + "share/";
if (check_file_exists(proc_share_path, true)) if (check_file_exists(proc_share_path, true)) {
return proc_share_path; yosys_share_dirname = proc_share_path;
return;
}
proc_share_path = proc_self_path + "../share/" + proc_program_prefix()+ "yosys/"; proc_share_path = proc_self_path + "../share/" + proc_program_prefix()+ "yosys/";
if (check_file_exists(proc_share_path, true)) if (check_file_exists(proc_share_path, true)) {
return proc_share_path; yosys_share_dirname = proc_share_path;
return;
}
# ifdef YOSYS_DATDIR # ifdef YOSYS_DATDIR
proc_share_path = YOSYS_DATDIR "/"; proc_share_path = YOSYS_DATDIR "/";
if (check_file_exists(proc_share_path, true)) if (check_file_exists(proc_share_path, true)) {
return proc_share_path; yosys_share_dirname = proc_share_path;
return;
}
# endif # endif
# endif # endif
log_error("proc_share_dirname: unable to determine share/ directory!\n");
} }
#endif #endif
void init_abc_executable_name()
{
#ifdef ABCEXTERNAL
std::string exe_file;
if (std::getenv("ABC")) {
yosys_abc_executable = std::getenv("ABC");
} else {
yosys_abc_executable = ABCEXTERNAL;
}
#else
yosys_abc_executable = proc_self_dirname() + proc_program_prefix()+ "yosys-abc";
#endif
#ifdef _WIN32
#ifndef ABCEXTERNAL
if (!check_file_exists(yosys_abc_executable + ".exe") && check_file_exists(proc_self_dirname() + "..\\" + proc_program_prefix() + "yosys-abc.exe"))
yosys_abc_executable = proc_self_dirname() + "..\\" + proc_program_prefix() + "yosys-abc";
#endif
#endif
}
std::string proc_share_dirname()
{
if (yosys_share_dirname.empty())
log_error("init_share_dirname: unable to determine share/ directory!\n");
return yosys_share_dirname;
}
std::string proc_program_prefix() std::string proc_program_prefix()
{ {
std::string program_prefix; std::string program_prefix;

View File

@ -366,6 +366,9 @@ extern std::map<std::string, void*> loaded_python_plugins;
extern std::map<std::string, std::string> loaded_plugin_aliases; extern std::map<std::string, std::string> loaded_plugin_aliases;
void load_plugin(std::string filename, std::vector<std::string> aliases); void load_plugin(std::string filename, std::vector<std::string> aliases);
extern std::string yosys_share_dirname;
extern std::string yosys_abc_executable;
YOSYS_NAMESPACE_END YOSYS_NAMESPACE_END
#endif #endif

View File

@ -1470,16 +1470,7 @@ struct AbcPass : public Pass {
pi_map.clear(); pi_map.clear();
po_map.clear(); po_map.clear();
#ifdef ABCEXTERNAL std::string exe_file = yosys_abc_executable;
std::string exe_file;
if (std::getenv("ABC")) {
exe_file = std::getenv("ABC");
} else {
exe_file = ABCEXTERNAL;
}
#else
std::string exe_file = proc_self_dirname() + proc_program_prefix() + "yosys-abc";
#endif
std::string script_file, liberty_file, constr_file, clk_str; std::string script_file, liberty_file, constr_file, clk_str;
std::string delay_target, sop_inputs, sop_products, lutin_shared = "-S 1"; std::string delay_target, sop_inputs, sop_products, lutin_shared = "-S 1";
bool fast_mode = false, dff_mode = false, keepff = false, cleanup = true; bool fast_mode = false, dff_mode = false, keepff = false, cleanup = true;
@ -1494,13 +1485,6 @@ struct AbcPass : public Pass {
enabled_gates.clear(); enabled_gates.clear();
cmos_cost = false; cmos_cost = false;
#ifdef _WIN32
#ifndef ABCEXTERNAL
if (!check_file_exists(exe_file + ".exe") && check_file_exists(proc_self_dirname() + "..\\" + proc_program_prefix()+ "yosys-abc.exe"))
exe_file = proc_self_dirname() + "..\\" + proc_program_prefix() + "yosys-abc";
#endif
#endif
// get arguments from scratchpad first, then override by command arguments // get arguments from scratchpad first, then override by command arguments
std::string lut_arg, luts_arg, g_arg; std::string lut_arg, luts_arg, g_arg;
exe_file = design->scratchpad_get_string("abc.exe", exe_file /* inherit default value if not set */); exe_file = design->scratchpad_get_string("abc.exe", exe_file /* inherit default value if not set */);

View File

@ -379,11 +379,7 @@ struct Abc9ExePass : public Pass {
{ {
log_header(design, "Executing ABC9_EXE pass (technology mapping using ABC9).\n"); log_header(design, "Executing ABC9_EXE pass (technology mapping using ABC9).\n");
#ifdef ABCEXTERNAL std::string exe_file = yosys_abc_executable;
std::string exe_file = ABCEXTERNAL;
#else
std::string exe_file = proc_self_dirname() + proc_program_prefix()+ "yosys-abc";
#endif
std::string script_file, clk_str, box_file, lut_file; std::string script_file, clk_str, box_file, lut_file;
std::string delay_target, lutin_shared = "-S 1", wire_delay; std::string delay_target, lutin_shared = "-S 1", wire_delay;
std::string tempdir_name; std::string tempdir_name;
@ -396,13 +392,6 @@ struct Abc9ExePass : public Pass {
show_tempdir = true; show_tempdir = true;
#endif #endif
#ifdef _WIN32
#ifndef ABCEXTERNAL
if (!check_file_exists(exe_file + ".exe") && check_file_exists(proc_self_dirname() + "..\\" + proc_program_prefix() + "yosys-abc.exe"))
exe_file = proc_self_dirname() + "..\\" + proc_program_prefix() + "yosys-abc";
#endif
#endif
std::string lut_arg, luts_arg; std::string lut_arg, luts_arg;
exe_file = design->scratchpad_get_string("abc9.exe", exe_file /* inherit default value if not set */); exe_file = design->scratchpad_get_string("abc9.exe", exe_file /* inherit default value if not set */);
script_file = design->scratchpad_get_string("abc9.script", script_file); script_file = design->scratchpad_get_string("abc9.script", script_file);