diff --git a/CMakeLists.txt b/CMakeLists.txt index 864c3aabd5..19c4b900b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,9 +16,10 @@ add_definitions ( -D__STDC_CONSTANT_MACROS ) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -fno-exceptions -std=c++0x") - include ("cmake/Platform.cmake") + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PLATFORM_CXX_FLAGS}") + include (CTest) # Sadly, we can't use the 'test' target, as that's coopted by ctest diff --git a/cmake/Platform.cmake b/cmake/Platform.cmake index 85470acdeb..1bfb373ee7 100644 --- a/cmake/Platform.cmake +++ b/cmake/Platform.cmake @@ -6,3 +6,10 @@ IF (APPLE) SET(PLATFORM_LIBS ${CORE_FOUNDATION_LIBRARY}) ENDIF() + +IF (MSVC) + SET(PLATFORM_CXX_FLAGS "/Wall") +ELSE() + SET(PLATFORM_CXX_FLAGS "-Wall -Werror -fno-exceptions -std=c++0x") + SET(PLATFORM_LIBS ${PLATFORM_LIBS} pthread dl) +ENDIF() diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index 9e96e79539..5086367cd4 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -32,8 +32,13 @@ class Args { template Args(Ts... ts) +#ifndef _MSC_VER : values{ts...} +#endif { +#ifdef _MSC_VER + setArrayElements(values, ts...); +#endif } operator util::Slice() diff --git a/include/avian/util/cpp.h b/include/avian/util/cpp.h index 6be12af1a8..209df50a46 100644 --- a/include/avian/util/cpp.h +++ b/include/avian/util/cpp.h @@ -44,6 +44,16 @@ struct ArgumentCount<> { enum { Result = 0 }; }; +template +void setArrayElements(T*) { +} + +template +void setArrayElements(T* arr, T elem, Ts... ts) { + *arr = elem; + setArrayElements(arr, ts...); +} + } // namespace util } // namespace avian diff --git a/src/avian/common.h b/src/avian/common.h index 82cdc046ce..b08e2dc659 100644 --- a/src/avian/common.h +++ b/src/avian/common.h @@ -39,29 +39,9 @@ #define strncasecmp _strnicmp -#define FP_NAN 0 -#define FP_INFINITE 1 #define FP_UNDEF 2 -inline int fpclassify(double d) -{ - switch (_fpclass(d)) { - case _FPCLASS_SNAN: - case _FPCLASS_QNAN: - return FP_NAN; - case _FPCLASS_PINF: - case _FPCLASS_NINF: - return FP_INFINITE; - } - return FP_UNDEF; -} - -inline int signbit(double d) -{ - return _copysign(1.0, d) < 0; -} - -#define not! +#define not ! #define or || #define and && #define xor ^ diff --git a/src/system/CMakeLists.txt b/src/system/CMakeLists.txt index 566ac8100f..5c6f2a58fa 100644 --- a/src/system/CMakeLists.txt +++ b/src/system/CMakeLists.txt @@ -1,3 +1,7 @@ -# TODO: use posix.cpp or windows.cpp, depending on platform -add_library(avian_system posix.cpp posix/crash.cpp) +if (MSVC) + #todo: support mingw compiler + add_library(avian_system windows.cpp windows/crash.cpp) +else() + add_library(avian_system posix.cpp posix/crash.cpp) +endif() diff --git a/src/tools/binary-to-object/main.cpp b/src/tools/binary-to-object/main.cpp index 4cd9ff5879..8889dbaf24 100644 --- a/src/tools/binary-to-object/main.cpp +++ b/src/tools/binary-to-object/main.cpp @@ -16,6 +16,7 @@ #include #ifdef WIN32 #include +#include #else #include #include @@ -90,7 +91,7 @@ void usageAndExit(const char* name) int main(int argc, const char** argv) { - if (argc < 7 or argc > 10) { + if (argc < 7 || argc > 10) { usageAndExit(argv[0]); } diff --git a/src/tools/object-writer/pe.cpp b/src/tools/object-writer/pe.cpp index dd3e976041..8384cbd64a 100644 --- a/src/tools/object-writer/pe.cpp +++ b/src/tools/object-writer/pe.cpp @@ -40,6 +40,12 @@ namespace { #define IMAGE_SCN_MEM_WRITE 0x80000000 #define IMAGE_SCN_CNT_CODE 32 +#ifdef _MSC_VER +#define PACKED_STRUCT _declspec(align(1)) +#else +#define PACKED_STRUCT __attribute__((packed)) +#endif + struct IMAGE_FILE_HEADER { uint16_t Machine; uint16_t NumberOfSections; @@ -48,7 +54,7 @@ struct IMAGE_FILE_HEADER { uint32_t NumberOfSymbols; uint16_t SizeOfOptionalHeader; uint16_t Characteristics; -} __attribute__((packed)); +} PACKED_STRUCT; struct IMAGE_SECTION_HEADER { uint8_t Name[IMAGE_SIZEOF_SHORT_NAME]; @@ -64,7 +70,7 @@ struct IMAGE_SECTION_HEADER { uint16_t NumberOfRelocations; uint16_t NumberOfLinenumbers; uint32_t Characteristics; -} __attribute__((packed)); +} PACKED_STRUCT; struct IMAGE_SYMBOL { union { @@ -78,7 +84,7 @@ struct IMAGE_SYMBOL { uint16_t Type; uint8_t StorageClass; uint8_t NumberOfAuxSymbols; -} __attribute__((packed)); +} PACKED_STRUCT; // --- winnt.h ---- inline unsigned pad(unsigned n) diff --git a/src/tools/object-writer/tools.cpp b/src/tools/object-writer/tools.cpp index 5bd3739825..ad736efd24 100644 --- a/src/tools/object-writer/tools.cpp +++ b/src/tools/object-writer/tools.cpp @@ -94,13 +94,13 @@ Platform* Platform::first = 0; PlatformInfo::Format PlatformInfo::formatFromString(const char* format) { - if (strcmp(format, "elf") == 0 or strcmp(format, "linux") == 0 - or strcmp(format, "freebsd") == 0 or strcmp(format, "qnx") == 0) { + if (strcmp(format, "elf") == 0 || strcmp(format, "linux") == 0 + || strcmp(format, "freebsd") == 0 || strcmp(format, "qnx") == 0) { return Elf; - } else if (strcmp(format, "pe") == 0 or strcmp(format, "windows") == 0) { + } else if (strcmp(format, "pe") == 0 || strcmp(format, "windows") == 0) { return Pe; - } else if (strcmp(format, "macho") == 0 or strcmp(format, "darwin") == 0 - or strcmp(format, "ios") == 0 or strcmp(format, "macosx") == 0) { + } else if (strcmp(format, "macho") == 0 || strcmp(format, "darwin") == 0 + || strcmp(format, "ios") == 0 || strcmp(format, "macosx") == 0) { return MachO; } else { return UnknownFormat; @@ -110,13 +110,13 @@ PlatformInfo::Format PlatformInfo::formatFromString(const char* format) PlatformInfo::Architecture PlatformInfo::archFromString(const char* arch) { if (strcmp(arch, "i386") == 0) { - return x86; + return Architecture::x86; } else if (strcmp(arch, "x86_64") == 0) { - return x86_64; + return Architecture::x86_64; } else if (strcmp(arch, "arm") == 0) { - return Arm; + return Architecture::Arm; } else { - return UnknownArch; + return Architecture::UnknownArch; } } diff --git a/src/tools/type-generator/io.h b/src/tools/type-generator/io.h index 346ca5fa84..f0ae32135f 100644 --- a/src/tools/type-generator/io.h +++ b/src/tools/type-generator/io.h @@ -124,7 +124,7 @@ class Output { { static const int Size = 32; char s[Size]; - int c UNUSED = ::snprintf(s, Size, "%d", i); + int c UNUSED = vm::snprintf(s, Size, "%d", i); assert(c > 0 and c < Size); write(s); } diff --git a/src/tools/type-generator/main.cpp b/src/tools/type-generator/main.cpp index 30549afd43..32dcf6f7f0 100644 --- a/src/tools/type-generator/main.cpp +++ b/src/tools/type-generator/main.cpp @@ -172,7 +172,7 @@ class Class { return ss.str(); } - void dumpToStdout() const AVIAN_EXPORT + void dumpToStdout() const { printf("%s\n", dump().c_str()); } @@ -615,13 +615,14 @@ const char* fieldType(const char* spec) void parseJavaClass(Module& module, ClassParser& clparser, Stream* s) { - uint32_t magic UNUSED = s->read4(); + uint32_t magic = s->read4(); assert(magic == 0xCAFEBABE); + (void)magic; s->read2(); // minor version s->read2(); // major version unsigned poolCount = s->read2() - 1; - uintptr_t pool[poolCount]; + std::vector pool(poolCount, -1); for (unsigned i = 0; i < poolCount; ++i) { unsigned c = s->read1(); diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index 0f4520d162..d810e3ffba 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -16,8 +16,6 @@ target_link_libraries (avian_unittest avian_system avian_heap avian_util - pthread - dl ${PLATFORM_LIBS} )