diff options
author | Andrew Scheidecker <andrew@scheidecker.net> | 2015-12-23 09:09:49 -0800 |
---|---|---|
committer | Andrew Scheidecker <andrew@scheidecker.net> | 2015-12-23 09:29:24 -0800 |
commit | 32490684ab0fa568d4e539c24f7c560295da57de (patch) | |
tree | 4e4a91591ea75ba52cc9c0d37698f8aac743896e | |
parent | a79329fbe135bab9a319fd3afc911620b12f0124 (diff) | |
download | binaryen-32490684ab0fa568d4e539c24f7c560295da57de.tar.gz binaryen-32490684ab0fa568d4e539c24f7c560295da57de.tar.bz2 binaryen-32490684ab0fa568d4e539c24f7c560295da57de.zip |
Fix a few Windows/VS2013 compile errors
-rw-r--r-- | CMakeLists.txt | 11 | ||||
-rw-r--r-- | src/emscripten-optimizer/colors.h | 14 | ||||
-rw-r--r-- | src/wasm-interpreter.h | 29 | ||||
-rw-r--r-- | src/wasm-validator.h | 28 | ||||
-rw-r--r-- | src/wasm.h | 1 |
5 files changed, 65 insertions, 18 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 95c303c94..ab711ac44 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,9 +5,14 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin") -SET(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}") -SET(CMAKE_CXX_FLAGS "-msse2 -mfpmath=sse ${CMAKE_CXX_FLAGS}") -SET(CMAKE_CXX_FLAGS "-O2 -Wall -Werror ${CMAKE_CXX_FLAGS}") +IF(MSVC) + SET(CMAKE_CXX_FLAGS "/arch:sse2 ${CMAKE_CXX_FLAGS}") + SET(CMAKE_CXX_FLAGS "/O2 /Wall /WX- ${CMAKE_CXX_FLAGS}") +ELSE() + SET(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}") + SET(CMAKE_CXX_FLAGS "-msse2 -mfpmath=sse ${CMAKE_CXX_FLAGS}") + SET(CMAKE_CXX_FLAGS "-O2 -Wall -Werror ${CMAKE_CXX_FLAGS}") +ENDIF() # clang doesn't print colored diagnostics when invoked from Ninja IF (UNIX AND diff --git a/src/emscripten-optimizer/colors.h b/src/emscripten-optimizer/colors.h index c3f48113f..9a8cb8ad6 100644 --- a/src/emscripten-optimizer/colors.h +++ b/src/emscripten-optimizer/colors.h @@ -17,6 +17,7 @@ #ifndef wasm_color_h #define wasm_color_h +#ifndef WIN32 #include <unistd.h> #include <cstdlib> #include <ostream> @@ -76,5 +77,18 @@ namespace Colors { #endif } }; +#else +namespace Colors { + inline bool use() { return false; } + inline void normal(std::ostream& stream) {} + inline void red(std::ostream& stream) {} + inline void magenta(std::ostream& stream) {} + inline void orange(std::ostream& stream) {} + inline void grey(std::ostream& stream) {} + inline void green(std::ostream& stream) {} + inline void blue(std::ostream& stream) {} + inline void bold(std::ostream& stream) {} +}; +#endif #endif // wasm_color_h diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 97958b041..3db818787 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -35,6 +35,25 @@ using namespace cashew; IString WASM("wasm"); + +#ifdef WIN32 +#include <intrin.h> + +int32_t safe_clz(int32_t v) { + unsigned long result; + return _BitScanReverse(&result,v) ? result : 32; +} + +int32_t safe_ctz(int32_t v) { + unsigned long result; + return _BitScanForward(&result,v) ? result : 32; +} + +int32_t platform_popcount(int32_t v) +{ + return __popcnt(v); +} +#else int32_t safe_clz(int32_t v) { if (v == 0) return 32; return __builtin_clz(v); @@ -45,6 +64,12 @@ int32_t safe_ctz(int32_t v) { return __builtin_ctz(v); } +int32_t platform_popcount(int32_t v) +{ + return __buildin_popcount(v); +} +#endif + enum { pageSize = 64*1024, maxCallDepth = 250 @@ -374,7 +399,7 @@ private: if (v == 0) return Literal(32); return Literal((int32_t)safe_ctz(v)); } - case Popcnt: return Literal((int32_t)__builtin_popcount(v)); + case Popcnt: return Literal((int32_t)platform_popcount(v)); case ReinterpretInt: { float v = value.reinterpretf32(); if (isnan(v)) { @@ -403,7 +428,7 @@ private: if (low == 0) return Literal(32+(int64_t)safe_ctz(high)); return Literal((int64_t)safe_ctz(low)); } - case Popcnt: return Literal(int64_t(__builtin_popcount(low) + __builtin_popcount(high))); + case Popcnt: return Literal(int64_t(platform_popcount(low) + platform_popcount(high))); case WrapInt64: return Literal(int32_t(value.geti64())); case ReinterpretInt: { return Literal(value.reinterpretf64()); diff --git a/src/wasm-validator.h b/src/wasm-validator.h index af0c4ba9d..46bcf7a2e 100644 --- a/src/wasm-validator.h +++ b/src/wasm-validator.h @@ -39,19 +39,6 @@ public: void visitLoop(Loop *curr) override { if (curr->in.is()) { - // the "in" label has a none type, since no one can receive its value. make sure no one breaks to it with a value. - struct ChildChecker : public WasmWalker { - Name in; - bool valid = true; - - ChildChecker(Name in) : in(in) {} - - void visitBreak(Break *curr) override { - if (curr->name == in && curr->value) { - valid = false; - } - } - }; ChildChecker childChecker(curr->in); childChecker.walk(curr->body); shouldBeTrue(childChecker.valid); @@ -109,6 +96,21 @@ public: } private: + + // the "in" label has a none type, since no one can receive its value. make sure no one breaks to it with a value. + struct ChildChecker : public WasmWalker { + Name in; + bool valid = true; + + ChildChecker(Name in) : in(in) {} + + void visitBreak(Break *curr) override { + if (curr->name == in && curr->value) { + valid = false; + } + } + }; + // helpers void shouldBeTrue(bool result) { diff --git a/src/wasm.h b/src/wasm.h index df7731094..86aca1fd3 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -51,6 +51,7 @@ #include <fstream> #include <map> #include <vector> +#include <string> #include "compiler-support.h" #include "emscripten-optimizer/simple_ast.h" |