summaryrefslogtreecommitdiffstats
path: root/source/slang/slang.cpp
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2025-07-09 14:41:19 +0800
committerGitHub <noreply@github.com>2025-07-09 06:41:19 +0000
commit00746bf09047cdf01c19dac513a532bcf3ed3ea3 (patch)
tree3424872a629307fc9fb4dc04ea5e9a0a787a6523 /source/slang/slang.cpp
parent4f54cccf0e0e06be38312e2ee97c2b50b82d7c10 (diff)
Stable names and backwards compat for serialized IR modules (#7644)
* stable names * tests, options and ci for stable names * Add back compat design document * fix warnings * formatting * comment * neaten * regenerate command line reference * consolidate ci scripts * faster ci * remove libreadline * Move new function to end of interface --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'source/slang/slang.cpp')
-rw-r--r--source/slang/slang.cpp46
1 files changed, 44 insertions, 2 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index b616eb555..090e34e9a 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -763,7 +763,7 @@ SlangResult Session::_readBuiltinModule(
// to deserialize the IR module.
//
RefPtr<IRModule> irModule;
- readSerializedModuleIR(irChunk, this, sourceLocReader, irModule);
+ SLANG_RETURN_ON_FAIL(readSerializedModuleIR(irChunk, this, sourceLocReader, irModule));
irModule->setName(module->getNameObj());
module->setIRModule(irModule);
@@ -1368,6 +1368,7 @@ Linkage::Linkage(Session* session, ASTBuilder* astBuilder, Linkage* builtinLinka
, m_sourceManager(&m_defaultSourceManager)
, m_astBuilder(astBuilder)
, m_cmdLineContext(new CommandLineContext())
+ , m_stringSlicePool(StringSlicePool::Style::Default)
{
getNamePool()->setRootNamePool(session->getRootNamePool());
@@ -1663,6 +1664,47 @@ SLANG_NO_THROW slang::IModule* SLANG_MCALL Linkage::loadModuleFromIRBlob(
return loadModuleFromBlob(moduleName, path, source, ModuleBlobType::IR, outDiagnostics);
}
+SLANG_NO_THROW SlangResult SLANG_MCALL Linkage::loadModuleInfoFromIRBlob(
+ slang::IBlob* source,
+ SlangInt& outModuleVersion,
+ const char*& outModuleCompilerVersion,
+ const char*& outModuleName)
+{
+ // We start by reading the content of the file as
+ // an in-memory RIFF container.
+ //
+ auto rootChunk = RIFF::RootChunk::getFromBlob(source);
+ if (!rootChunk)
+ {
+ return SLANG_FAIL;
+ }
+
+ auto moduleChunk = ModuleChunk::find(rootChunk);
+ if (!moduleChunk)
+ {
+ return SLANG_FAIL;
+ }
+
+ auto irChunk = moduleChunk->findIR();
+ if (!irChunk)
+ {
+ return SLANG_FAIL;
+ }
+
+ RefPtr<IRModule> irModule;
+ String compilerVersion;
+ UInt version;
+ String name;
+ SLANG_RETURN_ON_FAIL(readSerializedModuleInfo(irChunk, compilerVersion, version, name));
+ const auto compilerVersionSlice = m_stringSlicePool.addAndGetSlice(compilerVersion);
+ const auto nameSlice = m_stringSlicePool.addAndGetSlice(name);
+ outModuleCompilerVersion = compilerVersionSlice.begin();
+ outModuleName = nameSlice.begin();
+ outModuleVersion = SlangInt(version);
+
+ return SLANG_OK;
+}
+
SLANG_NO_THROW SlangResult SLANG_MCALL Linkage::createCompositeComponentType(
slang::IComponentType* const* componentTypes,
SlangInt componentTypeCount,
@@ -6801,7 +6843,7 @@ SlangResult Linkage::loadSerializedModuleContents(
module->setModuleDecl(moduleDecl);
RefPtr<IRModule> irModule;
- readSerializedModuleIR(irChunk, session, sourceLocReader, irModule);
+ SLANG_RETURN_ON_FAIL(readSerializedModuleIR(irChunk, session, sourceLocReader, irModule));
module->setIRModule(irModule);
// The handling of file dependencies is complicated, because of