diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2022-09-01 10:06:19 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-01 10:06:19 -0400 |
| commit | 3c0177134d126956336865623ea3d6861be59cfa (patch) | |
| tree | 920ba158afe75edde6f5254617dfa22ffeb98403 /source/slang | |
| parent | cd8715a7760189c54b36c0c250efbe1db5b8635c (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')
| -rw-r--r-- | source/slang/slang-compiler.cpp | 9 | ||||
| -rwxr-xr-x | source/slang/slang-compiler.h | 2 | ||||
| -rw-r--r-- | source/slang/slang-options.cpp | 6 | ||||
| -rw-r--r-- | source/slang/slang-preprocessor.cpp | 2 | ||||
| -rw-r--r-- | source/slang/slang.cpp | 43 |
5 files changed, 43 insertions, 19 deletions
diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp index 15a1ceb4b..ce380681e 100644 --- a/source/slang/slang-compiler.cpp +++ b/source/slang/slang-compiler.cpp @@ -1071,13 +1071,6 @@ namespace Slang SourceFile* sourceFile = sourceFiles[0]; - // Make it have an artifact if doesn't have one already - // This is useful because it will mean any reps will be kept in scope - // - // For example if file backing is needed, the file rep will last the lifetime of the - // SourceFile - sourceFile->maybeAddArtifact(nullptr); - sourceArtifact = sourceFile->getArtifact(); SLANG_ASSERT(sourceArtifact); } @@ -1258,7 +1251,7 @@ namespace Slang // Set up the library artifact auto artifact = Artifact::create(ArtifactDesc::make(ArtifactKind::Library, Artifact::Payload::HostCPU), toSlice("slang-rt")); - ComPtr<IFileArtifactRepresentation> fileRep(new FileArtifactRepresentation(IFileArtifactRepresentation::Kind::NameOnly, toSlice("slang-rt"), nullptr, nullptr)); + ComPtr<IOSFileArtifactRepresentation> fileRep(new OSFileArtifactRepresentation(IOSFileArtifactRepresentation::Kind::NameOnly, toSlice("slang-rt"), nullptr)); artifact->addRepresentation(fileRep); libraries.add(artifact); diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index 3c17d1c09..4c6b0a6b1 100755 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -3025,6 +3025,8 @@ SLANG_FORCE_INLINE EndToEndCompileRequest* asInternal(SlangCompileRequest* reque SLANG_FORCE_INLINE SlangCompileTarget asExternal(CodeGenTarget target) { return (SlangCompileTarget)target; } +SLANG_FORCE_INLINE SlangSourceLanguage asExternal(SourceLanguage sourceLanguage) { return (SlangSourceLanguage)sourceLanguage; } + } #endif diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp index f88f02221..a86cd5e6b 100644 --- a/source/slang/slang-options.cpp +++ b/source/slang/slang-options.cpp @@ -1491,15 +1491,15 @@ struct OptionsParser // Seeing as on all targets the baseName doesn't have an extension, and all library types do // if the name doesn't have an extension we can assume there is no path to it. - ComPtr<IFileArtifactRepresentation> fileRep; + ComPtr<IOSFileArtifactRepresentation> fileRep; if (Path::getPathExt(path).getLength() <= 0) { // If there is no extension *assume* it is the name of a system level library - fileRep = new FileArtifactRepresentation(IFileArtifactRepresentation::Kind::NameOnly, path.getUnownedSlice(), nullptr, nullptr); + fileRep = new OSFileArtifactRepresentation(IOSFileArtifactRepresentation::Kind::NameOnly, path.getUnownedSlice(), nullptr); } else { - fileRep = new FileArtifactRepresentation(IFileArtifactRepresentation::Kind::Reference, path.getUnownedSlice(), nullptr, nullptr); + fileRep = new OSFileArtifactRepresentation(IOSFileArtifactRepresentation::Kind::Reference, path.getUnownedSlice(), nullptr); if (!fileRep->exists()) { sink->diagnose(referenceModuleName.loc, Diagnostics::libraryDoesNotExist, path); diff --git a/source/slang/slang-preprocessor.cpp b/source/slang/slang-preprocessor.cpp index f1f7cffa4..739860915 100644 --- a/source/slang/slang-preprocessor.cpp +++ b/source/slang/slang-preprocessor.cpp @@ -3058,7 +3058,7 @@ static void HandleIncludeDirective(PreprocessorDirectiveContext* context) sourceFile = sourceManager->createSourceFileWithBlob(filePathInfo, foundSourceBlob); auto fileSystemExt = context->m_preprocessor->fileSystem; - sourceFile->maybeAddArtifact(fileSystemExt); + sourceFile->maybeAddArtifact(nullptr, fileSystemExt); sourceManager->addSourceFile(filePathInfo.uniqueIdentity, sourceFile); } 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); } |
