summaryrefslogtreecommitdiffstats
path: root/source/compiler-core/slang-artifact-associated-impl.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2022-08-16 18:19:56 -0400
committerGitHub <noreply@github.com>2022-08-16 18:19:56 -0400
commite68fab2bda5d979f8d991fc41122bb9aa71849a6 (patch)
tree0d07c5d3b957a23065fc61d8a4ad6c2c1726652d /source/compiler-core/slang-artifact-associated-impl.cpp
parenta10a94dcb86e51d74d7c545d99d98110f88e3081 (diff)
IDownstreamCompiler interface (#2361)
* WIP with hierarchical enums. * Some small fixes and improvements around artifact desc related types. * Improvements around hierarchical enum. * Fixes to get Artifact types refactor to be able to execute tests. * Attempt to better categorize PTX. * Work around for potentially unused function warning. * Typo fix. * Simplify Artifact header. * Small improvements around Artifact kind/payload/style. * Added IDestroyable/ICastable * Add IArtifactList. * First impl of IArtifactUtil. * Use the ICastable interface for IArtifactRepresentation. * Added IArtifactRepresentation & IArtifactAssociated. * Add SLANG_OVERRIDE to avoid gcc/clang warning. * Fix calling convention issue on win32. * Fix missing SLANG_OVERRIDE. * First attempt at file abstraction around Artifact. * Added creation of lock file. * Move functionality for determining file paths to the IArtifactUtil. Add casting to ICastable. * Added some casting/finding mechanisms. * Simplify IArtifact interface, and use Items for file reps. * Fix problem with libraries on DXIL. * Split out ArtifactRepresentation. * Move ArtifactDesc functionality to ArtifactDescUtil. ArtifactInfoUtil becomes ArtifactDescUtil. * Split implementations from the interfaces for Artifact. * Use TypeTextUtil for target name outputting. * Add artifact impls. * Add ICastableList * Added UnknownCastableAdapter * Make ISlangSharedLibrary derive from ICastable, and remain backwards compatible with slang-llvm. * Refactor Representation on Artifact. * Make our ISlangBlobs also derive from ICastable. Make ISlangBlob atomic ref counted. * Split out CastableList and related types, and placed in core. * Small fixes around IArtifact. Improve IArtifact docs. First impl of getChildren for IArtifact. * Documentation improvements for Artifact related types. * Fix typo. * Special case adding a ICastableList to a LazyCastableList. * Small simplification of LazyCastableList, by adding State member. * Removed the ILockFile interface because IFileArtifactRepresentation can be used. * Implement DiagnosticsArtifactRepresentation. * Added PostEmitMetadataArtifactRepresentation * Add searching by predicate. Added handling of accessing Artifact as ISharedLibrary * Fix typo. * Add find to IArtifacgtList. Fix some missing SLANG_NO_THROW. * Small improvements around ArtifactDesc types. * Another small change around ArtifactKind. * Some more shuffling of ArtifactDesc. * Make IArtifact castable Remove IArtifactList Made IArtifactContainer derive from IArtifact Made ModuleLibrary atomic ref counted/given IModuleLibrary interface. * Must call _requireChildren before any children access. * Fix missing SLANG_MCALL on castAs. * Fix missing SLANG_OVERRIDE. * Added IArtifactHandler * Use ICastable for basis of scope/lookup. * WIP first attempt to remove CompileResult. * Fix support for for downstream compiler shared library adapter. * Fix issues found when replacing CompileResult. * Fix typo. * Fix getting items form 'significant' member of an Artifact. * Split out ArtifactUtil & ArtifactHandler. * Work around for problem on Visual studio. * Improve searching. * Add missing files. * Split out Artifact associated types. Don't produce a container by default - use associated for 'metadata'. * Remove no longer used ArtifactPayload type. * Generalized converting representations. Small improvements to artifacts. * Fix intermediate dumping issue. * Removed #if 0 out CompileResult. Remove DownstreamCompileResult maybeDumpIntermediate. * Pull out functionality for dumping artifact output into ArtifactOutputUtil Fixed a bug in naming files based on ArtifactDesc. * std::atomic issue. * Pull out types from DownstreamCompile to simplify moving to an interface. * Fix typo. * Use IDownstreamCompiler interface. Split out DownstreamCompilerUtil and DownstreamCompilerSet. * Update projects. * Fix missing SLANG_MCALL. * Fix calling convention of IDownstreamCompiler impls. * Split out binary work arounds into a dep1.cpp/h * Small reorganising around DownstreamCompilerInfo. * Remove Desc library functionality to DownstreamCompilerUtil. * Expand IDiagnostics interface. Rename associated impls with Impl suffix. * Fix outputting as text bug. Some small improvements. * Add fix around prefix for dumping. Improved how handling for extensions work form ArtifactDesc. * Dump assembly if available. * Simplify some of Dep1 definitions.
Diffstat (limited to 'source/compiler-core/slang-artifact-associated-impl.cpp')
-rw-r--r--source/compiler-core/slang-artifact-associated-impl.cpp218
1 files changed, 207 insertions, 11 deletions
diff --git a/source/compiler-core/slang-artifact-associated-impl.cpp b/source/compiler-core/slang-artifact-associated-impl.cpp
index 17ede975e..dcca24a7c 100644
--- a/source/compiler-core/slang-artifact-associated-impl.cpp
+++ b/source/compiler-core/slang-artifact-associated-impl.cpp
@@ -11,9 +11,9 @@
namespace Slang {
-/* !!!!!!!!!!!!!!!!!!!!!!!!!!! ArtifactDiagnostics !!!!!!!!!!!!!!!!!!!!!!!!!!! */
+/* !!!!!!!!!!!!!!!!!!!!!!!!!!! DiagnosticsImpl !!!!!!!!!!!!!!!!!!!!!!!!!!! */
-void* ArtifactDiagnostics::getInterface(const Guid& guid)
+void* DiagnosticsImpl::getInterface(const Guid& guid)
{
if (guid == ISlangUnknown::getTypeGuid() ||
guid == ICastable::getTypeGuid() ||
@@ -24,13 +24,13 @@ void* ArtifactDiagnostics::getInterface(const Guid& guid)
return nullptr;
}
-void* ArtifactDiagnostics::getObject(const Guid& guid)
+void* DiagnosticsImpl::getObject(const Guid& guid)
{
SLANG_UNUSED(guid);
return nullptr;
}
-void* ArtifactDiagnostics::castAs(const Guid& guid)
+void* DiagnosticsImpl::castAs(const Guid& guid)
{
if (auto intf = getInterface(guid))
{
@@ -39,7 +39,16 @@ void* ArtifactDiagnostics::castAs(const Guid& guid)
return getObject(guid);
}
-ZeroTerminatedCharSlice ArtifactDiagnostics::_allocateSlice(const Slice<char>& in)
+void DiagnosticsImpl::reset()
+{
+ m_diagnostics.clear();
+ m_raw = ZeroTerminatedCharSlice();
+ m_result = SLANG_OK;
+
+ m_arena.deallocateAll();
+}
+
+ZeroTerminatedCharSlice DiagnosticsImpl::_allocateSlice(const Slice<char>& in)
{
if (in.count == 0)
{
@@ -49,7 +58,7 @@ ZeroTerminatedCharSlice ArtifactDiagnostics::_allocateSlice(const Slice<char>& i
return ZeroTerminatedCharSlice(dst, in.count);
}
-void ArtifactDiagnostics::add(const Diagnostic& inDiagnostic)
+void DiagnosticsImpl::add(const Diagnostic& inDiagnostic)
{
Diagnostic diagnostic(inDiagnostic);
@@ -60,9 +69,196 @@ void ArtifactDiagnostics::add(const Diagnostic& inDiagnostic)
m_diagnostics.add(diagnostic);
}
-/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! PostEmitMetadata !!!!!!!!!!!!!!!!!!!!!!!!!!! */
+void DiagnosticsImpl::setRaw(const ZeroTerminatedCharSlice& slice)
+{
+ m_raw = _allocateSlice(slice);
+}
+
+Count DiagnosticsImpl::getCountAtLeastSeverity(Severity severity)
+{
+ Index count = 0;
+ for (const auto& msg : m_diagnostics)
+ {
+ count += Index(Index(msg.severity) >= Index(severity));
+ }
+ return count;
+}
+
+Count DiagnosticsImpl::getCountBySeverity(Severity severity)
+{
+ Index count = 0;
+ for (const auto& msg : m_diagnostics)
+ {
+ count += Index(msg.severity == severity);
+ }
+ return count;
+}
+
+bool DiagnosticsImpl::hasOfAtLeastSeverity(Severity severity)
+{
+ for (const auto& msg : m_diagnostics)
+ {
+ if (Index(msg.severity) >= Index(severity))
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+Count DiagnosticsImpl::getCountByStage(Stage stage, Count outCounts[Int(Severity::CountOf)])
+{
+ Int count = 0;
+ ::memset(outCounts, 0, sizeof(Index) * Int(Severity::CountOf));
+ for (const auto& diagnostic : m_diagnostics)
+ {
+ if (diagnostic.stage == stage)
+ {
+ count++;
+ outCounts[Index(diagnostic.severity)]++;
+ }
+ }
+ return count++;
+}
+
+void DiagnosticsImpl::removeBySeverity(Severity severity)
+{
+ Index count = m_diagnostics.getCount();
+ for (Index i = 0; i < count; ++i)
+ {
+ if (m_diagnostics[i].severity == severity)
+ {
+ m_diagnostics.removeAt(i);
+ i--;
+ count--;
+ }
+ }
+}
+
+void DiagnosticsImpl::maybeAddNote(const ZeroTerminatedCharSlice& in)
+{
+ // Don't bother adding an empty line
+ if (UnownedStringSlice(in.begin(), in.end()).trim().getLength() == 0)
+ {
+ return;
+ }
+
+ // If there's nothing previous, we'll ignore too, as note should be in addition to
+ // a pre-existing error/warning
+ if (m_diagnostics.getCount() == 0)
+ {
+ return;
+ }
+
+ // Make it a note on the output
+ Diagnostic diagnostic;
+
+ diagnostic.severity = Severity::Info;
+ diagnostic.text = _allocateSlice(in);
+ m_diagnostics.add(diagnostic);
+}
+
+void DiagnosticsImpl::requireErrorDiagnostic()
+{
+ // If we find an error, we don't need to add a generic diagnostic
+ for (const auto& msg : m_diagnostics)
+ {
+ if (Index(msg.severity) >= Index(Severity::Error))
+ {
+ return;
+ }
+ }
+
+ Diagnostic diagnostic;
+ diagnostic.severity = Severity::Error;
+ diagnostic.text = m_raw;
+
+ // Add the diagnostic
+ m_diagnostics.add(diagnostic);
+}
+
+/* static */UnownedStringSlice _getSeverityText(IDiagnostics::Severity severity)
+{
+ typedef IDiagnostics::Severity Severity;
+ switch (severity)
+ {
+ default: return UnownedStringSlice::fromLiteral("Unknown");
+ case Severity::Info: return UnownedStringSlice::fromLiteral("Info");
+ case Severity::Warning: return UnownedStringSlice::fromLiteral("Warning");
+ case Severity::Error: return UnownedStringSlice::fromLiteral("Error");
+ }
+}
+
+static void _appendCounts(const Index counts[Int(IDiagnostics::Severity::CountOf)], StringBuilder& out)
+{
+ typedef IDiagnostics::Severity Severity;
+
+ for (Index i = 0; i < Int(Severity::CountOf); i++)
+ {
+ if (counts[i] > 0)
+ {
+ out << _getSeverityText(Severity(i)) << "(" << counts[i] << ") ";
+ }
+ }
+}
+
+static void _appendSimplified(const Index counts[Int(IDiagnostics::Severity::CountOf)], StringBuilder& out)
+{
+ typedef IDiagnostics::Severity Severity;
+ for (Index i = 0; i < Int(Severity::CountOf); i++)
+ {
+ if (counts[i] > 0)
+ {
+ out << _getSeverityText(Severity(i)) << " ";
+ }
+ }
+}
+
+void DiagnosticsImpl::appendSummary(ISlangBlob** outBlob)
+{
+ StringBuilder buf;
+
+ Index counts[Int(Severity::CountOf)];
+ if (getCountByStage(Stage::Compile, counts) > 0)
+ {
+ buf << "Compile: ";
+ _appendCounts(counts, buf);
+ buf << "\n";
+ }
+ if (getCountByStage(Stage::Link, counts) > 0)
+ {
+ buf << "Link: ";
+ _appendCounts(counts, buf);
+ buf << "\n";
+ }
+
+ *outBlob = StringBlob::moveCreate(buf).detach();
+}
+
+void DiagnosticsImpl::appendSimplifiedSummary(ISlangBlob** outBlob)
+{
+ StringBuilder buf;
+
+ Index counts[Int(Severity::CountOf)];
+ if (getCountByStage(Stage::Compile, counts) > 0)
+ {
+ buf << "Compile: ";
+ _appendSimplified(counts, buf);
+ buf << "\n";
+ }
+ if (getCountByStage(Stage::Link, counts) > 0)
+ {
+ buf << "Link: ";
+ _appendSimplified(counts, buf);
+ buf << "\n";
+ }
+
+ *outBlob = StringBlob::moveCreate(buf).detach();
+}
+
+/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! PostEmitMetadataImpl !!!!!!!!!!!!!!!!!!!!!!!!!!! */
-void* PostEmitMetadata::getInterface(const Guid& guid)
+void* PostEmitMetadataImpl::getInterface(const Guid& guid)
{
if (guid == ISlangUnknown::getTypeGuid() ||
guid == ICastable::getTypeGuid() ||
@@ -73,7 +269,7 @@ void* PostEmitMetadata::getInterface(const Guid& guid)
return nullptr;
}
-void* PostEmitMetadata::getObject(const Guid& uuid)
+void* PostEmitMetadataImpl::getObject(const Guid& uuid)
{
if (uuid == getTypeGuid())
{
@@ -82,7 +278,7 @@ void* PostEmitMetadata::getObject(const Guid& uuid)
return nullptr;
}
-void* PostEmitMetadata::castAs(const Guid& guid)
+void* PostEmitMetadataImpl::castAs(const Guid& guid)
{
if (auto ptr = getInterface(guid))
{
@@ -91,7 +287,7 @@ void* PostEmitMetadata::castAs(const Guid& guid)
return getObject(guid);
}
-Slice<ShaderBindingRange> PostEmitMetadata::getBindingRanges()
+Slice<ShaderBindingRange> PostEmitMetadataImpl::getUsedBindingRanges()
{
return Slice<ShaderBindingRange>(m_usedBindings.getBuffer(), m_usedBindings.getCount());
}