3 * Copyright (c) 2019 Collabora LTD
5 * Author: Gert Wollny <gert.wollny@collabora.com>
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * on the rights to use, copy, modify, merge, publish, distribute, sub
11 * license, and/or sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include "util/u_debug.h"
28 #include "sfn_debug.h"
32 class stderr_streambuf
: public std::streambuf
39 std::streamsize
xsputn ( const char *s
, std::streamsize n
);
42 stderr_streambuf::stderr_streambuf()
47 int stderr_streambuf::sync()
53 int stderr_streambuf::overflow(int c
)
59 static const struct debug_named_value sfn_debug_options
[] = {
60 {"instr", SfnLog::instr
, "Log all consumed nir instructions"},
61 {"ir", SfnLog::r600ir
, "Log created R600 IR"},
62 {"cc", SfnLog::cc
, "Log R600 IR to assembly code creation"},
63 {"noerr", SfnLog::err
, "Don't log shader conversion errors"},
64 {"si", SfnLog::shader_info
, "Log shader info (non-zero values)"},
65 {"ts", SfnLog::test_shader
, "Log shaders in tests"},
66 {"reg", SfnLog::reg
, "Log register allocation and lookup"},
67 {"io", SfnLog::io
, "Log shader in and output"},
68 {"ass", SfnLog::assembly
, "Log IR to assembly conversion"},
69 {"flow", SfnLog::flow
, "Log Flow instructions"},
70 {"merge", SfnLog::merge
, "Log register merge operations"},
71 {"nomerge", SfnLog::nomerge
, "Skup egister merge step"},
72 {"tex", SfnLog::tex
, "Log texture ops"},
73 {"trans", SfnLog::trans
, "Log generic translation messages"},
79 std::streamsize
stderr_streambuf::xsputn ( const char *s
, std::streamsize n
)
81 std::streamsize i
= n
;
88 m_active_log_flags(0),
90 m_output(new stderr_streambuf())
92 m_log_mask
= debug_get_flags_option("R600_NIR_DEBUG", sfn_debug_options
, 0);
96 SfnLog
& SfnLog::operator << (SfnLog::LogFlag
const l
)
98 m_active_log_flags
= l
;
102 SfnLog
& SfnLog::operator << (UNUSED
std::ostream
& (*f
)(std::ostream
&))
104 if (m_active_log_flags
& m_log_mask
)
109 SfnLog
& SfnLog::operator << (nir_shader
& sh
)
111 if (m_active_log_flags
& m_log_mask
)
112 nir_print_shader(&sh
, stderr
);
116 SfnLog
& SfnLog::operator << (nir_instr
&instr
)
118 if (m_active_log_flags
& m_log_mask
)
119 nir_print_instr(&instr
, stderr
);
123 SfnTrace::SfnTrace(SfnLog::LogFlag flag
, const char *msg
):
127 sfn_log
<< m_flag
<< std::string(" ", 2 * m_indention
++)
128 << "BEGIN: " << m_msg
<< "\n";
131 SfnTrace::~SfnTrace()
133 sfn_log
<< m_flag
<< std::string(" ", 2 * m_indention
--)
134 << "END: " << m_msg
<< "\n";
137 int SfnTrace::m_indention
= 0;