summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-options.cpp
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2024-10-29 14:49:26 +0800
committerGitHub <noreply@github.com>2024-10-29 14:49:26 +0800
commitf65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 (patch)
treeea1d61342cd29368e19135000ec2948813096205 /source/slang/slang-options.cpp
parenta729c15e9dce9f5116a38afc66329ab2ca4cea54 (diff)
format
* format * Minor test fixes * enable checking cpp format in ci
Diffstat (limited to 'source/slang/slang-options.cpp')
-rw-r--r--source/slang/slang-options.cpp1887
1 files changed, 1215 insertions, 672 deletions
diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp
index 72281cf05..969ce4143 100644
--- a/source/slang/slang-options.cpp
+++ b/source/slang/slang-options.cpp
@@ -5,44 +5,36 @@
#include "slang-options.h"
-#include "slang.h"
-
-#include "slang-compiler.h"
-#include "slang-profile.h"
-
#include "../compiler-core/slang-artifact-desc-util.h"
-
#include "../compiler-core/slang-artifact-impl.h"
#include "../compiler-core/slang-artifact-representation-impl.h"
-
-#include "../compiler-core/slang-name-convention-util.h"
-
-#include "slang-repro.h"
-#include "slang-serialize-ir.h"
-#include "slang-hlsl-to-vulkan-layout-options.h"
-
-#include "../core/slang-castable.h"
-#include "../core/slang-file-system.h"
-#include "../core/slang-type-text-util.h"
-#include "../core/slang-hex-dump-util.h"
-
#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-name-convention-util.h"
#include "../compiler-core/slang-source-embed-util.h"
-
-#include "../core/slang-string-slice-pool.h"
+#include "../core/slang-castable.h"
#include "../core/slang-char-util.h"
-
-#include "../core/slang-name-value.h"
#include "../core/slang-command-options-writer.h"
+#include "../core/slang-file-system.h"
+#include "../core/slang-hex-dump-util.h"
+#include "../core/slang-name-value.h"
+#include "../core/slang-string-slice-pool.h"
+#include "../core/slang-type-text-util.h"
#include "slang-compiler-options.h"
+#include "slang-compiler.h"
+#include "slang-hlsl-to-vulkan-layout-options.h"
+#include "slang-profile.h"
+#include "slang-repro.h"
+#include "slang-serialize-ir.h"
+#include "slang.h"
#include <assert.h>
-namespace Slang {
+namespace Slang
+{
-namespace { // anonymous
+namespace
+{ // anonymous
// All of the options are given an unique enum
typedef CompilerOptionName OptionKind;
@@ -67,7 +59,7 @@ enum class ValueCategory
DebugInfoFormat,
HelpStyle,
OptimizationLevel,
- DebugLevel,
+ DebugLevel,
FileSystemType,
VulkanShift,
SourceEmbedStyle,
@@ -75,10 +67,18 @@ enum class ValueCategory
CountOf,
};
-template <typename T>
+template<typename T>
struct GetValueCategory;
-#define SLANG_GET_VALUE_CATEGORY(cat, type) template <> struct GetValueCategory<type> { enum { Value = Index(ValueCategory::cat) }; };
+#define SLANG_GET_VALUE_CATEGORY(cat, type) \
+ template<> \
+ struct GetValueCategory<type> \
+ { \
+ enum \
+ { \
+ Value = Index(ValueCategory::cat) \
+ }; \
+ };
SLANG_GET_VALUE_CATEGORY(Compiler, SlangPassThrough)
SLANG_GET_VALUE_CATEGORY(ArchiveType, SlangArchiveType)
@@ -91,13 +91,14 @@ SLANG_GET_VALUE_CATEGORY(VulkanShift, HLSLToVulkanLayoutOptions::Kind)
SLANG_GET_VALUE_CATEGORY(SourceEmbedStyle, SourceEmbedUtil::Style)
SLANG_GET_VALUE_CATEGORY(Language, SourceLanguage)
-} // anonymous
+} // namespace
static void _addOptions(const ConstArrayView<Option>& options, CommandOptions& cmdOptions)
{
for (auto& opt : options)
{
- cmdOptions.add(opt.name, opt.usage, opt.description, CommandOptions::UserValue(opt.optionKind));
+ cmdOptions
+ .add(opt.name, opt.usage, opt.description, CommandOptions::UserValue(opt.optionKind));
}
}
@@ -112,52 +113,109 @@ void initCommandOptions(CommandOptions& options)
options.addCategory(CategoryKind::Option, "General", "General options");
options.addCategory(CategoryKind::Option, "Target", "Target code generation options");
options.addCategory(CategoryKind::Option, "Downstream", "Downstream compiler options");
- options.addCategory(CategoryKind::Option, "Debugging", "Compiler debugging/instrumentation options");
+ options.addCategory(
+ CategoryKind::Option,
+ "Debugging",
+ "Compiler debugging/instrumentation options");
options.addCategory(CategoryKind::Option, "Repro", "Slang repro system related");
- options.addCategory(CategoryKind::Option, "Experimental", "Experimental options (use at your own risk)");
- options.addCategory(CategoryKind::Option, "Internal", "Internal-use options (use at your own risk)");
- options.addCategory(CategoryKind::Option, "Deprecated", "Deprecated options (allowed but ignored; may be removed in future)");
+ options.addCategory(
+ CategoryKind::Option,
+ "Experimental",
+ "Experimental options (use at your own risk)");
+ options.addCategory(
+ CategoryKind::Option,
+ "Internal",
+ "Internal-use options (use at your own risk)");
+ options.addCategory(
+ CategoryKind::Option,
+ "Deprecated",
+ "Deprecated options (allowed but ignored; may be removed in future)");
// Do the easy ones
{
- options.addCategory(CategoryKind::Value, "compiler", "Downstream Compilers (aka Pass through)", UserValue(ValueCategory::Compiler));
+ options.addCategory(
+ CategoryKind::Value,
+ "compiler",
+ "Downstream Compilers (aka Pass through)",
+ UserValue(ValueCategory::Compiler));
options.addValues(TypeTextUtil::getCompilerInfos());
-
- options.addCategory(CategoryKind::Value, "language", "Language", UserValue(ValueCategory::Language));
+
+ options.addCategory(
+ CategoryKind::Value,
+ "language",
+ "Language",
+ UserValue(ValueCategory::Language));
options.addValues(TypeTextUtil::getLanguageInfos());
- options.addCategory(CategoryKind::Value, "archive-type", "Archive Type", UserValue(ValueCategory::ArchiveType));
+ options.addCategory(
+ CategoryKind::Value,
+ "archive-type",
+ "Archive Type",
+ UserValue(ValueCategory::ArchiveType));
options.addValues(TypeTextUtil::getArchiveTypeInfos());
- options.addCategory(CategoryKind::Value, "line-directive-mode", "Line Directive Mode", UserValue(ValueCategory::LineDirectiveMode));
+ options.addCategory(
+ CategoryKind::Value,
+ "line-directive-mode",
+ "Line Directive Mode",
+ UserValue(ValueCategory::LineDirectiveMode));
options.addValues(TypeTextUtil::getLineDirectiveInfos());
- options.addCategory(CategoryKind::Value, "debug-info-format", "Debug Info Format", UserValue(ValueCategory::DebugInfoFormat));
+ options.addCategory(
+ CategoryKind::Value,
+ "debug-info-format",
+ "Debug Info Format",
+ UserValue(ValueCategory::DebugInfoFormat));
options.addValues(TypeTextUtil::getDebugInfoFormatInfos());
- options.addCategory(CategoryKind::Value, "fp-mode", "Floating Point Mode", UserValue(ValueCategory::FloatingPointMode));
+ options.addCategory(
+ CategoryKind::Value,
+ "fp-mode",
+ "Floating Point Mode",
+ UserValue(ValueCategory::FloatingPointMode));
options.addValues(TypeTextUtil::getFloatingPointModeInfos());
- options.addCategory(CategoryKind::Value, "help-style", "Help Style", UserValue(ValueCategory::HelpStyle));
+ options.addCategory(
+ CategoryKind::Value,
+ "help-style",
+ "Help Style",
+ UserValue(ValueCategory::HelpStyle));
options.addValues(CommandOptionsWriter::getStyleInfos());
- options.addCategory(CategoryKind::Value, "optimization-level", "Optimization Level", UserValue(ValueCategory::OptimizationLevel));
+ options.addCategory(
+ CategoryKind::Value,
+ "optimization-level",
+ "Optimization Level",
+ UserValue(ValueCategory::OptimizationLevel));
options.addValues(TypeTextUtil::getOptimizationLevelInfos());
- options.addCategory(CategoryKind::Value, "debug-level", "Debug Level", UserValue(ValueCategory::DebugLevel));
+ options.addCategory(
+ CategoryKind::Value,
+ "debug-level",
+ "Debug Level",
+ UserValue(ValueCategory::DebugLevel));
options.addValues(TypeTextUtil::getDebugLevelInfos());
- options.addCategory(CategoryKind::Value, "file-system-type", "File System Type", UserValue(ValueCategory::FileSystemType));
+ 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.addCategory(
+ CategoryKind::Value,
+ "source-embed-style",
+ "Source Embed Style",
+ UserValue(ValueCategory::SourceEmbedStyle));
options.addValues(SourceEmbedUtil::getStyleInfos());
}
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! target !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
{
- options.addCategory(CategoryKind::Value, "target", "Target", UserValue(ValueCategory::Target));
+ options
+ .addCategory(CategoryKind::Value, "target", "Target", UserValue(ValueCategory::Target));
for (auto opt : TypeTextUtil::getCompileTargetInfos())
{
options.addValue(opt.names, opt.description, UserValue(opt.target));
@@ -169,9 +227,9 @@ void initCommandOptions(CommandOptions& options)
{
options.addCategory(CategoryKind::Value, "stage", "Stage", UserValue(ValueCategory::Stage));
List<NameValue> opts;
- for (auto& info: getStageInfos())
+ for (auto& info : getStageInfos())
{
- opts.add({ValueInt(info.stage), info.name });
+ opts.add({ValueInt(info.stage), info.name});
}
options.addValuesWithAliases(opts.getArrayView());
}
@@ -179,14 +237,20 @@ void initCommandOptions(CommandOptions& options)
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! vulkan-shift !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
{
- options.addCategory(CategoryKind::Value, "vulkan-shift", "Vulkan Shift", UserValue(ValueCategory::VulkanShift));
+ options.addCategory(
+ CategoryKind::Value,
+ "vulkan-shift",
+ "Vulkan Shift",
+ UserValue(ValueCategory::VulkanShift));
options.addValues(HLSLToVulkanLayoutOptions::getKindInfos());
}
-
+
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! capabilities !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
{
- options.addCategory(CategoryKind::Value, "capability",
+ options.addCategory(
+ CategoryKind::Value,
+ "capability",
"A capability describes an optional feature that a target may or "
"may not support. When a -capability is specified, the compiler "
"may assume that the target supports that capability, and generate "
@@ -200,9 +264,7 @@ void initCommandOptions(CommandOptions& options)
for (auto name : names)
{
- if (name.startsWith("__") ||
- name.startsWith("spirv_1_") ||
- name.startsWith("_"))
+ if (name.startsWith("__") || name.startsWith("spirv_1_") || name.startsWith("_"))
{
continue;
}
@@ -223,15 +285,16 @@ void initCommandOptions(CommandOptions& options)
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! extension !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
{
- options.addCategory(CategoryKind::Value, "file-extension",
+ options.addCategory(
+ CategoryKind::Value,
+ "file-extension",
"A <language>, <format>, and/or <stage> may be inferred from the "
"extension of an input or -o path");
// TODO(JS): It's concevable that these are enumerated via some other system
// rather than just being listed here
- const CommandOptions::ValuePair pairs[] =
- {
+ const CommandOptions::ValuePair pairs[] = {
{"hlsl,fx", "hlsl"},
{"dxbc", nullptr},
{"dxbc-asm", "dxbc-assembly"},
@@ -265,96 +328,202 @@ void initCommandOptions(CommandOptions& options)
options.setCategory("General");
- const Option generalOpts[] =
- {
- { OptionKind::MacroDefine, "-D?...", "-D<name>[=<value>], -D <name>[=<value>]",
- "Insert a preprocessor macro.\n"
- "The space between - D and <name> is optional. If no <value> is specified, Slang will define the macro with an empty value." },
- { OptionKind::DepFile, "-depfile", "-depfile <path>", "Save the source file dependency list in a file." },
- { OptionKind::EntryPointName, "-entry", "-entry <name>",
- "Specify the name of an entry-point function.\n"
- "When compiling from a single file, this defaults to main if you specify a stage using -stage.\n"
- "Multiple -entry options may be used in a single invocation. "
- "When they do, the file associated with the entry point will be the first one found when searching to the left in the command line.\n"
- "If no -entry options are given, compiler will use [shader(...)] "
- "attributes to detect entry points."},
- { OptionKind::Specialize, "-specialize", "-specialize <typename>",
- "Specialize the last entrypoint with <typename>.\n"},
- { OptionKind::EmitIr, "-emit-ir", nullptr, "Emit IR typically as a '.slang-module' when outputting to a container." },
- { OptionKind::Help, "-h,-help,--help", "-h or -h <help-category>", "Print this message, or help in specified category." },
- { OptionKind::HelpStyle, "-help-style", "-help-style <help-style>", "Help formatting style" },
- { OptionKind::Include, "-I?...", "-I<path>, -I <path>",
- "Add a path to be used in resolving '#include' "
- "and 'import' operations."},
- { OptionKind::Language, "-lang", "-lang <language>", "Set the language for the following input files."},
- { OptionKind::MatrixLayoutColumn, "-matrix-layout-column-major", nullptr, "Set the default matrix layout to column-major."},
- { OptionKind::MatrixLayoutRow,"-matrix-layout-row-major", nullptr, "Set the default matrix layout to row-major."},
- { OptionKind::RestrictiveCapabilityCheck,"-restrictive-capability-check", nullptr, "Many capability warnings will become an error."},
- { OptionKind::ZeroInitialize, "-zero-initialize", nullptr,
- "Initialize all variables to zero."
- "Structs will set all struct-fields without an init expression to 0."
- "All variables will call their default constructor if not explicitly initialized as usual."},
- { OptionKind::IgnoreCapabilities,"-ignore-capabilities", nullptr, "Do not warn or error if capabilities are violated"},
- { OptionKind::MinimumSlangOptimization, "-minimum-slang-optimization", nullptr, "Perform minimum code optimization in Slang to favor compilation time."},
- { OptionKind::DisableNonEssentialValidations, "-disable-non-essential-validations", nullptr, "Disable non-essential IR validations such as use of uninitialized variables."},
- { OptionKind::DisableSourceMap, "-disable-source-map", nullptr, "Disable source mapping in the Obfuscation."},
- { OptionKind::ModuleName, "-module-name", "-module-name <name>",
- "Set the module name to use when compiling multiple .slang source files into a single module."},
- { OptionKind::Output, "-o", "-o <path>",
- "Specify a path where generated output should be written.\n"
- "If no -target or -stage is specified, one may be inferred "
- "from file extension (see <file-extension>). "
- "If multiple -target options and a single -entry are present, each -o "
- "associates with the first -target to its left. "
- "Otherwise, if multiple -entry options are present, each -o associates "
- "with the first -entry to its left, and with the -target that matches "
- "the one inferred from <path>."},
- { OptionKind::Profile, "-profile", "-profile <profile>[+<capability>...]",
- "Specify the shader profile for code generation.\n"
- "Accepted profiles are:\n"
- "* sm_{4_0,4_1,5_0,5_1,6_0,6_1,6_2,6_3,6_4,6_5,6_6}\n"
- "* glsl_{110,120,130,140,150,330,400,410,420,430,440,450,460}\n"
- "Additional profiles that include -stage information:\n"
- "* {vs,hs,ds,gs,ps}_<version>\n"
- "See -capability for information on <capability>\n"
- "When multiple -target options are present, each -profile associates "
- "with the first -target to its left."},
- { OptionKind::Stage, "-stage", "-stage <stage>",
- "Specify the stage of an entry-point function.\n"
- "When multiple -entry options are present, each -stage associated with "
- "the first -entry to its left.\n"
- "May be omitted if entry-point function has a [shader(...)] attribute; "
- "otherwise required for each -entry option."},
- { OptionKind::Target, "-target", "-target <target>", "Specifies the format in which code should be generated."},
- { OptionKind::Version, "-v,-version", nullptr,
- "Display the build version. This is the contents of git describe --tags.\n"
- "It is typically only set from automated builds(such as distros available on github).A user build will by default be 'unknown'."},
- { OptionKind::WarningsAsErrors, "-warnings-as-errors", "-warnings-as-errors all or -warnings-as-errors <id>[,<id>...]",
- "all - Treat all warnings as errors.\n"
- "<id>[,<id>...]: Treat specific warning ids as errors.\n"},
- { OptionKind::DisableWarnings, "-warnings-disable", "-warnings-disable <id>[,<id>...]", "Disable specific warning ids."},
- { OptionKind::EnableWarning, "-W...", "-W<id>", "Enable a warning with the specified id."},
- { OptionKind::DisableWarning, "-Wno-...", "-Wno-<id>", "Disable warning with <id>"},
- { 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::ReportPerfBenchmark, "-report-perf-benchmark", nullptr, "Reports compiler performance benchmark results." },
- { OptionKind::ReportCheckpointIntermediates, "-report-checkpoint-intermediates", nullptr, "Reports information about checkpoint contexts used for reverse-mode automatic differentiation." },
- { OptionKind::SkipSPIRVValidation, "-skip-spirv-validation", nullptr, "Skips spirv validation." },
- { 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"},
- { OptionKind::DisableShortCircuit, "-disable-short-circuit", nullptr, "Disable short-circuiting for \"&&\" and \"||\" operations" },
- { OptionKind::UnscopedEnum, "-unscoped-enum", nullptr, "Treat enums types as unscoped by default."},
- { OptionKind::PreserveParameters, "-preserve-params", nullptr, "Preserve all resource parameters in the output code, even if they are not used by the shader."},
+ const Option generalOpts[] = {
+ {OptionKind::MacroDefine,
+ "-D?...",
+ "-D<name>[=<value>], -D <name>[=<value>]",
+ "Insert a preprocessor macro.\n"
+ "The space between - D and <name> is optional. If no <value> is specified, Slang will "
+ "define the macro with an empty value."},
+ {OptionKind::DepFile,
+ "-depfile",
+ "-depfile <path>",
+ "Save the source file dependency list in a file."},
+ {OptionKind::EntryPointName,
+ "-entry",
+ "-entry <name>",
+ "Specify the name of an entry-point function.\n"
+ "When compiling from a single file, this defaults to main if you specify a stage using "
+ "-stage.\n"
+ "Multiple -entry options may be used in a single invocation. "
+ "When they do, the file associated with the entry point will be the first one found when "
+ "searching to the left in the command line.\n"
+ "If no -entry options are given, compiler will use [shader(...)] "
+ "attributes to detect entry points."},
+ {OptionKind::Specialize,
+ "-specialize",
+ "-specialize <typename>",
+ "Specialize the last entrypoint with <typename>.\n"},
+ {OptionKind::EmitIr,
+ "-emit-ir",
+ nullptr,
+ "Emit IR typically as a '.slang-module' when outputting to a container."},
+ {OptionKind::Help,
+ "-h,-help,--help",
+ "-h or -h <help-category>",
+ "Print this message, or help in specified category."},
+ {OptionKind::HelpStyle, "-help-style", "-help-style <help-style>", "Help formatting style"},
+ {OptionKind::Include,
+ "-I?...",
+ "-I<path>, -I <path>",
+ "Add a path to be used in resolving '#include' "
+ "and 'import' operations."},
+ {OptionKind::Language,
+ "-lang",
+ "-lang <language>",
+ "Set the language for the following input files."},
+ {OptionKind::MatrixLayoutColumn,
+ "-matrix-layout-column-major",
+ nullptr,
+ "Set the default matrix layout to column-major."},
+ {OptionKind::MatrixLayoutRow,
+ "-matrix-layout-row-major",
+ nullptr,
+ "Set the default matrix layout to row-major."},
+ {OptionKind::RestrictiveCapabilityCheck,
+ "-restrictive-capability-check",
+ nullptr,
+ "Many capability warnings will become an error."},
+ {OptionKind::ZeroInitialize,
+ "-zero-initialize",
+ nullptr,
+ "Initialize all variables to zero."
+ "Structs will set all struct-fields without an init expression to 0."
+ "All variables will call their default constructor if not explicitly initialized as "
+ "usual."},
+ {OptionKind::IgnoreCapabilities,
+ "-ignore-capabilities",
+ nullptr,
+ "Do not warn or error if capabilities are violated"},
+ {OptionKind::MinimumSlangOptimization,
+ "-minimum-slang-optimization",
+ nullptr,
+ "Perform minimum code optimization in Slang to favor compilation time."},
+ {OptionKind::DisableNonEssentialValidations,
+ "-disable-non-essential-validations",
+ nullptr,
+ "Disable non-essential IR validations such as use of uninitialized variables."},
+ {OptionKind::DisableSourceMap,
+ "-disable-source-map",
+ nullptr,
+ "Disable source mapping in the Obfuscation."},
+ {OptionKind::ModuleName,
+ "-module-name",
+ "-module-name <name>",
+ "Set the module name to use when compiling multiple .slang source files into a single "
+ "module."},
+ {OptionKind::Output,
+ "-o",
+ "-o <path>",
+ "Specify a path where generated output should be written.\n"
+ "If no -target or -stage is specified, one may be inferred "
+ "from file extension (see <file-extension>). "
+ "If multiple -target options and a single -entry are present, each -o "
+ "associates with the first -target to its left. "
+ "Otherwise, if multiple -entry options are present, each -o associates "
+ "with the first -entry to its left, and with the -target that matches "
+ "the one inferred from <path>."},
+ {OptionKind::Profile,
+ "-profile",
+ "-profile <profile>[+<capability>...]",
+ "Specify the shader profile for code generation.\n"
+ "Accepted profiles are:\n"
+ "* sm_{4_0,4_1,5_0,5_1,6_0,6_1,6_2,6_3,6_4,6_5,6_6}\n"
+ "* glsl_{110,120,130,140,150,330,400,410,420,430,440,450,460}\n"
+ "Additional profiles that include -stage information:\n"
+ "* {vs,hs,ds,gs,ps}_<version>\n"
+ "See -capability for information on <capability>\n"
+ "When multiple -target options are present, each -profile associates "
+ "with the first -target to its left."},
+ {OptionKind::Stage,
+ "-stage",
+ "-stage <stage>",
+ "Specify the stage of an entry-point function.\n"
+ "When multiple -entry options are present, each -stage associated with "
+ "the first -entry to its left.\n"
+ "May be omitted if entry-point function has a [shader(...)] attribute; "
+ "otherwise required for each -entry option."},
+ {OptionKind::Target,
+ "-target",
+ "-target <target>",
+ "Specifies the format in which code should be generated."},
+ {OptionKind::Version,
+ "-v,-version",
+ nullptr,
+ "Display the build version. This is the contents of git describe --tags.\n"
+ "It is typically only set from automated builds(such as distros available on github).A "
+ "user build will by default be 'unknown'."},
+ {OptionKind::WarningsAsErrors,
+ "-warnings-as-errors",
+ "-warnings-as-errors all or -warnings-as-errors <id>[,<id>...]",
+ "all - Treat all warnings as errors.\n"
+ "<id>[,<id>...]: Treat specific warning ids as errors.\n"},
+ {OptionKind::DisableWarnings,
+ "-warnings-disable",
+ "-warnings-disable <id>[,<id>...]",
+ "Disable specific warning ids."},
+ {OptionKind::EnableWarning, "-W...", "-W<id>", "Enable a warning with the specified id."},
+ {OptionKind::DisableWarning, "-Wno-...", "-Wno-<id>", "Disable warning with <id>"},
+ {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::ReportPerfBenchmark,
+ "-report-perf-benchmark",
+ nullptr,
+ "Reports compiler performance benchmark results."},
+ {OptionKind::ReportCheckpointIntermediates,
+ "-report-checkpoint-intermediates",
+ nullptr,
+ "Reports information about checkpoint contexts used for reverse-mode automatic "
+ "differentiation."},
+ {OptionKind::SkipSPIRVValidation,
+ "-skip-spirv-validation",
+ nullptr,
+ "Skips spirv validation."},
+ {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"},
+ {OptionKind::DisableShortCircuit,
+ "-disable-short-circuit",
+ nullptr,
+ "Disable short-circuiting for \"&&\" and \"||\" operations"},
+ {OptionKind::UnscopedEnum,
+ "-unscoped-enum",
+ nullptr,
+ "Treat enums types as unscoped by default."},
+ {OptionKind::PreserveParameters,
+ "-preserve-params",
+ nullptr,
+ "Preserve all resource parameters in the output code, even if they are not used by the "
+ "shader."},
};
_addOptions(makeConstArrayView(generalOpts), options);
@@ -365,7 +534,9 @@ void initCommandOptions(CommandOptions& options)
StringBuilder vkShiftNames;
{
- for (auto nameSlice : NameValueUtil::getNames(NameValueUtil::NameKind::All, HLSLToVulkanLayoutOptions::getKindInfos()))
+ for (auto nameSlice : NameValueUtil::getNames(
+ NameValueUtil::NameKind::All,
+ HLSLToVulkanLayoutOptions::getKindInfos()))
{
// -fvk-{b|s|t|u}-shift
vkShiftNames << "-fvk-" << nameSlice << "-shift,";
@@ -374,63 +545,132 @@ void initCommandOptions(CommandOptions& options)
vkShiftNames.reduceLength(vkShiftNames.getLength() - 1);
}
- const Option targetOpts[] =
- {
- { OptionKind::Capability, "-capability", "-capability <capability>[+<capability>...]",
- "Add optional capabilities to a code generation target. See Capabilities below."},
- { OptionKind::DefaultImageFormatUnknown, "-default-image-format-unknown", nullptr,
- "Set the format of R/W images with unspecified format to 'unknown'. Otherwise try to guess the format."},
- { OptionKind::DisableDynamicDispatch, "-disable-dynamic-dispatch", nullptr, "Disables generating dynamic dispatch code." },
- { OptionKind::DisableSpecialization, "-disable-specialization", nullptr, "Disables generics and specialization pass." },
- { OptionKind::FloatingPointMode, "-fp-mode,-floating-point-mode", "-fp-mode <fp-mode>, -floating-point-mode <fp-mode>",
- "Control floating point optimizations"},
- { OptionKind::DebugInformation, "-g...", "-g, -g<debug-info-format>, -g<debug-level>",
- "Include debug information in the generated code, where possible.\n"
- "<debug-level> is the amount of information, 0..3, unspecified means 2\n"
- "<debug-info-format> specifies a debugging info format\n"
- "It is valid to have multiple -g options, such as a <debug-level> and a <debug-info-format>" },
- { OptionKind::LineDirectiveMode, "-line-directive-mode", "-line-directive-mode <line-directive-mode>",
- "Sets how the `#line` directives should be produced. Available options are:\n"
- "If not specified, default behavior is to use C-style `#line` directives "
- "for HLSL and C/C++ output, and traditional GLSL-style `#line` directives "
- "for GLSL output." },
- { OptionKind::Optimization, "-O...", "-O<optimization-level>", "Set the optimization level."},
- { OptionKind::Obfuscate, "-obfuscate", nullptr, "Remove all source file information from outputs." },
- { OptionKind::GLSLForceScalarLayout,
- "-force-glsl-scalar-layout,-fvk-use-scalar-layout", nullptr,
- "Make data accessed through ConstantBuffer, ParameterBlock, StructuredBuffer, ByteAddressBuffer and general pointers follow the 'scalar' layout when targeting GLSL or SPIRV."},
- { OptionKind::ForceDXLayout, "-fvk-use-dx-layout", nullptr, "Pack members using FXCs member packing rules when targeting GLSL or SPIRV." },
- { OptionKind::VulkanBindShift, vkShiftNames.getBuffer(), "-fvk-<vulkan-shift>-shift <N> <space>",
- "For example '-fvk-b-shift <N> <space>' shifts by N the inferred binding numbers for all resources in 'b' registers of space <space>. "
- "For a resource attached with :register(bX, <space>) but not [vk::binding(...)], "
- "sets its Vulkan descriptor set to <space> and binding number to X + N. If you need to shift the "
- "inferred binding numbers for more than one space, provide more than one such option. "
- "If more than one such option is provided for the same space, the last one takes effect. "
- "If you need to shift the inferred binding numbers for all sets, use 'all' as <space>. "
- "\n"
- "* [DXC description](https://github.com/Microsoft/DirectXShaderCompiler/blob/main/docs/SPIR-V.rst#implicit-binding-number-assignment)\n"
- "* [GLSL wiki](https://github.com/KhronosGroup/glslang/wiki/HLSL-FAQ#auto-mapped-binding-numbers)\n" },
- { OptionKind::VulkanBindGlobals, "-fvk-bind-globals", "-fvk-bind-globals <N> <descriptor-set>",
- "Places the $Globals cbuffer at descriptor set <descriptor-set> and binding <N>.\n"
- "It lets you specify the descriptor for the source at a certain register.\n"
- "* [DXC description](https://github.com/Microsoft/DirectXShaderCompiler/blob/main/docs/SPIR-V.rst#implicit-binding-number-assignment)\n" },
- { OptionKind::VulkanInvertY, "-fvk-invert-y", nullptr, "Negates (additively inverts) SV_Position.y before writing to stage output."},
- { OptionKind::VulkanUseDxPositionW, "-fvk-use-dx-position-w", nullptr, "Reciprocates (multiplicatively inverts) SV_Position.w after reading from stage input. For use in fragment shaders only."},
- { OptionKind::VulkanUseEntryPointName, "-fvk-use-entrypoint-name", nullptr, "Uses the entrypoint name from the source instead of 'main' in the spirv output."},
- { OptionKind::VulkanUseGLLayout, "-fvk-use-gl-layout", nullptr, "Use std430 layout instead of D3D buffer layout for raw buffer load/stores."},
- { OptionKind::VulkanEmitReflection, "-fspv-reflect", nullptr, "Include reflection decorations in the resulting SPIRV for shader parameters."},
- { OptionKind::EnableEffectAnnotations,
- "-enable-effect-annotations", nullptr,
+ const Option targetOpts[] = {
+ {OptionKind::Capability,
+ "-capability",
+ "-capability <capability>[+<capability>...]",
+ "Add optional capabilities to a code generation target. See Capabilities below."},
+ {OptionKind::DefaultImageFormatUnknown,
+ "-default-image-format-unknown",
+ nullptr,
+ "Set the format of R/W images with unspecified format to 'unknown'. Otherwise try to "
+ "guess the format."},
+ {OptionKind::DisableDynamicDispatch,
+ "-disable-dynamic-dispatch",
+ nullptr,
+ "Disables generating dynamic dispatch code."},
+ {OptionKind::DisableSpecialization,
+ "-disable-specialization",
+ nullptr,
+ "Disables generics and specialization pass."},
+ {OptionKind::FloatingPointMode,
+ "-fp-mode,-floating-point-mode",
+ "-fp-mode <fp-mode>, -floating-point-mode <fp-mode>",
+ "Control floating point optimizations"},
+ {OptionKind::DebugInformation,
+ "-g...",
+ "-g, -g<debug-info-format>, -g<debug-level>",
+ "Include debug information in the generated code, where possible.\n"
+ "<debug-level> is the amount of information, 0..3, unspecified means 2\n"
+ "<debug-info-format> specifies a debugging info format\n"
+ "It is valid to have multiple -g options, such as a <debug-level> and a "
+ "<debug-info-format>"},
+ {OptionKind::LineDirectiveMode,
+ "-line-directive-mode",
+ "-line-directive-mode <line-directive-mode>",
+ "Sets how the `#line` directives should be produced. Available options are:\n"
+ "If not specified, default behavior is to use C-style `#line` directives "
+ "for HLSL and C/C++ output, and traditional GLSL-style `#line` directives "
+ "for GLSL output."},
+ {OptionKind::Optimization,
+ "-O...",
+ "-O<optimization-level>",
+ "Set the optimization level."},
+ {OptionKind::Obfuscate,
+ "-obfuscate",
+ nullptr,
+ "Remove all source file information from outputs."},
+ {OptionKind::GLSLForceScalarLayout,
+ "-force-glsl-scalar-layout,-fvk-use-scalar-layout",
+ nullptr,
+ "Make data accessed through ConstantBuffer, ParameterBlock, StructuredBuffer, "
+ "ByteAddressBuffer and general pointers follow the 'scalar' layout when targeting GLSL or "
+ "SPIRV."},
+ {OptionKind::ForceDXLayout,
+ "-fvk-use-dx-layout",
+ nullptr,
+ "Pack members using FXCs member packing rules when targeting GLSL or SPIRV."},
+ {OptionKind::VulkanBindShift,
+ vkShiftNames.getBuffer(),
+ "-fvk-<vulkan-shift>-shift <N> <space>",
+ "For example '-fvk-b-shift <N> <space>' shifts by N the inferred binding numbers for all "
+ "resources in 'b' registers of space <space>. "
+ "For a resource attached with :register(bX, <space>) but not [vk::binding(...)], "
+ "sets its Vulkan descriptor set to <space> and binding number to X + N. If you need to "
+ "shift the "
+ "inferred binding numbers for more than one space, provide more than one such option. "
+ "If more than one such option is provided for the same space, the last one takes effect. "
+ "If you need to shift the inferred binding numbers for all sets, use 'all' as <space>. "
+ "\n"
+ "* [DXC "
+ "description](https://github.com/Microsoft/DirectXShaderCompiler/blob/main/docs/"
+ "SPIR-V.rst#implicit-binding-number-assignment)\n"
+ "* [GLSL "
+ "wiki](https://github.com/KhronosGroup/glslang/wiki/"
+ "HLSL-FAQ#auto-mapped-binding-numbers)\n"},
+ {OptionKind::VulkanBindGlobals,
+ "-fvk-bind-globals",
+ "-fvk-bind-globals <N> <descriptor-set>",
+ "Places the $Globals cbuffer at descriptor set <descriptor-set> and binding <N>.\n"
+ "It lets you specify the descriptor for the source at a certain register.\n"
+ "* [DXC "
+ "description](https://github.com/Microsoft/DirectXShaderCompiler/blob/main/docs/"
+ "SPIR-V.rst#implicit-binding-number-assignment)\n"},
+ {OptionKind::VulkanInvertY,
+ "-fvk-invert-y",
+ nullptr,
+ "Negates (additively inverts) SV_Position.y before writing to stage output."},
+ {OptionKind::VulkanUseDxPositionW,
+ "-fvk-use-dx-position-w",
+ nullptr,
+ "Reciprocates (multiplicatively inverts) SV_Position.w after reading from stage input. "
+ "For use in fragment shaders only."},
+ {OptionKind::VulkanUseEntryPointName,
+ "-fvk-use-entrypoint-name",
+ nullptr,
+ "Uses the entrypoint name from the source instead of 'main' in the spirv output."},
+ {OptionKind::VulkanUseGLLayout,
+ "-fvk-use-gl-layout",
+ nullptr,
+ "Use std430 layout instead of D3D buffer layout for raw buffer load/stores."},
+ {OptionKind::VulkanEmitReflection,
+ "-fspv-reflect",
+ nullptr,
+ "Include reflection decorations in the resulting SPIRV for shader parameters."},
+ {OptionKind::EnableEffectAnnotations,
+ "-enable-effect-annotations",
+ nullptr,
"Enables support for legacy effect annotation syntax."},
- { OptionKind::EmitSpirvViaGLSL, "-emit-spirv-via-glsl", nullptr,
- "Generate SPIR-V output by compiling generated GLSL with glslang" },
- { OptionKind::EmitSpirvDirectly, "-emit-spirv-directly", nullptr,
- "Generate SPIR-V output directly (default)" },
- { OptionKind::SPIRVCoreGrammarJSON, "-spirv-core-grammar", nullptr,
- "A path to a specific spirv.core.grammar.json to use when generating SPIR-V output" },
- { OptionKind::IncompleteLibrary, "-incomplete-library", nullptr,
- "Allow generating code from incomplete libraries with unresolved external functions" },
- { OptionKind::EmbedDownstreamIR, "-embed-downstream-ir", nullptr, "Embed downstream IR into emitted slang IR" },
+ {OptionKind::EmitSpirvViaGLSL,
+ "-emit-spirv-via-glsl",
+ nullptr,
+ "Generate SPIR-V output by compiling generated GLSL with glslang"},
+ {OptionKind::EmitSpirvDirectly,
+ "-emit-spirv-directly",
+ nullptr,
+ "Generate SPIR-V output directly (default)"},
+ {OptionKind::SPIRVCoreGrammarJSON,
+ "-spirv-core-grammar",
+ nullptr,
+ "A path to a specific spirv.core.grammar.json to use when generating SPIR-V output"},
+ {OptionKind::IncompleteLibrary,
+ "-incomplete-library",
+ nullptr,
+ "Allow generating code from incomplete libraries with unresolved external functions"},
+ {OptionKind::EmbedDownstreamIR,
+ "-embed-downstream-ir",
+ nullptr,
+ "Embed downstream IR into emitted slang IR"},
};
_addOptions(makeConstArrayView(targetOpts), options);
@@ -440,7 +680,9 @@ void initCommandOptions(CommandOptions& options)
options.setCategory("Downstream");
{
- auto namesList = NameValueUtil::getNames(NameValueUtil::NameKind::First, TypeTextUtil::getCompilerInfos());
+ auto namesList = NameValueUtil::getNames(
+ NameValueUtil::NameKind::First,
+ TypeTextUtil::getCompilerInfos());
StringBuilder names;
for (auto name : namesList)
{
@@ -449,24 +691,32 @@ void initCommandOptions(CommandOptions& options)
// remove last ,
names.reduceLength(names.getLength() - 1);
- options.add(names.getBuffer(), "-<compiler>-path <path>",
+ options.add(
+ names.getBuffer(),
+ "-<compiler>-path <path>",
"Specify path to a downstream <compiler> "
- "executable or library.\n",
+ "executable or library.\n",
UserValue(OptionKind::CompilerPath));
}
- const Option downstreamOpts[] =
- {
- { OptionKind::DefaultDownstreamCompiler, "-default-downstream-compiler", "-default-downstream-compiler <language> <compiler>",
- "Set a default compiler for the given language. See -lang for the list of languages." },
- { OptionKind::DownstreamArgs, "-X...", "-X<compiler> <option> -X<compiler>... <options> -X.",
- "Pass arguments to downstream <compiler>. Just -X<compiler> passes just the next argument "
- "to the downstream compiler. -X<compiler>... options -X. will pass *all* of the options "
- "inbetween the opening -X and -X. to the downstream compiler."},
- { OptionKind::PassThrough, "-pass-through", "-pass-through <compiler>",
- "Pass the input through mostly unmodified to the "
- "existing compiler <compiler>.\n"
- "These are intended for debugging/testing purposes, when you want to be able to see what these existing compilers do with the \"same\" input and options"},
+ const Option downstreamOpts[] = {
+ {OptionKind::DefaultDownstreamCompiler,
+ "-default-downstream-compiler",
+ "-default-downstream-compiler <language> <compiler>",
+ "Set a default compiler for the given language. See -lang for the list of languages."},
+ {OptionKind::DownstreamArgs,
+ "-X...",
+ "-X<compiler> <option> -X<compiler>... <options> -X.",
+ "Pass arguments to downstream <compiler>. Just -X<compiler> passes just the next argument "
+ "to the downstream compiler. -X<compiler>... options -X. will pass *all* of the options "
+ "inbetween the opening -X and -X. to the downstream compiler."},
+ {OptionKind::PassThrough,
+ "-pass-through",
+ "-pass-through <compiler>",
+ "Pass the input through mostly unmodified to the "
+ "existing compiler <compiler>.\n"
+ "These are intended for debugging/testing purposes, when you want to be able to see what "
+ "these existing compilers do with the \"same\" input and options"},
};
_addOptions(makeConstArrayView(downstreamOpts), options);
@@ -475,21 +725,37 @@ void initCommandOptions(CommandOptions& options)
options.setCategory("Repro");
- const Option reproOpts[] =
- {
- { OptionKind::DumpReproOnError, "-dump-repro-on-error", nullptr, "Dump `.slang-repro` file on any compilation error." },
- { OptionKind::ExtractRepro, "-extract-repro", "-extract-repro <name>", "Extract the repro files into a folder." },
- { OptionKind::LoadReproDirectory, "-load-repro-directory", "-load-repro-directory <path>", "Use repro along specified path" },
- { OptionKind::LoadRepro, "-load-repro", "-load-repro <name>", "Load repro"},
- { OptionKind::ReproFileSystem, "-repro-file-system", "-repro-file-system <name>", "Use a repro as a file system" },
- { OptionKind::DumpRepro, "-dump-repro", nullptr, "Dump a `.slang-repro` file that can be used to reproduce "
- "a compilation on another machine.\n"},
- { OptionKind::ReproFallbackDirectory, "-repro-fallback-directory <path>",
- "Specify a directory to use if a file isn't found in a repro. Should be specified *before* any repro usage such as `load-repro`. \n"
- "There are two *special* directories: \n\n"
- " * 'none:' indicates no fallback, so if the file isn't found in the repro compliation will fail\n"
- " * 'default:' is the default (which is the OS file system)"}
- };
+ const Option reproOpts[] = {
+ {OptionKind::DumpReproOnError,
+ "-dump-repro-on-error",
+ nullptr,
+ "Dump `.slang-repro` file on any compilation error."},
+ {OptionKind::ExtractRepro,
+ "-extract-repro",
+ "-extract-repro <name>",
+ "Extract the repro files into a folder."},
+ {OptionKind::LoadReproDirectory,
+ "-load-repro-directory",
+ "-load-repro-directory <path>",
+ "Use repro along specified path"},
+ {OptionKind::LoadRepro, "-load-repro", "-load-repro <name>", "Load repro"},
+ {OptionKind::ReproFileSystem,
+ "-repro-file-system",
+ "-repro-file-system <name>",
+ "Use a repro as a file system"},
+ {OptionKind::DumpRepro,
+ "-dump-repro",
+ nullptr,
+ "Dump a `.slang-repro` file that can be used to reproduce "
+ "a compilation on another machine.\n"},
+ {OptionKind::ReproFallbackDirectory,
+ "-repro-fallback-directory <path>",
+ "Specify a directory to use if a file isn't found in a repro. Should be specified "
+ "*before* any repro usage such as `load-repro`. \n"
+ "There are two *special* directories: \n\n"
+ " * 'none:' indicates no fallback, so if the file isn't found in the repro compliation "
+ "will fail\n"
+ " * 'default:' is the default (which is the OS file system)"}};
_addOptions(makeConstArrayView(reproOpts), options);
@@ -497,43 +763,88 @@ void initCommandOptions(CommandOptions& options)
options.setCategory("Debugging");
- const Option debuggingOpts[] =
- {
- { OptionKind::DumpAst, "-dump-ast", nullptr, "Dump the AST to a .slang-ast file next to the input." },
- { OptionKind::DumpIntermediatePrefix, "-dump-intermediate-prefix", "-dump-intermediate-prefix <prefix>",
- "File name prefix for -dump-intermediates outputs, default is 'slang-dump-'"},
- { OptionKind::DumpIntermediates, "-dump-intermediates", nullptr, "Dump intermediate outputs for debugging." },
- { OptionKind::DumpIr, "-dump-ir", nullptr, "Dump the IR for debugging." },
- { OptionKind::DumpIrIds, "-dump-ir-ids", nullptr, "Dump the IDs with -dump-ir (debug builds only)" },
- { OptionKind::PreprocessorOutput, "-E,-output-preprocessor", nullptr, "Output the preprocessing result and exit." },
- { OptionKind::NoCodeGen, "-no-codegen", nullptr, "Skip the code generation step, just check the code and generate layout." },
- { OptionKind::OutputIncludes, "-output-includes", nullptr, "Print the hierarchy of the processed source files." },
- { OptionKind::SerialIr, "-serial-ir", nullptr, "Serialize the IR between front-end and back-end." },
- { OptionKind::SkipCodeGen, "-skip-codegen", nullptr, "Skip the code generation phase." },
- { OptionKind::ValidateIr, "-validate-ir", nullptr, "Validate the IR between the phases." },
- { OptionKind::VerbosePaths, "-verbose-paths", nullptr, "When displaying diagnostic output aim to display more detailed path information. "
- "In practice this is typically the complete 'canonical' path to the source file used." },
- { OptionKind::VerifyDebugSerialIr, "-verify-debug-serial-ir", nullptr, "Verify IR in the front-end." }
- };
+ const Option debuggingOpts[] = {
+ {OptionKind::DumpAst,
+ "-dump-ast",
+ nullptr,
+ "Dump the AST to a .slang-ast file next to the input."},
+ {OptionKind::DumpIntermediatePrefix,
+ "-dump-intermediate-prefix",
+ "-dump-intermediate-prefix <prefix>",
+ "File name prefix for -dump-intermediates outputs, default is 'slang-dump-'"},
+ {OptionKind::DumpIntermediates,
+ "-dump-intermediates",
+ nullptr,
+ "Dump intermediate outputs for debugging."},
+ {OptionKind::DumpIr, "-dump-ir", nullptr, "Dump the IR for debugging."},
+ {OptionKind::DumpIrIds,
+ "-dump-ir-ids",
+ nullptr,
+ "Dump the IDs with -dump-ir (debug builds only)"},
+ {OptionKind::PreprocessorOutput,
+ "-E,-output-preprocessor",
+ nullptr,
+ "Output the preprocessing result and exit."},
+ {OptionKind::NoCodeGen,
+ "-no-codegen",
+ nullptr,
+ "Skip the code generation step, just check the code and generate layout."},
+ {OptionKind::OutputIncludes,
+ "-output-includes",
+ nullptr,
+ "Print the hierarchy of the processed source files."},
+ {OptionKind::SerialIr,
+ "-serial-ir",
+ nullptr,
+ "Serialize the IR between front-end and back-end."},
+ {OptionKind::SkipCodeGen, "-skip-codegen", nullptr, "Skip the code generation phase."},
+ {OptionKind::ValidateIr, "-validate-ir", nullptr, "Validate the IR between the phases."},
+ {OptionKind::VerbosePaths,
+ "-verbose-paths",
+ nullptr,
+ "When displaying diagnostic output aim to display more detailed path information. "
+ "In practice this is typically the complete 'canonical' path to the source file used."},
+ {OptionKind::VerifyDebugSerialIr,
+ "-verify-debug-serial-ir",
+ nullptr,
+ "Verify IR in the front-end."}};
_addOptions(makeConstArrayView(debuggingOpts), options);
-
+
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Experimental !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
options.setCategory("Experimental");
- const Option experimentalOpts[] =
- {
- { OptionKind::FileSystem, "-file-system", "-file-system <file-system-type>",
- "Set the filesystem hook to use for a compile request."},
- { OptionKind::Heterogeneous, "-heterogeneous", nullptr, "Output heterogeneity-related code." },
- { OptionKind::NoMangle, "-no-mangle", nullptr, "Do as little mangling of names as possible." },
- { OptionKind::NoHLSLBinding, "-no-hlsl-binding", nullptr, "Do not include explicit parameter binding semantics in the output HLSL code,"
- "except for parameters that has explicit bindings in the input source." },
- { OptionKind::NoHLSLPackConstantBufferElements, "-no-hlsl-pack-constant-buffer-elements", nullptr,
- "Do not pack elements of constant buffers into structs in the output HLSL code." },
- { OptionKind::ValidateUniformity, "-validate-uniformity", nullptr, "Perform uniformity validation analysis." },
- { OptionKind::AllowGLSL, "-allow-glsl", nullptr, "Enable GLSL as an input language." },
- { OptionKind::EnableExperimentalPasses, "-enable-experimental-passes", nullptr, "Enable experimental compiler passes" },
+ const Option experimentalOpts[] = {
+ {OptionKind::FileSystem,
+ "-file-system",
+ "-file-system <file-system-type>",
+ "Set the filesystem hook to use for a compile request."},
+ {OptionKind::Heterogeneous,
+ "-heterogeneous",
+ nullptr,
+ "Output heterogeneity-related code."},
+ {OptionKind::NoMangle,
+ "-no-mangle",
+ nullptr,
+ "Do as little mangling of names as possible."},
+ {OptionKind::NoHLSLBinding,
+ "-no-hlsl-binding",
+ nullptr,
+ "Do not include explicit parameter binding semantics in the output HLSL code,"
+ "except for parameters that has explicit bindings in the input source."},
+ {OptionKind::NoHLSLPackConstantBufferElements,
+ "-no-hlsl-pack-constant-buffer-elements",
+ nullptr,
+ "Do not pack elements of constant buffers into structs in the output HLSL code."},
+ {OptionKind::ValidateUniformity,
+ "-validate-uniformity",
+ nullptr,
+ "Perform uniformity validation analysis."},
+ {OptionKind::AllowGLSL, "-allow-glsl", nullptr, "Enable GLSL as an input language."},
+ {OptionKind::EnableExperimentalPasses,
+ "-enable-experimental-passes",
+ nullptr,
+ "Enable experimental compiler passes"},
};
_addOptions(makeConstArrayView(experimentalOpts), options);
@@ -541,23 +852,45 @@ void initCommandOptions(CommandOptions& options)
options.setCategory("Internal");
- const Option internalOpts[] =
- {
- { OptionKind::ArchiveType, "-archive-type", "-archive-type <archive-type>", "Set the archive type for -save-core-module. Default is zip." },
- { OptionKind::CompileCoreModule, "-compile-core-module", nullptr,
- "Compile the core module from embedded sources. "
- "Will return a failure if there is already a core module available."},
- { OptionKind::Doc, "-doc", nullptr, "Write documentation for -compile-core-module" },
- { OptionKind::IrCompression,"-ir-compression", "-ir-compression <type>",
- "Set compression for IR and AST outputs.\n"
- "Accepted compression types: none, lite"},
- { OptionKind::LoadCoreModule, "-load-core-module", "-load-core-module <filename>", "Load the core module from file." },
- { OptionKind::ReferenceModule, "-r", "-r <name>", "reference module <name>" },
- { OptionKind::SaveCoreModule, "-save-core-module", "-save-core-module <filename>", "Save the core module to an archive file." },
- { OptionKind::SaveCoreModuleBinSource, "-save-core-module-bin-source","-save-core-module-bin-source <filename>", "Same as -save-core-module but output "
- "the data as a C array.\n"},
- { OptionKind::TrackLiveness, "-track-liveness", nullptr, "Enable liveness tracking. Places SLANG_LIVE_START, and SLANG_LIVE_END in output source to indicate value liveness." },
- { OptionKind::LoopInversion, "-loop-inversion", nullptr, "Enable loop inversion in the code-gen optimization. Default is off" },
+ const Option internalOpts[] = {
+ {OptionKind::ArchiveType,
+ "-archive-type",
+ "-archive-type <archive-type>",
+ "Set the archive type for -save-core-module. Default is zip."},
+ {OptionKind::CompileCoreModule,
+ "-compile-core-module",
+ nullptr,
+ "Compile the core module from embedded sources. "
+ "Will return a failure if there is already a core module available."},
+ {OptionKind::Doc, "-doc", nullptr, "Write documentation for -compile-core-module"},
+ {OptionKind::IrCompression,
+ "-ir-compression",
+ "-ir-compression <type>",
+ "Set compression for IR and AST outputs.\n"
+ "Accepted compression types: none, lite"},
+ {OptionKind::LoadCoreModule,
+ "-load-core-module",
+ "-load-core-module <filename>",
+ "Load the core module from file."},
+ {OptionKind::ReferenceModule, "-r", "-r <name>", "reference module <name>"},
+ {OptionKind::SaveCoreModule,
+ "-save-core-module",
+ "-save-core-module <filename>",
+ "Save the core module to an archive file."},
+ {OptionKind::SaveCoreModuleBinSource,
+ "-save-core-module-bin-source",
+ "-save-core-module-bin-source <filename>",
+ "Same as -save-core-module but output "
+ "the data as a C array.\n"},
+ {OptionKind::TrackLiveness,
+ "-track-liveness",
+ nullptr,
+ "Enable liveness tracking. Places SLANG_LIVE_START, and SLANG_LIVE_END in output source "
+ "to indicate value liveness."},
+ {OptionKind::LoopInversion,
+ "-loop-inversion",
+ nullptr,
+ "Enable loop inversion in the code-gen optimization. Default is off"},
};
_addOptions(makeConstArrayView(internalOpts), options);
@@ -565,24 +898,37 @@ void initCommandOptions(CommandOptions& options)
options.setCategory("Deprecated");
- const Option deprecatedOpts[] =
- {
- { OptionKind::ParameterBlocksUseRegisterSpaces, "-parameter-blocks-use-register-spaces", nullptr, "Parameter blocks will use register spaces" },
+ const Option deprecatedOpts[] = {
+ {OptionKind::ParameterBlocksUseRegisterSpaces,
+ "-parameter-blocks-use-register-spaces",
+ nullptr,
+ "Parameter blocks will use register spaces"},
};
_addOptions(makeConstArrayView(deprecatedOpts), options);
- // We can now check that the whole range is available. If this fails it means there
+ // We can now check that the whole range is available. If this fails it means there
// is an enum in the list that hasn't been setup as an option!
- SLANG_ASSERT(options.hasContiguousUserValueRange(CommandOptions::LookupKind::Option, UserValue(0), UserValue(OptionKind::CountOfParsableOptions)));
- SLANG_ASSERT(options.hasContiguousUserValueRange(CommandOptions::LookupKind::Category, UserValue(0), UserValue(ValueCategory::CountOf)));
+ SLANG_ASSERT(options.hasContiguousUserValueRange(
+ CommandOptions::LookupKind::Option,
+ UserValue(0),
+ UserValue(OptionKind::CountOfParsableOptions)));
+ SLANG_ASSERT(options.hasContiguousUserValueRange(
+ CommandOptions::LookupKind::Category,
+ UserValue(0),
+ UserValue(ValueCategory::CountOf)));
}
-SlangResult _addLibraryReference(EndToEndCompileRequest* req, String path, IArtifact* artifact, bool includeEntryPoint);
+SlangResult _addLibraryReference(
+ EndToEndCompileRequest* req,
+ String path,
+ IArtifact* artifact,
+ bool includeEntryPoint);
class ReproPathVisitor : public Slang::Path::Visitor
{
public:
- virtual void accept(Slang::Path::Type type, const Slang::UnownedStringSlice& filename) SLANG_OVERRIDE
+ virtual void accept(Slang::Path::Type type, const Slang::UnownedStringSlice& filename)
+ SLANG_OVERRIDE
{
if (type == Path::Type::File && Path::getPathExt(filename) == "slang-repro")
{
@@ -637,9 +983,9 @@ struct OptionsParser
// request that already had some translation unit(s) added
// manually.
//
- int translationUnitID;
+ int translationUnitID;
};
-
+
// An entry point represents a function to be checked and possibly have
// code generated in one of our translation units. An entry point
// needs to have an associated stage, which might come via the
@@ -648,49 +994,50 @@ struct OptionsParser
//
struct RawEntryPoint
{
- String name;
- Stage stage = Stage::Unknown;
- int translationUnitIndex = -1;
- int entryPointID = -1;
+ String name;
+ Stage stage = Stage::Unknown;
+ int translationUnitIndex = -1;
+ int entryPointID = -1;
List<String> specializationArgs;
// State for tracking command-line errors
bool conflictingStagesSet = false;
bool redundantStageSet = false;
};
-
+
struct RawOutput
{
- String path;
- CodeGenTarget impliedFormat = CodeGenTarget::Unknown;
- int targetIndex = -1;
- int entryPointIndex = -1;
- bool isWholeProgram = false;
+ String path;
+ CodeGenTarget impliedFormat = CodeGenTarget::Unknown;
+ int targetIndex = -1;
+ int entryPointIndex = -1;
+ bool isWholeProgram = false;
};
-
+
struct RawTarget
{
- CodeGenTarget format = CodeGenTarget::Unknown;
- int targetID = -1;
- CompilerOptionSet optionSet;
+ CodeGenTarget format = CodeGenTarget::Unknown;
+ int targetID = -1;
+ CompilerOptionSet optionSet;
// State for tracking command-line errors
bool conflictingProfilesSet = false;
bool redundantProfileSet = false;
-
};
-
+
int addTranslationUnit(SlangSourceLanguage language, Stage impliedStage);
void addInputSlangPath(String const& path);
void addInputForeignShaderPath(
- String const& path,
- SlangSourceLanguage language,
- Stage impliedStage);
+ String const& path,
+ SlangSourceLanguage language,
+ Stage impliedStage);
static Profile::RawVal findGlslProfileFromPath(const String& path);
- SlangResult addInputPath(char const* inPath, SourceLanguage langOverride = SourceLanguage::Unknown);
+ SlangResult addInputPath(
+ char const* inPath,
+ SourceLanguage langOverride = SourceLanguage::Unknown);
void addOutputPath(String const& path, CodeGenTarget impliedFormat);
@@ -705,45 +1052,62 @@ struct OptionsParser
void addCapabilityAtom(RawTarget* rawTarget, CapabilityName atom);
void setFloatingPointMode(RawTarget* rawTarget, FloatingPointMode mode);
-
- SlangResult parse(
- SlangCompileRequest* compileRequest,
- int argc,
- char const* const* argv);
- SlangResult _parse(
- int argc,
- char const* const* argv);
+ SlangResult parse(SlangCompileRequest* compileRequest, int argc, char const* const* argv);
+
+ SlangResult _parse(int argc, char const* const* argv);
static bool _passThroughRequiresStage(PassThroughMode passThrough);
- SlangResult _compileReproDirectory(SlangSession* session, EndToEndCompileRequest* originalRequest, const String& dir);
+ SlangResult _compileReproDirectory(
+ SlangSession* session,
+ EndToEndCompileRequest* originalRequest,
+ const String& dir);
- // Pass Severity::Disabled to allow any original severity
- SlangResult _overrideDiagnostics(const UnownedStringSlice& identifierList, Severity originalSeverity, Severity overrideSeverity);
+ // Pass Severity::Disabled to allow any original severity
+ SlangResult _overrideDiagnostics(
+ const UnownedStringSlice& identifierList,
+ Severity originalSeverity,
+ Severity overrideSeverity);
- // Pass Severity::Disabled to allow any original severity
- SlangResult _overrideDiagnostic(const UnownedStringSlice& identifier, Severity originalSeverity, Severity overrideSeverity);
+ // Pass Severity::Disabled to allow any original severity
+ SlangResult _overrideDiagnostic(
+ const UnownedStringSlice& identifier,
+ Severity originalSeverity,
+ Severity overrideSeverity);
SlangResult _dumpDiagnostics(Severity originalSeverity);
- template <typename T>
+ template<typename T>
SlangResult _getValue(const CommandLineArg& arg, const UnownedStringSlice& name, T& ioValue)
{
CommandOptions::UserValue value;
- SLANG_RETURN_ON_FAIL(_getValue(ValueCategory(GetValueCategory<T>::Value), arg, name, value));
+ SLANG_RETURN_ON_FAIL(
+ _getValue(ValueCategory(GetValueCategory<T>::Value), arg, name, value));
ioValue = T(value);
return SLANG_OK;
}
- SlangResult _getValue(ValueCategory valueCategory, const CommandLineArg& arg, const UnownedStringSlice& name, CommandOptions::UserValue& outValue);
- SlangResult _getValue(ValueCategory valueCategory, const CommandLineArg& arg, CommandOptions::UserValue& outValue);
- SlangResult _getValue(const ConstArrayView<ValueCategory>& valueCategories, const CommandLineArg& arg, const UnownedStringSlice& name, ValueCategory& outCat, CommandOptions::UserValue& outValue);
-
+ SlangResult _getValue(
+ ValueCategory valueCategory,
+ const CommandLineArg& arg,
+ const UnownedStringSlice& name,
+ CommandOptions::UserValue& outValue);
+ SlangResult _getValue(
+ ValueCategory valueCategory,
+ const CommandLineArg& arg,
+ CommandOptions::UserValue& outValue);
+ SlangResult _getValue(
+ const ConstArrayView<ValueCategory>& valueCategories,
+ const CommandLineArg& arg,
+ const UnownedStringSlice& name,
+ ValueCategory& outCat,
+ CommandOptions::UserValue& outValue);
+
SlangResult _expectValue(ValueCategory valueCategory, CommandOptions::UserValue& outValue);
SlangResult _expectInt(const CommandLineArg& arg, Int& outInt);
- template <typename T>
+ template<typename T>
SlangResult _expectValue(T& ioValue)
{
CommandOptions::UserValue value;
@@ -801,7 +1165,7 @@ struct OptionsParser
slang::CompileCoreModuleFlags m_compileCoreModuleFlags;
SlangArchiveType m_archiveType = SLANG_ARCHIVE_TYPE_RIFF_LZ4;
-
+
List<RawOutput> m_rawOutputs;
DiagnosticSink m_parseSink;
@@ -817,9 +1181,7 @@ struct OptionsParser
CommandLineContext* m_cmdLineContext = nullptr;
};
-int OptionsParser::addTranslationUnit(
- SlangSourceLanguage language,
- Stage impliedStage)
+int OptionsParser::addTranslationUnit(SlangSourceLanguage language, Stage impliedStage)
{
auto translationUnitIndex = m_rawTranslationUnits.getCount();
auto translationUnitID = m_compileRequest->addTranslationUnit(language, nullptr);
@@ -841,18 +1203,20 @@ int OptionsParser::addTranslationUnit(
return int(translationUnitIndex);
}
-void OptionsParser::addInputSlangPath(
- String const& path)
+void OptionsParser::addInputSlangPath(String const& path)
{
// All of the input .slang files will be grouped into a single logical translation unit,
// which we create lazily when the first .slang file is encountered.
if (m_slangTranslationUnitIndex == -1)
{
m_translationUnitCount++;
- m_slangTranslationUnitIndex = addTranslationUnit(SLANG_SOURCE_LANGUAGE_SLANG, Stage::Unknown);
+ m_slangTranslationUnitIndex =
+ addTranslationUnit(SLANG_SOURCE_LANGUAGE_SLANG, Stage::Unknown);
}
- m_compileRequest->addTranslationUnitSourceFile(m_rawTranslationUnits[m_slangTranslationUnitIndex].translationUnitID, path.begin());
+ m_compileRequest->addTranslationUnitSourceFile(
+ m_rawTranslationUnits[m_slangTranslationUnitIndex].translationUnitID,
+ path.begin());
// Set the translation unit to be used by subsequent entry points
m_currentTranslationUnitIndex = m_slangTranslationUnitIndex;
@@ -860,16 +1224,18 @@ void OptionsParser::addInputSlangPath(
void OptionsParser::addInputForeignShaderPath(
String const& path,
- SlangSourceLanguage language,
- Stage impliedStage)
+ SlangSourceLanguage language,
+ Stage impliedStage)
{
m_translationUnitCount++;
m_currentTranslationUnitIndex = addTranslationUnit(language, impliedStage);
- m_compileRequest->addTranslationUnitSourceFile(m_rawTranslationUnits[m_currentTranslationUnitIndex].translationUnitID, path.begin());
+ m_compileRequest->addTranslationUnitSourceFile(
+ m_rawTranslationUnits[m_currentTranslationUnitIndex].translationUnitID,
+ path.begin());
}
-/* static */Profile::RawVal OptionsParser::findGlslProfileFromPath(const String& path)
+/* static */ Profile::RawVal OptionsParser::findGlslProfileFromPath(const String& path)
{
struct Entry
{
@@ -877,14 +1243,12 @@ void OptionsParser::addInputForeignShaderPath(
Profile::RawVal profileId;
};
- static const Entry entries[] =
- {
- { ".frag", Profile::GLSL_Fragment },
- { ".geom", Profile::GLSL_Geometry },
- { ".tesc", Profile::GLSL_TessControl },
- { ".tese", Profile::GLSL_TessEval },
- { ".comp", Profile::GLSL_Compute }
- };
+ static const Entry entries[] = {
+ {".frag", Profile::GLSL_Fragment},
+ {".geom", Profile::GLSL_Geometry},
+ {".tesc", Profile::GLSL_TessControl},
+ {".tese", Profile::GLSL_TessEval},
+ {".comp", Profile::GLSL_Compute}};
for (Index i = 0; i < SLANG_COUNT_OF(entries); ++i)
{
@@ -903,37 +1267,36 @@ SlangSourceLanguage findSourceLanguageFromPath(const String& path, Stage& outImp
{
const char* ext;
SlangSourceLanguage sourceLanguage;
- SlangStage impliedStage;
+ SlangStage impliedStage;
};
- static const Entry entries[] =
- {
- { ".slang", SLANG_SOURCE_LANGUAGE_SLANG, SLANG_STAGE_NONE },
-
- { ".hlsl", SLANG_SOURCE_LANGUAGE_HLSL, SLANG_STAGE_NONE },
- { ".fx", SLANG_SOURCE_LANGUAGE_HLSL, SLANG_STAGE_NONE },
-
- { ".glsl", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_NONE },
- { ".vert", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_VERTEX },
- { ".frag", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_FRAGMENT },
- { ".geom", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_GEOMETRY },
- { ".tesc", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_HULL },
- { ".tese", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_DOMAIN },
- { ".comp", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_COMPUTE },
- { ".mesh", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_MESH },
- { ".task", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_AMPLIFICATION },
- { ".rgen", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_RAY_GENERATION },
- { ".rint", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_INTERSECTION },
- { ".rahit", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_ANY_HIT },
- { ".rchit", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_CLOSEST_HIT },
- { ".rmiss", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_MISS },
- { ".rcall", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_CALLABLE },
-
- { ".c", SLANG_SOURCE_LANGUAGE_C, SLANG_STAGE_NONE },
- { ".cpp", SLANG_SOURCE_LANGUAGE_CPP, SLANG_STAGE_NONE },
- { ".cu", SLANG_SOURCE_LANGUAGE_CUDA, SLANG_STAGE_NONE },
-
- { ".wgsl", SLANG_SOURCE_LANGUAGE_WGSL, SLANG_STAGE_NONE },
+ static const Entry entries[] = {
+ {".slang", SLANG_SOURCE_LANGUAGE_SLANG, SLANG_STAGE_NONE},
+
+ {".hlsl", SLANG_SOURCE_LANGUAGE_HLSL, SLANG_STAGE_NONE},
+ {".fx", SLANG_SOURCE_LANGUAGE_HLSL, SLANG_STAGE_NONE},
+
+ {".glsl", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_NONE},
+ {".vert", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_VERTEX},
+ {".frag", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_FRAGMENT},
+ {".geom", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_GEOMETRY},
+ {".tesc", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_HULL},
+ {".tese", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_DOMAIN},
+ {".comp", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_COMPUTE},
+ {".mesh", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_MESH},
+ {".task", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_AMPLIFICATION},
+ {".rgen", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_RAY_GENERATION},
+ {".rint", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_INTERSECTION},
+ {".rahit", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_ANY_HIT},
+ {".rchit", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_CLOSEST_HIT},
+ {".rmiss", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_MISS},
+ {".rcall", SLANG_SOURCE_LANGUAGE_GLSL, SLANG_STAGE_CALLABLE},
+
+ {".c", SLANG_SOURCE_LANGUAGE_C, SLANG_STAGE_NONE},
+ {".cpp", SLANG_SOURCE_LANGUAGE_CPP, SLANG_STAGE_NONE},
+ {".cu", SLANG_SOURCE_LANGUAGE_CUDA, SLANG_STAGE_NONE},
+
+ {".wgsl", SLANG_SOURCE_LANGUAGE_WGSL, SLANG_STAGE_NONE},
};
for (Index i = 0; i < SLANG_COUNT_OF(entries); ++i)
@@ -948,7 +1311,7 @@ SlangSourceLanguage findSourceLanguageFromPath(const String& path, Stage& outImp
return SLANG_SOURCE_LANGUAGE_UNKNOWN;
}
-SlangResult OptionsParser::addInputPath(char const* inPath, SourceLanguage langOverride )
+SlangResult OptionsParser::addInputPath(char const* inPath, SourceLanguage langOverride)
{
// look at the extension on the file name to determine
// how we should handle it.
@@ -970,13 +1333,18 @@ SlangResult OptionsParser::addInputPath(char const* inPath, SourceLanguage langO
if (sourceLanguage == SLANG_SOURCE_LANGUAGE_UNKNOWN)
{
if (m_requestImpl->getLinkage()->m_optionSet.hasOption(CompilerOptionName::Language))
- sourceLanguage = SlangSourceLanguage(m_requestImpl->getLinkage()->m_optionSet.getEnumOption<SlangSourceLanguage>(CompilerOptionName::Language));
+ sourceLanguage = SlangSourceLanguage(
+ m_requestImpl->getLinkage()->m_optionSet.getEnumOption<SlangSourceLanguage>(
+ CompilerOptionName::Language));
else
sourceLanguage = findSourceLanguageFromPath(path, impliedStage);
}
if (sourceLanguage == SLANG_SOURCE_LANGUAGE_UNKNOWN)
{
- m_requestImpl->getSink()->diagnose(SourceLoc(), Diagnostics::cannotDeduceSourceLanguage, inPath);
+ m_requestImpl->getSink()->diagnose(
+ SourceLoc(),
+ Diagnostics::cannotDeduceSourceLanguage,
+ inPath);
return SLANG_FAIL;
}
@@ -985,9 +1353,7 @@ SlangResult OptionsParser::addInputPath(char const* inPath, SourceLanguage langO
return SLANG_OK;
}
-void OptionsParser::addOutputPath(
- String const& path,
- CodeGenTarget impliedFormat)
+void OptionsParser::addOutputPath(String const& path, CodeGenTarget impliedFormat)
{
RawOutput rawOutput;
rawOutput.path = path;
@@ -1000,9 +1366,7 @@ void OptionsParser::addOutputPath(char const* inPath)
String path = String(inPath);
String ext = Path::getPathExt(path);
- if (ext == toSlice("slang-module") ||
- ext == toSlice("slang-lib") ||
- ext == toSlice("dir") ||
+ if (ext == toSlice("slang-module") || ext == toSlice("slang-lib") || ext == toSlice("dir") ||
ext == toSlice("zip"))
{
// These extensions don't indicate a artifact container, just that we want to emit IR
@@ -1016,7 +1380,8 @@ void OptionsParser::addOutputPath(char const* inPath)
}
else
{
- const SlangCompileTarget target = TypeTextUtil::findCompileTargetFromExtension(ext.getUnownedSlice());
+ const SlangCompileTarget target =
+ TypeTextUtil::findCompileTargetFromExtension(ext.getUnownedSlice());
// If the target is not found the value returned is Unknown. This is okay because
// we allow an unknown-format `-o`, assuming we get a target format
// from another argument.
@@ -1094,24 +1459,27 @@ void OptionsParser::setFloatingPointMode(RawTarget* rawTarget, FloatingPointMode
rawTarget->optionSet.set(CompilerOptionName::FloatingPointMode, mode);
}
-/* static */bool OptionsParser::_passThroughRequiresStage(PassThroughMode passThrough)
+/* static */ bool OptionsParser::_passThroughRequiresStage(PassThroughMode passThrough)
{
switch (passThrough)
{
- case PassThroughMode::Glslang:
- case PassThroughMode::Dxc:
- case PassThroughMode::Fxc:
+ case PassThroughMode::Glslang:
+ case PassThroughMode::Dxc:
+ case PassThroughMode::Fxc:
{
return true;
}
- default:
+ default:
{
return false;
}
}
}
-static SlangResult _loadRepro(const String& path, DiagnosticSink* sink, EndToEndCompileRequest* request)
+static SlangResult _loadRepro(
+ const String& path,
+ DiagnosticSink* sink,
+ EndToEndCompileRequest* request)
{
List<uint8_t> buffer;
SLANG_RETURN_ON_FAIL(ReproUtil::loadState(path, sink, buffer));
@@ -1120,13 +1488,15 @@ static SlangResult _loadRepro(const String& path, DiagnosticSink* sink, EndToEnd
MemoryOffsetBase base;
base.set(buffer.getBuffer(), buffer.getCount());
- // If we can find a directory, that exists, we will set up a file system to load from that directory
+ // If we can find a directory, that exists, we will set up a file system to load from that
+ // directory
ComPtr<ISlangFileSystem> optionalFileSystem;
String dirPath;
if (SLANG_SUCCEEDED(ReproUtil::calcDirectoryPathFromFilename(path, dirPath)))
{
SlangPathType pathType;
- if (SLANG_SUCCEEDED(Path::getPathType(dirPath, &pathType)) && pathType == SLANG_PATH_TYPE_DIRECTORY)
+ if (SLANG_SUCCEEDED(Path::getPathType(dirPath, &pathType)) &&
+ pathType == SLANG_PATH_TYPE_DIRECTORY)
{
optionalFileSystem = new RelativeFileSystem(OSFileSystem::getExtSingleton(), dirPath);
}
@@ -1137,7 +1507,10 @@ static SlangResult _loadRepro(const String& path, DiagnosticSink* sink, EndToEnd
return SLANG_OK;
}
-SlangResult OptionsParser::_compileReproDirectory(SlangSession* session, EndToEndCompileRequest* originalRequest, const String& dir)
+SlangResult OptionsParser::_compileReproDirectory(
+ SlangSession* session,
+ EndToEndCompileRequest* originalRequest,
+ const String& dir)
{
auto stdOut = originalRequest->getWriter(WriterChannel::StdOutput);
@@ -1216,8 +1589,7 @@ SlangResult OptionsParser::_dumpDiagnostics(Severity originalSeverity)
for (const auto& diagnostic : diagnosticsLookup->getDiagnostics())
{
- if (originalSeverity != Severity::Disable &&
- diagnostic->severity != originalSeverity)
+ if (originalSeverity != Severity::Disable && diagnostic->severity != originalSeverity)
{
continue;
}
@@ -1225,7 +1597,11 @@ SlangResult OptionsParser::_dumpDiagnostics(Severity originalSeverity)
buf.clear();
buf << diagnostic->id << " : ";
- NameConventionUtil::convert(NameStyle::Camel, UnownedStringSlice(diagnostic->name), NameConvention::LowerKabab, buf);
+ NameConventionUtil::convert(
+ NameStyle::Camel,
+ UnownedStringSlice(diagnostic->name),
+ NameConvention::LowerKabab,
+ buf);
buf << "\n";
m_sink->diagnoseRaw(Severity::Note, buf.getUnownedSlice());
}
@@ -1254,12 +1630,18 @@ void OptionsParser::_appendMinimalUsage(StringBuilder& out)
}
-SlangResult OptionsParser::_getValue(ValueCategory valueCategory, const CommandLineArg& arg, const UnownedStringSlice& name, CommandOptions::UserValue& outValue)
+SlangResult OptionsParser::_getValue(
+ ValueCategory valueCategory,
+ const CommandLineArg& arg,
+ const UnownedStringSlice& name,
+ CommandOptions::UserValue& outValue)
{
- const auto optionIndex = m_cmdOptions->findOptionByCategoryUserValue(CommandOptions::UserValue(valueCategory), name);
+ const auto optionIndex =
+ m_cmdOptions->findOptionByCategoryUserValue(CommandOptions::UserValue(valueCategory), name);
if (optionIndex < 0)
{
- const auto categoryIndex = m_cmdOptions->findCategoryByUserValue(CommandOptions::UserValue(valueCategory));
+ const auto categoryIndex =
+ m_cmdOptions->findCategoryByUserValue(CommandOptions::UserValue(valueCategory));
SLANG_ASSERT(categoryIndex >= 0);
if (categoryIndex < 0)
{
@@ -1280,18 +1662,28 @@ SlangResult OptionsParser::_getValue(ValueCategory valueCategory, const CommandL
return SLANG_OK;
}
-SlangResult OptionsParser::_getValue(ValueCategory valueCategory, const CommandLineArg& arg, CommandOptions::UserValue& outValue)
+SlangResult OptionsParser::_getValue(
+ ValueCategory valueCategory,
+ const CommandLineArg& arg,
+ CommandOptions::UserValue& outValue)
{
return _getValue(valueCategory, arg, arg.value.getUnownedSlice(), outValue);
}
-SlangResult OptionsParser::_getValue(const ConstArrayView<ValueCategory>& valueCategories, const CommandLineArg& arg, const UnownedStringSlice& name, ValueCategory& outCat, CommandOptions::UserValue& outValue)
+SlangResult OptionsParser::_getValue(
+ const ConstArrayView<ValueCategory>& valueCategories,
+ const CommandLineArg& arg,
+ const UnownedStringSlice& name,
+ ValueCategory& outCat,
+ CommandOptions::UserValue& outValue)
{
auto& cmdOptions = asInternal(m_session)->m_commandOptions;
for (auto valueCategory : valueCategories)
{
- const auto optionIndex = cmdOptions.findOptionByCategoryUserValue(CommandOptions::UserValue(valueCategory), name);
+ const auto optionIndex = cmdOptions.findOptionByCategoryUserValue(
+ CommandOptions::UserValue(valueCategory),
+ name);
if (optionIndex >= 0)
{
outCat = valueCategory;
@@ -1303,7 +1695,8 @@ SlangResult OptionsParser::_getValue(const ConstArrayView<ValueCategory>& valueC
List<UnownedStringSlice> names;
for (auto valueCategory : valueCategories)
{
- const auto categoryIndex = cmdOptions.findCategoryByUserValue(CommandOptions::UserValue(valueCategory));
+ const auto categoryIndex =
+ cmdOptions.findCategoryByUserValue(CommandOptions::UserValue(valueCategory));
SLANG_ASSERT(categoryIndex >= 0);
if (categoryIndex < 0)
{
@@ -1319,7 +1712,9 @@ SlangResult OptionsParser::_getValue(const ConstArrayView<ValueCategory>& valueC
return SLANG_FAIL;
}
-SlangResult OptionsParser::_expectValue(ValueCategory valueCategory, CommandOptions::UserValue& outValue)
+SlangResult OptionsParser::_expectValue(
+ ValueCategory valueCategory,
+ CommandOptions::UserValue& outValue)
{
CommandLineArg arg;
SLANG_RETURN_ON_FAIL(m_reader.expectArg(arg));
@@ -1333,7 +1728,7 @@ SlangResult OptionsParser::_expectInt(const CommandLineArg& initArg, Int& outInt
CommandLineArg arg;
SLANG_RETURN_ON_FAIL(m_reader.expectArg(arg));
-
+
if (SLANG_FAILED(StringUtil::parseInt(arg.value.getUnownedSlice(), outInt)))
{
m_sink->diagnose(arg.loc, Diagnostics::expectingAnInteger);
@@ -1375,20 +1770,26 @@ SlangResult OptionsParser::addReferencedModule(String path, SourceLoc loc, bool
// Create the artifact
auto artifact = Artifact::create(desc, name.getUnownedSlice());
- // There is a problem here if I want to reference a library that is a 'system' library or is not directly a file
- // In that case the path shouldn't be set and the name should completely define the library.
- // Seeing as on all targets the baseName doesn't have an extension, and all library types do
- // if the name doesn't have an extension we can assume there is no path to it.
+ // There is a problem here if I want to reference a library that is a 'system' library or is not
+ // directly a file In that case the path shouldn't be set and the name should completely define
+ // the library. Seeing as on all targets the baseName doesn't have an extension, and all library
+ // types do if the name doesn't have an extension we can assume there is no path to it.
ComPtr<IOSFileArtifactRepresentation> fileRep;
if (Path::getPathExt(path).getLength() <= 0)
{
// If there is no extension *assume* it is the name of a system level library
- fileRep = new OSFileArtifactRepresentation(IOSFileArtifactRepresentation::Kind::NameOnly, path.getUnownedSlice(), nullptr);
+ fileRep = new OSFileArtifactRepresentation(
+ IOSFileArtifactRepresentation::Kind::NameOnly,
+ path.getUnownedSlice(),
+ nullptr);
}
else
{
- fileRep = new OSFileArtifactRepresentation(IOSFileArtifactRepresentation::Kind::Reference, path.getUnownedSlice(), nullptr);
+ fileRep = new OSFileArtifactRepresentation(
+ IOSFileArtifactRepresentation::Kind::Reference,
+ path.getUnownedSlice(),
+ nullptr);
if (!fileRep->exists())
{
m_sink->diagnose(loc, Diagnostics::libraryDoesNotExist, path);
@@ -1398,7 +1799,8 @@ SlangResult OptionsParser::addReferencedModule(String path, SourceLoc loc, bool
artifact->addRepresentation(fileRep);
SLANG_RETURN_ON_FAIL(_addLibraryReference(m_requestImpl, path, artifact, includeEntryPoint));
- for (Index i = m_rawTranslationUnits.getCount(); i < m_requestImpl->getTranslationUnitCount(); i++)
+ for (Index i = m_rawTranslationUnits.getCount(); i < m_requestImpl->getTranslationUnitCount();
+ i++)
{
RawTranslationUnit rawTU;
rawTU.translationUnitID = (int)i;
@@ -1442,13 +1844,15 @@ SlangResult OptionsParser::_parseReproFileSystem(const CommandLineArg& arg)
MemoryOffsetBase base;
base.set(buffer.getBuffer(), buffer.getCount());
- // If we can find a directory, that exists, we will set up a file system to load from that directory
+ // If we can find a directory, that exists, we will set up a file system to load from that
+ // directory
ComPtr<ISlangFileSystem> dirFileSystem;
String dirPath;
if (SLANG_SUCCEEDED(ReproUtil::calcDirectoryPathFromFilename(reproName.value, dirPath)))
{
SlangPathType pathType;
- if (SLANG_SUCCEEDED(Path::getPathType(dirPath, &pathType)) && pathType == SLANG_PATH_TYPE_DIRECTORY)
+ if (SLANG_SUCCEEDED(Path::getPathType(dirPath, &pathType)) &&
+ pathType == SLANG_PATH_TYPE_DIRECTORY)
{
dirFileSystem = new RelativeFileSystem(OSFileSystem::getExtSingleton(), dirPath, true);
}
@@ -1461,7 +1865,10 @@ SlangResult OptionsParser::_parseReproFileSystem(const CommandLineArg& arg)
SLANG_ASSERT(cacheFileSystem);
// I might want to make the dir file system the fallback file system...
- cacheFileSystem->setInnerFileSystem(dirFileSystem, cacheFileSystem->getUniqueIdentityMode(), cacheFileSystem->getPathStyle());
+ cacheFileSystem->setInnerFileSystem(
+ dirFileSystem,
+ cacheFileSystem->getUniqueIdentityMode(),
+ cacheFileSystem->getPathStyle());
// Set as the file system
m_compileRequest->setFileSystem(fileSystem);
@@ -1478,7 +1885,8 @@ SlangResult OptionsParser::_parseHelp(const CommandLineArg& arg)
{
auto catArg = m_reader.getArgAndAdvance();
- categoryIndex = m_cmdOptions->findCategoryByCaseInsensitiveName(catArg.value.getUnownedSlice());
+ categoryIndex =
+ m_cmdOptions->findCategoryByCaseInsensitiveName(catArg.value.getUnownedSlice());
if (categoryIndex < 0)
{
m_sink->diagnose(catArg.loc, Diagnostics::unknownHelpCategory);
@@ -1561,7 +1969,7 @@ SlangResult OptionsParser::_parseDebugInformation(const CommandLineArg& arg)
{
CommandOptions::UserValue value;
ValueCategory valueCat;
- ValueCategory valueCats[] = { ValueCategory::DebugLevel, ValueCategory::DebugInfoFormat };
+ ValueCategory valueCats[] = {ValueCategory::DebugLevel, ValueCategory::DebugInfoFormat};
SLANG_RETURN_ON_FAIL(_getValue(makeConstArrayView(valueCats), arg, name, valueCat, value));
if (valueCat == ValueCategory::DebugLevel)
@@ -1626,7 +2034,7 @@ SlangResult OptionsParser::_parseProfile(const CommandLineArg& arg)
// Any additional capability tokens will be assumed to represent `CapabilityAtom`s.
// Those atoms will need to be added to the supported capabilities of the target.
- //
+ //
for (Index i = 1; i < sliceCount; ++i)
{
UnownedStringSlice atomName = slices[i];
@@ -1643,9 +2051,7 @@ SlangResult OptionsParser::_parseProfile(const CommandLineArg& arg)
return SLANG_OK;
}
-SlangResult OptionsParser::_parse(
- int argc,
- char const* const* argv)
+SlangResult OptionsParser::_parse(int argc, char const* const* argv)
{
// Set up the args
CommandLineArgs args(m_cmdLineContext);
@@ -1698,56 +2104,58 @@ SlangResult OptionsParser::_parse(
switch (optionKind)
{
- case OptionKind::NoMangle:
- case OptionKind::ValidateUniformity:
- case OptionKind::AllowGLSL:
- case OptionKind::EnableExperimentalPasses:
- case OptionKind::EmitIr:
- case OptionKind::DumpIntermediates:
- case OptionKind::DumpReproOnError:
- case OptionKind::ReportDownstreamTime:
- case OptionKind::ReportPerfBenchmark:
- case OptionKind::ReportCheckpointIntermediates:
- case OptionKind::SkipSPIRVValidation:
- case OptionKind::DisableSpecialization:
- case OptionKind::DisableDynamicDispatch:
- case OptionKind::TrackLiveness:
- case OptionKind::SkipCodeGen:
- case OptionKind::ParameterBlocksUseRegisterSpaces:
- case OptionKind::ValidateIr:
- case OptionKind::DumpIr:
- case OptionKind::VulkanInvertY:
- case OptionKind::VulkanUseDxPositionW:
- case OptionKind::VulkanUseEntryPointName:
- case OptionKind::VulkanUseGLLayout:
- case OptionKind::VulkanEmitReflection:
- case OptionKind::ZeroInitialize:
- case OptionKind::IgnoreCapabilities:
- case OptionKind::RestrictiveCapabilityCheck:
- case OptionKind::MinimumSlangOptimization:
- case OptionKind::DisableNonEssentialValidations:
- case OptionKind::DisableSourceMap:
- case OptionKind::DefaultImageFormatUnknown:
- case OptionKind::Obfuscate:
- case OptionKind::OutputIncludes:
- case OptionKind::PreprocessorOutput:
- case OptionKind::DumpAst:
- case OptionKind::IncompleteLibrary:
- case OptionKind::NoHLSLBinding:
- case OptionKind::NoHLSLPackConstantBufferElements:
- case OptionKind::LoopInversion:
- case OptionKind::UnscopedEnum:
- case OptionKind::PreserveParameters:
- linkage->m_optionSet.set(optionKind, true);
- break;
- case OptionKind::MatrixLayoutRow:
- case OptionKind::MatrixLayoutColumn:
- linkage->m_optionSet.setMatrixLayoutMode((optionKind == OptionKind::MatrixLayoutRow) ? MatrixLayoutMode::kMatrixLayoutMode_RowMajor : MatrixLayoutMode::kMatrixLayoutMode_ColumnMajor);
- break;
- case OptionKind::NoCodeGen:
- linkage->m_optionSet.set(OptionKind::SkipCodeGen, true); break;
- break;
- case OptionKind::LoadCoreModule:
+ case OptionKind::NoMangle:
+ case OptionKind::ValidateUniformity:
+ case OptionKind::AllowGLSL:
+ case OptionKind::EnableExperimentalPasses:
+ case OptionKind::EmitIr:
+ case OptionKind::DumpIntermediates:
+ case OptionKind::DumpReproOnError:
+ case OptionKind::ReportDownstreamTime:
+ case OptionKind::ReportPerfBenchmark:
+ case OptionKind::ReportCheckpointIntermediates:
+ case OptionKind::SkipSPIRVValidation:
+ case OptionKind::DisableSpecialization:
+ case OptionKind::DisableDynamicDispatch:
+ case OptionKind::TrackLiveness:
+ case OptionKind::SkipCodeGen:
+ case OptionKind::ParameterBlocksUseRegisterSpaces:
+ case OptionKind::ValidateIr:
+ case OptionKind::DumpIr:
+ case OptionKind::VulkanInvertY:
+ case OptionKind::VulkanUseDxPositionW:
+ case OptionKind::VulkanUseEntryPointName:
+ case OptionKind::VulkanUseGLLayout:
+ case OptionKind::VulkanEmitReflection:
+ case OptionKind::ZeroInitialize:
+ case OptionKind::IgnoreCapabilities:
+ case OptionKind::RestrictiveCapabilityCheck:
+ case OptionKind::MinimumSlangOptimization:
+ case OptionKind::DisableNonEssentialValidations:
+ case OptionKind::DisableSourceMap:
+ case OptionKind::DefaultImageFormatUnknown:
+ case OptionKind::Obfuscate:
+ case OptionKind::OutputIncludes:
+ case OptionKind::PreprocessorOutput:
+ case OptionKind::DumpAst:
+ case OptionKind::IncompleteLibrary:
+ case OptionKind::NoHLSLBinding:
+ case OptionKind::NoHLSLPackConstantBufferElements:
+ case OptionKind::LoopInversion:
+ case OptionKind::UnscopedEnum:
+ case OptionKind::PreserveParameters: linkage->m_optionSet.set(optionKind, true); break;
+ case OptionKind::MatrixLayoutRow:
+ case OptionKind::MatrixLayoutColumn:
+ linkage->m_optionSet.setMatrixLayoutMode(
+ (optionKind == OptionKind::MatrixLayoutRow)
+ ? MatrixLayoutMode::kMatrixLayoutMode_RowMajor
+ : MatrixLayoutMode::kMatrixLayoutMode_ColumnMajor);
+ break;
+ case OptionKind::NoCodeGen:
+ linkage->m_optionSet.set(OptionKind::SkipCodeGen, true);
+ break;
+ break;
+ case OptionKind::LoadCoreModule:
{
CommandLineArg fileName;
SLANG_RETURN_ON_FAIL(m_reader.expectArg(fileName));
@@ -1755,20 +2163,22 @@ SlangResult OptionsParser::_parse(
// Load the file
ScopedAllocation contents;
SLANG_RETURN_ON_FAIL(File::readAllBytes(fileName.value, contents));
- SLANG_RETURN_ON_FAIL(m_session->loadCoreModule(contents.getData(), contents.getSizeInBytes()));
-
+ SLANG_RETURN_ON_FAIL(
+ m_session->loadCoreModule(contents.getData(), contents.getSizeInBytes()));
+
// Ensure that the linkage's AST builder is up-to-date.
- linkage->getASTBuilder()->m_cachedNodes = asInternal(m_session)->getGlobalASTBuilder()->m_cachedNodes;
+ linkage->getASTBuilder()->m_cachedNodes =
+ asInternal(m_session)->getGlobalASTBuilder()->m_cachedNodes;
break;
}
- case OptionKind::CompileCoreModule: m_compileCoreModule = true; break;
- case OptionKind::ArchiveType:
+ case OptionKind::CompileCoreModule: m_compileCoreModule = true; break;
+ case OptionKind::ArchiveType:
{
SLANG_RETURN_ON_FAIL(_expectValue(m_archiveType));
break;
}
- case OptionKind::SaveCoreModule:
+ case OptionKind::SaveCoreModule:
{
CommandLineArg fileName;
SLANG_RETURN_ON_FAIL(m_reader.expectArg(fileName));
@@ -1776,10 +2186,13 @@ SlangResult OptionsParser::_parse(
ComPtr<ISlangBlob> blob;
SLANG_RETURN_ON_FAIL(m_session->saveCoreModule(m_archiveType, blob.writeRef()));
- SLANG_RETURN_ON_FAIL(File::writeAllBytes(fileName.value, blob->getBufferPointer(), blob->getBufferSize()));
+ SLANG_RETURN_ON_FAIL(File::writeAllBytes(
+ fileName.value,
+ blob->getBufferPointer(),
+ blob->getBufferSize()));
break;
}
- case OptionKind::SaveCoreModuleBinSource:
+ case OptionKind::SaveCoreModuleBinSource:
{
CommandLineArg fileName;
SLANG_RETURN_ON_FAIL(m_reader.expectArg(fileName));
@@ -1791,24 +2204,28 @@ SlangResult OptionsParser::_parse(
StringBuilder builder;
StringWriter writer(&builder, 0);
- SLANG_RETURN_ON_FAIL(HexDumpUtil::dumpSourceBytes((const uint8_t*)blob->getBufferPointer(), blob->getBufferSize(), 16, &writer));
+ SLANG_RETURN_ON_FAIL(HexDumpUtil::dumpSourceBytes(
+ (const uint8_t*)blob->getBufferPointer(),
+ blob->getBufferSize(),
+ 16,
+ &writer));
File::writeAllText(fileName.value, builder);
break;
}
- case OptionKind::DumpIrIds:
+ case OptionKind::DumpIrIds:
{
m_frontEndReq->m_irDumpOptions.flags |= IRDumpOptions::Flag::DumpDebugIds;
break;
}
- case OptionKind::DumpIntermediatePrefix:
+ case OptionKind::DumpIntermediatePrefix:
{
CommandLineArg prefix;
SLANG_RETURN_ON_FAIL(m_reader.expectArg(prefix));
linkage->m_optionSet.set(CompilerOptionName::DumpIntermediatePrefix, prefix.value);
break;
}
- case OptionKind::Doc:
+ case OptionKind::Doc:
{
// When compiling the core module, it will write out a documentation.
m_compileCoreModuleFlags |= slang::CompileCoreModuleFlag::WriteDocumentation;
@@ -1817,7 +2234,7 @@ SlangResult OptionsParser::_parse(
linkage->m_optionSet.set(CompilerOptionName::Doc, true);
break;
}
- case OptionKind::DumpRepro:
+ case OptionKind::DumpRepro:
{
CommandLineArg dumpRepro;
SLANG_RETURN_ON_FAIL(m_reader.expectArg(dumpRepro));
@@ -1825,7 +2242,7 @@ SlangResult OptionsParser::_parse(
m_compileRequest->enableReproCapture();
break;
}
- case OptionKind::ExtractRepro:
+ case OptionKind::ExtractRepro:
{
CommandLineArg reproName;
SLANG_RETURN_ON_FAIL(m_reader.expectArg(reproName));
@@ -1834,13 +2251,16 @@ SlangResult OptionsParser::_parse(
const Result res = ReproUtil::extractFilesToDirectory(reproName.value, m_sink);
if (SLANG_FAILED(res))
{
- m_sink->diagnose(reproName.loc, Diagnostics::unableExtractReproToDirectory, reproName.value);
+ m_sink->diagnose(
+ reproName.loc,
+ Diagnostics::unableExtractReproToDirectory,
+ reproName.value);
return res;
}
}
break;
}
- case OptionKind::ModuleName:
+ case OptionKind::ModuleName:
{
CommandLineArg moduleName;
SLANG_RETURN_ON_FAIL(m_reader.expectArg(moduleName));
@@ -1848,16 +2268,17 @@ SlangResult OptionsParser::_parse(
m_compileRequest->setDefaultModuleName(moduleName.value.getBuffer());
break;
}
- case OptionKind::LoadRepro: SLANG_RETURN_ON_FAIL(_parseLoadRepro(arg)); break;
- case OptionKind::LoadReproDirectory:
+ case OptionKind::LoadRepro: SLANG_RETURN_ON_FAIL(_parseLoadRepro(arg)); break;
+ case OptionKind::LoadReproDirectory:
{
CommandLineArg reproDirectory;
SLANG_RETURN_ON_FAIL(m_reader.expectArg(reproDirectory));
- SLANG_RETURN_ON_FAIL(_compileReproDirectory(m_session, m_requestImpl, reproDirectory.value));
+ SLANG_RETURN_ON_FAIL(
+ _compileReproDirectory(m_session, m_requestImpl, reproDirectory.value));
break;
}
- case OptionKind::ReproFallbackDirectory:
+ case OptionKind::ReproFallbackDirectory:
{
CommandLineArg reproDirectory;
SLANG_RETURN_ON_FAIL(m_reader.expectArg(reproDirectory));
@@ -1877,91 +2298,110 @@ SlangResult OptionsParser::_parse(
auto osFileSystem = OSFileSystem::getExtSingleton();
SlangPathType pathType;
- if (SLANG_FAILED(osFileSystem->getPathType(reproDirectory.value.getBuffer(), &pathType) )
- || pathType != SLANG_PATH_TYPE_DIRECTORY)
+ if (SLANG_FAILED(osFileSystem->getPathType(
+ reproDirectory.value.getBuffer(),
+ &pathType)) ||
+ pathType != SLANG_PATH_TYPE_DIRECTORY)
{
return SLANG_FAIL;
}
- // Make the fallback directory use a relative file system, to the specified directory
- m_requestImpl->m_reproFallbackFileSystem = new RelativeFileSystem(osFileSystem, reproDirectory.value);
+ // Make the fallback directory use a relative file system, to the specified
+ // directory
+ m_requestImpl->m_reproFallbackFileSystem =
+ new RelativeFileSystem(osFileSystem, reproDirectory.value);
}
break;
}
- case OptionKind::ReproFileSystem: SLANG_RETURN_ON_FAIL(_parseReproFileSystem(arg)); break;
- case OptionKind::SerialIr: m_frontEndReq->useSerialIRBottleneck = true; break;
- case OptionKind::VerbosePaths:
- m_requestImpl->getSink()->setFlag(DiagnosticSink::Flag::VerbosePath); break;
- case OptionKind::DumpWarningDiagnostics: _dumpDiagnostics(Severity::Warning); break;
- case OptionKind::WarningsAsErrors:
+ case OptionKind::ReproFileSystem: SLANG_RETURN_ON_FAIL(_parseReproFileSystem(arg)); break;
+ case OptionKind::SerialIr: m_frontEndReq->useSerialIRBottleneck = true; break;
+ case OptionKind::VerbosePaths:
+ m_requestImpl->getSink()->setFlag(DiagnosticSink::Flag::VerbosePath);
+ break;
+ case OptionKind::DumpWarningDiagnostics: _dumpDiagnostics(Severity::Warning); break;
+ case OptionKind::WarningsAsErrors:
{
CommandLineArg operand;
SLANG_RETURN_ON_FAIL(m_reader.expectArg(operand));
- linkage->m_optionSet.add(OptionKind::WarningsAsErrors, operand.value.getUnownedSlice());
+ linkage->m_optionSet.add(
+ OptionKind::WarningsAsErrors,
+ operand.value.getUnownedSlice());
break;
}
- case OptionKind::DisableWarnings:
+ case OptionKind::DisableWarnings:
{
CommandLineArg operand;
SLANG_RETURN_ON_FAIL(m_reader.expectArg(operand));
- //SLANG_RETURN_ON_FAIL(_overrideDiagnostics(operand.value.getUnownedSlice(), Severity::Warning, Severity::Disable));
- linkage->m_optionSet.add(OptionKind::DisableWarnings, operand.value.getUnownedSlice());
+ // SLANG_RETURN_ON_FAIL(_overrideDiagnostics(operand.value.getUnownedSlice(),
+ // Severity::Warning, Severity::Disable));
+ linkage->m_optionSet.add(
+ OptionKind::DisableWarnings,
+ operand.value.getUnownedSlice());
break;
}
- case OptionKind::DisableWarning:
+ case OptionKind::DisableWarning:
{
// 5 because -Wno-
auto name = argValue.getUnownedSlice().tail(5);
linkage->m_optionSet.add(OptionKind::DisableWarning, name);
- //SLANG_RETURN_ON_FAIL(_overrideDiagnostic(name, Severity::Warning, Severity::Disable));
+ // SLANG_RETURN_ON_FAIL(_overrideDiagnostic(name, Severity::Warning,
+ // Severity::Disable));
break;
}
- case OptionKind::EnableWarning:
+ case OptionKind::EnableWarning:
{
// 2 because -W
auto name = argValue.getUnownedSlice().tail(2);
linkage->m_optionSet.add(OptionKind::EnableWarning, name);
// Enable the warning
- //SLANG_RETURN_ON_FAIL(_overrideDiagnostic(name, Severity::Warning, Severity::Warning));
+ // SLANG_RETURN_ON_FAIL(_overrideDiagnostic(name, Severity::Warning,
+ // Severity::Warning));
break;
}
- case OptionKind::VerifyDebugSerialIr: m_frontEndReq->verifyDebugSerialization = true; break;
- case OptionKind::IrCompression:
+ case OptionKind::VerifyDebugSerialIr: m_frontEndReq->verifyDebugSerialization = true; break;
+ case OptionKind::IrCompression:
{
CommandLineArg name;
SLANG_RETURN_ON_FAIL(m_reader.expectArg(name));
SerialCompressionType compressionType;
- SLANG_RETURN_ON_FAIL(SerialParseUtil::parseCompressionType(name.value.getUnownedSlice(), compressionType));
+ SLANG_RETURN_ON_FAIL(SerialParseUtil::parseCompressionType(
+ name.value.getUnownedSlice(),
+ compressionType));
linkage->m_optionSet.set(optionKind, compressionType);
break;
}
- case OptionKind::EmbedDownstreamIR:
+ case OptionKind::EmbedDownstreamIR:
{
getCurrentTarget()->optionSet.add(CompilerOptionName::EmbedDownstreamIR, true);
break;
}
- case OptionKind::Target:
+ case OptionKind::Target:
{
CommandLineArg name;
SLANG_RETURN_ON_FAIL(m_reader.expectArg(name));
- const CodeGenTarget format = (CodeGenTarget)TypeTextUtil::findCompileTargetFromName(name.value.getUnownedSlice());
+ const CodeGenTarget format = (CodeGenTarget)TypeTextUtil::findCompileTargetFromName(
+ name.value.getUnownedSlice());
if (format == CodeGenTarget::Unknown)
{
- m_sink->diagnose(name.loc, Diagnostics::unknownCodeGenerationTarget, name.value);
+ m_sink->diagnose(
+ name.loc,
+ Diagnostics::unknownCodeGenerationTarget,
+ name.value);
return SLANG_FAIL;
}
RawTarget rawTarget;
rawTarget.format = CodeGenTarget(format);
// Silently allow redundant targets if it is the same as the last specified target.
- if (m_rawTargets.getCount() != 0 && m_rawTargets.getLast().format == rawTarget.format)
+ if (m_rawTargets.getCount() != 0 &&
+ m_rawTargets.getLast().format == rawTarget.format)
break;
m_rawTargets.add(rawTarget);
break;
}
- case OptionKind::VulkanBindShift:
+ case OptionKind::VulkanBindShift:
{
// -fvk-{b|s|t|u}-shift <binding-shift> <set>
const auto slice = arg.value.getUnownedSlice().subString(5, 1);
@@ -1970,34 +2410,44 @@ SlangResult OptionsParser::_parse(
Int shift;
SLANG_RETURN_ON_FAIL(_expectInt(arg, shift));
-
+
if (m_reader.hasArg() && m_reader.peekArg().value == toSlice("all"))
{
m_reader.advance();
- linkage->m_optionSet.add(CompilerOptionName::VulkanBindShiftAll, (int)kind, (int)shift);
+ linkage->m_optionSet.add(
+ CompilerOptionName::VulkanBindShiftAll,
+ (int)kind,
+ (int)shift);
}
else
{
Int set;
SLANG_RETURN_ON_FAIL(_expectInt(arg, set));
- linkage->m_optionSet.add(CompilerOptionName::VulkanBindShift, (uint8_t)kind, (int)set, (int)shift);
+ linkage->m_optionSet.add(
+ CompilerOptionName::VulkanBindShift,
+ (uint8_t)kind,
+ (int)set,
+ (int)shift);
}
break;
}
- case OptionKind::VulkanBindGlobals:
+ case OptionKind::VulkanBindGlobals:
{
// -fvk-bind-globals <index> <set>
Int binding, bindingSet;
SLANG_RETURN_ON_FAIL(_expectInt(arg, binding));
SLANG_RETURN_ON_FAIL(_expectInt(arg, bindingSet));
- linkage->m_optionSet.set(OptionKind::VulkanBindGlobals, (int)binding, (int)bindingSet);
+ linkage->m_optionSet.set(
+ OptionKind::VulkanBindGlobals,
+ (int)binding,
+ (int)bindingSet);
break;
}
- case OptionKind::Profile: SLANG_RETURN_ON_FAIL(_parseProfile(arg)); break;
- case OptionKind::Capability:
+ case OptionKind::Profile: SLANG_RETURN_ON_FAIL(_parseProfile(arg)); break;
+ case OptionKind::Capability:
{
- // The `-capability` option is similar to `-profile` but does not set the actual profile
- // for a target (it just adds capabilities).
+ // The `-capability` option is similar to `-profile` but does not set the actual
+ // profile for a target (it just adds capabilities).
//
// TODO: Once profiles are treated as capabilities themselves, it might be possible
// to treat `-profile` and `-capability` as aliases, although there might still be
@@ -2024,7 +2474,7 @@ SlangResult OptionsParser::_parse(
}
break;
}
- case OptionKind::Stage:
+ case OptionKind::Stage:
{
CommandLineArg name;
SLANG_RETURN_ON_FAIL(m_reader.expectArg(name));
@@ -2041,23 +2491,23 @@ SlangResult OptionsParser::_parse(
}
break;
}
- case OptionKind::GLSLForceScalarLayout:
+ case OptionKind::GLSLForceScalarLayout:
{
getCurrentTarget()->optionSet.add(CompilerOptionName::GLSLForceScalarLayout, true);
break;
}
- case OptionKind::ForceDXLayout:
+ case OptionKind::ForceDXLayout:
{
getCurrentTarget()->optionSet.add(CompilerOptionName::ForceDXLayout, true);
break;
}
- case OptionKind::EnableEffectAnnotations:
+ case OptionKind::EnableEffectAnnotations:
{
m_compileRequest->setEnableEffectAnnotations(true);
break;
}
- case OptionKind::EntryPointName:
+ case OptionKind::EntryPointName:
{
CommandLineArg name;
SLANG_RETURN_ON_FAIL(m_reader.expectArg(name));
@@ -2066,12 +2516,13 @@ SlangResult OptionsParser::_parse(
rawEntryPoint.name = name.value;
rawEntryPoint.translationUnitIndex = m_currentTranslationUnitIndex;
// Silently allow duplicate entrypoints if it is the same as the last specified one.
- if (m_rawEntryPoints.getCount() != 0 && m_rawEntryPoints.getLast().name == rawEntryPoint.name)
+ if (m_rawEntryPoints.getCount() != 0 &&
+ m_rawEntryPoints.getLast().name == rawEntryPoint.name)
break;
m_rawEntryPoints.add(rawEntryPoint);
break;
}
- case OptionKind::Specialize:
+ case OptionKind::Specialize:
{
for (;;)
{
@@ -2089,12 +2540,13 @@ SlangResult OptionsParser::_parse(
}
break;
}
- case OptionKind::Language:
+ case OptionKind::Language:
{
CommandLineArg name;
SLANG_RETURN_ON_FAIL(m_reader.expectArg(name));
- const SourceLanguage sourceLanguage = (SourceLanguage)TypeTextUtil::findSourceLanguage(name.value.getUnownedSlice());
+ const SourceLanguage sourceLanguage =
+ (SourceLanguage)TypeTextUtil::findSourceLanguage(name.value.getUnownedSlice());
if (sourceLanguage == SourceLanguage::Unknown)
{
@@ -2105,19 +2557,22 @@ SlangResult OptionsParser::_parse(
{
while (m_reader.hasArg() && !m_reader.peekValue().startsWith("-"))
{
- SLANG_RETURN_ON_FAIL(addInputPath(m_reader.getValueAndAdvance().getBuffer(), sourceLanguage));
+ SLANG_RETURN_ON_FAIL(addInputPath(
+ m_reader.getValueAndAdvance().getBuffer(),
+ sourceLanguage));
}
}
linkage->m_optionSet.add(CompilerOptionName::Language, (int)sourceLanguage);
break;
}
- case OptionKind::PassThrough:
+ case OptionKind::PassThrough:
{
CommandLineArg name;
SLANG_RETURN_ON_FAIL(m_reader.expectArg(name));
SlangPassThrough passThrough = SLANG_PASS_THROUGH_NONE;
- if (SLANG_FAILED(TypeTextUtil::findPassThrough(name.value.getUnownedSlice(), passThrough)))
+ if (SLANG_FAILED(
+ TypeTextUtil::findPassThrough(name.value.getUnownedSlice(), passThrough)))
{
m_sink->diagnose(name.loc, Diagnostics::unknownPassThroughTarget, name.value);
return SLANG_FAIL;
@@ -2126,7 +2581,7 @@ SlangResult OptionsParser::_parse(
m_compileRequest->setPassThrough(passThrough);
break;
}
- case OptionKind::MacroDefine:
+ case OptionKind::MacroDefine:
{
// The value to be defined might be part of the same option, as in:
// -DFOO
@@ -2151,7 +2606,9 @@ SlangResult OptionsParser::_parse(
if (equalIndex >= 0)
{
// If we found an `=`, we split the string...
- m_compileRequest->addPreprocessorDefine(String(slice.head(equalIndex)).getBuffer(), String(slice.tail(equalIndex + 1)).getBuffer());
+ m_compileRequest->addPreprocessorDefine(
+ String(slice.head(equalIndex)).getBuffer(),
+ String(slice.tail(equalIndex + 1)).getBuffer());
}
else
{
@@ -2160,7 +2617,7 @@ SlangResult OptionsParser::_parse(
}
break;
}
- case OptionKind::Include:
+ case OptionKind::Include:
{
// The value to be defined might be part of the same option, as in:
// -IFOO
@@ -2180,7 +2637,7 @@ SlangResult OptionsParser::_parse(
m_compileRequest->addSearchPath(String(slice).getBuffer());
break;
}
- case OptionKind::Output:
+ case OptionKind::Output:
{
//
// A `-o` option is used to specify a desired output file.
@@ -2190,7 +2647,7 @@ SlangResult OptionsParser::_parse(
addOutputPath(outputPath.value.getBuffer());
break;
}
- case OptionKind::DepFile:
+ case OptionKind::DepFile:
{
CommandLineArg dependencyPath;
SLANG_RETURN_ON_FAIL(m_reader.expectArg(dependencyPath));
@@ -2201,30 +2658,32 @@ SlangResult OptionsParser::_parse(
}
else
{
- m_sink->diagnose(dependencyPath.loc, Diagnostics::duplicateDependencyOutputPaths);
+ m_sink->diagnose(
+ dependencyPath.loc,
+ Diagnostics::duplicateDependencyOutputPaths);
return SLANG_FAIL;
}
break;
}
- case OptionKind::LineDirectiveMode:
+ case OptionKind::LineDirectiveMode:
{
SlangLineDirectiveMode value;
SLANG_RETURN_ON_FAIL(_expectValue(value));
m_compileRequest->setLineDirectiveMode(value);
break;
}
- case OptionKind::FloatingPointMode:
+ case OptionKind::FloatingPointMode:
{
FloatingPointMode value;
SLANG_RETURN_ON_FAIL(_expectValue(value));
setFloatingPointMode(getCurrentTarget(), value);
break;
}
- case OptionKind::Optimization:
+ case OptionKind::Optimization:
{
UnownedStringSlice levelSlice = argValue.getUnownedSlice().tail(2);
SlangOptimizationLevel level = SLANG_OPTIMIZATION_LEVEL_DEFAULT;
-
+
if (levelSlice.getLength())
{
SLANG_RETURN_ON_FAIL(_getValue(arg, levelSlice, level));
@@ -2233,42 +2692,46 @@ SlangResult OptionsParser::_parse(
m_compileRequest->setOptimizationLevel(level);
break;
}
- case OptionKind::DebugInformation: SLANG_RETURN_ON_FAIL(_parseDebugInformation(arg)); break;
- case OptionKind::FileSystem:
+ case OptionKind::DebugInformation: SLANG_RETURN_ON_FAIL(_parseDebugInformation(arg)); break;
+ case OptionKind::FileSystem:
{
typedef TypeTextUtil::FileSystemType FileSystemType;
FileSystemType value;
SLANG_RETURN_ON_FAIL(_expectValue(value));
-
+
switch (value)
{
- case FileSystemType::Default: m_compileRequest->setFileSystem(nullptr); break;
- case FileSystemType::LoadFile: m_compileRequest->setFileSystem(OSFileSystem::getLoadSingleton()); break;
- case FileSystemType::Os: m_compileRequest->setFileSystem(OSFileSystem::getExtSingleton()); break;
+ case FileSystemType::Default: m_compileRequest->setFileSystem(nullptr); break;
+ case FileSystemType::LoadFile:
+ m_compileRequest->setFileSystem(OSFileSystem::getLoadSingleton());
+ break;
+ case FileSystemType::Os:
+ m_compileRequest->setFileSystem(OSFileSystem::getExtSingleton());
+ break;
}
break;
}
- case OptionKind::ReferenceModule: SLANG_RETURN_ON_FAIL(_parseReferenceModule(arg)); break;
- case OptionKind::Version:
+ case OptionKind::ReferenceModule: SLANG_RETURN_ON_FAIL(_parseReferenceModule(arg)); break;
+ case OptionKind::Version:
{
m_sink->diagnoseRaw(Severity::Note, m_session->getBuildTagString());
break;
}
- case OptionKind::HelpStyle: SLANG_RETURN_ON_FAIL(_expectValue(m_helpStyle)); break;
- case OptionKind::Help:
+ case OptionKind::HelpStyle: SLANG_RETURN_ON_FAIL(_expectValue(m_helpStyle)); break;
+ case OptionKind::Help:
{
SLANG_RETURN_ON_FAIL(_parseHelp(arg));
// We retun an error so after this has successfully passed, we quit
return SLANG_FAIL;
}
- case OptionKind::EmitSpirvViaGLSL:
- case OptionKind::EmitSpirvDirectly:
+ case OptionKind::EmitSpirvViaGLSL:
+ case OptionKind::EmitSpirvDirectly:
{
getCurrentTarget()->optionSet.add(optionKind, true);
}
break;
- case OptionKind::SPIRVCoreGrammarJSON:
+ case OptionKind::SPIRVCoreGrammarJSON:
{
CommandLineArg path;
SLANG_RETURN_ON_FAIL(m_reader.expectArg(path));
@@ -2276,34 +2739,47 @@ SlangResult OptionsParser::_parse(
}
break;
- case OptionKind::DefaultDownstreamCompiler:
+ case OptionKind::DefaultDownstreamCompiler:
{
CommandLineArg sourceLanguageArg, compilerArg;
SLANG_RETURN_ON_FAIL(m_reader.expectArg(sourceLanguageArg));
SLANG_RETURN_ON_FAIL(m_reader.expectArg(compilerArg));
- SlangSourceLanguage sourceLanguage = TypeTextUtil::findSourceLanguage(sourceLanguageArg.value.getUnownedSlice());
+ SlangSourceLanguage sourceLanguage =
+ TypeTextUtil::findSourceLanguage(sourceLanguageArg.value.getUnownedSlice());
if (sourceLanguage == SLANG_SOURCE_LANGUAGE_UNKNOWN)
{
- m_sink->diagnose(sourceLanguageArg.loc, Diagnostics::unknownSourceLanguage, sourceLanguageArg.value);
+ m_sink->diagnose(
+ sourceLanguageArg.loc,
+ Diagnostics::unknownSourceLanguage,
+ sourceLanguageArg.value);
return SLANG_FAIL;
}
SlangPassThrough compiler;
- if (SLANG_FAILED(TypeTextUtil::findPassThrough(compilerArg.value.getUnownedSlice(), compiler)))
+ if (SLANG_FAILED(TypeTextUtil::findPassThrough(
+ compilerArg.value.getUnownedSlice(),
+ compiler)))
{
- m_sink->diagnose(compilerArg.loc, Diagnostics::unknownPassThroughTarget, compilerArg.value);
+ m_sink->diagnose(
+ compilerArg.loc,
+ Diagnostics::unknownPassThroughTarget,
+ compilerArg.value);
return SLANG_FAIL;
}
if (SLANG_FAILED(m_session->setDefaultDownstreamCompiler(sourceLanguage, compiler)))
{
- m_sink->diagnose(arg.loc, Diagnostics::unableToSetDefaultDownstreamCompiler, compilerArg.value, sourceLanguageArg.value);
+ m_sink->diagnose(
+ arg.loc,
+ Diagnostics::unableToSetDefaultDownstreamCompiler,
+ compilerArg.value,
+ sourceLanguageArg.value);
return SLANG_FAIL;
}
break;
}
- case OptionKind::CompilerPath:
+ case OptionKind::CompilerPath:
{
const Index index = argValue.lastIndexOf('-');
if (index >= 0)
@@ -2311,24 +2787,29 @@ SlangResult OptionsParser::_parse(
CommandLineArg name;
SLANG_RETURN_ON_FAIL(m_reader.expectArg(name));
- UnownedStringSlice passThroughSlice = argValue.getUnownedSlice().head(index).tail(1);
+ UnownedStringSlice passThroughSlice =
+ argValue.getUnownedSlice().head(index).tail(1);
// Skip the initial -, up to the last -
SlangPassThrough passThrough = SLANG_PASS_THROUGH_NONE;
- if (SLANG_SUCCEEDED(TypeTextUtil::findPassThrough(passThroughSlice, passThrough)))
+ if (SLANG_SUCCEEDED(
+ TypeTextUtil::findPassThrough(passThroughSlice, passThrough)))
{
m_session->setDownstreamCompilerPath(passThrough, name.value.getBuffer());
continue;
}
else
{
- m_sink->diagnose(arg.loc, Diagnostics::unknownDownstreamCompiler, passThroughSlice);
+ m_sink->diagnose(
+ arg.loc,
+ Diagnostics::unknownDownstreamCompiler,
+ passThroughSlice);
return SLANG_FAIL;
}
}
break;
}
- case OptionKind::InputFilesRemain:
+ case OptionKind::InputFilesRemain:
{
// The `--` option causes us to stop trying to parse options,
// and treat the rest of the command line as input file names:
@@ -2338,23 +2819,24 @@ SlangResult OptionsParser::_parse(
}
break;
}
- case OptionKind::SourceEmbedStyle:
+ case OptionKind::SourceEmbedStyle:
{
SLANG_RETURN_ON_FAIL(_expectValue(m_requestImpl->m_sourceEmbedStyle));
break;
}
- case OptionKind::SourceEmbedName:
+ case OptionKind::SourceEmbedName:
{
CommandLineArg name;
SLANG_RETURN_ON_FAIL(m_reader.expectArg(name));
m_requestImpl->m_sourceEmbedName = name.value;
break;
}
- case OptionKind::SourceEmbedLanguage:
+ case OptionKind::SourceEmbedLanguage:
{
SLANG_RETURN_ON_FAIL(_expectValue(m_requestImpl->m_sourceEmbedLanguage));
- if (!SourceEmbedUtil::isSupported((SlangSourceLanguage)m_requestImpl->m_sourceEmbedLanguage))
+ if (!SourceEmbedUtil::isSupported(
+ (SlangSourceLanguage)m_requestImpl->m_sourceEmbedLanguage))
{
m_sink->diagnose(arg.loc, Diagnostics::unhandledLanguageForSourceEmbedding);
return SLANG_FAIL;
@@ -2362,14 +2844,15 @@ SlangResult OptionsParser::_parse(
break;
}
- case OptionKind::DisableShortCircuit:
+ case OptionKind::DisableShortCircuit:
{
linkage->m_optionSet.add(OptionKind::DisableShortCircuit, true);
break;
}
- default:
+ default:
{
- // Hmmm, we looked up and produced a valid enum, but it wasn't handled in the switch...
+ // Hmmm, we looked up and produced a valid enum, but it wasn't handled in the
+ // switch...
m_sink->diagnose(arg.loc, Diagnostics::unknownCommandLineOption, argValue);
_outputMinimalUsage();
@@ -2395,10 +2878,9 @@ SlangResult OptionsParser::_parse(
// of the translation unit, then we assume they wanted to compile a single
// entry point named `main`.
//
- if (m_rawEntryPoints.getCount() == 0
- && m_rawTranslationUnits.getCount() == 1
- && (m_defaultEntryPoint.stage != Stage::Unknown
- || m_rawTranslationUnits[0].impliedStage != Stage::Unknown))
+ if (m_rawEntryPoints.getCount() == 0 && m_rawTranslationUnits.getCount() == 1 &&
+ (m_defaultEntryPoint.stage != Stage::Unknown ||
+ m_rawTranslationUnits[0].impliedStage != Stage::Unknown))
{
RawEntryPoint entry;
entry.name = "main";
@@ -2437,11 +2919,15 @@ SlangResult OptionsParser::_parse(
{
if (m_rawEntryPoints.getCount() == 0)
{
- m_sink->diagnose(SourceLoc(), Diagnostics::stageSpecificationIgnoredBecauseNoEntryPoints);
+ m_sink->diagnose(
+ SourceLoc(),
+ Diagnostics::stageSpecificationIgnoredBecauseNoEntryPoints);
}
else
{
- m_sink->diagnose(SourceLoc(), Diagnostics::stageSpecificationIgnoredBecauseBeforeAllEntryPoints);
+ m_sink->diagnose(
+ SourceLoc(),
+ Diagnostics::stageSpecificationIgnoredBecauseBeforeAllEntryPoints);
}
}
}
@@ -2457,7 +2943,8 @@ SlangResult OptionsParser::_parse(
entryPoint.translationUnitIndex = 0;
}
}
- else if (m_frontEndReq->additionalLoadedModules &&
+ else if (
+ m_frontEndReq->additionalLoadedModules &&
m_frontEndReq->additionalLoadedModules->getCount() == 0)
{
// Otherwise, we require that all entry points be specified after
@@ -2473,7 +2960,9 @@ SlangResult OptionsParser::_parse(
}
if (anyEntryPointWithoutTranslationUnit)
{
- m_sink->diagnose(SourceLoc(), Diagnostics::entryPointsNeedToBeAssociatedWithTranslationUnits);
+ m_sink->diagnose(
+ SourceLoc(),
+ Diagnostics::entryPointsNeedToBeAssociatedWithTranslationUnits);
return SLANG_FAIL;
}
}
@@ -2494,7 +2983,8 @@ SlangResult OptionsParser::_parse(
if (rawEntryPoint.translationUnitIndex == -1)
continue;
- auto impliedStage = m_rawTranslationUnits[rawEntryPoint.translationUnitIndex].impliedStage;
+ auto impliedStage =
+ m_rawTranslationUnits[rawEntryPoint.translationUnitIndex].impliedStage;
if (impliedStage != Stage::Unknown)
rawEntryPoint.stage = impliedStage;
}
@@ -2512,11 +3002,18 @@ SlangResult OptionsParser::_parse(
{
if (rawEntryPoint.conflictingStagesSet)
{
- m_sink->diagnose(SourceLoc(), Diagnostics::conflictingStagesForEntryPoint, rawEntryPoint.name);
+ m_sink->diagnose(
+ SourceLoc(),
+ Diagnostics::conflictingStagesForEntryPoint,
+ rawEntryPoint.name);
}
else if (rawEntryPoint.redundantStageSet)
{
- m_sink->diagnose(SourceLoc(), Diagnostics::sameStageSpecifiedMoreThanOnce, rawEntryPoint.stage, rawEntryPoint.name);
+ m_sink->diagnose(
+ SourceLoc(),
+ Diagnostics::sameStageSpecifiedMoreThanOnce,
+ rawEntryPoint.stage,
+ rawEntryPoint.name);
}
else if (rawEntryPoint.translationUnitIndex != -1)
{
@@ -2524,12 +3021,18 @@ SlangResult OptionsParser::_parse(
// stage, but the user manually specified something different for
// their entry point, give a warning in case they made a mistake.
- auto& rawTranslationUnit = m_rawTranslationUnits[rawEntryPoint.translationUnitIndex];
- if (rawTranslationUnit.impliedStage != Stage::Unknown
- && rawEntryPoint.stage != Stage::Unknown
- && rawTranslationUnit.impliedStage != rawEntryPoint.stage)
+ auto& rawTranslationUnit =
+ m_rawTranslationUnits[rawEntryPoint.translationUnitIndex];
+ if (rawTranslationUnit.impliedStage != Stage::Unknown &&
+ rawEntryPoint.stage != Stage::Unknown &&
+ rawTranslationUnit.impliedStage != rawEntryPoint.stage)
{
- m_sink->diagnose(SourceLoc(), Diagnostics::explicitStageDoesntMatchImpliedStage, rawEntryPoint.name, rawEntryPoint.stage, rawTranslationUnit.impliedStage);
+ m_sink->diagnose(
+ SourceLoc(),
+ Diagnostics::explicitStageDoesntMatchImpliedStage,
+ rawEntryPoint.name,
+ rawEntryPoint.stage,
+ rawTranslationUnit.impliedStage);
}
}
}
@@ -2545,7 +3048,10 @@ SlangResult OptionsParser::_parse(
{
if (rawEntryPoint.stage == Stage::Unknown)
{
- m_sink->diagnose(SourceLoc(), Diagnostics::noStageSpecifiedInPassThroughMode, rawEntryPoint.name);
+ m_sink->diagnose(
+ SourceLoc(),
+ Diagnostics::noStageSpecifiedInPassThroughMode,
+ rawEntryPoint.name);
}
}
}
@@ -2558,7 +3064,8 @@ SlangResult OptionsParser::_parse(
if (rawEntryPoint.translationUnitIndex < 0)
continue;
- auto translationUnitID = m_rawTranslationUnits[rawEntryPoint.translationUnitIndex].translationUnitID;
+ auto translationUnitID =
+ m_rawTranslationUnits[rawEntryPoint.translationUnitIndex].translationUnitID;
List<const char*> specializationArgs;
for (auto& arg : rawEntryPoint.specializationArgs)
@@ -2592,7 +3099,8 @@ SlangResult OptionsParser::_parse(
{
for (auto& rawOutput : m_rawOutputs)
{
- // Some outputs don't imply a target format, and we shouldn't use those for inference.
+ // Some outputs don't imply a target format, and we shouldn't use those for
+ // inference.
auto impliedFormat = rawOutput.impliedFormat;
if (impliedFormat == CodeGenTarget::Unknown)
continue;
@@ -2640,9 +3148,9 @@ SlangResult OptionsParser::_parse(
// because there were no output paths), but there was a profile specified,
// then we can try to infer a target from the profile.
//
- if (m_rawTargets.getCount() == 0
- && m_defaultTarget.optionSet.getProfileVersion() != ProfileVersion::Unknown
- && !m_defaultTarget.conflictingProfilesSet)
+ if (m_rawTargets.getCount() == 0 &&
+ m_defaultTarget.optionSet.getProfileVersion() != ProfileVersion::Unknown &&
+ !m_defaultTarget.conflictingProfilesSet)
{
// Let's see if the chosen profile allows us to infer
// the code gen target format that the user probably meant.
@@ -2693,7 +3201,9 @@ SlangResult OptionsParser::_parse(
// Similar to the case for entry points, if there is a single target,
// then we allow some of its options to come from the "default"
// target state.
- auto defaultTargetFloatingPointMode = m_defaultTarget.optionSet.getEnumOption<FloatingPointMode>(CompilerOptionName::FloatingPointMode);
+ auto defaultTargetFloatingPointMode =
+ m_defaultTarget.optionSet.getEnumOption<FloatingPointMode>(
+ CompilerOptionName::FloatingPointMode);
if (m_rawTargets.getCount() == 1)
{
@@ -2713,11 +3223,15 @@ SlangResult OptionsParser::_parse(
// so we didn't try to infer a target, or if the `-profile` option
// somehow didn't imply a target.
//
- m_sink->diagnose(SourceLoc(), Diagnostics::profileSpecificationIgnoredBecauseNoTargets);
+ m_sink->diagnose(
+ SourceLoc(),
+ Diagnostics::profileSpecificationIgnoredBecauseNoTargets);
}
else
{
- m_sink->diagnose(SourceLoc(), Diagnostics::profileSpecificationIgnoredBecauseBeforeAllTargets);
+ m_sink->diagnose(
+ SourceLoc(),
+ Diagnostics::profileSpecificationIgnoredBecauseBeforeAllTargets);
}
}
@@ -2729,20 +3243,28 @@ SlangResult OptionsParser::_parse(
}
else
{
- m_sink->diagnose(SourceLoc(), Diagnostics::targetFlagsIgnoredBecauseBeforeAllTargets);
+ m_sink->diagnose(
+ SourceLoc(),
+ Diagnostics::targetFlagsIgnoredBecauseBeforeAllTargets);
}
}
-
}
for (auto& rawTarget : m_rawTargets)
{
if (rawTarget.conflictingProfilesSet)
{
- m_sink->diagnose(SourceLoc(), Diagnostics::conflictingProfilesSpecifiedForTarget, rawTarget.format);
+ m_sink->diagnose(
+ SourceLoc(),
+ Diagnostics::conflictingProfilesSpecifiedForTarget,
+ rawTarget.format);
}
else if (rawTarget.redundantProfileSet)
{
- m_sink->diagnose(SourceLoc(), Diagnostics::sameProfileSpecifiedMoreThanOnce, rawTarget.optionSet.getProfileVersion(), rawTarget.format);
+ m_sink->diagnose(
+ SourceLoc(),
+ Diagnostics::sameProfileSpecifiedMoreThanOnce,
+ rawTarget.optionSet.getProfileVersion(),
+ rawTarget.format);
}
}
@@ -2759,17 +3281,22 @@ SlangResult OptionsParser::_parse(
if (rawTarget.optionSet.getProfileVersion() != ProfileVersion::Unknown)
{
- m_compileRequest->setTargetProfile(targetID, SlangProfileID(Profile(rawTarget.optionSet.getProfileVersion()).raw));
+ m_compileRequest->setTargetProfile(
+ targetID,
+ SlangProfileID(Profile(rawTarget.optionSet.getProfileVersion()).raw));
}
for (auto atom : rawTarget.optionSet.getArray(CompilerOptionName::Capability))
{
m_requestImpl->addTargetCapability(targetID, SlangCapabilityID(atom.intValue));
}
- auto floatingPointMode = rawTarget.optionSet.getEnumOption<FloatingPointMode>(CompilerOptionName::FloatingPointMode);
+ auto floatingPointMode = rawTarget.optionSet.getEnumOption<FloatingPointMode>(
+ CompilerOptionName::FloatingPointMode);
if (floatingPointMode != FloatingPointMode::Default)
{
- m_compileRequest->setTargetFloatingPointMode(targetID, SlangFloatingPointMode(floatingPointMode));
+ m_compileRequest->setTargetFloatingPointMode(
+ targetID,
+ SlangFloatingPointMode(floatingPointMode));
}
if (rawTarget.optionSet.shouldUseScalarLayout())
@@ -2791,7 +3318,6 @@ SlangResult OptionsParser::_parse(
{
m_compileRequest->setTargetEmbedDownstreamIR(targetID, true);
}
-
}
// Next we need to sort out the output files specified with `-o`, and
@@ -2819,25 +3345,25 @@ SlangResult OptionsParser::_parse(
}
}
- // If we don't have any raw outputs but do have a raw target,
- // add an empty' rawOutput for certain targets where the expected behavior is obvious.
- if (m_rawOutputs.getCount() == 0 &&
- m_rawTargets.getCount() == 1 &&
- (m_rawTargets[0].format == CodeGenTarget::HostCPPSource ||
- m_rawTargets[0].format == CodeGenTarget::PyTorchCppBinding ||
- m_rawTargets[0].format == CodeGenTarget::CUDASource ||
- m_rawTargets[0].format == CodeGenTarget::SPIRV ||
- m_rawTargets[0].format == CodeGenTarget::SPIRVAssembly ||
- m_rawTargets[0].format == CodeGenTarget::Metal ||
- m_rawTargets[0].format == CodeGenTarget::MetalLib ||
- m_rawTargets[0].format == CodeGenTarget::MetalLibAssembly ||
- ArtifactDescUtil::makeDescForCompileTarget(asExternal(m_rawTargets[0].format)).kind == ArtifactKind::HostCallable))
- {
- RawOutput rawOutput;
- rawOutput.impliedFormat = m_rawTargets[0].format;
- rawOutput.targetIndex = 0;
- m_rawOutputs.add(rawOutput);
- }
+ // If we don't have any raw outputs but do have a raw target,
+ // add an empty' rawOutput for certain targets where the expected behavior is obvious.
+ if (m_rawOutputs.getCount() == 0 && m_rawTargets.getCount() == 1 &&
+ (m_rawTargets[0].format == CodeGenTarget::HostCPPSource ||
+ m_rawTargets[0].format == CodeGenTarget::PyTorchCppBinding ||
+ m_rawTargets[0].format == CodeGenTarget::CUDASource ||
+ m_rawTargets[0].format == CodeGenTarget::SPIRV ||
+ m_rawTargets[0].format == CodeGenTarget::SPIRVAssembly ||
+ m_rawTargets[0].format == CodeGenTarget::Metal ||
+ m_rawTargets[0].format == CodeGenTarget::MetalLib ||
+ m_rawTargets[0].format == CodeGenTarget::MetalLibAssembly ||
+ ArtifactDescUtil::makeDescForCompileTarget(asExternal(m_rawTargets[0].format)).kind ==
+ ArtifactKind::HostCallable))
+ {
+ RawOutput rawOutput;
+ rawOutput.impliedFormat = m_rawTargets[0].format;
+ rawOutput.targetIndex = 0;
+ m_rawOutputs.add(rawOutput);
+ }
// Consider the output files specified via `-o` and try to figure
// out how to deal with them.
@@ -2862,7 +3388,10 @@ SlangResult OptionsParser::_parse(
// format, but the file path doesn't direclty imply a format
// (it doesn't have a suffix like `.spv` that tells us what to write).
//
- m_sink->diagnose(SourceLoc(), Diagnostics::cannotDeduceOutputFormatFromPath, rawOutput.path);
+ m_sink->diagnose(
+ SourceLoc(),
+ Diagnostics::cannotDeduceOutputFormatFromPath,
+ rawOutput.path);
}
else if (mapFormatToTargetIndex.tryGetValue(rawOutput.impliedFormat, targetIndex))
{
@@ -2870,7 +3399,11 @@ SlangResult OptionsParser::_parse(
}
else
{
- m_sink->diagnose(SourceLoc(), Diagnostics::cannotMatchOutputFileToTarget, rawOutput.path, rawOutput.impliedFormat);
+ m_sink->diagnose(
+ SourceLoc(),
+ Diagnostics::cannotMatchOutputFileToTarget,
+ rawOutput.path,
+ rawOutput.impliedFormat);
}
}
@@ -2901,9 +3434,7 @@ SlangResult OptionsParser::_parse(
case CodeGenTarget::DXIL:
case CodeGenTarget::MetalLib:
case CodeGenTarget::MetalLibAssembly:
- case CodeGenTarget::Metal:
- rawOutput.isWholeProgram = true;
- break;
+ case CodeGenTarget::Metal: rawOutput.isWholeProgram = true; break;
case CodeGenTarget::SPIRV:
case CodeGenTarget::SPIRVAssembly:
if (getCurrentTarget()->optionSet.shouldEmitSPIRVDirectly())
@@ -2920,7 +3451,10 @@ SlangResult OptionsParser::_parse(
default:
if (rawOutput.path.getLength() != 0)
{
- m_sink->diagnose(SourceLoc(), Diagnostics::cannotMatchOutputFileToEntryPoint, rawOutput.path);
+ m_sink->diagnose(
+ SourceLoc(),
+ Diagnostics::cannotMatchOutputFileToEntryPoint,
+ rawOutput.path);
}
break;
}
@@ -2937,7 +3471,8 @@ SlangResult OptionsParser::_parse(
//
for (auto& rawOutput : m_rawOutputs)
{
- if (rawOutput.targetIndex == -1) continue;
+ if (rawOutput.targetIndex == -1)
+ continue;
auto targetID = m_rawTargets[rawOutput.targetIndex].targetID;
auto target = m_requestImpl->getLinkage()->targets[targetID];
RefPtr<EndToEndCompileRequest::TargetInfo> targetInfo;
@@ -2951,7 +3486,10 @@ SlangResult OptionsParser::_parse(
{
if (targetInfo->wholeTargetOutputPath != "")
{
- m_sink->diagnose(SourceLoc(), Diagnostics::duplicateOutputPathsForTarget, target->getTarget());
+ m_sink->diagnose(
+ SourceLoc(),
+ Diagnostics::duplicateOutputPathsForTarget,
+ target->getTarget());
}
else
{
@@ -2961,21 +3499,29 @@ SlangResult OptionsParser::_parse(
}
else
{
- if (rawOutput.entryPointIndex == -1) continue;
+ if (rawOutput.entryPointIndex == -1)
+ continue;
auto entryPoint = m_rawEntryPoints[rawOutput.entryPointIndex];
Int entryPointID = entryPoint.entryPointID;
if (entryPointID == -1)
{
- m_sink->diagnose(SourceLoc(), Diagnostics::entryPointFunctionNotFound, entryPoint.name);
+ m_sink->diagnose(
+ SourceLoc(),
+ Diagnostics::entryPointFunctionNotFound,
+ entryPoint.name);
continue;
}
auto entryPointReq = m_requestImpl->getFrontEndReq()->getEntryPointReqs()[entryPointID];
- //String outputPath;
+ // String outputPath;
if (targetInfo->entryPointOutputPaths.containsKey(entryPointID))
{
- m_sink->diagnose(SourceLoc(), Diagnostics::duplicateOutputPathsForEntryPointAndTarget, entryPointReq->getName(), target->getTarget());
+ m_sink->diagnose(
+ SourceLoc(),
+ Diagnostics::duplicateOutputPathsForEntryPointAndTarget,
+ entryPointReq->getName(),
+ target->getTarget());
}
else
{
@@ -2990,8 +3536,9 @@ SlangResult OptionsParser::_parse(
{
target->getOptionSet().inheritFrom(linkage->m_optionSet);
- // If there is no target specified in command line, we should inherit the default target options.
- if(m_rawTargets.getCount() == 0)
+ // If there is no target specified in command line, we should inherit the default target
+ // options.
+ if (m_rawTargets.getCount() == 0)
{
target->getOptionSet().inheritFrom(m_defaultTarget.optionSet);
}
@@ -3004,7 +3551,7 @@ SlangResult OptionsParser::_parse(
{
m_requestImpl->m_optionSetForDefaultTarget = m_defaultTarget.optionSet;
}
-
+
applySettingsToDiagnosticSink(m_requestImpl->getSink(), m_sink, linkage->m_optionSet);
return (m_sink->getErrorCount() == 0) ? SLANG_OK : SLANG_FAIL;
@@ -3012,11 +3559,11 @@ SlangResult OptionsParser::_parse(
SlangResult OptionsParser::parse(
SlangCompileRequest* compileRequest,
- int argc,
+ int argc,
char const* const* argv)
{
m_compileRequest = compileRequest;
-
+
// Set up useful members
m_requestImpl = asInternal(compileRequest);
@@ -3033,24 +3580,25 @@ SlangResult OptionsParser::parse(
// Why create a new DiagnosticSink?
// We *don't* want the lexer that comes as default (it's for Slang source!)
// We may want to set flags that are different
- // We will need to use a new sourceManager that will just last for this parse and will map locs to
- // source lines.
+ // We will need to use a new sourceManager that will just last for this parse and will map locs
+ // to source lines.
//
// The *problem* is that we still need to communicate to the requestSink in some suitable way.
//
// 1) We could have some kind of scoping mechanism (and only one sink)
// 2) We could have a 'parent' diagnostic sink, that if we set we route output too
- // 3) We use something like the ISlangWriter to always be the thing output too (this has problems because
- // some code assumes the diagnostics are accessible as a string)
+ // 3) We use something like the ISlangWriter to always be the thing output too (this has
+ // problems because some code assumes the diagnostics are accessible as a string)
//
- // The solution used here is to have DiagnosticsSink have a 'parent' that also gets diagnostics reported to.
+ // The solution used here is to have DiagnosticsSink have a 'parent' that also gets diagnostics
+ // reported to.
m_parseSink.init(m_cmdLineContext->getSourceManager(), nullptr);
{
m_parseSink.setFlags(requestSink->getFlags());
// Allow HumaneLoc - it won't display much for command line parsing - just (1):
// Leaving allows for diagnostics to be compatible with other Slang diagnostic parsing.
- //parseSink.resetFlag(DiagnosticSink::Flag::HumaneLoc);
+ // parseSink.resetFlag(DiagnosticSink::Flag::HumaneLoc);
m_parseSink.setFlag(DiagnosticSink::Flag::SourceLocationLine);
}
@@ -3059,22 +3607,19 @@ SlangResult OptionsParser::parse(
m_sink = &m_parseSink;
Result res = _parse(argc, argv);
-
+
m_sink = nullptr;
if (m_parseSink.getErrorCount() > 0)
{
- // Put the errors in the diagnostic
+ // Put the errors in the diagnostic
m_requestImpl->m_diagnosticOutput = m_parseSink.outputBuffer.produceString();
}
return res;
}
-SlangResult parseOptions(
- SlangCompileRequest* inCompileRequest,
- int argc,
- char const* const* argv)
+SlangResult parseOptions(SlangCompileRequest* inCompileRequest, int argc, char const* const* argv)
{
OptionsParser parser;
return parser.parse(inCompileRequest, argc, argv);
@@ -3082,5 +3627,3 @@ SlangResult parseOptions(
} // namespace Slang
-
-