summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--slang.h7
-rwxr-xr-xsource/slang/slang-compiler.h4
-rw-r--r--source/slang/slang.cpp30
3 files changed, 41 insertions, 0 deletions
diff --git a/slang.h b/slang.h
index 38acc3997..74de9d293 100644
--- a/slang.h
+++ b/slang.h
@@ -3931,6 +3931,13 @@ namespace slang
const char* moduleName,
IBlob** outDiagnostics = nullptr) = 0;
+ /** Load a module from Slang source code.
+ */
+ virtual SLANG_NO_THROW IModule* SLANG_MCALL loadModuleFromSource(
+ const char* moduleName,
+ slang::IBlob* source,
+ slang::IBlob** outDiagnostics = nullptr) = 0;
+
/** Combine multiple component types to create a composite component type.
The `componentTypes` array must contain `componentTypeCount` pointers
diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h
index a7903dd5a..46f16f0d5 100755
--- a/source/slang/slang-compiler.h
+++ b/source/slang/slang-compiler.h
@@ -1415,6 +1415,10 @@ namespace Slang
SLANG_NO_THROW slang::IModule* SLANG_MCALL loadModule(
const char* moduleName,
slang::IBlob** outDiagnostics = nullptr) override;
+ SLANG_NO_THROW slang::IModule* SLANG_MCALL loadModuleFromSource(
+ const char* moduleName,
+ slang::IBlob* source,
+ slang::IBlob** outDiagnostics = nullptr) override;
SLANG_NO_THROW SlangResult SLANG_MCALL createCompositeComponentType(
slang::IComponentType* const* componentTypes,
SlangInt componentTypeCount,
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> 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,