diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2019-08-20 09:43:59 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-08-20 09:43:59 -0400 |
| commit | 7258ef4ddebd021208a019f6ee73edcda57a88f7 (patch) | |
| tree | 30cccf48c8f03e59e48a2d265e05494238fe758d /source/core | |
| parent | 3e78e4654cdf9556869325f2ed2da517f252d879 (diff) | |
User defined downstream compiler prelude (#1028)
* Added setDownstreamCompilerPrelude
Renamed setPassThroughPath to setDownstreamCompilerPath.
Fixed tests.
Added prelude directory & code to TestToolUtil to setup default preludes for testing/command line apis.
* Fix merge problem
* Remove hacks to make prelude work by adding a search path as no longer needed with 'user prelude'.
* Split up prelude into scalar intrinsics, and types.
Use slang.h for main header.
slang-cpp-prelude.h can now just include what it needs (relative to prelude directory) and define the few remaining things/work arounds.
* Fix typo.
Diffstat (limited to 'source/core')
| -rw-r--r-- | source/core/slang-test-tool-util.cpp | 45 | ||||
| -rw-r--r-- | source/core/slang-test-tool-util.h | 3 |
2 files changed, 48 insertions, 0 deletions
diff --git a/source/core/slang-test-tool-util.cpp b/source/core/slang-test-tool-util.cpp index 20ba2fc47..9bf404e5e 100644 --- a/source/core/slang-test-tool-util.cpp +++ b/source/core/slang-test-tool-util.cpp @@ -1,6 +1,11 @@ #include "slang-test-tool-util.h" +#include "../../slang-com-helper.h" + +#include "slang-io.h" +#include "slang-string-util.h" + namespace Slang { @@ -32,6 +37,46 @@ namespace Slang } } +/* static */SlangResult TestToolUtil::setSessionDefaultPrelude(const char* exePath, slang::IGlobalSession* session) +{ + // Set the prelude to a path + String canonicalPath; + if (SLANG_SUCCEEDED(Path::getCanonical(exePath, canonicalPath))) + { + // Get the directory + canonicalPath = Path::getParentDirectory(canonicalPath); + + String path = Path::combine(canonicalPath, "../../../prelude/slang-cpp-prelude.h"); + if (SLANG_SUCCEEDED(Path::getCanonical(path, canonicalPath))) + { + // 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()); + } + } + } + + return SLANG_OK; +} + } diff --git a/source/core/slang-test-tool-util.h b/source/core/slang-test-tool-util.h index a5d7541ec..9df2a6d6a 100644 --- a/source/core/slang-test-tool-util.h +++ b/source/core/slang-test-tool-util.h @@ -46,6 +46,9 @@ struct TestToolUtil /// Given a slang result, returns a return code that can be returned from an executable static ToolReturnCode getReturnCode(SlangResult res); + + /// Sets the default preludes on the session based on the executable path + static SlangResult setSessionDefaultPrelude(const char* exePath, slang::IGlobalSession* session); }; } // namespace Slang |
