1 /*
2 * Copyright © 2022 Imagination Technologies Ltd.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * 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 THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
24 #include "nir/nir.h"
25 #include "rogue.h"
26 #include "util/macros.h"
27 #include "util/u_debug.h"
28
29 #include <stdbool.h>
30 #include <stdio.h>
31 #include <unistd.h>
32
33 /**
34 * \file rogue_debug.c
35 *
36 * \brief Contains debugging functions and data.
37 */
38
39 static const struct debug_named_value rogue_debug_options[] = {
40 { "nir", ROGUE_DEBUG_NIR, "Print NIR" },
41 { "nir_passes", ROGUE_DEBUG_NIR_PASSES, "Print NIR passes" },
42 { "ir", ROGUE_DEBUG_IR, "Print Rogue IR" },
43 { "ir_passes", ROGUE_DEBUG_IR_PASSES, "Print Rogue IR passes" },
44 { "ir_details",
45 ROGUE_DEBUG_IR_DETAILS,
46 "Print Rogue IR details (with ir/ir_passes enabled)" },
47 { "vld_skip", ROGUE_DEBUG_VLD_SKIP, "Skip Rogue IR validation" },
48 { "vld_nonfatal", ROGUE_DEBUG_VLD_NONFATAL, "Non-fatal Rogue IR validation" },
49 DEBUG_NAMED_VALUE_END,
50 };
51
52 #define ROGUE_DEBUG_DEFAULT 0U
53 DEBUG_GET_ONCE_FLAGS_OPTION(rogue_debug,
54 "ROGUE_DEBUG",
55 rogue_debug_options,
56 ROGUE_DEBUG_DEFAULT)
57
58 PUBLIC
59 unsigned long rogue_debug = ROGUE_DEBUG_DEFAULT;
60
61 DEBUG_GET_ONCE_OPTION(rogue_color, "ROGUE_COLOR", NULL)
62
63 bool rogue_color = false;
64
rogue_debug_init_once(void)65 static void rogue_debug_init_once(void)
66 {
67 /* Get debug flags. */
68 rogue_debug = debug_get_option_rogue_debug();
69
70 /* Get/parse color option. */
71 const char *color_opt = debug_get_option_rogue_color();
72 if (!color_opt || !strcmp(color_opt, "auto") || !strcmp(color_opt, "a"))
73 rogue_color = isatty(fileno(stdout));
74 else if (!strcmp(color_opt, "on") || !strcmp(color_opt, "1"))
75 rogue_color = true;
76 else if (!strcmp(color_opt, "off") || !strcmp(color_opt, "0"))
77 rogue_color = false;
78 }
79
80 PUBLIC
rogue_debug_init(void)81 void rogue_debug_init(void)
82 {
83 static once_flag flag = ONCE_FLAG_INIT;
84 call_once(&flag, rogue_debug_init_once);
85 }
86