diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2022-09-01 09:35:18 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-01 09:35:18 -0400 |
| commit | cd8715a7760189c54b36c0c250efbe1db5b8635c (patch) | |
| tree | cd1b2e840e64cbdd9e9a383646f0e58a7f14ae97 /source/compiler-core/slang-slice-allocator.h | |
| parent | 5c2c2cfc9918bb43225159e67a851e196e17759a (diff) | |
Passing source to Downstream compilation as artifacts (#2382)
* #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.
Diffstat (limited to 'source/compiler-core/slang-slice-allocator.h')
| -rw-r--r-- | source/compiler-core/slang-slice-allocator.h | 56 |
1 files changed, 31 insertions, 25 deletions
diff --git a/source/compiler-core/slang-slice-allocator.h b/source/compiler-core/slang-slice-allocator.h index 41ed3943a..984ad32eb 100644 --- a/source/compiler-core/slang-slice-allocator.h +++ b/source/compiler-core/slang-slice-allocator.h @@ -10,43 +10,35 @@ namespace Slang { -/* -The reason to wrap in a struct rather than have as free functions is doing so will lead to compile time -errors with incorrect usage around temporaries. -*/ -struct SliceCaster + +struct SliceAllocator; + +struct SliceUtil { + /// Convert into a list of strings + static List<String> toList(const Slice<TerminatedCharSlice>& in); + + /// Gets a 0 terminated string from a blob. If not possible returns nullptr + static const char* getTerminated(ISlangBlob* blob, TerminatedCharSlice& outSlice); + + /// NOTE! the slice is only guarenteed to stay in scope whilst the blob does + static TerminatedCharSlice toTerminatedCharSlice(SliceAllocator& allocator, ISlangBlob* blob); + /// + static TerminatedCharSlice toTerminatedCharSlice(StringBuilder& storage, ISlangBlob* blob); + /// The slice will only be in scope whilst the string is static TerminatedCharSlice asTerminatedCharSlice(const String& in) { auto unowned = in.getUnownedSlice(); return TerminatedCharSlice(unowned.begin(), unowned.getLength()); } + /// Get string as a char slice static CharSlice asCharSlice(const String& in) { auto unowned = in.getUnownedSlice(); return CharSlice(unowned.begin(), unowned.getLength()); } template <typename T> - static Slice<T*> asSlice(const List<ComPtr<T>>& list) { return makeSlice((T*const*)list.getBuffer(), list.getCount()); } + static Slice<T*> asSlice(const List<ComPtr<T>>& list) { return makeSlice((T* const*)list.getBuffer(), list.getCount()); } /// Get a list as a slice template <typename T> static Slice<T> asSlice(const List<T>& list) { return Slice<T>(list.getBuffer(), list.getCount()); } -private: - /// We don't want to make a temporary list into a slice.. - template <typename T> - static Slice<T> asSlice(const List<T>&& list) = delete; - // We don't want temporaries to be 'asSliced' so disable - static TerminatedCharSlice asTerminatedCharSlice(const String&& in) = delete; - static CharSlice asCharSlice(const String&& in) = delete; -}; - -struct SliceAllocator; - -struct SliceConverter -{ - /// Convert into a list of strings - static List<String> toList(const Slice<TerminatedCharSlice>& in); - - /// NOTE! the slice is only guarenteed to stay in scope whilst the blob does - static TerminatedCharSlice toTerminatedCharSlice(SliceAllocator& allocator, ISlangBlob* blob); - template <typename T> static List<ComPtr<T>> toComPtrList(const Slice<T*>& in) { @@ -57,6 +49,20 @@ struct SliceConverter for (Index i = 0; i < in.count; ++i) list[i] = ComPtr<T>(in[i]); return list; } + +private: + + /* + A reason to wrap in a struct rather than have as free functions is doing so will lead to compile time + errors with incorrect usage around temporaries. + */ + + /// We don't want to make a temporary list into a slice.. + template <typename T> + static Slice<T> asSlice(const List<T>&& list) = delete; + // We don't want temporaries to be 'asSliced' so disable + static TerminatedCharSlice asTerminatedCharSlice(const String&& in) = delete; + static CharSlice asCharSlice(const String&& in) = delete; }; SLANG_FORCE_INLINE UnownedStringSlice asStringSlice(const CharSlice& slice) |
