From 19c0866b050a022406867aa650302f4efbf8e010 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Sat, 29 Apr 2023 09:24:26 -0400 Subject: CommandOptions (#2856) * WIP CommandOptions * Fix some output issues. * Simplify word wrapping. * Add file extensions. * Change how lookup takes place. Add appendSplit functions to StringUtil. Make Categories hold the index range of their options. * Small improvement. * Lookup with partial option names. * Associate user values. * Encoding flags in the name. * Refactor setting up of command options. * Use CommandOptions in slang-options. * Remove old help text. * Cache the CommandOptions on the Session. * Range checking. Fix bug in the Options handling. * Extra checks for validity. * Get categories directly. * Slight improvements over output. * Added NameValue types. * Fix typo. Remove some now unused diagnostics. Fix diagnostic in testing, as output has changed. * Add minimal usage message. * Remove platform executable extension from diagnostics output. * Some improvements around getting names from NameValue types. * Improve some option descriptions. * Small fixes. --- source/slang/slang-capability.cpp | 9 + source/slang/slang-capability.h | 4 + source/slang/slang-compiler.cpp | 13 +- source/slang/slang-compiler.h | 4 + source/slang/slang-diagnostic-defs.h | 5 +- source/slang/slang-options.cpp | 1223 +++++++++++++++++++++------------- source/slang/slang-options.h | 4 + source/slang/slang-profile.h | 8 + source/slang/slang.cpp | 4 + 9 files changed, 795 insertions(+), 479 deletions(-) (limited to 'source/slang') diff --git a/source/slang/slang-capability.cpp b/source/slang/slang-capability.cpp index 770685247..28dea8d23 100644 --- a/source/slang/slang-capability.cpp +++ b/source/slang/slang-capability.cpp @@ -117,6 +117,15 @@ static CapabilityAtomInfo const& _getInfo(CapabilityAtom atom) return kCapabilityAtoms[Int(atom)]; } +void getCapabilityAtomNames(List& ioNames) +{ + ioNames.setCount(Count(CapabilityAtom::Count)); + for (Index i = 0; i < Count(CapabilityAtom::Count); ++i) + { + ioNames[i] = UnownedStringSlice(_getInfo(CapabilityAtom(i)).name); + } +} + CapabilityAtom findCapabilityAtom(UnownedStringSlice const& name) { // For now we are implementing a linear search over the diff --git a/source/slang/slang-capability.h b/source/slang/slang-capability.h index 90b03ed29..55c5044ed 100644 --- a/source/slang/slang-capability.h +++ b/source/slang/slang-capability.h @@ -161,4 +161,8 @@ bool isCapabilityDerivedFrom(CapabilityAtom atom, CapabilityAtom base); /// Find a capability atom with the given `name`, or return CapabilityAtom::Invalid. CapabilityAtom findCapabilityAtom(UnownedStringSlice const& name); + + /// Gets the capability names. +void getCapabilityAtomNames(List& ioNames); + } diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp index 0aa7e48a9..4ca76c53a 100644 --- a/source/slang/slang-compiler.cpp +++ b/source/slang/slang-compiler.cpp @@ -372,13 +372,9 @@ namespace Slang } } - static const struct + static const StageInfo kStages[] = { - char const* name; - Stage stage; - } kStages[] = - { - #define PROFILE_STAGE(ID, NAME, ENUM) \ + #define PROFILE_STAGE(ID, NAME, ENUM) \ { #NAME, Stage::ID }, #define PROFILE_STAGE_ALIAS(ID, NAME, VAL) \ @@ -387,6 +383,11 @@ namespace Slang #include "slang-profile-defs.h" }; + ConstArrayView getStageInfos() + { + return makeConstArrayView(kStages); + } + Stage findStageByName(String const& name) { for(auto entry : kStages) diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index 83acbdd9d..fc46b25b6 100755 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -13,6 +13,7 @@ #include "../compiler-core/slang-command-line-args.h" #include "../core/slang-std-writers.h" +#include "../core/slang-command-options.h" #include "../../slang-com-ptr.h" @@ -3005,6 +3006,9 @@ namespace Slang DownstreamCompilerLocatorFunc m_downstreamCompilerLocators[int(PassThroughMode::CountOf)]; Name* m_completionTokenName = nullptr; ///< The name of a completion request token. + /// For parsing command line options + CommandOptions m_commandOptions; + private: void _initCodeGenTransitionMap(); diff --git a/source/slang/slang-diagnostic-defs.h b/source/slang/slang-diagnostic-defs.h index cb441ade8..8738c71cc 100644 --- a/source/slang/slang-diagnostic-defs.h +++ b/source/slang/slang-diagnostic-defs.h @@ -76,8 +76,6 @@ DIAGNOSTIC( 19, Error, unknownSourceLanguage, "unknown source language '$0'") DIAGNOSTIC( 20, Error, entryPointsNeedToBeAssociatedWithTranslationUnits, "when using multiple source files, entry points must be specified after their corresponding source file(s)") DIAGNOSTIC( 22, Error, unknownDownstreamCompiler, "unknown downstream compiler '$0'") -DIAGNOSTIC( 24, Error, unknownLineDirectiveMode, "unknown '#line' directive mode '$0'") -DIAGNOSTIC( 25, Error, unknownFloatingPointMode, "unknown floating-point mode '$0'") DIAGNOSTIC( 26, Error, unknownOptimiziationLevel, "unknown optimization level '$0'") DIAGNOSTIC( 27, Error, unknownDebugInfoLevel, "unknown debug info level '$0'") @@ -104,6 +102,9 @@ DIAGNOSTIC( 50, Error, duplicateTargets, "the target '$0' has been specified DIAGNOSTIC( 60, Error, cannotDeduceOutputFormatFromPath, "cannot infer an output format from the output path '$0'") DIAGNOSTIC( 61, Error, cannotMatchOutputFileToTarget, "no specified '-target' option matches the output path '$0', which implies the '$1' format") +DIAGNOSTIC( 62, Error, unknownCommandLineValue, "unknown value for option. Valid values are '$0'") +DIAGNOSTIC( 63, Error, unknownHelpCategory, "unknown help category") + DIAGNOSTIC( 70, Error, cannotMatchOutputFileToEntryPoint, "the output path '$0' is not associated with any entry point; a '-o' option for a compiled kernel must follow the '-entry' option for its corresponding entry point") DIAGNOSTIC( 80, Error, duplicateOutputPathsForEntryPointAndTarget, "multiple output paths have been specified entry point '$0' on target '$1'") diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp index 8817095df..6cb53496f 100644 --- a/source/slang/slang-options.cpp +++ b/source/slang/slang-options.cpp @@ -29,12 +29,494 @@ #include "../compiler-core/slang-artifact-desc-util.h" #include "../compiler-core/slang-core-diagnostics.h" +#include "../core/slang-string-slice-pool.h" #include "../core/slang-char-util.h" +#include "../core/slang-command-options.h" + #include namespace Slang { +namespace { // anonymous + +// All of the options are given an unique enum +enum class OptionKind +{ + // General + + MacroDefine, + DepFile, + EntryPointName, + Help, + Include, + Language, + MatrixLayoutColumn, + MatrixLayoutRow, + ModuleName, + Output, + Profile, + Stage, + Target, + Version, + WarningsAsErrors, + DisableWarnings, + EnableWarning, + DisableWarning, + DumpWarningDiagnostics, + InputFilesRemain, + EmitIr, + + // Target + + Capability, + DefaultImageFormatUnknown, + DisableDynamicDispatch, + DisableSpecialization, + FloatingPointMode, + DebugInformation, + LineDirectiveMode, + Optimization, + Obfuscate, + + // Downstream + + CompilerPath, + DefaultDownstreamCompiler, + DownstreamArgs, + PassThrough, + + // Debugging + + DumpAst, + DumpIntermediatePrefix, + DumpIntermediates, + DumpIr, + DumpIrIds, + DumpRepro, + DumpReproOnError, + PreprocessorOutput, + ExtractRepro, + LoadRepro, + LoadReproDirectory, + NoCodeGen, + OutputIncludes, + ReproFileSystem, + SerialIr, + SkipCodeGen, + ValidateIr, + VerbosePaths, + VerifyDebugSerialIr, + + // Experimental + + EmitSpirvDirectly, + FileSystem, + Heterogeneous, + NoMangle, + + // Internal + + ArchiveType, + CompileStdLib, + Doc, + IrCompression, + LoadStdLib, + ReferenceModule, + SaveStdLib, + SaveStdLibBinSource, + TrackLiveness, + + // Depreciated + 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, + + CountOf, +}; + +} // anonymous + +static void _addOptions(const ConstArrayView