summaryrefslogtreecommitdiff
path: root/source/compiler-core/slang-downstream-compiler.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2022-08-24 09:25:51 -0400
committerGitHub <noreply@github.com>2022-08-24 09:25:51 -0400
commitf5755019246504ad4da4614d1e34a00d74970ea7 (patch)
tree8a0228427bd493681cffa2a94052c61dbc497a5d /source/compiler-core/slang-downstream-compiler.cpp
parent6ab0baf910dea838dca2d29557c3361297180a34 (diff)
Assorted Artifact improvements (#2374)
* #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. * Use SemanticVersion for DownstreamCompilerDesc. Set sizes for enum types. * Depreciate old incompatible CompileOptions. Change SemanticVersion use 32 bits for the patch. * Split out CastableUtil. * Change IDownstreamCompiler to use canConvert and convert to use artifact types. * Fix typos. * Fix typo bug. Allow trafficing in PTX assembly/binaries * struct DownstreamCompilerBaseUtil -> struct DownstreamCompilerUtilBase * Add other riff types. * Small fix around artifact kind. * Make using slices instead of strings explicit on atomic ref counted types. (not complete). Added IArtifactList. Use IArtifactList to hold the 'associated' files. Use IUnknown for scoping for atomic ref counting. Small naming improvements. * Make artifact not use String in construction (so it owns contents). * Calculate compile products as artifacts. * Small improvements around ArtifactDesc. * Use ICastableList for list of artifacts and remove IArtifactList.
Diffstat (limited to 'source/compiler-core/slang-downstream-compiler.cpp')
-rw-r--r--source/compiler-core/slang-downstream-compiler.cpp61
1 files changed, 39 insertions, 22 deletions
diff --git a/source/compiler-core/slang-downstream-compiler.cpp b/source/compiler-core/slang-downstream-compiler.cpp
index 498903727..13d605b3d 100644
--- a/source/compiler-core/slang-downstream-compiler.cpp
+++ b/source/compiler-core/slang-downstream-compiler.cpp
@@ -14,8 +14,14 @@
#include "../core/slang-castable-util.h"
+#include "slang-artifact-impl.h"
+#include "slang-artifact-representation-impl.h"
#include "slang-artifact-associated-impl.h"
#include "slang-artifact-util.h"
+#include "slang-artifact-helper.h"
+#include "slang-artifact-desc-util.h"
+
+#include "../core/slang-castable-list-impl.h"
namespace Slang
{
@@ -101,12 +107,7 @@ SlangResult CommandLineDownstreamArtifactRepresentation::createRepresentation(co
}
// The shared library needs to keep temp files in scope
- auto temporarySharedLibrary = new TemporarySharedLibrary(handle, m_moduleFilePath);
- ComPtr<ISlangSharedLibrary> lib(temporarySharedLibrary);
-
- // Set any additional info on the non COM pointer
- temporarySharedLibrary->m_temporaryFileSet = m_temporaryFiles;
-
+ ComPtr<ISlangSharedLibrary> lib(new ScopeSharedLibrary(handle, m_artifactList));
*outCastable = lib.detach();
return SLANG_OK;
}
@@ -117,7 +118,7 @@ SlangResult CommandLineDownstreamArtifactRepresentation::createRepresentation(co
// Read the contents of the binary
SLANG_RETURN_ON_FAIL(File::readAllBytes(m_moduleFilePath, contents));
- auto blob = ScopeRefObjectBlob::create(ListBlob::moveCreate(contents), m_temporaryFiles);
+ auto blob = ScopeBlob::create(ListBlob::moveCreate(contents), m_artifactList);
*outCastable = CastableUtil::getCastable(blob).detach();
return SLANG_OK;
@@ -169,9 +170,14 @@ SlangResult CommandLineDownstreamCompiler::compile(const CompileOptions& inOptio
CompileOptions options(inOptions);
+ auto helper = DefaultArtifactHelper::getSingleton();
+
// Find all the files that will be produced
- RefPtr<TemporaryFileSet> productFileSet(new TemporaryFileSet);
-
+
+ auto artifactList = CastableList::create();
+
+ ComPtr<IFileArtifactRepresentation> lockFile;
+
if (options.modulePath.getLength() == 0 || options.sourceContents.getLength() != 0)
{
String modulePath = options.modulePath;
@@ -179,15 +185,14 @@ SlangResult CommandLineDownstreamCompiler::compile(const CompileOptions& inOptio
// If there is no module path, generate one.
if (modulePath.getLength() == 0)
{
- // Holds the temporary lock path, if a temporary path is used
- String temporaryLockPath;
+ SLANG_RETURN_ON_FAIL(helper->createLockFile("slang-generated", nullptr, lockFile.writeRef()));
- // Generate a unique module path name
- SLANG_RETURN_ON_FAIL(File::generateTemporary(UnownedStringSlice::fromLiteral("slang-generated"), temporaryLockPath));
- productFileSet->add(temporaryLockPath);
+ auto lockArtifact = Artifact::create(ArtifactDesc::make(ArtifactKind::Base, ArtifactPayload::Lock, ArtifactStyle::None));
+ lockArtifact->addRepresentation(lockFile);
- modulePath = temporaryLockPath;
+ artifactList->add(lockArtifact);
+ modulePath = lockFile->getPath();
options.modulePath = modulePath;
}
@@ -199,7 +204,6 @@ SlangResult CommandLineDownstreamCompiler::compile(const CompileOptions& inOptio
{
String compileSourcePath = modulePath;
- // NOTE: Strictly speaking producing filenames by modifying the generateTemporary path that may introduce a temp filename clash, but in practice is extraordinary unlikely
compileSourcePath.append("-src");
// Make the temporary filename have the appropriate extension.
@@ -213,9 +217,15 @@ SlangResult CommandLineDownstreamCompiler::compile(const CompileOptions& inOptio
}
// Write it out
- productFileSet->add(compileSourcePath);
SLANG_RETURN_ON_FAIL(File::writeAllText(compileSourcePath, options.sourceContents));
+ // Create the reference to the file
+ auto fileRep = FileArtifactRepresentation::create(IFileArtifactRepresentation::Kind::Owned, compileSourcePath.getUnownedSlice(), lockFile, nullptr);
+ auto fileArtifact = ArtifactUtil::createArtifact(ArtifactDescUtil::makeDescForSourceLanguage(options.sourceLanguage));
+ fileArtifact->addRepresentation(fileRep);
+
+ artifactList->add(fileArtifact);
+
// Add it as a source file
options.sourceFiles.add(compileSourcePath);
}
@@ -232,14 +242,20 @@ SlangResult CommandLineDownstreamCompiler::compile(const CompileOptions& inOptio
{
StringBuilder builder;
- SLANG_RETURN_ON_FAIL(calcModuleFilePath(options, builder));
+ const auto desc = ArtifactDescUtil::makeDescForCompileTarget(options.targetType);
+ SLANG_RETURN_ON_FAIL(ArtifactDescUtil::calcPathForDesc(desc, options.modulePath.getUnownedSlice(), builder));
+
moduleFilePath = builder.ProduceString();
}
{
- List<String> paths;
- SLANG_RETURN_ON_FAIL(calcCompileProducts(options, DownstreamProductFlag::All, paths));
- productFileSet->add(paths);
+ List<ComPtr<IArtifact>> artifacts;
+ SLANG_RETURN_ON_FAIL(calcCompileProducts(options, DownstreamProductFlag::All, lockFile, artifacts));
+
+ for (IArtifact* artifact : artifacts)
+ {
+ artifactList->add(artifact);
+ }
}
ExecuteResult exeRes;
@@ -269,8 +285,9 @@ SlangResult CommandLineDownstreamCompiler::compile(const CompileOptions& inOptio
// Add the artifact
artifact->addAssociated(diagnostics);
- ComPtr<IArtifactRepresentation> rep(new CommandLineDownstreamArtifactRepresentation(moduleFilePath, productFileSet));
+ ComPtr<IArtifactRepresentation> rep(new CommandLineDownstreamArtifactRepresentation(moduleFilePath.getUnownedSlice(), artifactList));
artifact->addRepresentation(rep);
+ artifact->addAssociated(artifactList);
*outArtifact = artifact.detach();