Mesa (master): spirv2nir: Rework argument handling

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Sep 7 15:14:15 UTC 2020


Module: Mesa
Branch: master
Commit: 013a2b123d75ed53af603e23a8f6fd0d6e3b5490
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=013a2b123d75ed53af603e23a8f6fd0d6e3b5490

Author: Jason Ekstrand <jason at jlekstrand.net>
Date:   Fri Sep  4 17:14:39 2020 -0500

spirv2nir: Rework argument handling

The argument handling of this little tool was pretty rubbish.  It had no
help and it required the filename to come first which is just strange.
This reworks it and makes things much nicer.  It's still rubbish but at
least there's a chance people can figure out how to use it now.

Reviewed-by: Iago Toral Quiroga <itoral at igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6607>

---

 src/compiler/spirv/spirv2nir.c | 53 +++++++++++++++++++++++++++++-------------
 1 file changed, 37 insertions(+), 16 deletions(-)

diff --git a/src/compiler/spirv/spirv2nir.c b/src/compiler/spirv/spirv2nir.c
index bbec4d2af6a..c6dfab0d366 100644
--- a/src/compiler/spirv/spirv2nir.c
+++ b/src/compiler/spirv/spirv2nir.c
@@ -65,6 +65,20 @@ stage_to_enum(char *stage)
       return MESA_SHADER_NONE;
 }
 
+static void
+print_usage(char *exec_name, FILE *f)
+{
+   fprintf(f,
+"Usage: %s [options] file\n"
+"Options:\n"
+"  -h  --help              Print this help.\n"
+"  -s, --stage <stage>     Specify the shader stage.  Valid stages are:\n"
+"                          vertex, tess-ctrl, tess-eval, geometry, fragment,\n"
+"                          compute, and kernel (OpenCL-style compute).\n"
+"  -e, --entry <name>      Specify the entry-point name.\n"
+   , exec_name);
+}
+
 int main(int argc, char **argv)
 {
    gl_shader_stage shader_stage = MESA_SHADER_FRAGMENT;
@@ -73,36 +87,43 @@ int main(int argc, char **argv)
 
    static struct option long_options[] =
      {
+       {"help",         no_argument, 0, 'h'},
        {"stage",  required_argument, 0, 's'},
        {"entry",  required_argument, 0, 'e'},
        {0, 0, 0, 0}
      };
 
-   while ((ch = getopt_long(argc - 1, argv + 1, "s:e:", long_options, NULL)) != -1)
+   while ((ch = getopt_long(argc, argv, "hs:e:", long_options, NULL)) != -1)
    {
       switch (ch)
       {
-         case 's':
-            shader_stage = stage_to_enum(optarg);
-            if (shader_stage == MESA_SHADER_NONE)
-            {
-               fprintf(stderr, "Unknown stage %s\n", optarg);
-               return 1;
-            }
-            break;
-         case 'e':
-            entry_point = optarg;
-            break;
-         default:
-            fprintf(stderr, "Unrecognized option.\n");
+      case 'h':
+         print_usage(argv[0], stdout);
+         return 0;
+      case 's':
+         shader_stage = stage_to_enum(optarg);
+         if (shader_stage == MESA_SHADER_NONE)
+         {
+            fprintf(stderr, "Unknown stage \"%s\"\n", optarg);
+            print_usage(argv[0], stderr);
             return 1;
+         }
+         break;
+      case 'e':
+         entry_point = optarg;
+         break;
+      default:
+         fprintf(stderr, "Unrecognized option \"%s\".\n", optarg);
+         print_usage(argv[0], stderr);
+         return 1;
       }
    }
 
-   int fd = open(argv[1], O_RDONLY);
+   const char *filename = argv[optind];
+   int fd = open(filename, O_RDONLY);
    if (fd < 0)
    {
-      fprintf(stderr, "Failed to open %s\n", argv[1]);
+      fprintf(stderr, "Failed to open %s\n", filename);
       return 1;
    }
 



More information about the mesa-commit mailing list