diff options
Diffstat (limited to 'source/slang-record-replay/replay/decoder-helper.cpp')
| -rw-r--r-- | source/slang-record-replay/replay/decoder-helper.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/source/slang-record-replay/replay/decoder-helper.cpp b/source/slang-record-replay/replay/decoder-helper.cpp new file mode 100644 index 000000000..c9252bbc6 --- /dev/null +++ b/source/slang-record-replay/replay/decoder-helper.cpp @@ -0,0 +1,60 @@ +#include <cstdlib> +#include <vector> +#include "decoder-helper.h" +#include "parameter-decoder.h" + +namespace SlangRecord +{ + DecoderAllocatorSingleton* DecoderAllocatorSingleton::getInstance() + { + thread_local DecoderAllocatorSingleton instance; + return &instance; + } + + void* DecoderAllocatorSingleton::allocate(size_t size) + { + void* data = calloc(1, size); + + if (!data) + { + slangRecordLog(LogLevel::Error, "Failed to allocate memory\n"); + std::abort(); + } + + m_allocations.add(data); + return data; + } + + DecoderAllocatorSingleton::~DecoderAllocatorSingleton() + { + for (auto allocation : m_allocations) + { + free(allocation); + } + } + + template <typename T, typename U> + size_t StructDecoder<T, U>::decode(const uint8_t* buffer, int64_t bufferSize) + { + return ParameterDecoder::decodeStruct(buffer, bufferSize, *this); + } + + size_t BlobDecoder::decode(const uint8_t* buffer, int64_t bufferSize) + { + size_t readByte = 0; + readByte = ParameterDecoder::decodeAddress(buffer, bufferSize, m_address); + + if (!m_address) + { + readByte += ParameterDecoder::decodePointer(buffer + readByte, bufferSize - readByte, m_blobData); + } + return readByte; + } + + template class StructDecoder<slang::SessionDesc>; + template class StructDecoder<slang::PreprocessorMacroDesc>; + template class StructDecoder<slang::CompilerOptionEntry>; + template class StructDecoder<slang::CompilerOptionValue>; + template class StructDecoder<slang::TargetDesc>; + template class StructDecoder<slang::SpecializationArg>; +} |
