summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-compiler.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2022-09-01 15:38:17 -0400
committerGitHub <noreply@github.com>2022-09-01 15:38:17 -0400
commitbe8497804f803c02cfab1aa2c54d921042e90ec9 (patch)
treec9451382ba2bf112848441f9d61470a90ed764ee /source/slang/slang-compiler.cpp
parent174048f26c147e31a6f72907a3af5dfafeedb877 (diff)
Remove artifact from SourceFile (#2384)
* #include an absolute path didn't work - because paths were taken to always be relative. * Make DownstreamCompileOptions use POD types. * CharSliceAllocator -> SliceAllocator Added SliceConverter CharSliceCaster -> SliceCaster * First attempt at zero terminating around blobs. * Fix clang warning. * Add SlangTerminatedChars Make Blob implementations support it. Make most blobs 'terminated'. * Fix bug setting up sourceFiles for CommandLineDownstreamCompiler. * Traffic in TerminatedCharSlice for sourceFiles. Use ArtifactDesc to generate temporary file names for source. * Fix typo in testing for shared library/C++. * Working with source being passed as artifacts to DownstreamCompiler. * Use artifacts in SourceManager/SourceFile. * Support infering extension from the original file extension. * * Infer extension if can't determine from the artifact type * Split IOSFile/IExtFile representations * Move responsibility for creating OS file to the handler. * Disable the check memory path. * Remove artifact from SourceFile. Lazily generate SourceFile from artifacts as needed. * Fix some small bugs. * Remove maybeAddArtifact. * Load artifacts if repro capture is enabled. * Remove adding by string, because doing so means source will be allocated twice or there is a potential race around ref counting to the contained String. * Add built in source as a blob. * Fix warning. * Make StringBlob own the contents if moved. Fix some compilation issues. * Share StringBlob uniqueness code. * Do move unique on Ctor. * Change MoveUnique to not have any values. * MoveUnique can more sensibly be a struct. Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/slang/slang-compiler.cpp')
-rw-r--r--source/slang/slang-compiler.cpp50
1 files changed, 27 insertions, 23 deletions
diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp
index ce380681e..06cc9d759 100644
--- a/source/slang/slang-compiler.cpp
+++ b/source/slang/slang-compiler.cpp
@@ -578,6 +578,22 @@ namespace Slang
}
}
+ SlangResult CodeGenContext::requireTranslationUnitSourceFiles()
+ {
+ if (auto endToEndReq = isPassThroughEnabled())
+ {
+ for (auto entryPointIndex : getEntryPointIndices())
+ {
+ auto translationUnit = getPassThroughTranslationUnit(endToEndReq, entryPointIndex);
+ SLANG_ASSERT(translationUnit);
+ /// Make sure we have the source files
+ SLANG_RETURN_ON_FAIL(translationUnit->requireSourceFiles());
+ }
+ }
+
+ return SLANG_OK;
+ }
+
#if SLANG_VC
// TODO(JS): This is a workaround
// In debug VS builds there is a warning on line about it being unreachable.
@@ -587,9 +603,11 @@ namespace Slang
# pragma warning(disable:4702)
#endif
SlangResult CodeGenContext::emitEntryPointsSource(ComPtr<IArtifact>& outArtifact)
- {
+ {
outArtifact.setNull();
+ SLANG_RETURN_ON_FAIL(requireTranslationUnitSourceFiles());
+
auto endToEndReq = isPassThroughEnabled();
if(endToEndReq)
{
@@ -597,6 +615,10 @@ namespace Slang
{
auto translationUnit = getPassThroughTranslationUnit(endToEndReq, entryPointIndex);
SLANG_ASSERT(translationUnit);
+
+ /// Make sure we have the source files
+ SLANG_RETURN_ON_FAIL(translationUnit->requireSourceFiles());
+
// Generate a string that includes the content of
// the source file(s), along with a line directive
// to ensure that we get reasonable messages
@@ -835,23 +857,7 @@ namespace Slang
if (compiler->isFileBased())
{
// It can only have *one* source file as otherwise we have to combine to make a new source file anyway
- const auto& sourceFiles = translationUnit->getSourceFiles();
-
- // The *assumption* here is that if it's file based that assuming it can find the file with the same contents
- // it can compile directly without having to save off as a file
- if (sourceFiles.getCount() == 1)
- {
- const SourceFile* sourceFile = sourceFiles[0];
- // We need the path to be found and set
- //
- // NOTE! That the downstream compiler can determine if the path and contents match such that it can be used
- // without writing file
- const PathInfo& pathInfo = sourceFile->getPathInfo();
- if ((pathInfo.type == PathInfo::Type::FoundPath || pathInfo.type == PathInfo::Type::Normal) && pathInfo.foundPath.getLength())
- {
- return false;
- }
- }
+ return translationUnit->getSourceArtifacts().getCount() != 1;
}
return true;
}
@@ -1066,12 +1072,10 @@ namespace Slang
else
{
// Special case if we have a single file, so that we pass the path, and the contents as is.
- const auto& sourceFiles = translationUnit->getSourceFiles();
- SLANG_ASSERT(sourceFiles.getCount() == 1);
-
- SourceFile* sourceFile = sourceFiles[0];
+ const auto& sourceArtifacts = translationUnit->getSourceArtifacts();
+ SLANG_ASSERT(sourceArtifacts.getCount() == 1);
- sourceArtifact = sourceFile->getArtifact();
+ sourceArtifact = sourceArtifacts[0];
SLANG_ASSERT(sourceArtifact);
}
}