mirror of https://github.com/YosysHQ/yosys.git
- kernel/register.h, kernel/driver.cc: refactor rewrite_yosys_exe()/get_share_file_name() to portable proc_self_dirname()/proc_share_dirname().
This refactoring improves robustness and allows OSX support with only 7 new lines of code, and easy extension for other systems. - passes/abc/abc.cc, passes/cmds/show.cc, passes/techmap/techmap.cc: use new, refactored semantics. - Makefile: no need to add $(PWD) to $(PATH) anymore.
This commit is contained in:
parent
50423e3935
commit
5a50760e2c
2
Makefile
2
Makefile
|
@ -26,8 +26,6 @@ CXXFLAGS = -Wall -Wextra -ggdb -I"$(shell pwd)" -I${DESTDIR}/include -MD -D_YOSY
|
||||||
LDFLAGS = -L${DESTDIR}/lib
|
LDFLAGS = -L${DESTDIR}/lib
|
||||||
LDLIBS = -lstdc++ -lreadline -lm -ldl
|
LDLIBS = -lstdc++ -lreadline -lm -ldl
|
||||||
|
|
||||||
export PATH := $(PWD):$(DESTDIR)/bin:$(PATH)
|
|
||||||
|
|
||||||
ifeq (Darwin,$(findstring Darwin,$(shell uname)))
|
ifeq (Darwin,$(findstring Darwin,$(shell uname)))
|
||||||
# add macports include and library path to search directories, don't use '-rdynamic' and '-lrt':
|
# add macports include and library path to search directories, don't use '-rdynamic' and '-lrt':
|
||||||
CXXFLAGS += -I/opt/local/include
|
CXXFLAGS += -I/opt/local/include
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
@ -427,42 +428,46 @@ extern RTLIL::Design *yosys_get_design()
|
||||||
return yosys_design;
|
return yosys_design;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string rewrite_yosys_exe(std::string exe)
|
#if defined(__linux__)
|
||||||
|
std::string proc_self_dirname ()
|
||||||
{
|
{
|
||||||
char buffer[1024];
|
char path [PATH_MAX];
|
||||||
ssize_t buflen = readlink("/proc/self/exe", buffer, sizeof(buffer)-1);
|
ssize_t buflen = readlink("/proc/self/exe", path, sizeof(path));
|
||||||
|
if (buflen < 0) {
|
||||||
if (buflen < 0)
|
log_cmd_error("readlink(\"/proc/self/exe\") failed: %s", strerror(errno));
|
||||||
return exe;
|
log_abort();
|
||||||
|
|
||||||
buffer[buflen] = 0;
|
|
||||||
std::string newexe = stringf("%s/%s", dirname(buffer), exe.c_str());
|
|
||||||
if (access(newexe.c_str(), X_OK) == 0)
|
|
||||||
return newexe;
|
|
||||||
|
|
||||||
return exe;
|
|
||||||
}
|
}
|
||||||
|
while (buflen > 0 && path[buflen-1] != '/')
|
||||||
std::string get_share_file_name(std::string file)
|
buflen--;
|
||||||
|
return std::string(path, buflen);
|
||||||
|
}
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
#include <mach-o/dyld.h>
|
||||||
|
std::string proc_self_dirname ()
|
||||||
{
|
{
|
||||||
char buffer[1024];
|
char * path = NULL;
|
||||||
ssize_t buflen = readlink("/proc/self/exe", buffer, sizeof(buffer)-1);
|
uint32_t buflen = 0;
|
||||||
|
while (_NSGetExecutablePath(path, &buflen) != 0)
|
||||||
|
path = (char *) realloc((void *) path, buflen);
|
||||||
|
while (buflen > 0 && path[buflen-1] != '/')
|
||||||
|
buflen--;
|
||||||
|
return std::string(path, buflen);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#error Dont know how to determine process executable base path!
|
||||||
|
#endif
|
||||||
|
|
||||||
if (buflen < 0)
|
std::string proc_share_dirname ()
|
||||||
log_error("Can't find file `%s': reading of /proc/self/exe failed!\n", file.c_str());
|
{
|
||||||
|
std::string proc_self_path = proc_self_dirname();
|
||||||
buffer[buflen] = 0;
|
std::string proc_share_path = proc_self_path + "share/";
|
||||||
const char *dir = dirname(buffer);
|
if (access(proc_share_path.c_str(), X_OK) == 0)
|
||||||
|
return proc_share_path;
|
||||||
std::string newfile_inplace = stringf("%s/share/%s", dir, file.c_str());
|
proc_share_path = proc_self_path + "../share/yosys/";
|
||||||
if (access(newfile_inplace.c_str(), F_OK) == 0)
|
if (access(proc_share_path.c_str(), X_OK) == 0)
|
||||||
return newfile_inplace;
|
return proc_share_path;
|
||||||
|
log_cmd_error("proc_share_dirname: unable to determine share/ directory!");
|
||||||
std::string newfile_system = stringf("%s/../share/yosys/%s", dir, file.c_str());
|
log_abort();
|
||||||
if (access(newfile_system.c_str(), F_OK) == 0)
|
|
||||||
return newfile_system;
|
|
||||||
|
|
||||||
log_error("Can't find file `%s': no `%s' and no `%s' found!\n", file.c_str(), newfile_inplace.c_str(), newfile_system.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
|
|
|
@ -36,8 +36,8 @@ extern const char *yosys_version_str;
|
||||||
|
|
||||||
// implemented in driver.cc
|
// implemented in driver.cc
|
||||||
extern RTLIL::Design *yosys_get_design();
|
extern RTLIL::Design *yosys_get_design();
|
||||||
std::string rewrite_yosys_exe(std::string exe);
|
extern std::string proc_self_dirname();
|
||||||
std::string get_share_file_name(std::string file);
|
extern std::string proc_share_dirname();
|
||||||
const char *create_prompt(RTLIL::Design *design, int recursion_counter);
|
const char *create_prompt(RTLIL::Design *design, int recursion_counter);
|
||||||
|
|
||||||
// from passes/cmds/design.cc
|
// from passes/cmds/design.cc
|
||||||
|
|
|
@ -969,7 +969,7 @@ struct AbcPass : public Pass {
|
||||||
log_header("Executing ABC pass (technology mapping using ABC).\n");
|
log_header("Executing ABC pass (technology mapping using ABC).\n");
|
||||||
log_push();
|
log_push();
|
||||||
|
|
||||||
std::string exe_file = rewrite_yosys_exe("yosys-abc");
|
std::string exe_file = proc_self_dirname() + "yosys-abc";
|
||||||
std::string script_file, liberty_file, constr_file, clk_str;
|
std::string script_file, liberty_file, constr_file, clk_str;
|
||||||
bool dff_mode = false, keepff = false, cleanup = true;
|
bool dff_mode = false, keepff = false, cleanup = true;
|
||||||
int lut_mode = 0;
|
int lut_mode = 0;
|
||||||
|
|
|
@ -751,7 +751,8 @@ struct ShowPass : public Pass {
|
||||||
log_cmd_error("Shell command failed!\n");
|
log_cmd_error("Shell command failed!\n");
|
||||||
} else
|
} else
|
||||||
if (format.empty()) {
|
if (format.empty()) {
|
||||||
std::string cmd = stringf("fuser -s '%s' || '%s' '%s' &", out_file.c_str(), rewrite_yosys_exe("yosys-svgviewer").c_str(), out_file.c_str());
|
std::string svgviewer = proc_self_dirname() + "yosys-svgviewer";
|
||||||
|
std::string cmd = stringf("fuser -s '%s' || '%s' '%s' &", out_file.c_str(), svgviewer.c_str(), out_file.c_str());
|
||||||
log("Exec: %s\n", cmd.c_str());
|
log("Exec: %s\n", cmd.c_str());
|
||||||
if (system(cmd.c_str()) != 0)
|
if (system(cmd.c_str()) != 0)
|
||||||
log_cmd_error("Shell command failed!\n");
|
log_cmd_error("Shell command failed!\n");
|
||||||
|
|
|
@ -548,13 +548,14 @@ struct TechmapPass : public Pass {
|
||||||
int max_iter = -1;
|
int max_iter = -1;
|
||||||
|
|
||||||
size_t argidx;
|
size_t argidx;
|
||||||
|
std::string proc_share_path = proc_share_dirname();
|
||||||
for (argidx = 1; argidx < args.size(); argidx++) {
|
for (argidx = 1; argidx < args.size(); argidx++) {
|
||||||
if (args[argidx] == "-map" && argidx+1 < args.size()) {
|
if (args[argidx] == "-map" && argidx+1 < args.size()) {
|
||||||
map_files.push_back(args[++argidx]);
|
map_files.push_back(args[++argidx]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (args[argidx] == "-share_map" && argidx+1 < args.size()) {
|
if (args[argidx] == "-share_map" && argidx+1 < args.size()) {
|
||||||
map_files.push_back(get_share_file_name(args[++argidx]));
|
map_files.push_back(proc_share_path + args[++argidx]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (args[argidx] == "-max_iter" && argidx+1 < args.size()) {
|
if (args[argidx] == "-max_iter" && argidx+1 < args.size()) {
|
||||||
|
|
Loading…
Reference in New Issue