summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-options.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2023-05-22 17:22:22 -0400
committerGitHub <noreply@github.com>2023-05-22 17:22:22 -0400
commit972a931452c3f06a23a4f67ccfb655851df53fa4 (patch)
tree309a75c5239af163e47bc0e123d023683c1ec74a /source/slang/slang-options.cpp
parent33e15236c6fd8623bc516a194ca65e8810f1f855 (diff)
Source embedding for output (#2889)
* #include an absolute path didn't work - because paths were taken to always be relative. * Fix typo. * Add options for source embedding. * Small improvements. * Working with tests. * Add check for supported language types for embedding. * Try and remove assume warning. * Fix warning on MacOSX. * Some extra checking around Style::Text. * Some small improvements to docs/handling for headers extensions. * Fix md issue. * Small fixes around zeroing partial last element. * Another small fix.... * Small improvement in hex conversion. * Add an assert for unsignedness.
Diffstat (limited to 'source/slang/slang-options.cpp')
-rw-r--r--source/slang/slang-options.cpp46
1 files changed, 46 insertions, 0 deletions
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...