diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2019-01-07 09:31:31 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-01-07 09:31:31 -0500 |
| commit | eb331446e3bee812d1df19cf59eb2d23d287ac74 (patch) | |
| tree | 34e2bc99746606cf53e775c423871496e9ee302d /source/core/stream.cpp | |
| parent | d155eaa92d56a4ec00109d25c8c70fe12fb96c2e (diff) | |
Feature/serialization debug info (#767)
* Remove AppContext. Use StdChannels to hold writers, and TestToolUtil to hold test tool specific functionality.
* StdChannels -> StdWriters
* getStdOut -> getOut, getStdError -> getError
* Renamed main.cpp files of tools to try and stop visual studio getting confused between files - such that clicking on an error takes editor to the right location.
* Work in progress on being able to serialize debug information.
* * Added MemoryStream
* First pass converting to IRSerialData
* Able to read and write IRSerialData with debug data
* Start at reconstruting IR serialized data.
* First pass of generation debug SourceLocs from debug data. Works for test set for line nos.
* Bug fixes.
Moved testing of serialization into IRSerialUtil
* Work around problem with irModule = generateIRForTranslationUnit(translationUnit); two times in a row produces different output(!). Fix by just creating once.
* Remove problem with use of ternary op in slang.cpp on gcc/clang.
* Added -verify-debug-serial-ir option that makes IR modules go through full serialization with debug information and verification.
* Add a test that does serial debug verification that is run by default on linux.
Diffstat (limited to 'source/core/stream.cpp')
| -rw-r--r-- | source/core/stream.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/source/core/stream.cpp b/source/core/stream.cpp index 949ce718c..19ae3cdea 100644 --- a/source/core/stream.cpp +++ b/source/core/stream.cpp @@ -153,6 +153,7 @@ namespace Slang break; case Slang::SeekOrigin::End: _origin = SEEK_END; + // JS TODO: This doesn't seem right, the offset can mean it's not at the end endReached = true; break; case Slang::SeekOrigin::Current: @@ -215,4 +216,79 @@ namespace Slang { return endReached; } + + // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! MemoryStream !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + void MemoryStream::Seek(SeekOrigin origin, Int64 offset) + { + Int64 pos = 0; + switch (origin) + { + case Slang::SeekOrigin::Start: + pos = offset; + break; + case Slang::SeekOrigin::End: + pos = Int64(m_contents.Count()) + offset; + break; + case Slang::SeekOrigin::Current: + pos = Int64(m_position) + offset; + break; + default: + throw NotSupportedException("Unsupported seek origin."); + break; + } + + m_atEnd = false; + + // Clamp to the valid range + pos = (pos < 0) ? 0 : pos; + pos = (pos > Int64(m_contents.Count())) ? Int64(m_contents.Count()) : pos; + + m_position = UInt(pos); + } + + Int64 MemoryStream::Read(void * buffer, Int64 length) + { + if (!CanRead()) + { + throw IOException("Cannot read this stream."); + } + + const Int64 maxRead = Int64(m_contents.Count() - m_position); + + if (maxRead == 0 && length > 0) + { + m_atEnd = true; + throw EndOfStreamException("End of file is reached."); + } + + length = length > maxRead ? maxRead : length; + + ::memcpy(buffer, m_contents.begin() + m_position, size_t(length)); + m_position += UInt(length); + return maxRead; + } + + Int64 MemoryStream::Write(const void * buffer, Int64 length) + { + if (!CanWrite()) + { + throw IOException("Cannot write this stream."); + } + + if (m_position == m_contents.Count()) + { + m_contents.AddRange((const uint8_t*)buffer, UInt(length)); + } + else + { + m_contents.InsertRange(m_position, (const uint8_t*)buffer, UInt(length)); + } + + m_atEnd = false; + + m_position += UInt(length); + return length; + } + } |
