// slang-options.cpp // Implementation of options parsing for `slangc` command line, // and also for API interface that takes command-line argument strings. #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-source-embed-util.h" #include "../core/slang-string-slice-pool.h" #include "../core/slang-char-util.h" #include "../core/slang-name-value.h" #include "../core/slang-command-options-writer.h" #include namespace Slang { namespace { // anonymous // All of the options are given an unique enum enum class OptionKind { // General MacroDefine, DepFile, EntryPointName, Help, HelpStyle, Include, Language, MatrixLayoutColumn, MatrixLayoutRow, ModuleName, Output, Profile, Stage, Target, Version, WarningsAsErrors, DisableWarnings, EnableWarning, DisableWarning, DumpWarningDiagnostics, InputFilesRemain, EmitIr, ReportDownstreamTime, ReportPerfBenchmark, SourceEmbedStyle, SourceEmbedName, SourceEmbedLanguage, // Target Capability, DefaultImageFormatUnknown, DisableDynamicDispatch, DisableSpecialization, FloatingPointMode, DebugInformation, LineDirectiveMode, Optimization, Obfuscate, VulkanBindShift, VulkanBindGlobals, VulkanInvertY, VulkanUseEntryPointName, VulkanUseGLLayout, VulkanEmitReflection, GLSLForceScalarLayout, EnableEffectAnnotations, EmitSpirvViaGLSL, EmitSpirvDirectly, SPIRVCoreGrammarJSON, // Downstream CompilerPath, DefaultDownstreamCompiler, DownstreamArgs, PassThrough, // Repro DumpRepro, DumpReproOnError, ExtractRepro, LoadRepro, LoadReproDirectory, ReproFallbackDirectory, // Debugging DumpAst, DumpIntermediatePrefix, DumpIntermediates, DumpIr, DumpIrIds, PreprocessorOutput, NoCodeGen, OutputIncludes, ReproFileSystem, SerialIr, SkipCodeGen, ValidateIr, VerbosePaths, VerifyDebugSerialIr, // Experimental FileSystem, Heterogeneous, NoMangle, AllowGLSL, // Internal ArchiveType, CompileStdLib, Doc, IrCompression, LoadStdLib, ReferenceModule, SaveStdLib, SaveStdLibBinSource, TrackLiveness, // Deprecated ParameterBlocksUseRegisterSpaces, CountOf, }; struct Option { OptionKind optionKind; const char* name; const char* usage = nullptr; const char* description = nullptr; }; enum class ValueCategory { Compiler, Target, Language, FloatingPointMode, ArchiveType, Stage, LineDirectiveMode, DebugInfoFormat, HelpStyle, OptimizationLevel, DebugLevel, FileSystemType, VulkanShift, SourceEmbedStyle, CountOf, }; template struct GetValueCategory; #define SLANG_GET_VALUE_CATEGORY(cat, type) template <> struct GetValueCategory { enum { Value = Index(ValueCategory::cat) }; }; SLANG_GET_VALUE_CATEGORY(Compiler, SlangPassThrough) SLANG_GET_VALUE_CATEGORY(ArchiveType, SlangArchiveType) SLANG_GET_VALUE_CATEGORY(LineDirectiveMode, SlangLineDirectiveMode) SLANG_GET_VALUE_CATEGORY(FloatingPointMode, FloatingPointMode) SLANG_GET_VALUE_CATEGORY(FileSystemType, TypeTextUtil::FileSystemType) SLANG_GET_VALUE_CATEGORY(HelpStyle, CommandOptionsWriter::Style) SLANG_GET_VALUE_CATEGORY(OptimizationLevel, SlangOptimizationLevel) SLANG_GET_VALUE_CATEGORY(VulkanShift, HLSLToVulkanLayoutOptions::Kind) SLANG_GET_VALUE_CATEGORY(SourceEmbedStyle, SourceEmbedUtil::Style) SLANG_GET_VALUE_CATEGORY(Language, SourceLanguage) } // anonymous static void _addOptions(const ConstArrayView