Fix matrix dimensioning
[mesa.git] / ir_print_visitor.cpp
1 /*
2 * Copyright © 2010 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 #include <cstdio>
24 #include "ir_print_visitor.h"
25 #include "glsl_types.h"
26
27 static void
28 print_type(const glsl_type *t)
29 {
30 if (t->base_type == GLSL_TYPE_ARRAY) {
31 printf("array\n");
32 printf(" (");
33 print_type(t->fields.array);
34 printf(")\n");
35
36 printf(" (%u)\n", t->length);
37 printf(")");
38 } else if (t->base_type == GLSL_TYPE_STRUCT) {
39 printf("struct (%s %u\n", t->name ? t->name : "@", t->length);
40 printf(" (FINISHME: structure fields go here)\n");
41 printf(")");
42 } else {
43 printf("%s", t->name);
44 }
45 }
46
47
48 void ir_print_visitor::visit(ir_variable *ir)
49 {
50 printf("(declare \n");
51
52 const char *const cent = (ir->centroid) ? "centroid " : "";
53 const char *const inv = (ir->invariant) ? "invariant " : "";
54 const char *const mode[] = { "", "uniform ", "in ", "out ", "inout " };
55 const char *const interp[] = { "", "flat", "noperspective" };
56
57 printf(" (%s%s%s%s)\n",
58 cent, inv, mode[ir->mode], interp[ir->interpolation]);
59
60 printf(" (");
61 print_type(ir->type);
62 printf(")\n");
63
64 printf(" (%s)\n", ir->name);
65 printf(")\n");
66 }
67
68
69 void ir_print_visitor::visit(ir_label *ir)
70 {
71 printf("(label %s)\n", ir->label);
72 }
73
74
75 void ir_print_visitor::visit(ir_function_signature *ir)
76 {
77 printf("%s:%d:\n", __func__, __LINE__);
78 (void) ir;
79 }
80
81
82 void ir_print_visitor::visit(ir_function *ir)
83 {
84 printf("(function %s\n", ir->name);
85 printf(")\n");
86 }
87
88
89 void ir_print_visitor::visit(ir_expression *ir)
90 {
91 printf("%s:%d:\n", __func__, __LINE__);
92 (void) ir;
93 }
94
95
96 void ir_print_visitor::visit(ir_dereference *ir)
97 {
98 printf("%s:%d:\n", __func__, __LINE__);
99 (void) ir;
100 }
101
102
103 void ir_print_visitor::visit(ir_assignment *ir)
104 {
105 printf("(assign\n");
106
107 printf(" (");
108 if (ir->condition)
109 ir->condition->accept(this);
110 else
111 printf("true");
112 printf(")\n");
113
114 printf(" (");
115 ir->lhs->accept(this);
116 printf(")\n");
117
118 printf(" (");
119 ir->rhs->accept(this);
120 printf(")\n");
121 }
122
123
124 void ir_print_visitor::visit(ir_constant *ir)
125 {
126 (void) ir;
127
128 printf("(constant\n");
129 printf(" (");
130 print_type(ir->type);
131 printf(")\n");
132 printf(" (FINISHME: value goes here)\n");
133 printf(")\n");
134 }
135
136
137 void
138 ir_print_visitor::visit(ir_call *ir)
139 {
140 (void) ir;
141
142 printf("(call FINISHME: function name here\n");
143 printf(" (FINISHME: function paramaters here))\n");
144 }
145
146
147 void
148 ir_print_visitor::visit(ir_return *ir)
149 {
150 printf("(return");
151
152 ir_expression *const value = ir->get_value();
153 if (value) {
154 printf(" ");
155 value->accept(this);
156 }
157
158 printf(")\n");
159 }