summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-diagnostic-defs.h2
-rw-r--r--source/slang/slang-file-system.cpp27
-rw-r--r--source/slang/slang-file-system.h36
-rw-r--r--source/slang/slang-options.cpp25
-rw-r--r--source/slang/slang.cpp8
5 files changed, 80 insertions, 18 deletions
diff --git a/source/slang/slang-diagnostic-defs.h b/source/slang/slang-diagnostic-defs.h
index 802c89f8b..c1c207fd7 100644
--- a/source/slang/slang-diagnostic-defs.h
+++ b/source/slang/slang-diagnostic-defs.h
@@ -69,6 +69,8 @@ DIAGNOSTIC( 14, Error, unknownProfile, "unknown profile '$0'");
DIAGNOSTIC( 15, Error, unknownStage, "unknown stage '$0'");
DIAGNOSTIC( 16, Error, unknownPassThroughTarget, "unknown pass-through target '$0'");
DIAGNOSTIC( 17, Error, unknownCommandLineOption, "unknown command-line option '$0'");
+DIAGNOSTIC( 18, Error, unknownFileSystemOption, "unknown file-system option '$0'");
+
DIAGNOSTIC( 20, Error, entryPointsNeedToBeAssociatedWithTranslationUnits, "when using multiple source files, entry points must be specified after their corresponding source file(s)");
DIAGNOSTIC( 21, Error, expectedArgumentForOption, "expected an argument for command-line option '$0'");
diff --git a/source/slang/slang-file-system.cpp b/source/slang/slang-file-system.cpp
index f8c423e84..975d35f2c 100644
--- a/source/slang/slang-file-system.cpp
+++ b/source/slang/slang-file-system.cpp
@@ -36,9 +36,18 @@ static SlangResult _calcCombinedPath(SlangPathType fromPathType, const char* fro
return SLANG_OK;
}
-/* !!!!!!!!!!!!!!!!!!!!!!!!!! IncludeFileSystem !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
+/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!! OSFileSystem !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
-/* static */OSFileSystem OSFileSystem::s_singleton;
+/* static */OSFileSystem OSFileSystem::s_singleton;
+
+ISlangUnknown* OSFileSystem::getInterface(const Guid& guid)
+{
+ return (guid == IID_ISlangUnknown || guid == IID_ISlangFileSystem ) ? static_cast<ISlangFileSystem*>(this) : nullptr;
+}
+
+/* !!!!!!!!!!!!!!!!!!!!!!!!!! OSFileSystemExt !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
+
+/* static */OSFileSystemExt OSFileSystemExt::s_singleton;
template <typename T>
static ISlangFileSystemExt* _getInterface(T* ptr, const Guid& guid)
@@ -46,7 +55,7 @@ static ISlangFileSystemExt* _getInterface(T* ptr, const Guid& guid)
return (guid == IID_ISlangUnknown || guid == IID_ISlangFileSystem || guid == IID_ISlangFileSystemExt) ? static_cast<ISlangFileSystemExt*>(ptr) : nullptr;
}
-ISlangUnknown* OSFileSystem::getInterface(const Guid& guid)
+ISlangUnknown* OSFileSystemExt::getInterface(const Guid& guid)
{
return _getInterface(this, guid);
}
@@ -62,13 +71,13 @@ static String _fixPathDelimiters(const char* pathIn)
#endif
}
-SlangResult OSFileSystem::getFileUniqueIdentity(const char* pathIn, ISlangBlob** outUniqueIdentity)
+SlangResult OSFileSystemExt::getFileUniqueIdentity(const char* pathIn, ISlangBlob** outUniqueIdentity)
{
// By default we use the canonical path to uniquely identify a file
return getCanonicalPath(pathIn, outUniqueIdentity);
}
-SlangResult OSFileSystem::getCanonicalPath(const char* path, ISlangBlob** outCanonicalPath)
+SlangResult OSFileSystemExt::getCanonicalPath(const char* path, ISlangBlob** outCanonicalPath)
{
String canonicalPath;
SLANG_RETURN_ON_FAIL(Path::getCanonical(_fixPathDelimiters(path), canonicalPath));
@@ -76,25 +85,25 @@ SlangResult OSFileSystem::getCanonicalPath(const char* path, ISlangBlob** outCan
return SLANG_OK;
}
-SlangResult OSFileSystem::getSimplifiedPath(const char* pathIn, ISlangBlob** outSimplifiedPath)
+SlangResult OSFileSystemExt::getSimplifiedPath(const char* pathIn, ISlangBlob** outSimplifiedPath)
{
String simplifiedPath = Path::simplify(_fixPathDelimiters(pathIn));
*outSimplifiedPath = StringUtil::createStringBlob(simplifiedPath).detach();
return SLANG_OK;
}
-SlangResult OSFileSystem::calcCombinedPath(SlangPathType fromPathType, const char* fromPath, const char* path, ISlangBlob** pathOut)
+SlangResult OSFileSystemExt::calcCombinedPath(SlangPathType fromPathType, const char* fromPath, const char* path, ISlangBlob** pathOut)
{
// Don't need to fix delimiters - because combine path handles both path delimiter types
return _calcCombinedPath(fromPathType, fromPath, path, pathOut);
}
-SlangResult SLANG_MCALL OSFileSystem::getPathType(const char* pathIn, SlangPathType* pathTypeOut)
+SlangResult SLANG_MCALL OSFileSystemExt::getPathType(const char* pathIn, SlangPathType* pathTypeOut)
{
return Path::getPathType(_fixPathDelimiters(pathIn), pathTypeOut);
}
-SlangResult OSFileSystem::loadFile(char const* pathIn, ISlangBlob** outBlob)
+SlangResult OSFileSystemExt::loadFile(char const* pathIn, ISlangBlob** outBlob)
{
// Default implementation that uses the `core` libraries facilities for talking to the OS filesystem.
//
diff --git a/source/slang/slang-file-system.h b/source/slang/slang-file-system.h
index 1d747d73f..d91d8ff65 100644
--- a/source/slang/slang-file-system.h
+++ b/source/slang/slang-file-system.h
@@ -11,7 +11,8 @@
namespace Slang
{
-class OSFileSystem : public ISlangFileSystemExt
+// Implementation of ISlangFileSystemExt for the OS
+class OSFileSystemExt : public ISlangFileSystemExt
{
public:
// ISlangUnknown
@@ -55,11 +56,40 @@ public:
private:
/// Make so not constructible
- OSFileSystem() {}
- virtual ~OSFileSystem() {}
+ OSFileSystemExt() {}
+ virtual ~OSFileSystemExt() {}
ISlangUnknown* getInterface(const Guid& guid);
+ static OSFileSystemExt s_singleton;
+};
+
+// Implementation of ISlangFileSystem for the OS (ie only has simplified interface of just loadFile)
+class OSFileSystem : public ISlangFileSystem
+{
+public:
+ // ISlangUnknown
+ SLANG_IUNKNOWN_QUERY_INTERFACE
+ SLANG_NO_THROW uint32_t SLANG_MCALL addRef() SLANG_OVERRIDE { return 1; }
+ SLANG_NO_THROW uint32_t SLANG_MCALL release() SLANG_OVERRIDE { return 1; }
+
+ // ISlangFileSystem
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL loadFile(
+ char const* path,
+ ISlangBlob** outBlob) SLANG_OVERRIDE
+ {
+ // Can just use OsFileSystemExt impl
+ return OSFileSystemExt::getSingleton()->loadFile(path, outBlob);
+ }
+
+ static ISlangFileSystem* getSingleton() { return &s_singleton; }
+
+private:
+ /// Make so not constructible
+ OSFileSystem() {}
+ virtual ~OSFileSystem() {}
+
+ ISlangUnknown* getInterface(const Guid& guid);
static OSFileSystem s_singleton;
};
diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp
index 81fb468eb..5918f1551 100644
--- a/source/slang/slang-options.cpp
+++ b/source/slang/slang-options.cpp
@@ -8,6 +8,8 @@
#include "slang-compiler.h"
#include "slang-profile.h"
+#include "slang-file-system.h"
+
#include <assert.h>
namespace Slang {
@@ -632,7 +634,7 @@ struct OptionsParser
SLANG_RETURN_ON_FAIL(tryReadCommandLineArgument(sink, arg, &argCursor, argEnd, name));
addSharedLibraryPath(SharedLibraryType::Fxc, name);
}
- else if (argStr[1] == 'D')
+ else if (argStr.getLength() >= 2 && argStr[1] == 'D')
{
// The value to be defined might be part of the same option, as in:
// -DFOO
@@ -677,7 +679,7 @@ struct OptionsParser
"");
}
}
- else if (argStr[1] == 'I')
+ else if (argStr.getLength() >= 2 && argStr[1] == 'I')
{
// The value to be defined might be part of the same option, as in:
// -IFOO
@@ -803,6 +805,25 @@ struct OptionsParser
{
requestImpl->getBackEndReq()->useUnknownImageFormatAsDefault = true;
}
+ else if (argStr == "-file-system")
+ {
+ String name;
+ SLANG_RETURN_ON_FAIL(tryReadCommandLineArgument(sink, arg, &argCursor, argEnd, name));
+
+ if (name == "default")
+ {
+ spSetFileSystem(compileRequest, nullptr);
+ }
+ else if (name == "load-file")
+ {
+ spSetFileSystem(compileRequest, OSFileSystem::getSingleton());
+ }
+ else
+ {
+ sink->diagnose(SourceLoc(), Diagnostics::unknownFileSystemOption, name);
+ return SLANG_FAIL;
+ }
+ }
else if (argStr == "--")
{
// The `--` option causes us to stop trying to parse options,
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index f0570132f..eef0dff6f 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -2365,17 +2365,17 @@ void Linkage::setFileSystem(ISlangFileSystem* inFileSystem)
// Set the fileSystem
fileSystem = inFileSystem;
- // Set up fileSystemExt appropriately
+ // If nullptr passed in set up default
if (inFileSystem == nullptr)
{
- fileSystemExt = new Slang::CacheFileSystem(Slang::OSFileSystem::getSingleton());
+ fileSystemExt = new Slang::CacheFileSystem(Slang::OSFileSystemExt::getSingleton());
}
else
{
- // See if we have the interface
+ // See if we have the full ISlangFileSystemExt interface, if we do just use it
inFileSystem->queryInterface(IID_ISlangFileSystemExt, (void**)fileSystemExt.writeRef());
- // If not wrap with WrapFileSytem that keeps the old behavior
+ // If not wrap with CacheFileSystem that emulates ISlangFileSystemExt from the ISlangFileSystem interface
if (!fileSystemExt)
{
// Construct a wrapper to emulate the extended interface behavior