Merged a few fixes for non-posix systems from github.com/Siesh1oo/yosys
authorClifford Wolf <clifford@clifford.at>
Tue, 11 Mar 2014 13:24:24 +0000 (14:24 +0100)
committerClifford Wolf <clifford@clifford.at>
Tue, 11 Mar 2014 13:24:24 +0000 (14:24 +0100)
(see https://github.com/cliffordwolf/yosys/pull/28)

README
frontends/vhdl2verilog/vhdl2verilog.cc
kernel/driver.cc
kernel/log.h
kernel/register.cc
libs/ezsat/ezminisat.cc
libs/ezsat/ezsat.cc
passes/abc/abc.cc
passes/cmds/select.cc
passes/fsm/fsm_recode.cc
passes/techmap/dfflibmap.cc

diff --git a/README b/README
index 385ee2c0afad63f737b3b3c2f0d7b3b2bc4b0e71..45febc2f9cc98ecdaa23b691cff920c91c6db55a 100644 (file)
--- a/README
+++ b/README
@@ -292,7 +292,7 @@ a recent version of gcc:
 This is a bug in the minisat header. It can be fixed by adding spaces before
 and after each occurrence of PRIi64 in the header file:
 
-        sudo sed -i 's/PRIi64/ & /' /usr/include/minisat/utils/Options.h
+        sudo sed -i -e 's/PRIi64/ & /' /usr/include/minisat/utils/Options.h
 
 
 Roadmap / Large-scale TODOs
index 0467810e5478f28b147bc5089ef3e8a03f27b841..83035d329001e183b6d4a704328d0e21b5089116 100644 (file)
@@ -26,6 +26,8 @@
 #include <stdio.h>
 #include <string.h>
 #include <dirent.h>
+#include <errno.h>
+#include <limits.h>
 
 struct Vhdl2verilogPass : public Pass {
        Vhdl2verilogPass() : Pass("vhdl2verilog", "importing VHDL designs using vhdl2verilog") { }
@@ -93,9 +95,12 @@ struct Vhdl2verilogPass : public Pass {
                        log_error("For some reason mkdtemp() failed!\n");
 
                if (!out_file.empty() && out_file[0] != '/') {
-                       char *pwd = get_current_dir_name();
+                       char pwd [PATH_MAX];
+                       if (!getcwd(pwd, sizeof(pwd))) {
+                               log_cmd_error("getcwd failed: %s", strerror(errno));
+                               log_abort();
+                       }
                        out_file = pwd + ("/" + out_file);
-                       free(pwd);
                }
 
                FILE *f = fopen(stringf("%s/files.list", tempdir_name).c_str(), "wt");
@@ -104,9 +109,12 @@ struct Vhdl2verilogPass : public Pass {
                        if (file.empty())
                                continue;
                        if (file[0] != '/') {
-                               char *pwd = get_current_dir_name();
+                               char pwd [PATH_MAX];
+                               if (!getcwd(pwd, sizeof(pwd))) {
+                                       log_cmd_error("getcwd failed: %s", strerror(errno));
+                                       log_abort();
+                               }
                                file = pwd + ("/" + file);
-                               free(pwd);
                        }
                        fprintf(f, "%s\n", file.c_str());
                        log("Adding '%s' to the file list.\n", file.c_str());
index 00a61ec0fc372c5ccac4c20be54ba8e05a81e070..ce95cad4fee9a4b2ca8e95be106fd2b522af19c1 100644 (file)
@@ -24,6 +24,7 @@
 #include <unistd.h>
 #include <libgen.h>
 #include <dlfcn.h>
+#include <errno.h>
 
 #include <algorithm>
 
index c4c03352af7815f0408d62c63b3009a6b5ae70f2..fbc3c1c39be5dd19edcb1e188796213450df0d03 100644 (file)
@@ -23,6 +23,8 @@
 #include "kernel/rtlil.h"
 #include <stdio.h>
 #include <time.h>
+#include <sys/time.h>
+#include <sys/resource.h>
 #include <vector>
 
 extern std::vector<FILE*> log_files;
@@ -65,9 +67,23 @@ struct PerformanceTimer
        }
 
        static int64_t query() {
+#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0)
                struct timespec ts;
                clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts);
                return int64_t(ts.tv_sec)*1000000000 + ts.tv_nsec;
+#elif defined(RUSAGE_SELF)
+               struct rusage rusage;
+               int64_t t;
+               if (getrusage(RUSAGE_SELF, &rusage) == -1) {
+                       log_cmd_error("getrusage failed!\n");
+                       log_abort();
+               }
+               t = 1000000000ULL * (int64_t) rusage.ru_utime.tv_sec + (int64_t) rusage.ru_utime.tv_usec * 1000ULL;
+               t += 1000000000ULL * (int64_t) rusage.ru_stime.tv_sec + (int64_t) rusage.ru_stime.tv_usec * 1000ULL;
+               return t;
+#else
+       #error Dont know how to measure per-process CPU time. Need alternative method (times()/clocks()/gettimeofday()?).
+#endif
        }
 
        void reset() {
index ee14ffbad7996bc594ee5e21b1dacd5a2115e805..ab5cba11bced70e4a1bb640ea3509ad1718bd38f 100644 (file)
@@ -23,6 +23,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <errno.h>
 
 using namespace REGISTER_INTERN;
 #define MAX_REG_COUNT 1000
index d488a90623d6f21d5cee307c7c75553180ac9d2e..4677f68bd77801dfa55e5a66d6fef64ba4db435b 100644 (file)
@@ -25,7 +25,7 @@
 
 #include <limits.h>
 #include <stdint.h>
-#include <signal.h>
+#include <csignal>
 #include <cinttypes>
 
 #include <minisat/core/Solver.h>
@@ -170,14 +170,18 @@ contradiction:
 #endif
        }
 
-       sighandler_t old_alarm_sighandler = NULL;
+       struct sigaction sig_action;
+       struct sigaction old_sig_action;
        int old_alarm_timeout = 0;
 
        if (solverTimeout > 0) {
+               sig_action.sa_handler = alarmHandler;
+               sigemptyset(&sig_action.sa_mask);
+               sig_action.sa_flags = SA_RESTART;
                alarmHandlerThis = this;
                alarmHandlerTimeout = clock() + solverTimeout*CLOCKS_PER_SEC;
                old_alarm_timeout = alarm(0);
-               old_alarm_sighandler = signal(SIGALRM, alarmHandler);
+               sigaction(SIGALRM, &sig_action, &old_sig_action);
                alarm(1);
        }
 
@@ -187,7 +191,7 @@ contradiction:
                if (alarmHandlerTimeout == 0)
                        solverTimoutStatus = true;
                alarm(0);
-               signal(SIGALRM, old_alarm_sighandler);
+               sigaction(SIGALRM, &old_sig_action, NULL);
                alarm(old_alarm_timeout);
        }
 
index fb3d249967dce70bfcfa8c71bf5d6e2bbca3787b..6da363fc11eb28ffdf5c3cee7ded030e9793d6ab 100644 (file)
 
 #include "ezsat.h"
 
+#include <cmath>
 #include <algorithm>
+#include <cassert>
 
 #include <stdlib.h>
-#include <assert.h>
 
 const int ezSAT::TRUE = 1;
 const int ezSAT::FALSE = 2;
index 2829e660f8c59046bb99944c4b136dc4a331e47a..286b750cc1e2f2789c58bc936b09cfadb27e2592 100644 (file)
@@ -43,7 +43,9 @@
 #include <stdio.h>
 #include <string.h>
 #include <dirent.h>
+#include <cerrno>
 #include <sstream>
+#include <climits>
 
 #include "blifparse.h"
 
@@ -973,7 +975,11 @@ struct AbcPass : public Pass {
                int lut_mode = 0;
 
                size_t argidx;
-               char *pwd = get_current_dir_name();
+               char pwd [PATH_MAX];
+               if (!getcwd(pwd, sizeof(pwd))) {
+                       log_cmd_error("getcwd failed: %s\n", strerror(errno));
+                       log_abort();
+               }
                for (argidx = 1; argidx < args.size(); argidx++) {
                        std::string arg = args[argidx];
                        if (arg == "-exe" && argidx+1 < args.size()) {
@@ -1020,7 +1026,6 @@ struct AbcPass : public Pass {
                        }
                        break;
                }
-               free(pwd);
                extra_args(args, argidx, design);
 
                if (lut_mode != 0 && !liberty_file.empty())
index 3a886b1c8af2c05a369429a42e7d0b2ee9bc6fbe..59f936b01396525b70e24d4bcab76feeee8770fd 100644 (file)
@@ -23,6 +23,7 @@
 #include "kernel/log.h"
 #include <string.h>
 #include <fnmatch.h>
+#include <errno.h>
 
 using RTLIL::id2cstr;
 
index 5a4e091cf6dc1411e0b9666646b907a760d487ba..b02287962a158adf6bd30a9b6cdb59166624c8f8 100644 (file)
@@ -23,8 +23,9 @@
 #include "kernel/consteval.h"
 #include "kernel/celltypes.h"
 #include "fsmdata.h"
-#include "math.h"
+#include <math.h>
 #include <string.h>
+#include <errno.h>
 
 static void fm_set_fsm_print(RTLIL::Cell *cell, RTLIL::Module *module, FsmData &fsm_data, const char *prefix, FILE *f)
 {
index fd5fa86e17863c04ec37ec2bcb62f4fefc175c96..4bf73358bfdb8c3075b9d8ddcb5d32d38aa36361 100644 (file)
@@ -21,6 +21,7 @@
 #include "kernel/log.h"
 #include "libparse.h"
 #include <string.h>
+#include <errno.h>
 
 using namespace PASS_DFFLIBMAP;