summaryrefslogtreecommitdiffstats
path: root/source/core
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-01-08 09:36:25 -0500
committerGitHub <noreply@github.com>2020-01-08 09:36:25 -0500
commit17285faf9b4fe7f6c28b43972212068465bdb42e (patch)
tree8e060c69287aaf92298879129194e32e6dda097b /source/core
parent0c87001d7fb9dabaa17f9784e99d7438592d2373 (diff)
CUDA generated first test compiles. (#1161)
Diffstat (limited to 'source/core')
-rw-r--r--source/core/slang-test-tool-util.cpp88
1 files changed, 63 insertions, 25 deletions
diff --git a/source/core/slang-test-tool-util.cpp b/source/core/slang-test-tool-util.cpp
index 9bf404e5e..3b89321a1 100644
--- a/source/core/slang-test-tool-util.cpp
+++ b/source/core/slang-test-tool-util.cpp
@@ -37,6 +37,61 @@ namespace Slang
}
}
+static SlangResult _calcIncludePath(const String& parentPath, const char* path, String& outIncludePath)
+{
+ String includePath;
+ SLANG_RETURN_ON_FAIL(Path::getCanonical(Path::combine(parentPath, path), includePath));
+
+ // Use forward slashes, to avoid escaping the path
+ includePath = StringUtil::calcCharReplaced(includePath, '\\', '/');
+
+ // It must exist!
+ if (!File::exists(includePath))
+ {
+ return SLANG_FAIL;
+ }
+
+ outIncludePath = includePath;
+ return SLANG_OK;
+}
+
+static SlangResult _addCPPPrelude(const String& parentPath, slang::IGlobalSession* session)
+{
+ String includePath;
+ SLANG_RETURN_ON_FAIL(_calcIncludePath(parentPath, "../../../prelude/slang-cpp-prelude.h", includePath));
+
+ StringBuilder prelude;
+ prelude << "#include \"" << includePath << "\"\n\n";
+ const SlangPassThrough downstreamCompilers[] = {
+ SLANG_PASS_THROUGH_CLANG, ///< Clang C/C++ compiler
+ SLANG_PASS_THROUGH_VISUAL_STUDIO, ///< Visual studio C/C++ compiler
+ SLANG_PASS_THROUGH_GCC, ///< GCC C/C++ compiler
+ SLANG_PASS_THROUGH_GENERIC_C_CPP,
+ };
+ for (auto downstreamCompiler : downstreamCompilers)
+ {
+ session->setDownstreamCompilerPrelude(downstreamCompiler, prelude.getBuffer());
+ }
+ return SLANG_OK;
+}
+
+static SlangResult _addCUDAPrelude(const String& parentPath, slang::IGlobalSession* session)
+{
+ String includePath;
+ SLANG_RETURN_ON_FAIL(_calcIncludePath(parentPath, "../../../prelude/slang-cuda-prelude.h", includePath));
+
+ StringBuilder prelude;
+ prelude << "#include \"" << includePath << "\"\n\n";
+ const SlangPassThrough downstreamCompilers[] = {
+ SLANG_PASS_THROUGH_NVRTC, ///< nvrtc CUDA compiler
+ };
+ for (auto downstreamCompiler : downstreamCompilers)
+ {
+ session->setDownstreamCompilerPrelude(downstreamCompiler, prelude.getBuffer());
+ }
+ return SLANG_OK;
+}
+
/* static */SlangResult TestToolUtil::setSessionDefaultPrelude(const char* exePath, slang::IGlobalSession* session)
{
// Set the prelude to a path
@@ -44,33 +99,16 @@ namespace Slang
if (SLANG_SUCCEEDED(Path::getCanonical(exePath, canonicalPath)))
{
// Get the directory
- canonicalPath = Path::getParentDirectory(canonicalPath);
+ String parentPath = Path::getParentDirectory(canonicalPath);
+
+ if (SLANG_FAILED(_addCPPPrelude(parentPath, session)))
+ {
+ SLANG_ASSERT(!"Couldn't find the C++ prelude relative to the executable");
+ }
- String path = Path::combine(canonicalPath, "../../../prelude/slang-cpp-prelude.h");
- if (SLANG_SUCCEEDED(Path::getCanonical(path, canonicalPath)))
+ if (SLANG_FAILED(_addCUDAPrelude(parentPath, session)))
{
- // Use forward slashes, to avoid escaping the path
- canonicalPath = StringUtil::calcCharReplaced(canonicalPath, '\\', '/');
-
- // It must exist!
- if (!File::exists(canonicalPath))
- {
- SLANG_ASSERT(!"Couldn't find the prelude relative to the executable");
- return SLANG_FAIL;
- }
-
- StringBuilder prelude;
- prelude << "#include \"" << canonicalPath << "\"\n\n";
- const SlangPassThrough downstreamCompilers[] = {
- SLANG_PASS_THROUGH_CLANG, ///< Clang C/C++ compiler
- SLANG_PASS_THROUGH_VISUAL_STUDIO, ///< Visual studio C/C++ compiler
- SLANG_PASS_THROUGH_GCC, ///< GCC C/C++ compiler
- SLANG_PASS_THROUGH_GENERIC_C_CPP,
- };
- for (auto downstreamCompiler : downstreamCompilers)
- {
- session->setDownstreamCompilerPrelude(downstreamCompiler, prelude.getBuffer());
- }
+ SLANG_ASSERT(!"Couldn't find the CUDA prelude relative to the executable");
}
}