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.cpp | |
| 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.cpp')
| -rw-r--r-- | source/compiler-core/slang-slice-allocator.cpp | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/source/compiler-core/slang-slice-allocator.cpp b/source/compiler-core/slang-slice-allocator.cpp index 9985f6b19..9a0620ced 100644 --- a/source/compiler-core/slang-slice-allocator.cpp +++ b/source/compiler-core/slang-slice-allocator.cpp @@ -5,9 +5,9 @@ namespace Slang { -/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! SliceConverter !!!!!!!!!!!!!!!!!!!!!!!!!!! */ +/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! SliceUtil !!!!!!!!!!!!!!!!!!!!!!!!!!! */ -/* static */ List<String> SliceConverter::toList(const Slice<TerminatedCharSlice>& in) +/* static */ List<String> SliceUtil::toList(const Slice<TerminatedCharSlice>& in) { List<String> list; const auto count = in.count; @@ -20,20 +20,21 @@ namespace Slang { return list; } -/* static */TerminatedCharSlice SliceConverter::toTerminatedCharSlice(SliceAllocator& allocator, ISlangBlob* blob) +/* static */const char* SliceUtil::getTerminated(ISlangBlob* blob, TerminatedCharSlice& outSlice) { const auto size = blob->getBufferSize(); - if (size == 0) { - return TerminatedCharSlice(); + outSlice = TerminatedCharSlice(); + return outSlice.begin(); } // If there is a 0 at the end byte, we are zero terminated const char* chars = (const char*)blob->getBufferPointer(); if (chars[size - 1] == 0) { - return TerminatedCharSlice(chars, Count(size - 1)); + outSlice = TerminatedCharSlice(chars, Count(size - 1)); + return chars; } // See if it has a castable interface @@ -42,15 +43,44 @@ namespace Slang { { if (castable->castAs(SlangTerminatedChars::getTypeGuid())) { - return TerminatedCharSlice(chars, Count(size)); + outSlice = TerminatedCharSlice(chars, Count(size)); + return chars; } } + return nullptr; +} + +/* static */TerminatedCharSlice SliceUtil::toTerminatedCharSlice(SliceAllocator& allocator, ISlangBlob* blob) +{ + TerminatedCharSlice slice; + if (SliceUtil::getTerminated(blob, slice)) + { + return slice; + } + const auto size = blob->getBufferSize(); // We are out of options, we just have to allocate with zero termination which allocateString does - auto dst = allocator.getArena().allocateString(chars, Count(size)); + auto dst = allocator.getArena().allocateString((const char*)blob->getBufferPointer(), Count(size)); return TerminatedCharSlice(dst, Count(size)); } +/* static */TerminatedCharSlice SliceUtil::toTerminatedCharSlice(StringBuilder& storage, ISlangBlob* blob) +{ + TerminatedCharSlice slice; + if (SliceUtil::getTerminated(blob, slice)) + { + return slice; + } + + const auto size = blob->getBufferSize(); + auto chars = (const char*)blob->getBufferPointer(); + + storage.Clear(); + storage.append(UnownedStringSlice(chars, size)); + + return TerminatedCharSlice(storage.getBuffer(), Count(size)); +} + /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! SliceAllocator !!!!!!!!!!!!!!!!!!!!!!!!!!! */ TerminatedCharSlice SliceAllocator::allocate(const char* in) |
