diff options
| author | Theresa Foley <10618364+tangent-vector@users.noreply.github.com> | 2025-07-24 12:59:58 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-24 19:59:58 +0000 |
| commit | 8ccd495d5eaa82cb831378c28dd190e657b6c999 (patch) | |
| tree | c39dc364d95f78984fd4ba2776d259ff944d2596 /source/slang/slang-entry-point.cpp | |
| parent | 2d23a962766a97cbb11bcee5483a66aec923da49 (diff) | |
Organize code better by splitting some big files (#7890)
* Organize code better by splitting some big files
The basic change here is that the majority of the declarations in `slang-compiler.h` have been split out into a set of smaller and more focused files.
As a result, the implement of those declarations have been moved from `slang-compiler.cpp` and `slang.cpp` over to those new files when the proper home for code is obvious.
I have tried as much as possible to *not* make any edits to the code along the way, and just copy-paste declarations from one place to another as-is.
The exceptions I am aware of are:
* In some cases a function that used to be file-scope `static` was used by code that landed in two or more different `.cpp` files. In these cases, I changed the function to be non-`static` (removing the `_` prefix from its name, if it had one, per our naming conventions), and put a declaration for the function into the most appropriate header I could identify.
* I added a few comments in places where I saw ugly or unfortunate things in the code I was moving, and wanted to tag them with `TODO`s so we can hopefully get to them in the fullness of time.
* I added top-level comments to each of the new `.h` files that was introduced to try to explain the logic for what goes into that file.
* In cases where one of the new header files mostly existed to declare a single type, I sometimes added more detail to the doc comment on that type, to better explain the type and its role in the compiler (this is text that otherwise might have gone into the comment at the top leve lof the file, but I figured that the doc comment would have higher discoverability).
I expect that the most contentious choice here is that the `Session` class lands in `slang-global-session.h` while `slang-session.h` holds the `Linkage` class.
The names used in this change are consistent with how the relevant concepts in the public Slang API are named, and are consistent with how we *intend* to rename the classes themselves in time.
* format code
* fixup
---------
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'source/slang/slang-entry-point.cpp')
| -rw-r--r-- | source/slang/slang-entry-point.cpp | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/source/slang/slang-entry-point.cpp b/source/slang/slang-entry-point.cpp new file mode 100644 index 000000000..0cce90646 --- /dev/null +++ b/source/slang/slang-entry-point.cpp @@ -0,0 +1,159 @@ +// slang-entry-point.cpp +#include "slang-entry-point.h" + +#include "slang-compiler.h" +#include "slang-mangle.h" + +namespace Slang +{ + +// +// EntryPoint +// + +ISlangUnknown* EntryPoint::getInterface(const Guid& guid) +{ + if (guid == slang::IEntryPoint::getTypeGuid()) + return static_cast<slang::IEntryPoint*>(this); + + return Super::getInterface(guid); +} + +RefPtr<EntryPoint> EntryPoint::create( + Linkage* linkage, + DeclRef<FuncDecl> funcDeclRef, + Profile profile) +{ + RefPtr<EntryPoint> entryPoint = + new EntryPoint(linkage, funcDeclRef.getName(), profile, funcDeclRef); + entryPoint->m_mangledName = getMangledName(linkage->getASTBuilder(), funcDeclRef); + return entryPoint; +} + +RefPtr<EntryPoint> EntryPoint::createDummyForPassThrough( + Linkage* linkage, + Name* name, + Profile profile) +{ + RefPtr<EntryPoint> entryPoint = new EntryPoint(linkage, name, profile, DeclRef<FuncDecl>()); + return entryPoint; +} + +RefPtr<EntryPoint> EntryPoint::createDummyForDeserialize( + Linkage* linkage, + Name* name, + Profile profile, + String mangledName) +{ + RefPtr<EntryPoint> entryPoint = new EntryPoint(linkage, name, profile, DeclRef<FuncDecl>()); + entryPoint->m_mangledName = mangledName; + return entryPoint; +} + +EntryPoint::EntryPoint(Linkage* linkage, Name* name, Profile profile, DeclRef<FuncDecl> funcDeclRef) + : ComponentType(linkage), m_name(name), m_profile(profile), m_funcDeclRef(funcDeclRef) +{ + // Collect any specialization parameters used by the entry point + // + _collectShaderParams(); +} + +Module* EntryPoint::getModule() +{ + return Slang::getModule(getFuncDecl()); +} + +Index EntryPoint::getSpecializationParamCount() +{ + return m_genericSpecializationParams.getCount() + m_existentialSpecializationParams.getCount(); +} + +SpecializationParam const& EntryPoint::getSpecializationParam(Index index) +{ + auto genericParamCount = m_genericSpecializationParams.getCount(); + if (index < genericParamCount) + { + return m_genericSpecializationParams[index]; + } + else + { + return m_existentialSpecializationParams[index - genericParamCount]; + } +} + +Index EntryPoint::getRequirementCount() +{ + // The only requirement of an entry point is the module that contains it. + // + // TODO: We will eventually want to support the case of an entry + // point nested in a `struct` type, in which case there should be + // a single requirement representing that outer type (so that multiple + // entry points nested under the same type can share the storage + // for parameters at that scope). + + // Note: the defensive coding is here because the + // "dummy" entry points we create for pass-through + // compilation will not have an associated module. + // + if (const auto module = getModule()) + { + return 1; + } + return 0; +} + +RefPtr<ComponentType> EntryPoint::getRequirement(Index index) +{ + SLANG_UNUSED(index); + SLANG_ASSERT(index == 0); + SLANG_ASSERT(getModule()); + return getModule(); +} + +String EntryPoint::getEntryPointMangledName(Index index) +{ + SLANG_UNUSED(index); + SLANG_ASSERT(index == 0); + + return m_mangledName; +} + +String EntryPoint::getEntryPointNameOverride(Index index) +{ + SLANG_UNUSED(index); + SLANG_ASSERT(index == 0); + + return m_name ? m_name->text : ""; +} + +void EntryPoint::acceptVisitor( + ComponentTypeVisitor* visitor, + SpecializationInfo* specializationInfo) +{ + visitor->visitEntryPoint(this, as<EntryPointSpecializationInfo>(specializationInfo)); +} + +void EntryPoint::buildHash(DigestBuilder<SHA1>& builder) +{ + SLANG_UNUSED(builder); +} + +List<Module*> const& EntryPoint::getModuleDependencies() +{ + if (auto module = getModule()) + return module->getModuleDependencies(); + + static List<Module*> empty; + return empty; +} + +List<SourceFile*> const& EntryPoint::getFileDependencies() +{ + if (const auto module = getModule()) + return getModule()->getFileDependencies(); + + static List<SourceFile*> empty; + return empty; +} + +} // namespace Slang |
