summaryrefslogtreecommitdiffstats
path: root/source/slang/slang.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-01-31 16:26:03 -0800
committerGitHub <noreply@github.com>2022-01-31 16:26:03 -0800
commite59516fa8c3a16eb7b99a928c5b85b97bf44fd72 (patch)
tree869c2b8df0cc0d368af928324d53079a9f7999e0 /source/slang/slang.cpp
parent2bb43bbe4709533e0c6e53df1c62d368132dcd73 (diff)
Revise entrypoint renaming interface. (#2113)
Changed the interface from `IEntryPoint::getRenamedEntryPoint` to `IComponentType::renameEntryPoint`. The underlying implementation creates a `RenamedEntryPointComponentType` wrapper object around the base entry-point. This new implementation allows the user to specify entry point renaming on an IComponentType that isn't just a `EntryPoint`, but also on `SpecializedComponentType` or `CompositeComponentType` as long as the component defines a single entry point. Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang.cpp')
-rw-r--r--source/slang/slang.cpp56
1 files changed, 55 insertions, 1 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index 1333e3660..3880d1114 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -3160,6 +3160,15 @@ SLANG_NO_THROW SlangResult SLANG_MCALL ComponentType::specialize(
return SLANG_OK;
}
+SLANG_NO_THROW SlangResult SLANG_MCALL
+ ComponentType::renameEntryPoint(const char* newName, IComponentType** outEntryPoint)
+{
+ RefPtr<RenamedEntryPointComponentType> result =
+ new RenamedEntryPointComponentType(this, newName);
+ *outEntryPoint = result.detach();
+ return SLANG_OK;
+}
+
RefPtr<ComponentType> fillRequirements(
ComponentType* inComponentType);
@@ -3195,6 +3204,13 @@ struct EnumerateModulesVisitor : ComponentTypeVisitor
void visitEntryPoint(EntryPoint*, EntryPoint::EntryPointSpecializationInfo*) SLANG_OVERRIDE {}
+ void visitRenamedEntryPoint(
+ RenamedEntryPointComponentType* entryPoint,
+ EntryPoint::EntryPointSpecializationInfo* specializationInfo) SLANG_OVERRIDE
+ {
+ entryPoint->getBase()->acceptVisitor(this, specializationInfo);
+ }
+
void visitModule(Module* module, Module::ModuleSpecializationInfo*) SLANG_OVERRIDE
{
m_callback(module, m_userData);
@@ -3236,6 +3252,13 @@ struct EnumerateIRModulesVisitor : ComponentTypeVisitor
void visitEntryPoint(EntryPoint*, EntryPoint::EntryPointSpecializationInfo*) SLANG_OVERRIDE {}
+ void visitRenamedEntryPoint(
+ RenamedEntryPointComponentType* entryPoint,
+ EntryPoint::EntryPointSpecializationInfo* specializationInfo) SLANG_OVERRIDE
+ {
+ entryPoint->getBase()->acceptVisitor(this, specializationInfo);
+ }
+
void visitModule(Module* module, Module::ModuleSpecializationInfo*) SLANG_OVERRIDE
{
m_callback(module->getIRModule(), m_userData);
@@ -3427,7 +3450,6 @@ void CompositeComponentType::acceptVisitor(ComponentTypeVisitor* visitor, Specia
visitor->visitComposite(this, as<CompositeSpecializationInfo>(specializationInfo));
}
-
RefPtr<ComponentType::SpecializationInfo> CompositeComponentType::_validateSpecializationArgsImpl(
SpecializationArg const* args,
Index argCount,
@@ -3562,6 +3584,13 @@ struct SpecializationArgModuleCollector : ComponentTypeVisitor
collectReferencedModules(specializationInfo->existentialSpecializationArgs);
}
+ void visitRenamedEntryPoint(
+ RenamedEntryPointComponentType* entryPoint,
+ EntryPoint::EntryPointSpecializationInfo* specializationInfo) SLANG_OVERRIDE
+ {
+ entryPoint->getBase()->acceptVisitor(this, specializationInfo);
+ }
+
void visitModule(Module* module, Module::ModuleSpecializationInfo* specializationInfo) SLANG_OVERRIDE
{
SLANG_UNUSED(module);
@@ -3801,6 +3830,14 @@ SpecializedComponentType::SpecializedComponentType(
(*entryPointNameOverrides).add(entryPoint->getEntryPointNameOverride(0));
}
+ void visitRenamedEntryPoint(
+ RenamedEntryPointComponentType* entryPoint,
+ EntryPoint::EntryPointSpecializationInfo* specializationInfo) SLANG_OVERRIDE
+ {
+ entryPoint->getBase()->acceptVisitor(this, specializationInfo);
+ (*entryPointNameOverrides).getLast() = entryPoint->getEntryPointNameOverride(0);
+ }
+
void visitModule(Module*, Module::ModuleSpecializationInfo*) SLANG_OVERRIDE
{}
void visitComposite(CompositeComponentType* composite, CompositeComponentType::CompositeSpecializationInfo* specializationInfo) SLANG_OVERRIDE
@@ -3854,6 +3891,23 @@ String SpecializedComponentType::getEntryPointNameOverride(Index index)
return m_entryPointNameOverrides[index];
}
+// RenamedEntryPointComponentType
+
+RenamedEntryPointComponentType::RenamedEntryPointComponentType(
+ ComponentType* base, String newName)
+ : ComponentType(base->getLinkage())
+ , m_base(base)
+ , m_entryPointNameOverride(newName)
+{
+}
+
+void RenamedEntryPointComponentType::acceptVisitor(
+ ComponentTypeVisitor* visitor, SpecializationInfo* specializationInfo)
+{
+ visitor->visitRenamedEntryPoint(
+ this, as<EntryPoint::EntryPointSpecializationInfo>(specializationInfo));
+}
+
void ComponentTypeVisitor::visitChildren(CompositeComponentType* composite, CompositeComponentType::CompositeSpecializationInfo* specializationInfo)
{
auto childCount = composite->getChildComponentCount();