summaryrefslogtreecommitdiffstats
path: root/source/slang/slang.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2022-09-01 10:06:19 -0400
committerGitHub <noreply@github.com>2022-09-01 10:06:19 -0400
commit3c0177134d126956336865623ea3d6861be59cfa (patch)
tree920ba158afe75edde6f5254617dfa22ffeb98403 /source/slang/slang.cpp
parentcd8715a7760189c54b36c0c250efbe1db5b8635c (diff)
Make FileSystem files and OS files distinct (#2383)
* #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.
Diffstat (limited to 'source/slang/slang.cpp')
-rw-r--r--source/slang/slang.cpp43
1 files changed, 36 insertions, 7 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index a9868898e..a7a4fc8dc 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -2564,7 +2564,42 @@ void FrontEndCompileRequest::addTranslationUnitSourceFile(
int translationUnitIndex,
SourceFile* sourceFile)
{
- translationUnits[translationUnitIndex]->addSourceFile(sourceFile);
+ auto translationUnit = translationUnits[translationUnitIndex];
+
+ // TODO(JS):
+ // The larger problem here is that a file on a file system *could* be interpretted in different ways.
+ // When the user supplies the source as a string, we use the source type specified for the translation unit.
+ //
+ // If it's on the file system it could be (say) compiled as HLSL or some other way. A *downstream* compiler
+ // that used the file system may care.
+ //
+ // We will assume here, that if it's loaded from the file system, it's path extension defines how it should be interpretted
+ // If that wasn't the case we'd have to either *copy*, or do some command line fiddling to tell it for the downstream compiler
+ // what the file is.
+
+ const auto& pathInfo = sourceFile->getPathInfo();
+ const auto pathType = pathInfo.type;
+
+ switch (pathType)
+ {
+ case PathInfo::Type::FromString:
+ {
+ // Set the artifact type from the the source language type
+ auto sourceDesc = ArtifactDescUtil::makeDescForSourceLanguage(asExternal(translationUnit->sourceLanguage));
+ sourceFile->maybeAddArtifact(&sourceDesc, nullptr);
+ break;
+ }
+ case PathInfo::Type::FoundPath:
+ case PathInfo::Type::Normal:
+ {
+ // We'll *not* use the source for the artifact type. Doing so will lead to the type being determined via extension
+ sourceFile->maybeAddArtifact(nullptr, getLinkage()->getFileSystemExt());
+ break;
+ }
+ }
+
+ // Add the source file
+ translationUnit->addSourceFile(sourceFile);
}
void FrontEndCompileRequest::addTranslationUnitSourceBlob(
@@ -2575,8 +2610,6 @@ void FrontEndCompileRequest::addTranslationUnitSourceBlob(
// The path specified may or may not be a file path - mark as being constructed 'FromString'.
SourceFile* sourceFile = getSourceManager()->createSourceFileWithBlob(PathInfo::makeFromString(path), sourceBlob);
- sourceFile->maybeAddArtifact(nullptr);
-
addTranslationUnitSourceFile(translationUnitIndex, sourceFile);
}
@@ -2588,8 +2621,6 @@ void FrontEndCompileRequest::addTranslationUnitSourceString(
// The path specified may or may not be a file path - mark as being constructed 'FromString'.
SourceFile* sourceFile = getSourceManager()->createSourceFileWithString(PathInfo::makeFromString(path), source);
- sourceFile->maybeAddArtifact(nullptr);
-
addTranslationUnitSourceFile(translationUnitIndex, sourceFile);
}
@@ -2622,8 +2653,6 @@ void FrontEndCompileRequest::addTranslationUnitSourceFile(
// Was loaded from the specified path
SourceFile* sourceFile = getSourceManager()->createSourceFileWithBlob(pathInfo, sourceBlob);
- sourceFile->maybeAddArtifact(getLinkage()->getFileSystemExt());
-
addTranslationUnitSourceFile(translationUnitIndex, sourceFile);
}