Skip to content

Commit 8056dea

Browse files
committed
Merge pull request #78 from ix-dcourtois/fix/windows_build
* ix-dcourtois/fix/windows_build: create a static lib on Windows fixed __attribute__ not defined on Windows fixed Vec on Windows fixed a warning and a compilation error on Windows another missing header on Windows fixed dlfcn.h not available on Windows fixed __VERSION__ not defined on Windows added a missing header on Windows compilation fix on Windows implemented Time on Windows Signed-off-by: David Aguilar <[email protected]>
2 parents 1e9ce12 + bba7589 commit 8056dea

File tree

8 files changed

+53
-12
lines changed

8 files changed

+53
-12
lines changed

src/SeExpr/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,11 @@ endif()
7979

8080
## Make the SeExpr library with and without LLVM support
8181
file(GLOB llvm_cpp "*.cpp")
82-
add_library(SeExpr2 SHARED ${io_cpp} ${core_cpp} ${parser_cpp} ${llvm_cpp})
8382
if (NOT WIN32)
83+
add_library(SeExpr2 SHARED ${io_cpp} ${core_cpp} ${parser_cpp} ${llvm_cpp})
8484
target_link_libraries(SeExpr2 "dl" "pthread")
85+
else()
86+
add_library(SeExpr2 STATIC ${io_cpp} ${core_cpp} ${parser_cpp} ${llvm_cpp})
8587
endif()
8688

8789
## Install binary and includes

src/SeExpr/ExprNode.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#ifndef MAKEDEPEND
1919
#include <math.h>
2020
#include <sstream>
21+
#include <algorithm>
2122
#endif
2223
#include "Vec.h"
2324
#include "ExprType.h"

src/SeExpr/Expression.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,13 @@ bool Expression::debugging = getenv("SE_EXPR_DEBUG") != 0;
4545
// And the environment variables SE_EXPR_DEBUG
4646
static Expression::EvaluationStrategy chooseDefaultEvaluationStrategy() {
4747
if (Expression::debugging) {
48-
std::cerr << "SeExpr2 Debug Mode Enabled " << __VERSION__
49-
<< std::endl;
48+
std::cerr << "SeExpr2 Debug Mode Enabled " <<
49+
#if defined(WINDOWS)
50+
_MSC_FULL_VER
51+
#else
52+
__VERSION__
53+
#endif
54+
<< std::endl;
5055
}
5156
#ifdef SEEXPR_ENABLE_LLVM
5257
if (char* env = getenv("SE_EXPR_EVAL")) {

src/SeExpr/Interpreter.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717
#include "ExprNode.h"
1818
#include "Interpreter.h"
1919
#include "VarBlock.h"
20+
#include "Platform.h"
2021
#include <iostream>
2122
#include <cstdio>
23+
#include <algorithm>
24+
#if !defined(WINDOWS)
2225
#include <dlfcn.h>
26+
#endif
2327

2428
// TODO: optimize to write to location directly on a CondNode
2529
namespace SeExpr2 {
@@ -48,9 +52,11 @@ void Interpreter::eval(VarBlock* block, bool debug) {
4852
void Interpreter::print(int pc) const {
4953
std::cerr << "---- ops ----------------------" << std::endl;
5054
for (size_t i = 0; i < ops.size(); i++) {
51-
Dl_info info;
5255
const char* name = "";
56+
#if !defined(WINDOWS)
57+
Dl_info info;
5358
if (dladdr((void*)ops[i].first, &info)) name = info.dli_sname;
59+
#endif
5460
fprintf(stderr, "%s %s %p (", pc == (int)i ? "-->" : " ", name, ops[i].first);
5561
int nextGuy = (i == ops.size() - 1 ? opData.size() : ops[i + 1].second);
5662
for (int k = ops[i].second; k < nextGuy; k++) {

src/SeExpr/Noise.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ T noiseHelper(const T* X, const int* period = 0) {
9696
weights[1][k] = weights[0][k] - 1; // dist to cell with index one above
9797
}
9898
// compute function values propagated from zero from each node
99-
int num = 1 << d;
99+
const int num = 1 << d;
100100
T vals[num];
101101
for (int dummy = 0; dummy < num; dummy++) {
102102
int latticeIndex[d];

src/SeExpr/Platform.h

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include <string.h>
5252
#include <pthread.h>
5353
#include <inttypes.h>
54+
#include <sys/time.h>
5455
// OS for spinlock
5556
#ifdef __APPLE__
5657
#include <libkern/OSAtomic.h>
@@ -62,7 +63,6 @@
6263
#include <stdio.h>
6364
#include <math.h>
6465
#include <assert.h>
65-
#include <sys/time.h>
6666

6767
// missing functions on Windows
6868
#ifdef WINDOWS
@@ -125,19 +125,42 @@ class Timer {
125125
};
126126
#else // Windows
127127
class Timer {
128+
__int64 ticksPerSeconds;
129+
__int64 startTime, stopTime;
130+
bool started;
131+
132+
__int64 time() {
133+
LARGE_INTEGER perfCounter;
134+
QueryPerformanceCounter(&perfCounter);
135+
return perfCounter.QuadPart;
136+
}
137+
128138
public:
129-
Timer() : started(false) {}
139+
Timer() : started(false) {
140+
// get the timer frequency
141+
LARGE_INTEGER frequency;
142+
QueryPerformanceFrequency(&frequency);
143+
ticksPerSeconds = frequency.QuadPart;
144+
}
130145

131-
void start() { std::cerr << "timer not implemented on Windows" << std::endl; }
132-
long elapsedTime() { return 0; }
146+
void start() {
147+
started = true;
148+
startTime = this->time();
149+
}
150+
151+
long elapsedTime() {
152+
stopTime = this->time();
153+
return static_cast<long>(((stopTime - startTime) * 1000000) / ticksPerSeconds);
154+
}
133155
};
134156
#endif
135157

136158
class PrintTiming {
137159
public:
138160
PrintTiming(const std::string& s) : _s(s) { _timer.start(); }
139161

140-
~PrintTiming() { std::cout << _s << " (" << _timer.elapsedTime() << " ms)" << std::endl; }
162+
~PrintTiming() { std::cout << _s.c_str() << " (" << _timer.elapsedTime() << " ms)" << std::endl; }
163+
141164

142165
private:
143166
Timer _timer;

src/SeExpr/Vec.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <cstdlib>
2121
#include <cmath>
2222
#include <iostream>
23+
#include "Platform.h"
2324

2425
//#############################################################################
2526
// Template Metaprogramming Helpers
@@ -40,7 +41,11 @@ struct my_enable_if {
4041
};
4142
//! Enable_if failure case (substitution failure is not an error)
4243
template <class T>
43-
struct my_enable_if<false, T> {};
44+
struct my_enable_if<false, T> {
45+
#if defined(WINDOWS)
46+
typedef T TYPE;
47+
#endif
48+
};
4449

4550
//! Static conditional type true case
4651
template <bool c, class T1, class T2>

windows7/SeExpr/generated/ExprParser.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,6 @@ while (SeExprYYID (0))
10301030

10311031
/* Print *SeExprYYLOCP on SeExprYYO. Private, do not rely on its existence. */
10321032

1033-
__attribute__((__unused__))
10341033
#if (defined __STDC__ || defined __C99__FUNC__ \
10351034
|| defined __cplusplus || defined _MSC_VER)
10361035
static unsigned

0 commit comments

Comments
 (0)