2 * Copyright © 2010 Intel Corporation
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:
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
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.
25 * \file ir_constant_expression.cpp
26 * Evaluate and process constant valued expressions
28 * In GLSL, constant valued expressions are used in several places. These
29 * must be processed and evaluated very early in the compilation process.
32 * * Initializers for uniforms
33 * * Initializers for \c const variables
38 #include "ir_visitor.h"
41 * Visitor class for evaluating constant expressions
43 class ir_constant_visitor
: public ir_visitor
{
51 virtual ~ir_constant_visitor()
59 * As typical for the visitor pattern, there must be one \c visit method for
60 * each concrete subclass of \c ir_instruction. Virtual base classes within
61 * the hierarchy should not have \c visit methods.
64 virtual void visit(ir_variable
*);
65 virtual void visit(ir_label
*);
66 virtual void visit(ir_function_signature
*);
67 virtual void visit(ir_function
*);
68 virtual void visit(ir_expression
*);
69 virtual void visit(ir_swizzle
*);
70 virtual void visit(ir_dereference
*);
71 virtual void visit(ir_assignment
*);
72 virtual void visit(ir_constant
*);
73 virtual void visit(ir_call
*);
74 virtual void visit(ir_return
*);
75 virtual void visit(ir_if
*);
79 * Value of the constant expression.
82 * This field will be \c NULL if the expression is not constant valued.
84 /* FINIHSME: This cannot hold values for constant arrays or structures. */
90 ir_instruction::constant_expression_value()
92 ir_constant_visitor visitor
;
94 this->accept(& visitor
);
100 ir_constant_visitor::visit(ir_variable
*ir
)
108 ir_constant_visitor::visit(ir_label
*ir
)
116 ir_constant_visitor::visit(ir_function_signature
*ir
)
124 ir_constant_visitor::visit(ir_function
*ir
)
132 ir_constant_visitor::visit(ir_expression
*ir
)
140 ir_constant_visitor::visit(ir_swizzle
*ir
)
148 ir_constant_visitor::visit(ir_dereference
*ir
)
156 ir_constant_visitor::visit(ir_assignment
*ir
)
164 ir_constant_visitor::visit(ir_constant
*ir
)
171 ir_constant_visitor::visit(ir_call
*ir
)
179 ir_constant_visitor::visit(ir_return
*ir
)
187 ir_constant_visitor::visit(ir_if
*ir
)