summaryrefslogtreecommitdiffstats
path: root/source/compiler-core/slang-include-system.h
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2021-05-14 17:50:00 -0400
committerGitHub <noreply@github.com>2021-05-14 17:50:00 -0400
commitd4316c88457a32f1169b2d7d82053ccbc05fa7ed (patch)
treecbc87350b9ef2f5be31ebc20783e08b895767779 /source/compiler-core/slang-include-system.h
parent79d106fac18f5792fcac448a0b037aa834fa6042 (diff)
FXC as DownstreamCompiler (#1844)
* #include an absolute path didn't work - because paths were taken to always be relative. * WIP Fxc as downstream compiler. * First pass FXC downstream compiler working. * GCC compile fix. * Fix FXC parsing issue. * Special case filesystem access. * Use StringUtil getSlice. * Fix isses with not emitting source for FXC. * Small fixes for DXBC handling.
Diffstat (limited to 'source/compiler-core/slang-include-system.h')
-rw-r--r--source/compiler-core/slang-include-system.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/source/compiler-core/slang-include-system.h b/source/compiler-core/slang-include-system.h
new file mode 100644
index 000000000..70f6dd81e
--- /dev/null
+++ b/source/compiler-core/slang-include-system.h
@@ -0,0 +1,62 @@
+#ifndef SLANG_INCLUDE_SYSTEM_H
+#define SLANG_INCLUDE_SYSTEM_H
+// slang-include-system.h
+
+#include "../compiler-core/slang-source-loc.h"
+
+namespace Slang
+{
+
+// A directory to be searched when looking for files (e.g., `#include`)
+struct SearchDirectory
+{
+ SearchDirectory() = default;
+ SearchDirectory(SearchDirectory const& other) = default;
+ SearchDirectory(String const& path)
+ : path(path)
+ {}
+
+ String path;
+};
+
+/// A list of directories to search for files (e.g., `#include`)
+struct SearchDirectoryList
+{
+ // A parent list that should also be searched
+ SearchDirectoryList* parent = nullptr;
+
+ // Directories to be searched
+ List<SearchDirectory> searchDirectories;
+};
+
+/* A helper class that builds basic include handling on top of searchDirectories/fileSystemExt and optionally a sourceManager */
+struct IncludeSystem
+{
+ IncludeSystem(SearchDirectoryList* searchDirectories, ISlangFileSystemExt* fileSystemExt, SourceManager* sourceManager = nullptr) :
+ m_searchDirectories(searchDirectories),
+ m_fileSystemExt(fileSystemExt),
+ m_sourceManager(sourceManager)
+ {
+ }
+
+ SlangResult findFile(const String& pathToInclude, const String& pathIncludedFrom, PathInfo& outPathInfo);
+ SlangResult findFile(SlangPathType fromPathType, const String& fromPath, const String& path, PathInfo& outPathInfo);
+ String simplifyPath(const String& path);
+ SlangResult loadFile(const PathInfo& pathInfo, ComPtr<ISlangBlob>& outBlob);
+
+ SlangResult findAndLoadFile(const String& pathToInclude, const String& pathIncludedFrom, PathInfo& outPathInfo, ComPtr<ISlangBlob>& outBlob);
+
+ SearchDirectoryList* getSearchDirectoryList() const { return m_searchDirectories; }
+ ISlangFileSystemExt* getFileSystem() const { return m_fileSystemExt; }
+ SourceManager* getSourceManager() const { return m_sourceManager; }
+
+protected:
+
+ SearchDirectoryList* m_searchDirectories;
+ ISlangFileSystemExt* m_fileSystemExt;
+ SourceManager* m_sourceManager; ///< If not set, will not look up the content in the source manager
+};
+
+}
+
+#endif // SLANG_INCLUDE_HANDLER_H