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/slang/slang-compiler.cpp | |
| 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/slang/slang-compiler.cpp')
| -rw-r--r-- | source/slang/slang-compiler.cpp | 85 |
1 files changed, 15 insertions, 70 deletions
diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp index 75cd61bf9..07e2b66fe 100644 --- a/source/slang/slang-compiler.cpp +++ b/source/slang/slang-compiler.cpp @@ -474,7 +474,7 @@ namespace Slang return SLANG_E_NOT_IMPLEMENTED; } - static PassThroughMode _getExternalCompilerRequiredForTarget(CodeGenTarget target) + PassThroughMode getDownstreamCompilerRequiredForTarget(CodeGenTarget target) { switch (target) { @@ -530,9 +530,22 @@ namespace Slang return PassThroughMode::None; } + PassThroughMode getPassThroughModeForCPPCompiler(CPPCompiler::CompilerType type) + { + typedef CPPCompiler::CompilerType CompilerType; + + switch (type) + { + case CompilerType::VisualStudio: return PassThroughMode::VisualStudio; + case CompilerType::GCC: return PassThroughMode::Gcc; + case CompilerType::Clang: return PassThroughMode::Clang; + default: return PassThroughMode::None; + } + } + SlangResult checkCompileTargetSupport(Session* session, CodeGenTarget target) { - const PassThroughMode mode = _getExternalCompilerRequiredForTarget(target); + const PassThroughMode mode = getDownstreamCompilerRequiredForTarget(target); return (mode != PassThroughMode::None) ? checkExternalCompilerSupport(session, mode) : SLANG_OK; @@ -561,21 +574,6 @@ namespace Slang return translationUnit; } - static TranslationUnitRequest* _getTranslationUnit( - EndToEndCompileRequest* endToEndReq, - Int entryPointIndex) - { - // If there isn't an end-to-end compile going on, - // there can be no pass-through. - // - if (!endToEndReq) return nullptr; - - auto frontEndReq = endToEndReq->getFrontEndReq(); - auto entryPointReq = frontEndReq->getEntryPointReq(entryPointIndex); - auto translationUnit = entryPointReq->getTranslationUnit(); - return translationUnit; - } - static void _appendEscapedPath(const UnownedStringSlice& path, StringBuilder& outBuilder) { for (auto c : path) @@ -1316,28 +1314,6 @@ SlangResult dissassembleDXILUsingDXC( } else { - // TODO(JS): This is a hack for two reasons - // * That we just inject the source path for C/C++ include paths if we find the file - // * We should access the files through the ISlangFileSystem - - translationUnit = _getTranslationUnit(endToEndReq, entryPointIndex); - - const auto& sourceFiles = translationUnit->getSourceFiles(); - if (sourceFiles.getCount() == 1) - { - const SourceFile* sourceFile = sourceFiles[0]; - const PathInfo& pathInfo = sourceFile->getPathInfo(); - if (pathInfo.type == PathInfo::Type::FoundPath || pathInfo.type == PathInfo::Type::Normal || pathInfo.type == PathInfo::Type::FromString) - { - String canonicalPath; - if (File::exists(pathInfo.foundPath) && SLANG_SUCCEEDED(Path::getCanonical(pathInfo.foundPath, canonicalPath))) - { - String sourceDir = Path::getParentDirectory(canonicalPath); - includePaths.add(sourceDir); - } - } - } - rawSource = emitCPPForEntryPoint( slangRequest, entryPoint, @@ -1477,37 +1453,6 @@ SlangResult dissassembleDXILUsingDXC( } } - // TODO(JS): HACK! We need to include the prelude from somewhere, but where? The generated output - // is sitting in some temp directory. - // So here, we search all the 'sourceFiles', and try their paths for plausibility, and take the first - { - auto frontEndReq = endToEndReq->getFrontEndReq(); - auto entryPointReq = frontEndReq->getEntryPointReq(entryPointIndex); - auto translationUnit = entryPointReq->getTranslationUnit(); - - for (SourceFile* sourceFile : translationUnit->m_sourceFiles) - { - const auto& pathInfo = sourceFile->getPathInfo(); - - if (pathInfo.type == PathInfo::Type::FoundPath || - pathInfo.type == PathInfo::Type::Normal) - { - String originalSourceDirectory = Path::getParentDirectory(pathInfo.foundPath); - - if (originalSourceDirectory.getLength() && File::exists(originalSourceDirectory)) - { - // We can't use this path directly, so make canonical so it is absolute - StringBuilder canonicalPath; - if (SLANG_SUCCEEDED(Path::getCanonical(originalSourceDirectory, canonicalPath))) - { - options.includePaths.add(canonicalPath.ProduceString()); - break; - } - } - } - } - } - // Compile CPPCompiler::Output output; SLANG_RETURN_ON_FAIL(compiler->compile(options, output)); |
