glsl: add just-log option for the standalone compiler.
[mesa.git] / src / compiler / glsl / main.cpp
1 /*
2 * Copyright © 2008, 2009 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #include <stdio.h>
25 #include <getopt.h>
26
27 /** @file main.cpp
28 *
29 * This file is the main() routine and scaffolding for producing
30 * builtin_compiler (which doesn't include builtins itself and is used
31 * to generate the profile information for builtin_function.cpp), and
32 * for glsl_compiler (which does include builtins and can be used to
33 * offline compile GLSL code and examine the resulting GLSL IR.
34 */
35
36 #include "main/mtypes.h"
37 #include "standalone.h"
38
39 static struct standalone_options options;
40
41 const struct option compiler_opts[] = {
42 { "dump-ast", no_argument, &options.dump_ast, 1 },
43 { "dump-hir", no_argument, &options.dump_hir, 1 },
44 { "dump-lir", no_argument, &options.dump_lir, 1 },
45 { "link", no_argument, &options.do_link, 1 },
46 { "just-log", no_argument, &options.just_log, 1 },
47 { "version", required_argument, NULL, 'v' },
48 { NULL, 0, NULL, 0 }
49 };
50
51 /**
52 * \brief Print proper usage and exit with failure.
53 */
54 void
55 usage_fail(const char *name)
56 {
57
58 const char *header =
59 "usage: %s [options] <file.vert | file.tesc | file.tese | file.geom | file.frag | file.comp>\n"
60 "\n"
61 "Possible options are:\n";
62 printf(header, name);
63 for (const struct option *o = compiler_opts; o->name != 0; ++o) {
64 printf(" --%s\n", o->name);
65 }
66 exit(EXIT_FAILURE);
67 }
68
69 int
70 main(int argc, char * const* argv)
71 {
72 int status = EXIT_SUCCESS;
73
74 int c;
75 int idx = 0;
76 while ((c = getopt_long(argc, argv, "", compiler_opts, &idx)) != -1) {
77 switch (c) {
78 case 'v':
79 options.glsl_version = strtol(optarg, NULL, 10);
80 break;
81 default:
82 break;
83 }
84 }
85
86 if (argc <= optind)
87 usage_fail(argv[0]);
88
89 struct gl_shader_program *whole_program;
90
91 whole_program = standalone_compile_shader(&options, argc - optind, &argv[optind]);
92
93 if (!whole_program)
94 usage_fail(argv[0]);
95
96 standalone_compiler_cleanup(whole_program);
97
98 return status;
99 }