summaryrefslogtreecommitdiffstats
path: root/source/slang/slang.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2021-08-26 10:30:35 -0700
committerGitHub <noreply@github.com>2021-08-26 10:30:35 -0700
commitb2ad8e99a82884bb157e1be76b1ad7eb0e481457 (patch)
tree3f5357083b5972761d516b70cb51a4fa7ab72cd5 /source/slang/slang.cpp
parent33f7e1599cbecb32c23787b37b2bf3b34bdd5c84 (diff)
Add API to control interface specialization. (#1925)
Diffstat (limited to 'source/slang/slang.cpp')
-rw-r--r--source/slang/slang.cpp47
1 files changed, 46 insertions, 1 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index ef6872e76..e62d2c9ae 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -1043,6 +1043,33 @@ SLANG_NO_THROW SlangResult SLANG_MCALL Linkage::getTypeConformanceWitnessSequent
return SLANG_OK;
}
+SLANG_NO_THROW SlangResult SLANG_MCALL Linkage::createTypeConformanceComponentType(
+ slang::TypeReflection* type,
+ slang::TypeReflection* interfaceType,
+ slang::ITypeConformance** outConformanceComponentType,
+ SlangInt conformanceIdOverride,
+ ISlangBlob** outDiagnostics)
+{
+ RefPtr<TypeConformance> result;
+ DiagnosticSink sink;
+ try
+ {
+ SharedSemanticsContext sharedSemanticsContext(this, nullptr, &sink);
+ SemanticsVisitor visitor(&sharedSemanticsContext);
+ auto witness =
+ visitor.tryGetSubtypeWitness((Slang::Type*)type, (Slang::Type*)interfaceType);
+ if (auto subtypeWitness = as<SubtypeWitness>(witness))
+ {
+ result = new TypeConformance(this, subtypeWitness, conformanceIdOverride, &sink);
+ }
+ }
+ catch (...)
+ {}
+ sink.getBlobIfNeeded(outDiagnostics);
+ *outConformanceComponentType = result.detach();
+ return result ? SLANG_OK : SLANG_FAIL;
+}
+
SLANG_NO_THROW SlangResult SLANG_MCALL Linkage::createCompileRequest(
SlangCompileRequest** outCompileRequest)
{
@@ -3041,6 +3068,11 @@ struct EnumerateModulesVisitor : ComponentTypeVisitor
{
visitChildren(specialized);
}
+
+ void visitTypeConformance(TypeConformance* conformance) SLANG_OVERRIDE
+ {
+ SLANG_UNUSED(conformance);
+ }
};
@@ -3079,6 +3111,11 @@ struct EnumerateIRModulesVisitor : ComponentTypeVisitor
m_callback(specialized->getIRModule(), m_userData);
}
+
+ void visitTypeConformance(TypeConformance* conformance) SLANG_OVERRIDE
+ {
+ m_callback(conformance->getIRModule(), m_userData);
+ }
};
void ComponentType::enumerateIRModules(EnumerateIRModulesCallback callback, void* userData)
@@ -3401,6 +3438,11 @@ struct SpecializationArgModuleCollector : ComponentTypeVisitor
{
visitChildren(specialized);
}
+
+ void visitTypeConformance(TypeConformance* conformance) SLANG_OVERRIDE
+ {
+ SLANG_UNUSED(conformance);
+ }
};
SpecializedComponentType::SpecializedComponentType(
@@ -3616,7 +3658,10 @@ SpecializedComponentType::SpecializedComponentType(
{ visitChildren(composite, specializationInfo); }
void visitSpecialized(SpecializedComponentType* specialized) SLANG_OVERRIDE
{ visitChildren(specialized); }
-
+ void visitTypeConformance(TypeConformance* conformance) SLANG_OVERRIDE
+ {
+ SLANG_UNUSED(conformance);
+ }
EntryPointMangledNameCollector(ASTBuilder* astBuilder):
m_astBuilder(astBuilder)
{