mirror of https://github.com/YosysHQ/yosys.git
fix: function naming and locations
This commit is contained in:
parent
8c731658c2
commit
820232eaca
|
@ -53,78 +53,6 @@
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <sys/stat.h> // _stat
|
|
||||||
#include <errno.h> // errno, ENOENT, EEXIST
|
|
||||||
#if defined(_WIN32)
|
|
||||||
# include <direct.h>
|
|
||||||
# define mkdir(path, mode) _mkdir(path)
|
|
||||||
# define PATH_DELIMETER "\\"
|
|
||||||
#else
|
|
||||||
# define PATH_DELIMETER "/"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool isDirExist(const std::string& path)
|
|
||||||
{
|
|
||||||
#if defined(_WIN32)
|
|
||||||
struct _stat info;
|
|
||||||
if (_stat(path.c_str(), &info) != 0)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return (info.st_mode & _S_IFDIR) != 0;
|
|
||||||
#else
|
|
||||||
struct stat info;
|
|
||||||
if (stat(path.c_str(), &info) != 0)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return (info.st_mode & S_IFDIR) != 0;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
bool makePath(const std::string& path)
|
|
||||||
{
|
|
||||||
#if defined(_WIN32)
|
|
||||||
int ret = _mkdir(path.c_str());
|
|
||||||
#else
|
|
||||||
mode_t mode = 0755;
|
|
||||||
int ret = mkdir(path.c_str(), mode);
|
|
||||||
#endif
|
|
||||||
if (ret == 0)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
switch (errno)
|
|
||||||
{
|
|
||||||
case ENOENT:
|
|
||||||
// parent didn't exist, try to create it
|
|
||||||
{
|
|
||||||
int pos = path.find_last_of('/');
|
|
||||||
if (pos == std::string::npos)
|
|
||||||
#if defined(_WIN32)
|
|
||||||
pos = path.find_last_of('\\');
|
|
||||||
if (pos == std::string::npos)
|
|
||||||
#endif
|
|
||||||
return false;
|
|
||||||
if (!makePath( path.substr(0, pos) ))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// now, try to create again
|
|
||||||
#if defined(_WIN32)
|
|
||||||
return 0 == _mkdir(path.c_str());
|
|
||||||
#else
|
|
||||||
return 0 == mkdir(path.c_str(), mode);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
case EEXIST:
|
|
||||||
// done!
|
|
||||||
return isDirExist(path);
|
|
||||||
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
USING_YOSYS_NAMESPACE
|
USING_YOSYS_NAMESPACE
|
||||||
|
|
||||||
char *optarg;
|
char *optarg;
|
||||||
|
@ -329,8 +257,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
if (!state_dir.empty()) {
|
if (!state_dir.empty()) {
|
||||||
std::string yosys_dir = state_dir + "/yosys";
|
std::string yosys_dir = state_dir + "/yosys";
|
||||||
// mkdir(yosys_dir.c_str(), 0777);
|
create_directory(yosys_dir);
|
||||||
makePath(yosys_dir);
|
|
||||||
|
|
||||||
yosys_history_file = yosys_dir + "/history";
|
yosys_history_file = yosys_dir + "/history";
|
||||||
read_history(yosys_history_file.c_str());
|
read_history(yosys_history_file.c_str());
|
||||||
|
|
|
@ -436,6 +436,25 @@ std::string make_temp_dir(std::string template_str)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool check_dir_exists(const std::string& path)
|
||||||
|
{
|
||||||
|
#if defined(_WIN32)
|
||||||
|
struct _stat info;
|
||||||
|
if (_stat(path.c_str(), &info) != 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return (info.st_mode & _S_IFDIR) != 0;
|
||||||
|
#else
|
||||||
|
struct stat info;
|
||||||
|
if (stat(path.c_str(), &info) != 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return (info.st_mode & S_IFDIR) != 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
bool check_file_exists(std::string filename, bool)
|
bool check_file_exists(std::string filename, bool)
|
||||||
{
|
{
|
||||||
|
@ -481,6 +500,48 @@ void remove_directory(std::string dirname)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool create_directory(const std::string& path)
|
||||||
|
{
|
||||||
|
#if defined(_WIN32)
|
||||||
|
int ret = _mkdir(path.c_str());
|
||||||
|
#else
|
||||||
|
mode_t mode = 0755;
|
||||||
|
int ret = mkdir(path.c_str(), mode);
|
||||||
|
#endif
|
||||||
|
if (ret == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
switch (errno)
|
||||||
|
{
|
||||||
|
case ENOENT:
|
||||||
|
// parent didn't exist, try to create it
|
||||||
|
{
|
||||||
|
std::string::size_type pos = path.find_last_of('/');
|
||||||
|
if (pos == std::string::npos)
|
||||||
|
#if defined(_WIN32)
|
||||||
|
pos = path.find_last_of('\\');
|
||||||
|
if (pos == std::string::npos)
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
if (!create_directory( path.substr(0, pos) ))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// now, try to create again
|
||||||
|
#if defined(_WIN32)
|
||||||
|
return 0 == _mkdir(path.c_str());
|
||||||
|
#else
|
||||||
|
return 0 == mkdir(path.c_str(), mode);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
case EEXIST:
|
||||||
|
// done!
|
||||||
|
return check_dir_exists(path);
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::string escape_filename_spaces(const std::string& filename)
|
std::string escape_filename_spaces(const std::string& filename)
|
||||||
{
|
{
|
||||||
std::string out;
|
std::string out;
|
||||||
|
@ -781,10 +842,10 @@ static int tcl_yosys_cmd(ClientData, Tcl_Interp *interp, int argc, const char *a
|
||||||
|
|
||||||
int yosys_tcl_iterp_init(Tcl_Interp *interp)
|
int yosys_tcl_iterp_init(Tcl_Interp *interp)
|
||||||
{
|
{
|
||||||
if (Tcl_Init(interp)!=TCL_OK)
|
if (Tcl_Init(interp)!=TCL_OK)
|
||||||
log_warning("Tcl_Init() call failed - %s\n",Tcl_ErrnoMsg(Tcl_GetErrno()));
|
log_warning("Tcl_Init() call failed - %s\n",Tcl_ErrnoMsg(Tcl_GetErrno()));
|
||||||
Tcl_CreateCommand(interp, "yosys", tcl_yosys_cmd, NULL, NULL);
|
Tcl_CreateCommand(interp, "yosys", tcl_yosys_cmd, NULL, NULL);
|
||||||
return TCL_OK ;
|
return TCL_OK ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void yosys_tcl_activate_repl()
|
void yosys_tcl_activate_repl()
|
||||||
|
|
|
@ -66,6 +66,8 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#ifdef WITH_PYTHON
|
#ifdef WITH_PYTHON
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
|
@ -341,8 +343,10 @@ std::string get_base_tmpdir();
|
||||||
std::string make_temp_file(std::string template_str = get_base_tmpdir() + "/yosys_XXXXXX");
|
std::string make_temp_file(std::string template_str = get_base_tmpdir() + "/yosys_XXXXXX");
|
||||||
std::string make_temp_dir(std::string template_str = get_base_tmpdir() + "/yosys_XXXXXX");
|
std::string make_temp_dir(std::string template_str = get_base_tmpdir() + "/yosys_XXXXXX");
|
||||||
bool check_file_exists(std::string filename, bool is_exec = false);
|
bool check_file_exists(std::string filename, bool is_exec = false);
|
||||||
|
bool check_dir_exists(const std::string& path);
|
||||||
bool is_absolute_path(std::string filename);
|
bool is_absolute_path(std::string filename);
|
||||||
void remove_directory(std::string dirname);
|
void remove_directory(std::string dirname);
|
||||||
|
bool create_directory(const std::string& path);
|
||||||
std::string escape_filename_spaces(const std::string& filename);
|
std::string escape_filename_spaces(const std::string& filename);
|
||||||
|
|
||||||
template<typename T> int GetSize(const T &obj) { return obj.size(); }
|
template<typename T> int GetSize(const T &obj) { return obj.size(); }
|
||||||
|
|
Loading…
Reference in New Issue