From 15055d20c143cb398bd3e269541eebf24777390a Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 22 Aug 2022 10:08:25 -0400 Subject: Replace DownstreamCompileResult with Artifact (#2369) * #include an absolute path didn't work - because paths were taken to always be relative. * WIP replacing DownstreamCompileResult. * First attempt at replacing DownstreamCompileResult with IArtifact and associated types. * Small renaming around CharSlice. * ICastable -> ISlangCastable Added IClonable Fix issue with cloning in ArtifactDiagnostics. * Only add the blob if one is defined in DXC. * Guard adding blob representation. * Make cloneInterface available across code base. Set enums backing type for ArtifactDiagnostic. * Added ::create for ArtifactDiagnostics. --- source/compiler-core/slang-dxc-compiler.cpp | 51 ++++++++++++++++------------- 1 file changed, 29 insertions(+), 22 deletions(-) (limited to 'source/compiler-core/slang-dxc-compiler.cpp') diff --git a/source/compiler-core/slang-dxc-compiler.cpp b/source/compiler-core/slang-dxc-compiler.cpp index 5126e53cc..7a3281463 100644 --- a/source/compiler-core/slang-dxc-compiler.cpp +++ b/source/compiler-core/slang-dxc-compiler.cpp @@ -19,7 +19,9 @@ #include "../core/slang-shared-library.h" -#include "../compiler-core/slang-artifact-util.h" +#include "slang-artifact-associated-impl.h" +#include "slang-artifact-util.h" +#include "slang-artifact-diagnostic-util.h" // Enable calling through to `dxc` to // generate code on Windows. @@ -161,7 +163,7 @@ public: typedef DownstreamCompilerBase Super; // IDownstreamCompiler - virtual SLANG_NO_THROW SlangResult SLANG_MCALL compile(const CompileOptions& options, RefPtr& outResult) SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL compile(const CompileOptions& options, IArtifact** outArtifact) SLANG_OVERRIDE; virtual SLANG_NO_THROW SlangResult SLANG_MCALL disassemble(SlangCompileTarget sourceBlobTarget, const void* blob, size_t blobSize, ISlangBlob** out) SLANG_OVERRIDE; virtual SLANG_NO_THROW bool SLANG_MCALL isFileBased() SLANG_OVERRIDE { return false; } @@ -192,7 +194,7 @@ SlangResult DXCDownstreamCompiler::init(ISlangSharedLibrary* library) return SLANG_OK; } -static SlangResult _parseDiagnosticLine(const UnownedStringSlice& line, List& lineSlices, DownstreamDiagnostic& outDiagnostic) +static SlangResult _parseDiagnosticLine(CharSliceAllocator& allocator, const UnownedStringSlice& line, List& lineSlices, IArtifactDiagnostics::Diagnostic& outDiagnostic) { /* tests/diagnostics/syntax-error-intrinsic.slang:14:2: error: expected expression */ if (lineSlices.getCount() < 5) @@ -200,27 +202,27 @@ static SlangResult _parseDiagnosticLine(const UnownedStringSlice& line, List& outBlob) +static SlangResult _handleOperationResult(IDxcOperationResult* dxcResult, IArtifactDiagnostics* diagnostics, ComPtr& outBlob) { // Retrieve result. HRESULT resultCode = S_OK; @@ -231,9 +233,9 @@ static SlangResult _handleOperationResult(IDxcOperationResult* dxcResult, Downst // *unless* the compile failed (no way to get // warnings out!?). - if (SLANG_SUCCEEDED(ioDiagnostics.result)) + if (SLANG_SUCCEEDED(diagnostics->getResult())) { - ioDiagnostics.result = resultCode; + diagnostics->setResult(resultCode); } // Try getting the error/diagnostics blob @@ -245,13 +247,11 @@ static SlangResult _handleOperationResult(IDxcOperationResult* dxcResult, Downst const UnownedStringSlice diagnosticsSlice = _getSlice(dxcErrorBlob); if (diagnosticsSlice.getLength()) { - if (ioDiagnostics.rawDiagnostics.getLength() > 0) - { - ioDiagnostics.rawDiagnostics.append("\n"); - } - ioDiagnostics.rawDiagnostics.append(diagnosticsSlice); + diagnostics->appendRaw(asCharSlice(diagnosticsSlice)); - SlangResult diagnosticParseRes = DownstreamDiagnostic::parseColonDelimitedDiagnostics(diagnosticsSlice, 0, _parseDiagnosticLine, ioDiagnostics.diagnostics); + CharSliceAllocator allocator; + List parsedDiagnostics; + SlangResult diagnosticParseRes = ArtifactDiagnosticUtil::parseColonDelimitedDiagnostics(allocator, diagnosticsSlice, 0, _parseDiagnosticLine, diagnostics); SLANG_UNUSED(diagnosticParseRes); SLANG_ASSERT(SLANG_SUCCEEDED(diagnosticParseRes)); @@ -262,7 +262,7 @@ static SlangResult _handleOperationResult(IDxcOperationResult* dxcResult, Downst if (SLANG_FAILED(resultCode)) { // In case the parsing failed, we still have an error -> so require there is one in the diagnostics - ioDiagnostics.requireErrorDiagnostic(); + diagnostics->requireErrorDiagnostic(); } else { @@ -274,7 +274,7 @@ static SlangResult _handleOperationResult(IDxcOperationResult* dxcResult, Downst return SLANG_OK; } -SlangResult DXCDownstreamCompiler::compile(const CompileOptions& options, RefPtr& outResult) +SlangResult DXCDownstreamCompiler::compile(const CompileOptions& options, IArtifact** outArtifact) { // This compiler doesn't read files, they should be read externally and stored in sourceContents/sourceContentsPath if (options.sourceFiles.getCount() > 0) @@ -446,8 +446,8 @@ SlangResult DXCDownstreamCompiler::compile(const CompileOptions& options, RefPtr &includeHandler, // `#include` handler dxcResult.writeRef())); - DownstreamDiagnostics diagnostics; - + auto diagnostics = ArtifactDiagnostics::create(); + ComPtr dxcResultBlob; SLANG_RETURN_ON_FAIL(_handleOperationResult(dxcResult, diagnostics, dxcResultBlob)); @@ -517,7 +517,14 @@ SlangResult DXCDownstreamCompiler::compile(const CompileOptions& options, RefPtr dxcResultBlob = linkedBlob; } - outResult = new BlobDownstreamCompileResult(diagnostics, (ISlangBlob*)dxcResultBlob.get()); + auto artifact = ArtifactUtil::createArtifactForCompileTarget(options.targetType); + artifact->addAssociated(diagnostics); + if (dxcResultBlob) + { + artifact->addRepresentationUnknown((ISlangBlob*)dxcResultBlob.get()); + } + + *outArtifact = artifact.detach(); return SLANG_OK; } -- cgit v1.2.3