r600g: various fixes
[mesa.git] / src / gallium / drivers / r600 / r600_compiler_dump.c
1 /*
2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23 #include <stdlib.h>
24 #include <string.h>
25 #include <stdint.h>
26 #include <stdio.h>
27 #include "r600_compiler.h"
28
29 static const char *c_file_swz[] = {
30 "x",
31 "y",
32 "z",
33 "w",
34 "0",
35 "1",
36 ".",
37 };
38
39 static const char *c_file_str[] = {
40 "NULL",
41 "CONSTANT",
42 "INPUT",
43 "OUTPUT",
44 "TEMPORARY",
45 "SAMPLER",
46 "ADDRESS",
47 "IMMEDIATE",
48 "LOOP",
49 "PREDICATE",
50 "SYSTEM_VALUE",
51 };
52
53 static const char *c_semantic_str[] = {
54 "POSITION",
55 "COLOR",
56 "BCOLOR",
57 "FOG",
58 "PSIZE",
59 "GENERIC",
60 "NORMAL",
61 "FACE",
62 "EDGEFLAG",
63 "PRIMID",
64 "INSTANCEID",
65 };
66
67 static const char *c_opcode_str[] = {
68 "ARL",
69 "MOV",
70 "LIT",
71 "RCP",
72 "RSQ",
73 "EXP",
74 "LOG",
75 "MUL",
76 "ADD",
77 "DP3",
78 "DP4",
79 "DST",
80 "MIN",
81 "MAX",
82 "SLT",
83 "SGE",
84 "MAD",
85 "SUB",
86 "LRP",
87 "CND",
88 "(INVALID)",
89 "DP2A",
90 "(INVALID)",
91 "(INVALID)",
92 "FRC",
93 "CLAMP",
94 "FLR",
95 "ROUND",
96 "EX2",
97 "LG2",
98 "POW",
99 "XPD",
100 "(INVALID)",
101 "ABS",
102 "RCC",
103 "DPH",
104 "COS",
105 "DDX",
106 "DDY",
107 "KILP",
108 "PK2H",
109 "PK2US",
110 "PK4B",
111 "PK4UB",
112 "RFL",
113 "SEQ",
114 "SFL",
115 "SGT",
116 "SIN",
117 "SLE",
118 "SNE",
119 "STR",
120 "TEX",
121 "TXD",
122 "TXP",
123 "UP2H",
124 "UP2US",
125 "UP4B",
126 "UP4UB",
127 "X2D",
128 "ARA",
129 "ARR",
130 "BRA",
131 "CAL",
132 "RET",
133 "SSG",
134 "CMP",
135 "SCS",
136 "TXB",
137 "NRM",
138 "DIV",
139 "DP2",
140 "TXL",
141 "BRK",
142 "IF",
143 "BGNFOR",
144 "REP",
145 "ELSE",
146 "ENDIF",
147 "ENDFOR",
148 "ENDREP",
149 "PUSHA",
150 "POPA",
151 "CEIL",
152 "I2F",
153 "NOT",
154 "TRUNC",
155 "SHL",
156 "(INVALID)",
157 "AND",
158 "OR",
159 "MOD",
160 "XOR",
161 "SAD",
162 "TXF",
163 "TXQ",
164 "CONT",
165 "EMIT",
166 "ENDPRIM",
167 "BGNLOOP",
168 "BGNSUB",
169 "ENDLOOP",
170 "ENDSUB",
171 "(INVALID)",
172 "(INVALID)",
173 "(INVALID)",
174 "(INVALID)",
175 "NOP",
176 "(INVALID)",
177 "(INVALID)",
178 "(INVALID)",
179 "(INVALID)",
180 "NRM4",
181 "CALLNZ",
182 "IFC",
183 "BREAKC",
184 "KIL",
185 "END",
186 "(INVALID)",
187 "F2I",
188 "IDIV",
189 "IMAX",
190 "IMIN",
191 "INEG",
192 "ISGE",
193 "ISHR",
194 "ISLT",
195 "F2U",
196 "U2F",
197 "UADD",
198 "UDIV",
199 "UMAD",
200 "UMAX",
201 "UMIN",
202 "UMOD",
203 "UMUL",
204 "USEQ",
205 "USGE",
206 "USHR",
207 "USLT",
208 "USNE",
209 "SWITCH",
210 "CASE",
211 "DEFAULT",
212 "ENDSWITCH",
213 "VFETCH",
214 "ENTRY",
215 };
216
217 static inline const char *c_get_name(const char *name[], unsigned i)
218 {
219 return name[i];
220 }
221
222 static void pindent(unsigned indent)
223 {
224 unsigned i;
225 for (i = 0; i < indent; i++)
226 fprintf(stderr, " ");
227 }
228
229 static void c_node_dump(struct c_node *node, unsigned indent)
230 {
231 struct c_instruction *i;
232 unsigned j;
233
234 pindent(indent); fprintf(stderr, "# node %s\n", c_get_name(c_opcode_str, node->opcode));
235 c_list_for_each(i, &node->insts) {
236 pindent(indent); fprintf(stderr, "%s", c_get_name(c_opcode_str, i->opcode));
237 fprintf(stderr, " %s[%d][%s%s%s%s]",
238 c_get_name(c_file_str, i->output.vector->file),
239 i->output.vector->id,
240 c_get_name(c_file_swz, i->output.swizzle[0]),
241 c_get_name(c_file_swz, i->output.swizzle[1]),
242 c_get_name(c_file_swz, i->output.swizzle[2]),
243 c_get_name(c_file_swz, i->output.swizzle[3]));
244 for (j = 0; j < i->ninput; j++) {
245 fprintf(stderr, " %s[%d][%s%s%s%s]",
246 c_get_name(c_file_str, i->input[j].vector->file),
247 i->input[j].vector->id,
248 c_get_name(c_file_swz, i->input[j].swizzle[0]),
249 c_get_name(c_file_swz, i->input[j].swizzle[1]),
250 c_get_name(c_file_swz, i->input[j].swizzle[2]),
251 c_get_name(c_file_swz, i->input[j].swizzle[3]));
252 }
253 fprintf(stderr, ";\n");
254 }
255 }
256
257 static void c_shader_dump_rec(struct c_shader *shader, struct c_node *node, unsigned indent)
258 {
259 struct c_node_link *link;
260
261 c_node_dump(node, indent);
262 c_list_for_each(link, &node->childs) {
263 c_shader_dump_rec(shader, link->node, indent + 1);
264 }
265 }
266
267 void c_shader_dump(struct c_shader *shader)
268 {
269 c_shader_dump_rec(shader, &shader->entry, 0);
270 }