summaryrefslogtreecommitdiffstats
path: root/source/slang
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang')
-rw-r--r--source/slang/slang-artifact-output-util.cpp4
-rw-r--r--source/slang/slang-compiler.cpp77
-rwxr-xr-xsource/slang/slang-compiler.h10
-rw-r--r--source/slang/slang-diagnostic-defs.h2
-rw-r--r--source/slang/slang-options.cpp46
5 files changed, 117 insertions, 22 deletions
diff --git a/source/slang/slang-artifact-output-util.cpp b/source/slang/slang-artifact-output-util.cpp
index 80c11a466..32aff9f43 100644
--- a/source/slang/slang-artifact-output-util.cpp
+++ b/source/slang/slang-artifact-output-util.cpp
@@ -25,7 +25,7 @@ namespace Slang
assemblyDesc.kind = ArtifactKind::Assembly;
// Check it seems like a plausbile disassembly
- if (!ArtifactDescUtil::isDissassembly(desc, assemblyDesc))
+ if (!ArtifactDescUtil::isDisassembly(desc, assemblyDesc))
{
if (sink)
{
@@ -77,7 +77,7 @@ SlangResult ArtifactOutputUtil::maybeDisassemble(Session* session, IArtifact* ar
toDesc.kind = ArtifactKind::Assembly;
// If this likes a playsible disassebly conversion
- if (ArtifactDescUtil::isDissassembly(desc, toDesc))
+ if (ArtifactDescUtil::isDisassembly(desc, toDesc))
{
ComPtr<IArtifact> disassemblyArtifact;
diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp
index 4ca76c53a..8426b7eec 100644
--- a/source/slang/slang-compiler.cpp
+++ b/source/slang/slang-compiler.cpp
@@ -1648,24 +1648,52 @@ namespace Slang
return String();
}
+ SlangResult EndToEndCompileRequest::_writeArtifact(const String& path, IArtifact* artifact)
+ {
+ if (path.getLength() > 0)
+ {
+ SLANG_RETURN_ON_FAIL(ArtifactOutputUtil::writeToFile(artifact, getSink(), path));
+ }
+ else if (m_containerFormat == ContainerFormat::None)
+ {
+ // If we aren't writing to a container and we didn't write to a file, we can output to standard output
+ writeArtifactToStandardOutput(artifact, getSink());
+ }
+ return SLANG_OK;
+ }
+
SlangResult EndToEndCompileRequest::_maybeWriteArtifact(const String& path, IArtifact* artifact)
{
// We don't have to do anything if there is no artifact
- if (artifact)
+ if (!artifact)
{
- if (path.getLength())
- {
- SLANG_RETURN_ON_FAIL(ArtifactOutputUtil::writeToFile(artifact, getSink(), path));
- return SLANG_OK;
- }
+ return SLANG_OK;
+ }
+
+ // If embedding is enabled...
+ if (m_sourceEmbedStyle != SourceEmbedUtil::Style::None)
+ {
+ SourceEmbedUtil::Options options;
- // If we aren't writing to a container and we didn't write to a file, we can output to
- if (m_containerFormat == ContainerFormat::None)
+ options.style = m_sourceEmbedStyle;
+ options.variableName = m_sourceEmbedName;
+ options.language = (SlangSourceLanguage)m_sourceEmbedLanguage;
+
+ ComPtr<IArtifact> embeddedArtifact;
+ SLANG_RETURN_ON_FAIL(SourceEmbedUtil::createEmbedded(artifact, options, embeddedArtifact));
+
+ if (!embeddedArtifact)
{
- writeArtifactToStandardOutput(artifact, getSink());
+ return SLANG_FAIL;
}
+ SLANG_RETURN_ON_FAIL(_writeArtifact(SourceEmbedUtil::getPath(path, options), embeddedArtifact));
+ return SLANG_OK;
}
-
+ else
+ {
+ SLANG_RETURN_ON_FAIL(_writeArtifact(path, artifact));
+ }
+
return SLANG_OK;
}
@@ -2118,14 +2146,16 @@ namespace Slang
}
}
+
void EndToEndCompileRequest::generateOutput()
{
generateOutput(getSpecializedGlobalAndEntryPointsComponentType());
-
+
// If we are in command-line mode, we might be expected to actually
// write output to one or more files here.
- if (m_isCommandLineCompile)
+ if (m_isCommandLineCompile &&
+ m_containerFormat == ContainerFormat::None)
{
auto linkage = getLinkage();
auto program = getSpecializedGlobalAndEntryPointsComponentType();
@@ -2136,23 +2166,27 @@ namespace Slang
if (targetReq->isWholeProgramRequest())
{
- const auto path = _getWholeProgramPath(targetReq);
- const auto artifact = targetProgram->getExistingWholeProgramResult();
+ if (const auto artifact = targetProgram->getExistingWholeProgramResult())
+ {
+ const auto path = _getWholeProgramPath(targetReq);
- _maybeWriteArtifact(path, artifact);
+ _maybeWriteArtifact(path, artifact);
+ }
}
else
{
Index entryPointCount = program->getEntryPointCount();
for (Index ee = 0; ee < entryPointCount; ++ee)
{
- const auto path = _getEntryPointPath(targetReq, ee);
- const auto artifact = targetProgram->getExistingEntryPointResult(ee);
-
- _maybeWriteArtifact(path, artifact);
+ if (const auto artifact = targetProgram->getExistingEntryPointResult(ee))
+ {
+ const auto path = _getEntryPointPath(targetReq, ee);
+
+ _maybeWriteArtifact(path, artifact);
+ }
}
}
- }
+ }
}
// Maybe create the container
@@ -2161,6 +2195,9 @@ namespace Slang
// If it's a command line compile we may need to write the container to a file
if (m_isCommandLineCompile)
{
+ // TODO(JS):
+ // We could write the container into a source embedded format potentially
+
maybeWriteContainer(m_containerOutputPath);
_writeDependencyFile(this);
diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h
index 1386b37e8..4d3df5433 100755
--- a/source/slang/slang-compiler.h
+++ b/source/slang/slang-compiler.h
@@ -12,6 +12,8 @@
#include "../compiler-core/slang-include-system.h"
#include "../compiler-core/slang-command-line-args.h"
+#include "../compiler-core/slang-source-embed-util.h"
+
#include "../core/slang-std-writers.h"
#include "../core/slang-command-options.h"
@@ -2667,6 +2669,13 @@ namespace Slang
// Should we just pass the input to another compiler?
PassThroughMode m_passThrough = PassThroughMode::None;
+ /// If output should be source embedded, define the style of the embedding
+ SourceEmbedUtil::Style m_sourceEmbedStyle = SourceEmbedUtil::Style::None;
+ /// The language to be used for source embedding
+ SourceLanguage m_sourceEmbedLanguage = SourceLanguage::C;
+ /// Source embed variable name. Note may be used as a basis for names if multiple items written
+ String m_sourceEmbedName;
+
/// Source code for the specialization arguments to use for the global specialization parameters of the program.
List<String> m_globalSpecializationArgStrings;
@@ -2802,6 +2811,7 @@ namespace Slang
/// Maybe write the artifact to the path (if set), or stdout (if there is no container or path)
SlangResult _maybeWriteArtifact(const String& path, IArtifact* artifact);
+ SlangResult _writeArtifact(const String& path, IArtifact* artifact);
ISlangUnknown* getInterface(const Guid& guid);
diff --git a/source/slang/slang-diagnostic-defs.h b/source/slang/slang-diagnostic-defs.h
index 25c86fa05..722f25843 100644
--- a/source/slang/slang-diagnostic-defs.h
+++ b/source/slang/slang-diagnostic-defs.h
@@ -98,6 +98,8 @@ DIAGNOSTIC( 43, Error, targetFlagsIgnoredBecauseBeforeAllTargets, "when using
DIAGNOSTIC( 50, Error, duplicateTargets, "the target '$0' has been specified more than once")
+DIAGNOSTIC( 51, Error, unhandledLanguageForSourceEmbedding, "unhandled source language for source embedding")
+
DIAGNOSTIC( 60, Error, cannotDeduceOutputFormatFromPath, "cannot infer an output format from the output path '$0'")
DIAGNOSTIC( 61, Error, cannotMatchOutputFileToTarget, "no specified '-target' option matches the output path '$0', which implies the '$1' format")
diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp
index f69e0ec3a..09c46b7ef 100644
--- a/source/slang/slang-options.cpp
+++ b/source/slang/slang-options.cpp
@@ -29,6 +29,7 @@
#include "../compiler-core/slang-command-line-args.h"
#include "../compiler-core/slang-artifact-desc-util.h"
#include "../compiler-core/slang-core-diagnostics.h"
+#include "../compiler-core/slang-source-embed-util.h"
#include "../core/slang-string-slice-pool.h"
#include "../core/slang-char-util.h"
@@ -72,6 +73,10 @@ enum class OptionKind
EmitIr,
ReportDownstreamTime,
+ SourceEmbedStyle,
+ SourceEmbedName,
+ SourceEmbedLanguage,
+
// Target
Capability,
@@ -167,6 +172,7 @@ enum class ValueCategory
DebugLevel,
FileSystemType,
VulkanShift,
+ SourceEmbedStyle,
CountOf,
};
@@ -184,6 +190,8 @@ SLANG_GET_VALUE_CATEGORY(FileSystemType, TypeTextUtil::FileSystemType)
SLANG_GET_VALUE_CATEGORY(HelpStyle, CommandOptionsWriter::Style)
SLANG_GET_VALUE_CATEGORY(OptimizationLevel, SlangOptimizationLevel)
SLANG_GET_VALUE_CATEGORY(VulkanShift, HLSLToVulkanLayoutOptions::Kind)
+SLANG_GET_VALUE_CATEGORY(SourceEmbedStyle, SourceEmbedUtil::Style)
+SLANG_GET_VALUE_CATEGORY(Language, SourceLanguage)
} // anonymous
@@ -242,6 +250,9 @@ void initCommandOptions(CommandOptions& options)
options.addCategory(CategoryKind::Value, "file-system-type", "File System Type", UserValue(ValueCategory::FileSystemType));
options.addValues(TypeTextUtil::getFileSystemTypeInfos());
+
+ options.addCategory(CategoryKind::Value, "source-embed-style", "Source Embed Style", UserValue(ValueCategory::SourceEmbedStyle));
+ options.addValues(SourceEmbedUtil::getStyleInfos());
}
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! target !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
@@ -416,6 +427,17 @@ void initCommandOptions(CommandOptions& options)
{ OptionKind::DumpWarningDiagnostics, "-dump-warning-diagnostics", nullptr, "Dump to output list of warning diagnostic numeric and name ids." },
{ OptionKind::InputFilesRemain, "--", nullptr, "Treat the rest of the command line as input files."},
{ OptionKind::ReportDownstreamTime, "-report-downstream-time", nullptr, "Reports the time spent in the downstream compiler." },
+ { OptionKind::SourceEmbedStyle, "-source-embed-style", "-source-embed-style <source-embed-style>",
+ "If source embedding is enabled, defines the style used. When enabled (with any style other than `none`), "
+ "will write compile results into embeddable source for the target language. "
+ "If no output file is specified, the output is written to stdout. If an output file is specified "
+ "it is written either to that file directly (if it is appropriate for the target language), "
+ "or it will be output to the filename with an appropriate extension.\n\n"
+ "Note for C/C++ with u16/u32/u64 types it is necessary to have \"#include <stdint.h>\" before the generated file.\n" },
+ { OptionKind::SourceEmbedName, "-source-embed-name", "-source-embed-name <name>",
+ "The name used as the basis for variables output for source embedding."},
+ { OptionKind::SourceEmbedLanguage, "-source-embed-language", "-source-embed-language <language>",
+ "The language to be used for source embedding. Defaults to C/C++. Currently only C/C++ are supported"},
};
_addOptions(makeConstArrayView(generalOpts), options);
@@ -2287,6 +2309,30 @@ SlangResult OptionsParser::_parse(
}
break;
}
+ case OptionKind::SourceEmbedStyle:
+ {
+ SLANG_RETURN_ON_FAIL(_expectValue(m_requestImpl->m_sourceEmbedStyle));
+ break;
+ }
+ case OptionKind::SourceEmbedName:
+ {
+ CommandLineArg name;
+ SLANG_RETURN_ON_FAIL(m_reader.expectArg(name));
+ m_requestImpl->m_sourceEmbedName = name.value;
+ break;
+ }
+ case OptionKind::SourceEmbedLanguage:
+ {
+ SLANG_RETURN_ON_FAIL(_expectValue(m_requestImpl->m_sourceEmbedLanguage));
+
+ if (!SourceEmbedUtil::isSupported((SlangSourceLanguage)m_requestImpl->m_sourceEmbedLanguage))
+ {
+ m_sink->diagnose(arg.loc, Diagnostics::unhandledLanguageForSourceEmbedding);
+ return SLANG_FAIL;
+ }
+
+ break;
+ }
default:
{
// Hmmm, we looked up and produced a valid enum, but it wasn't handled in the switch...