Fixed log so it will compile under Visual Studio
[yosys.git] / kernel / log.cc
index 87a75410dd85e529832a6d5553ec3c8ef57c50dc..4585e7eff8ca7a10cdde85dcee0324e17621f445 100644 (file)
 #include "libs/sha1/sha1.h"
 #include "backends/ilang/ilang_backend.h"
 
-#include <sys/time.h>
+#ifndef _WIN32
+       #include <sys/time.h>
+#endif
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -48,6 +51,26 @@ static struct timeval initial_tv = { 0, 0 };
 static bool next_print_log = false;
 static int log_newline_count = 0;
 
+#ifdef _WIN32
+// this will get time information and return it in timeval, simulating gettimeofday()
+int gettimeofday(struct timeval *tv, struct timezone *tz)
+{
+       LARGE_INTEGER counter;
+       LARGE_INTEGER freq;
+
+       QueryPerformanceFrequency(&freq);
+       QueryPerformanceCounter(&counter);
+
+       counter.QuadPart *= 1000000;
+       counter.QuadPart /= freq.QuadPart;
+
+       tv->tv_sec = counter.QuadPart / 1000000;
+       tv->tv_usec = counter.QuadPart % 1000000;
+
+       return 0;
+}
+#endif
+
 void logv(const char *format, va_list ap)
 {
        while (format[0] == '\n' && format[1] != 0) {