summaryrefslogtreecommitdiff
path: root/source/core/slang-platform.h
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-05-31 17:20:37 -0400
committerGitHub <noreply@github.com>2019-05-31 17:20:37 -0400
commit6cbc3929a54d37bd23cb5efa8e3320ba02f78b2f (patch)
tree5a23cb47782e9e2a77762c90dd35da1005eba8d0 /source/core/slang-platform.h
parentb81ff3ef968d1cc4e954b31a1812b3c391d17b02 (diff)
Use slang- prefix on slang compiler and core source (#973)
* Prefixing source files in source/slang with slang- * Prefix source in source/slang with slang- prefix. * Rename core source files with slang- prefix. * Update project files. * Fix problems from automatic merge.
Diffstat (limited to 'source/core/slang-platform.h')
-rw-r--r--source/core/slang-platform.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/source/core/slang-platform.h b/source/core/slang-platform.h
new file mode 100644
index 000000000..e33c5599d
--- /dev/null
+++ b/source/core/slang-platform.h
@@ -0,0 +1,67 @@
+// slang-platform.h
+#ifndef SLANG_CORE_PLATFORM_H
+#define SLANG_CORE_PLATFORM_H
+
+#include "../../slang.h"
+#include "../core/slang-string.h"
+
+namespace Slang
+{
+ // Interface for working with shared libraries
+ // in a platform-independent fashion.
+ struct SharedLibrary
+ {
+ typedef struct SharedLibraryImpl* Handle;
+
+ typedef void(*FuncPtr)(void);
+
+ /// Load via an unadorned filename
+ ///
+ /// @param the unadorned filename
+ /// @return Returns a non null handle for the shared library on success. nullptr indicated failure
+ static SlangResult load(const char* filename, Handle& handleOut);
+
+ /// Attempt to load a shared library for
+ /// the current platform. Returns null handle on failure
+ /// The platform specific filename can be generated from a call to appendPlatformFileName
+ ///
+ /// @param platformFileName the platform specific file name.
+ /// @return Returns a non null handle for the shared library on success. nullptr indicated failure
+ static SlangResult loadWithPlatformFilename(char const* platformFileName, Handle& handleOut);
+
+ /// Unload the library that was returned from load as handle
+ /// @param The valid handle returned from load
+ static void unload(Handle handle);
+
+ /// Given a shared library handle and a name, return the associated function
+ /// Return nullptr if function is not found
+ /// @param The shared library handle as returned by loadPlatformLibrary
+ static FuncPtr findFuncByName(Handle handle, char const* name);
+
+ /// Append to the end of dst, the name, with any platform specific additions
+ /// The input name should be unadorned with any 'lib' prefix or extension
+ static void appendPlatformFileName(const UnownedStringSlice& name, StringBuilder& dst);
+
+ private:
+ /// Not constructible!
+ SharedLibrary();
+ };
+
+ struct PlatformUtil
+ {
+ /// Appends a text interpretation of a result (as defined by supporting OS)
+ /// @param res Result to produce a string for
+ /// @param builderOut Append the string produced to builderOut
+ /// @return SLANG_OK if string is found and appended. Fail otherwise. SLANG_E_NOT_IMPLEMENTED if there is no impl for this platform.
+ static SlangResult appendResult(SlangResult res, StringBuilder& builderOut);
+ };
+
+#ifndef _MSC_VER
+ #define _fileno fileno
+ #define _isatty isatty
+ #define _setmode setmode
+ #define _O_BINARY O_BINARY
+#endif
+}
+
+#endif