From cd8715a7760189c54b36c0c250efbe1db5b8635c Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 1 Sep 2022 09:35:18 -0400 Subject: 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. --- source/compiler-core/slang-slice-allocator.h | 56 +++++++++++++++------------- 1 file changed, 31 insertions(+), 25 deletions(-) (limited to 'source/compiler-core/slang-slice-allocator.h') 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 toList(const Slice& 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 - static Slice asSlice(const List>& list) { return makeSlice((T*const*)list.getBuffer(), list.getCount()); } + static Slice asSlice(const List>& list) { return makeSlice((T* const*)list.getBuffer(), list.getCount()); } /// Get a list as a slice template static Slice asSlice(const List& list) { return Slice(list.getBuffer(), list.getCount()); } -private: - /// We don't want to make a temporary list into a slice.. - template - static Slice asSlice(const List&& 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 toList(const Slice& in); - - /// NOTE! the slice is only guarenteed to stay in scope whilst the blob does - static TerminatedCharSlice toTerminatedCharSlice(SliceAllocator& allocator, ISlangBlob* blob); - template static List> toComPtrList(const Slice& in) { @@ -57,6 +49,20 @@ struct SliceConverter for (Index i = 0; i < in.count; ++i) list[i] = ComPtr(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 + static Slice asSlice(const List&& 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) -- cgit v1.2.3