From 79ec0cfdb5f3461c763e0bf712cf42eb87fccb90 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 10 Dec 2019 10:02:19 -0500 Subject: DownstreamCompiler abstraction (#1149) * CPPCompiler -> DownstreamCompiler * Added DownstreamCompileResult to start abstraction such that we don't need files. * * Split out slang-blob.cpp * Made CompileResult hold a DownstreamCompileResult - for access to binary or ISlangSharedLibrary * Keep temporary files in scope. * Add a hash to the hex dump stream. * Move all file tracking into DownstreamCompiler. --- source/core/slang-blob.h | 126 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 source/core/slang-blob.h (limited to 'source/core/slang-blob.h') diff --git a/source/core/slang-blob.h b/source/core/slang-blob.h new file mode 100644 index 000000000..aab131a36 --- /dev/null +++ b/source/core/slang-blob.h @@ -0,0 +1,126 @@ +#ifndef SLANG_CORE_BLOB_H +#define SLANG_CORE_BLOB_H + +#include "../../slang.h" + +#include "slang-string.h" +#include "slang-list.h" + +#include + +#include "../../slang-com-helper.h" +#include "../../slang-com-ptr.h" + +namespace Slang { + +/** Base class for simple blobs. +*/ +class BlobBase : public ISlangBlob, public RefObject +{ +public: + // ISlangUnknown + SLANG_REF_OBJECT_IUNKNOWN_ALL + +protected: + ISlangUnknown* getInterface(const Guid& guid); +}; + +/** A blob that uses a `String` for its storage. +*/ +class StringBlob : public BlobBase +{ +public: + // ISlangBlob + SLANG_NO_THROW void const* SLANG_MCALL getBufferPointer() SLANG_OVERRIDE { return m_string.getBuffer(); } + SLANG_NO_THROW size_t SLANG_MCALL getBufferSize() SLANG_OVERRIDE { return m_string.getLength(); } + + /// Get the contained string + SLANG_FORCE_INLINE const String& getString() const { return m_string; } + + explicit StringBlob(String const& string) + : m_string(string) + {} + +protected: + String m_string; +}; + +class ListBlob : public BlobBase +{ +public: + typedef BlobBase Super; + typedef ListBlob ThisType; + + // ISlangBlob + SLANG_NO_THROW void const* SLANG_MCALL getBufferPointer() SLANG_OVERRIDE { return m_data.getBuffer(); } + SLANG_NO_THROW size_t SLANG_MCALL getBufferSize() SLANG_OVERRIDE { return m_data.getCount(); } + + ListBlob() {} + + ListBlob(const List& data): m_data(data) {} + // Move ctor + ListBlob(List&& data): m_data(data) {} + + static RefPtr moveCreate(List& data) { return new ListBlob(_Move(data)); } + + List m_data; + +protected: + void operator=(const ThisType& rhs) = delete; +}; + +/** A blob that manages some raw data that it owns. +*/ +class RawBlob : public BlobBase +{ +public: + // ISlangBlob + SLANG_NO_THROW void const* SLANG_MCALL getBufferPointer() SLANG_OVERRIDE { return m_data; } + SLANG_NO_THROW size_t SLANG_MCALL getBufferSize() SLANG_OVERRIDE { return m_size; } + + // Ctor + RawBlob(const void* data, size_t size) : + m_size(size) + { + m_data = malloc(size); + memcpy(m_data, data, size); + } + ~RawBlob() + { + free(m_data); + } + +protected: + void* m_data; + size_t m_size; +}; + +/// Create a blob that will retain (a copy of) raw data. +/// +inline ComPtr createRawBlob(void const* inData, size_t size) +{ + return ComPtr(new RawBlob(inData, size)); +} + +class ScopeRefObjectBlob : public BlobBase +{ +public: + // ISlangBlob + SLANG_NO_THROW void const* SLANG_MCALL getBufferPointer() SLANG_OVERRIDE { return m_blob->getBufferPointer(); } + SLANG_NO_THROW size_t SLANG_MCALL getBufferSize() SLANG_OVERRIDE { return m_blob->getBufferSize(); } + + // Ctor + ScopeRefObjectBlob(ISlangBlob* blob, RefObject* scope) : + m_blob(blob), + m_scope(scope) + { + } + +protected: + RefPtr m_scope; + ComPtr m_blob; +}; + +} // namespace Slang + +#endif // SLANG_CORE_BLOB_H -- cgit v1.2.3