Merge pull request #317 from joshuawarner32/cmake-vs

Get cmake build working with visual studio 2013
This commit is contained in:
Joel Dice 2014-07-31 08:16:48 -06:00
commit 60ea4b2cc2
20 changed files with 117 additions and 194 deletions

View File

@ -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

View File

@ -8,7 +8,6 @@
There is NO WARRANTY for this software. See license.txt for
details. */
#include "math.h"
#include "stdlib.h"
#include "time.h"
#include "string.h"
@ -19,6 +18,11 @@
#include "fcntl.h"
#include "ctype.h"
// Make sure M_* constants (in particular M_E) are exposed in math.h.
// This was a problem on the default mingw install on ubuntu precise
#undef __STRICT_ANSI__
#include "math.h"
#ifdef PLATFORM_WINDOWS
#include "windows.h"

View File

@ -6,3 +6,13 @@ 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()
find_package(ZLIB REQUIRED)
include_directories(${ZLIB_INCLUDE_DIRS})

View File

@ -32,8 +32,13 @@ class Args {
template <class... Ts>
Args(Ts... ts)
#ifndef _MSC_VER
: values{ts...}
#endif
{
#ifdef _MSC_VER
setArrayElements(values, ts...);
#endif
}
operator util::Slice<ir::Value*>()

View File

@ -44,6 +44,16 @@ struct ArgumentCount<> {
enum { Result = 0 };
};
template<class T>
void setArrayElements(T*) {
}
template<class T, class... Ts>
void setArrayElements(T* arr, T elem, Ts... ts) {
*arr = elem;
setArrayElements(arr, ts...);
}
} // namespace util
} // namespace avian

View File

@ -39,28 +39,8 @@
#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 or ||
#define and &&

View File

@ -13,11 +13,39 @@
#include "context.h"
#ifndef _MSC_VER
#include <cpuid.h>
#else
// MSVC implementation:
static int __get_cpuid(unsigned int __level,
unsigned int* __eax,
unsigned int* __ebx,
unsigned int* __ecx,
unsigned int* __edx)
{
_asm
{
mov eax, __level;
cpuid;
mov[__eax], eax;
mov[__ebx], ebx;
mov[__ecx], ecx;
mov[__edx], edx;
}
return 1;
}
#define bit_SSE (1 << 25)
#define bit_SSE2 (1 << 26)
#endif
namespace avian {
namespace codegen {
namespace x86 {
extern "C" bool detectFeature(unsigned ecx, unsigned edx);
// TODO: this should be moved such that it's called by the client (e.g. whatever
// allocates the Archivecture). That way, we can link the x86 code generator on
// another architecture (e.g. arm).
bool useSSE(ArchitectureContext* c)
{
@ -27,8 +55,11 @@ bool useSSE(ArchitectureContext* c)
} else if (c->useNativeFeatures) {
static int supported = -1;
if (supported == -1) {
supported = detectFeature(0, 0x2000000) // SSE 1
and detectFeature(0, 0x4000000); // SSE 2
unsigned eax;
unsigned ebx;
unsigned ecx;
unsigned edx;
supported = __get_cpuid(1, &eax, &ebx, &ecx, &edx) && (edx & bit_SSE) && (edx & bit_SSE2);
}
return supported;
} else {

View File

@ -1288,7 +1288,7 @@ loop:
}
goto loop;
case dup: {
case vm::dup: {
if (DebugStack) {
fprintf(stderr, "dup\n");
}
@ -1323,7 +1323,7 @@ loop:
}
goto loop;
case dup2: {
case vm::dup2: {
if (DebugStack) {
fprintf(stderr, "dup2\n");
}

View File

@ -4,7 +4,7 @@
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef WIN32
#ifdef _WIN32
#include <windows.h>
#else
#include <sys/mman.h>
@ -65,7 +65,7 @@ int main(int argc, const char** argv)
struct stat s;
int r = fstat(fd, &s);
if (r != -1) {
#ifdef WIN32
#ifdef _WIN32
HANDLE fm;
HANDLE h = (HANDLE)_get_osfhandle(fd);
@ -178,7 +178,7 @@ int main(int argc, const char** argv)
fprintf(stderr, "unable to determine uncompressed size\n");
}
#ifdef WIN32
#ifdef _WIN32
UnmapViewOfFile(data);
#else
munmap(data, size);

View File

@ -1,3 +1,7 @@
# TODO: use posix.cpp or windows.cpp, depending on platform
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()

View File

@ -16,6 +16,7 @@
#include <sys/stat.h>
#ifdef _WIN32
#include <windows.h>
#include <io.h>
#else
#include <sys/mman.h>
#include <unistd.h>
@ -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]);
}
@ -119,7 +120,7 @@ int main(int argc, const char** argv)
struct stat s;
int r = fstat(fd, &s);
if (r != -1) {
#ifdef WIN32
#ifdef _WIN32
HANDLE fm;
HANDLE h = (HANDLE)_get_osfhandle(fd);
@ -156,7 +157,7 @@ int main(int argc, const char** argv)
fprintf(stderr, "unable to open %s\n", argv[2]);
}
#ifdef WIN32
#ifdef _WIN32
UnmapViewOfFile(data);
#else
munmap(data, size);

View File

@ -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)

View File

@ -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;
}
}

View File

@ -4,8 +4,6 @@ target_link_libraries(type_generator
avian_jvm_finder
avian_system
avian_util
z
pthread
dl
${ZLIB_LIBRARIES}
${PLATFORM_LIBS}
)

View File

@ -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);
}

View File

@ -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<uintptr_t> pool(poolCount, -1);
for (unsigned i = 0; i < poolCount; ++i) {
unsigned c = s->read1();

View File

@ -27,37 +27,6 @@
#define CHECKPOINT_STACK 48
#ifdef __MINGW32__
.globl GLOBAL(detectFeature)
GLOBAL(detectFeature):
pushq %rbp
movq %rsp, %rbp
pushq %rdx
pushq %rcx
pushq %rbx
pushq %rsi
pushq %rdi
movl %ecx, %edi
movl %edx, %esi
movl $1, %eax
cpuid
andl %esi, %edx
andl %edi, %ecx
orl %edx, %ecx
test %ecx, %ecx
je LOCAL(NOSSE)
movl $1, %eax
jmp LOCAL(SSEEND)
LOCAL(NOSSE):
movl $0, %eax
LOCAL(SSEEND):
popq %rdi
popq %rsi
popq %rbx
popq %rcx
popq %rdx
movq %rbp,%rsp
popq %rbp
ret
.globl GLOBAL(vmNativeCall)
GLOBAL(vmNativeCall):
@ -219,31 +188,6 @@ GLOBAL(vmRun_returnAddress):
ret
#else // not __MINGW32__
.globl GLOBAL(detectFeature)
GLOBAL(detectFeature):
pushq %rbp
movq %rsp, %rbp
pushq %rdx
pushq %rcx
pushq %rbx
movl $1, %eax
cpuid
andl %esi, %edx
andl %edi, %ecx
orl %edx, %ecx
test %ecx, %ecx
je LOCAL(NOSSE)
movl $1, %eax
jmp LOCAL(SSEEND)
LOCAL(NOSSE):
movl $0, %eax
LOCAL(SSEEND):
popq %rbx
popq %rcx
popq %rdx
movq %rbp,%rsp
popq %rbp
ret
.globl GLOBAL(vmNativeCall)
GLOBAL(vmNativeCall):
@ -403,38 +347,6 @@ GLOBAL(vmRun_returnAddress):
#define CHECKPOINT_STACK 24
#define CHECKPOINT_BASE 28
.globl GLOBAL(detectFeature)
GLOBAL(detectFeature):
pushl %ebp
movl %esp, %ebp
pushl %edx
pushl %ecx
pushl %ebx
pushl %esi
pushl %edi
movl 12(%ebp), %esi
movl 8(%ebp), %edi
movl $1, %eax
cpuid
andl %esi, %edx
andl %edi, %ecx
orl %edx, %ecx
test %ecx, %ecx
je LOCAL(NOSSE)
movl $1, %eax
jmp LOCAL(SSEEND)
LOCAL(NOSSE):
movl $0, %eax
LOCAL(SSEEND):
popl %edi
popl %esi
popl %ebx
popl %ecx
popl %edx
movl %ebp,%esp
popl %ebp
ret
.globl GLOBAL(vmNativeCall)
GLOBAL(vmNativeCall):
pushl %ebp

View File

@ -30,40 +30,6 @@ CHECKPOINT_BASE equ 28
_TEXT SEGMENT
public C detectFeature
detectFeature:
push ebp
mov ebp,esp
push edx
push ecx
push ebx
push esi
push edi
mov esi,ds:dword ptr[12+ebp]
mov edi,ds:dword ptr[8+ebp]
mov eax,1
cpuid
and edx,esi
and ecx,edi
or ecx,edx
test ecx,ecx
je LNOSSE
mov eax,1
jmp LSSEEND
LNOSSE:
mov eax,0
LSSEEND:
pop edi
pop esi
pop ebx
pop ecx
pop edx
mov esp,ebp
pop ebp
ret
public C vmNativeCall
vmNativeCall:
push ebp

View File

@ -23,18 +23,14 @@ run_cmake() {
cd ..
}
if [ ${#} -gt 0 ]; then
run make ${@}
else
run_cmake -DCMAKE_BUILD_TYPE=Debug
run make jdk-test
run make test
run make mode=debug test
run make process=interpret test
run make bootimage=true test
run make mode=debug bootimage=true test
run make openjdk=$JAVA_HOME test
run make tails=true continuations=true heapdump=true test
run make codegen-targets=all
fi
run make ${@} test
run make ${@} mode=debug test
run make ${@} process=interpret test
run make ${@} bootimage=true test
run make ${@} mode=debug bootimage=true test
run make ${@} openjdk=$JAVA_HOME test
run make ${@} tails=true continuations=true heapdump=true test
run make ${@} codegen-targets=all

View File

@ -16,8 +16,6 @@ target_link_libraries (avian_unittest
avian_system
avian_heap
avian_util
pthread
dl
${PLATFORM_LIBS}
)