From 2a80bcfa96089967b299eea0454d9debe52fa0f6 Mon Sep 17 00:00:00 2001 From: Alexey Panteleev Date: Tue, 8 Mar 2022 12:16:32 -0800 Subject: Slangc improvements: help message, downstream error passthrough (#2152) * Pass through the downstream compiler error messages if they are not recognized. * Added a help message that is printed on -h, -help, --help. Added -version as an alias for -v. * Fixed the bug in -lang option processing. --- source/compiler-core/slang-downstream-compiler.cpp | 2 +- source/slang/slang-options.cpp | 221 ++++++++++++++++++++- 2 files changed, 220 insertions(+), 3 deletions(-) diff --git a/source/compiler-core/slang-downstream-compiler.cpp b/source/compiler-core/slang-downstream-compiler.cpp index daf31c9eb..1dfaea0a4 100644 --- a/source/compiler-core/slang-downstream-compiler.cpp +++ b/source/compiler-core/slang-downstream-compiler.cpp @@ -221,7 +221,7 @@ void DownstreamDiagnostics::requireErrorDiagnostic() DownstreamDiagnostic diagnostic; diagnostic.reset(); diagnostic.severity = DownstreamDiagnostic::Severity::Error; - diagnostic.text = "Generic error during compilation"; + diagnostic.text = rawDiagnostics; // Add the diagnostic diagnostics.add(diagnostic); diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp index 07f474c78..5d8d52a09 100644 --- a/source/slang/slang-options.cpp +++ b/source/slang/slang-options.cpp @@ -487,6 +487,218 @@ struct OptionsParser return SLANG_OK; } + static char const* getHelpText() + { +#ifdef _WIN32 +#define EXECUTABLE_EXTENSION ".exe" +#else +#define EXECUTABLE_EXTENSION "" +#endif + + return + "Usage: slangc" EXECUTABLE_EXTENSION " [options...] [--] \n" + "\n" + "General options:\n" + "\n" + " -D[=], -D [=]: Insert a preprocessor macro.\n" + " -entry : Specify the name of an entry-point function.\n" + " Multiple -entry options may be used in a single invocation.\n" + " If no -entry options are given, compiler will use [shader(...)]\n" + " attributes to detect entry points.\n" + " -h, -help, --help: Print this message.\n" + " -I, -I : Add a path to be used in resolving '#include'\n" + " and 'import' operations.\n" + " -lang : Set the language for the following input files.\n" + " Accepted languages are:\n" + " c, cpp, c++, cxx, slang, glsl, hlsl, cu, cuda\n" + " -matrix-layout-column-major: Set the default matrix layout to column-major.\n" + " -matrix-layout-row-major: Set the default matrix layout to row-major.\n" + " -module-name : Set the module name to use when compiling multiple\n" + " .slang source files into a single module.\n" + " -o : Specify a path where generated output should be written.\n" + " If no -target or -stage is specified, one may be inferred\n" + " from file extension (see File Extensions).\n" + " If multiple -target options and a single -entry are present, each -o\n" + " associates with the first -target to its left.\n" + " Otherwise, if multiple -entry options are present, each -o associates\n" + " with the first -entry to its left, and with the -target that matches\n" + " the one inferred from .\n" + " -profile [+...]: Specify the shader profile for code\n" + " 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}_\n" + " See -capability for information on \n" + " When multiple -target options are present, each -profile associates\n" + " with the first -target to its left.\n" + " -stage : Specify the stage of an entry-point function.\n" + " Accepted stages are:\n" + " vertex, hull, domain, geometry, fragment, compute,\n" + " raygeneration, intersection, anyhit, closesthit, miss, callable\n" + " When multiple -entry options are present, each -stage associated with\n" + " the first -entry to its left.\n" + " May be omitted if entry-point function has a [shader(...)] attribute;\n" + " otherwise required for each -entry option.\n" + " -target : Specifies the format in which code should be generated.\n" + " Accepted formats are:\n" + " glsl, hlsl, spirv, spirv-assembly, dxbc,\n" + " dxbc-assembly, dxil, dxil-assembly\n" + " -v, -version: Display the build version.\n" + " --: Treat the rest of the command line as input files.\n" + "\n" + "Target code generation options:\n" + "\n" + " -capability [+...]: Add optional capabilities\n" + " to a code generation target. See Capabilities below.\n" + " -default-image-format-unknown: Set the format of R/W images with unspecified\n" + " format to 'unknown'. Otherwise try to guess the format.\n" + " -disable-dynamic-dispatch: Disables generating dynamic dispatch code.\n" + " -disable-specialization: Disables generics and specialization pass.\n" + " -fp-mode , -floating-point-mode : Set the floating point mode.\n" + " Accepted modes are:\n" + " precise : Disable optimization that could change the output of floating-\n" + " point computations, including around infinities, NaNs, denormalized\n" + " values, and negative zero. Prefer the most precise versions of special\n" + " functions supported by the target.\n" + " fast : Allow optimizations that may change results of floating-point\n" + " computations. Prefer the fastest version of special functions supported\n" + " by the target.\n" + " -g, -g: Include debug information in the generated code, where possible.\n" + " N is the amount of information, 0..3, unspecified means 2\n" + " -line-directive-mode : Sets how the `#line` directives should be\n" + " produced. Available options are:\n" + " none : Don't emit `#line` directives at all\n" + " If not specified, default behavior is to use C-style `#line` directives\n" + " for HLSL and C/C++ output, and traditional GLSL-style `#line` directives\n" + " for GLSL output.\n" + " -O: Set the optimization level.\n" + " N is the amount of optimization, 0..3, default is 1\n" + " -obfuscate: Remove all source file information from outputs.\n" + "\n" + "Downstream compiler options:\n" + "\n" + " --path: Specify path to a downstream \n" + " executable or library. Accepted compilers are:\n" + " fxc (d3dcompiler_47.dll)\n" + " dxc (dxcompiler.*)\n" + " glslang (slang-glslang.*)\n" + " vs = visualstudio (cl.exe)\n" + " clang\n" + " gcc (g++)\n" + " c = cpp = genericcpp\n" + " nvrtc\n" + " llvm\n" + " -default-downstream-compiler : Set a default compiler\n" + " for the given language. See -lang for the list of languages.\n" + " -X