From 6736b0c1c5fa3e89bc561eb7965a1a0d17af3466 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 29 Sep 2021 11:29:46 -0700 Subject: Add ISession::loadModuleFromSource. (#1950) Co-authored-by: Yong He --- source/slang/slang.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'source/slang/slang.cpp') diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 1362cb038..0fc5f6122 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -839,6 +839,36 @@ SLANG_NO_THROW slang::IModule* SLANG_MCALL Linkage::loadModule( } } +SLANG_NO_THROW slang::IModule* SLANG_MCALL Linkage::loadModuleFromSource( + const char* moduleName, + slang::IBlob* source, + slang::IBlob** outDiagnostics) +{ + try + { + auto name = getNamePool()->getName(moduleName); + RefPtr loadedModule; + if (mapNameToLoadedModules.TryGetValue(name, loadedModule)) + { + return loadedModule; + } + DiagnosticSink sink(getSourceManager(), Lexer::sourceLocationLexer); + auto module = loadModule( + name, + PathInfo::makeFromString(moduleName), + source, + SourceLoc(), + &sink); + sink.getBlobIfNeeded(outDiagnostics); + return asExternal(module); + + } + catch (const AbortCompilationException&) + { + return nullptr; + } +} + SLANG_NO_THROW SlangResult SLANG_MCALL Linkage::createCompositeComponentType( slang::IComponentType* const* componentTypes, SlangInt componentTypeCount, -- cgit v1.2.3