diff options
| author | jarcherNV <jarcher@nvidia.com> | 2025-08-15 13:16:09 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-15 20:16:09 +0000 |
| commit | af27de01532904508e6a630c213249e93fdd1c66 (patch) | |
| tree | 771a04869c4539653ce2c9f44476ea0d14bd81fb /source | |
| parent | dcda42e7dcdb5e260013757763bf5dbf67d69568 (diff) | |
Add static functions to create blobs from data (#8179)
Add helper functions to create ISlangBlob and load module data from
source.
---------
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-api.cpp | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/source/slang/slang-api.cpp b/source/slang/slang-api.cpp index 9b7b605a2..14bfc8a72 100644 --- a/source/slang/slang-api.cpp +++ b/source/slang/slang-api.cpp @@ -982,3 +982,87 @@ SLANG_API void spSetDiagnosticFlags(slang::ICompileRequest* request, SlangDiagno request->setDiagnosticFlags(flags); } + +/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!! Blob Creation !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ + +SLANG_EXTERN_C SLANG_API ISlangBlob* slang_createBlob(const void* data, size_t size) +{ + // Disallow empty blobs. + if (!data || size == 0) + return nullptr; + + Slang::ComPtr<ISlangBlob> blob = Slang::RawBlob::create(data, size); + if (!blob) + return nullptr; + + return blob.detach(); +} + +/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!! Module Loading !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ + +SLANG_EXTERN_C SLANG_API slang::IModule* slang_loadModuleFromSource( + slang::ISession* session, + const char* moduleName, + const char* path, + const char* source, + size_t sourceSize, + ISlangBlob** outDiagnostics) +{ + if (!session || !moduleName || !path || !source || sourceSize == 0) + return nullptr; + + // Create a blob from the source data using the slang_createBlob function. + Slang::ComPtr<ISlangBlob> sourceBlob; + sourceBlob = slang_createBlob(source, sourceSize); + if (!sourceBlob) + return nullptr; + + // Load the module using the existing blob-based API. + return session->loadModuleFromSource(moduleName, path, sourceBlob, outDiagnostics); +} + +SLANG_EXTERN_C SLANG_API slang::IModule* slang_loadModuleFromIRBlob( + slang::ISession* session, + const char* moduleName, + const char* path, + const void* source, + size_t sourceSize, + ISlangBlob** outDiagnostics) +{ + if (!session || !moduleName || !path || !source || sourceSize == 0) + return nullptr; + + // Create a blob from the source data using the slang_createBlob function. + Slang::ComPtr<ISlangBlob> sourceBlob; + sourceBlob = slang_createBlob(source, sourceSize); + if (!sourceBlob) + return nullptr; + + // Load the module using the existing IR blob-based API. + return session->loadModuleFromIRBlob(moduleName, path, sourceBlob, outDiagnostics); +} + +SLANG_EXTERN_C SLANG_API SlangResult slang_loadModuleInfoFromIRBlob( + slang::ISession* session, + const void* source, + size_t sourceSize, + SlangInt& outModuleVersion, + const char*& outModuleCompilerVersion, + const char*& outModuleName) +{ + if (!session || !source || sourceSize == 0) + return SLANG_E_INVALID_ARG; + + // Create a blob from the source data using the slang_createBlob function. + Slang::ComPtr<ISlangBlob> sourceBlob; + sourceBlob = slang_createBlob(source, sourceSize); + if (!sourceBlob) + return SLANG_E_INVALID_ARG; + + // Load module info using the existing IR blob-based API. + return session->loadModuleInfoFromIRBlob( + sourceBlob, + outModuleVersion, + outModuleCompilerVersion, + outModuleName); +} |
