summaryrefslogtreecommitdiffstats
path: root/source/core
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2017-09-27 11:17:39 -0700
committerGitHub <noreply@github.com>2017-09-27 11:17:39 -0700
commit74f2f47cb63b02638270beecd20acea1a0f5665e (patch)
treeaf50d0355c7fccb4fb93fc1a0d45c66b5d07f1c9 /source/core
parentb6cf0f4ae0f3f9d1f377d3f134dcf994676e68b4 (diff)
First attempt at a Linux build (#193)
* First attempt at a Linux build - Fix up places where C++ idioms were written assuming lenient behavior of Microsoft's compiler - Add a few more alternatives for platform-specific behavior where Windows was the only platform accounted for. - Add a basic Makefile that can at least invoke our build, even if it isn't going good dependency tracking, etc. - Build `libslang.so` and `slangc` that depends on it, using a relative `RPATH` to make the binary portable (I hope) - Add an initial `.travis.yml` to see if we can trigger their build process. * Fixup: const bug in `List::Sort` I'm not clear why this gets picked up by the gcc *and* clang that Travis uses, but not the (newer) gcc I'm using on Ubuntu here, but I'm hoping it is just some missing `const` qualifiers. * Fixup: reorder specialization of "class info" Clang complains about things being specialized after being instantiated (implicilty), and I hope it is just the fact that I generate the class info for the roots of the hierarchy after the other cases. We'll see. * Fixup: add `platform.cpp` to unified/lumped build * Fixup: Windows uses `FreeLibrary` and not `UnloadLibrary` * Fixup: fix Windows project file to include new source file This obviously points to the fact that we are going to need to be generating these files sooner or later.
Diffstat (limited to 'source/core')
-rw-r--r--source/core/array-view.h2
-rw-r--r--source/core/common.h16
-rw-r--r--source/core/core.vcxproj1
-rw-r--r--source/core/hash.h1
-rw-r--r--source/core/list.h2
-rw-r--r--source/core/platform.cpp74
-rw-r--r--source/core/platform.h38
-rw-r--r--source/core/secure-crt.h1
-rw-r--r--source/core/slang-string.h61
-rw-r--r--source/core/smart-pointer.h2
-rw-r--r--source/core/stream.cpp2
-rw-r--r--source/core/stream.h2
12 files changed, 155 insertions, 47 deletions
diff --git a/source/core/array-view.h b/source/core/array-view.h
index 4e0057cdb..193aedbbb 100644
--- a/source/core/array-view.h
+++ b/source/core/array-view.h
@@ -1,7 +1,7 @@
#ifndef CORE_LIB_ARRAY_VIEW_H
#define CORE_LIB_ARRAY_VIEW_H
-#include "Exception.h"
+#include "exception.h"
namespace Slang
{
diff --git a/source/core/common.h b/source/core/common.h
index f0f6902d1..dbb837821 100644
--- a/source/core/common.h
+++ b/source/core/common.h
@@ -13,13 +13,15 @@
namespace Slang
{
+ typedef int32_t Int32;
+ typedef uint32_t UInt32;
+
typedef int64_t Int64;
- typedef unsigned short Word;
-#ifdef _M_X64
- typedef int64_t PtrInt;
-#else
- typedef int PtrInt;
-#endif
+ typedef uint64_t UInt64;
+
+// typedef unsigned short Word;
+
+ typedef intptr_t PtrInt;
template <typename T>
inline T&& _Move(T & obj)
@@ -38,7 +40,7 @@ namespace Slang
#ifdef _MSC_VER
#define SLANG_RETURN_NEVER __declspec(noreturn)
#else
-#efine SLANG_RETURN_NEVER /* empty */
+#define SLANG_RETURN_NEVER /* empty */
#endif
SLANG_RETURN_NEVER void signalUnexpectedError(char const* message);
diff --git a/source/core/core.vcxproj b/source/core/core.vcxproj
index 88e776703..ba9fe3d98 100644
--- a/source/core/core.vcxproj
+++ b/source/core/core.vcxproj
@@ -39,6 +39,7 @@
<ClInclude Include="type-traits.h" />
</ItemGroup>
<ItemGroup>
+ <ClCompile Include="platform.cpp" />
<ClCompile Include="slang-io.cpp" />
<ClCompile Include="slang-string.cpp" />
<ClCompile Include="stream.cpp" />
diff --git a/source/core/hash.h b/source/core/hash.h
index dd2086305..8ee5b088f 100644
--- a/source/core/hash.h
+++ b/source/core/hash.h
@@ -3,6 +3,7 @@
#include "slang-math.h"
#include <string.h>
+#include <type_traits>
namespace Slang
{
diff --git a/source/core/list.h b/source/core/list.h
index aeba9557f..af32a39ef 100644
--- a/source/core/list.h
+++ b/source/core/list.h
@@ -525,7 +525,7 @@ namespace Slang
void Sort()
{
- Sort([](T& t1, T& t2){return t1<t2;});
+ Sort([](T const& t1, T const& t2){return t1<t2;});
}
bool Contains(const T & val)
diff --git a/source/core/platform.cpp b/source/core/platform.cpp
new file mode 100644
index 000000000..dbb536b0f
--- /dev/null
+++ b/source/core/platform.cpp
@@ -0,0 +1,74 @@
+// platform.cpp
+#include "platform.h"
+
+#ifdef _WIN32
+ #define WIN32_LEAN_AND_MEAN
+ #define NOMINMAX
+ #include <Windows.h>
+ #undef WIN32_LEAN_AND_MEAN
+ #undef NOMINMAX
+#else
+ #include <dlfcn.h>
+#endif
+
+namespace Slang
+{
+ // SharedLibrary
+
+ SharedLibrary SharedLibrary::load(char const* name)
+ {
+ SharedLibrary result;
+ result.handle = nullptr;
+
+#ifdef _WIN32
+ {
+ HMODULE h = LoadLibraryA(name);
+ result.handle = (Handle) h;
+ }
+#else
+ {
+ void* h = dlopen(name, RTLD_LOCAL);
+ result.handle = (Handle) h;
+
+ }
+#endif
+
+ return result;
+ }
+
+ void SharedLibrary::unload()
+ {
+#ifdef _WIN32
+ {
+ FreeLibrary(
+ (HMODULE) handle);
+ }
+#else
+ {
+ dlclose(handle);
+ }
+#endif
+
+ }
+
+ SharedLibrary::FuncPtr SharedLibrary::findFuncByName(char const* name)
+ {
+ FuncPtr funcPtr = nullptr;
+
+#ifdef _WIN32
+ {
+ funcPtr = (FuncPtr) GetProcAddress(
+ (HMODULE) handle,
+ name);
+ }
+#else
+ {
+ funcPtr = (FuncPtr) dlsym(
+ (void*) handle,
+ name);
+ }
+#endif
+
+ return funcPtr;
+ }
+} \ No newline at end of file
diff --git a/source/core/platform.h b/source/core/platform.h
new file mode 100644
index 000000000..fef698e6f
--- /dev/null
+++ b/source/core/platform.h
@@ -0,0 +1,38 @@
+// platform.h
+#ifndef SLANG_CORE_PLATFORM_H_INCLUDED
+#define SLANG_CORE_PLATFORM_H_INCLUDED
+
+namespace Slang
+{
+ // Interface for working with shared libraries
+ // in a platfomr-independent fashion.
+ struct SharedLibrary
+ {
+ typedef struct SharedLibraryImpl* Handle;
+ Handle handle;
+
+ // Attempt to load a shared library for
+ // the current platform.
+ static SharedLibrary load(char const* name);
+
+ // If this refers to a valid loaded library,
+ // then attempt to unload it
+ void unload();
+
+ typedef void (*FuncPtr)(void);
+
+ FuncPtr findFuncByName(char const* name);
+
+
+ operator Handle() { return handle; }
+ };
+
+#ifndef _MSC_VER
+ #define _fileno fileno
+ #define _isatty isatty
+ #define _setmode setmode
+ #define _O_BINARY O_BINARY
+#endif
+}
+
+#endif
diff --git a/source/core/secure-crt.h b/source/core/secure-crt.h
index 12927cc24..a76fb2679 100644
--- a/source/core/secure-crt.h
+++ b/source/core/secure-crt.h
@@ -2,6 +2,7 @@
#ifndef CORE_LIB_SECURE_CRT_H
#define CORE_LIB_SECURE_CRT_H
#include <stdarg.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
diff --git a/source/core/slang-string.h b/source/core/slang-string.h
index ed333f8e8..23ab54c23 100644
--- a/source/core/slang-string.h
+++ b/source/core/slang-string.h
@@ -222,7 +222,7 @@ namespace Slang
char* getData() const
{
- return buffer ? buffer->getData() : "";
+ return buffer ? buffer->getData() : (char*)"";
}
UInt getLength() const
@@ -270,50 +270,29 @@ namespace Slang
void append(String const& str);
void append(StringSlice const& slice);
- String(int val, int radix = 10)
+ String(int32_t val, int radix = 10)
{
append(val, radix);
-#if 0
- buffer = StringRepresentation::createWithLength(33);
- buffer->length = IntToAscii(getData(), val, radix);
- ReverseInternalAscii(getData(), getLength());
-#endif
}
- String(unsigned int val, int radix = 10)
+ String(uint32_t val, int radix = 10)
{
append(val, radix);
-#if 0
- buffer = StringRepresentation::createWithLength(33);
- buffer->length = IntToAscii(getData(), val, radix);
- ReverseInternalAscii(getData(), getLength());
-#endif
}
- String(long long val, int radix = 10)
+ String(int64_t val, int radix = 10)
+ {
+ append(val, radix);
+ }
+ String(uint64_t val, int radix = 10)
{
append(val, radix);
-#if 0
- buffer = StringRepresentation::createWithLength(65);
- buffer->length = IntToAscii(getData(), val, radix);
- ReverseInternalAscii(getData(), getLength());
-#endif
}
String(float val, const char * format = "%g")
{
append(val, format);
-#if 0
- buffer = StringRepresentation::createWithLength(128);
- sprintf_s(getData(), 128, format, val);
- buffer->length = (int)strnlen_s(begin(), 128);
-#endif
}
String(double val, const char * format = "%g")
{
append(val, format);
-#if 0
- buffer = StringRepresentation::createWithLength(128);
- sprintf_s(getData(), 128, format, val);
- buffer->length = (int)strnlen_s(begin(), 128);
-#endif
}
String(const char * str)
{
@@ -656,17 +635,22 @@ namespace Slang
Append(&ch, 1);
return *this;
}
- StringBuilder & operator << (int val)
+ StringBuilder & operator << (Int32 val)
+ {
+ Append(val);
+ return *this;
+ }
+ StringBuilder & operator << (UInt32 val)
{
Append(val);
return *this;
}
- StringBuilder & operator << (unsigned int val)
+ StringBuilder & operator << (Int64 val)
{
Append(val);
return *this;
}
- StringBuilder & operator << (long long val)
+ StringBuilder & operator << (UInt64 val)
{
Append(val);
return *this;
@@ -714,21 +698,28 @@ namespace Slang
int len = (int)strnlen_s(buf, 128);
Append(buf, len);
}
- void Append(unsigned int value, int radix = 10)
+ void Append(Int32 value, int radix = 10)
{
char vBuffer[33];
int len = IntToAscii(vBuffer, value, radix);
ReverseInternalAscii(vBuffer, len);
Append(vBuffer);
}
- void Append(int value, int radix = 10)
+ void Append(UInt32 value, int radix = 10)
{
char vBuffer[33];
int len = IntToAscii(vBuffer, value, radix);
ReverseInternalAscii(vBuffer, len);
Append(vBuffer);
}
- void Append(long long value, int radix = 10)
+ void Append(Int64 value, int radix = 10)
+ {
+ char vBuffer[65];
+ int len = IntToAscii(vBuffer, value, radix);
+ ReverseInternalAscii(vBuffer, len);
+ Append(vBuffer);
+ }
+ void Append(UInt64 value, int radix = 10)
{
char vBuffer[65];
int len = IntToAscii(vBuffer, value, radix);
diff --git a/source/core/smart-pointer.h b/source/core/smart-pointer.h
index 3e64eac96..17d6caaa4 100644
--- a/source/core/smart-pointer.h
+++ b/source/core/smart-pointer.h
@@ -127,7 +127,7 @@ namespace Slang
template <typename U>
typename EnableIf<IsConvertible<T*, U*>::value, void>::type
- operator=(RefPtr<U> const& ptr)
+ operator=(RefPtr<U> const& p)
{
T* old = pointer;
addReference(p.pointer);
diff --git a/source/core/stream.cpp b/source/core/stream.cpp
index 62e9092af..f78e5af83 100644
--- a/source/core/stream.cpp
+++ b/source/core/stream.cpp
@@ -1,4 +1,4 @@
-#include "Stream.h"
+#include "stream.h"
#ifdef _WIN32
#include <share.h>
#endif
diff --git a/source/core/stream.h b/source/core/stream.h
index 9a8ea8366..4eea6a909 100644
--- a/source/core/stream.h
+++ b/source/core/stream.h
@@ -1,7 +1,7 @@
#ifndef CORE_LIB_STREAM_H
#define CORE_LIB_STREAM_H
-#include "Basic.h"
+#include "basic.h"
namespace Slang
{