Home | History | Annotate | Download | only in glsl
      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 
     24 /**
     25  * \file ir_rvalue_visitor.cpp
     26  *
     27  * Generic class to implement the common pattern we have of wanting to
     28  * visit each ir_rvalue * and possibly change that node to a different
     29  * class.
     30  */
     31 
     32 #include "ir.h"
     33 #include "ir_visitor.h"
     34 #include "ir_rvalue_visitor.h"
     35 #include "ir_print_visitor.h"
     36 #include "glsl_types.h"
     37 
     38 ir_visitor_status
     39 ir_rvalue_base_visitor::rvalue_visit(ir_expression *ir)
     40 {
     41    unsigned int operand;
     42 
     43    for (operand = 0; operand < ir->get_num_operands(); operand++) {
     44       handle_rvalue(&ir->operands[operand]);
     45    }
     46 
     47    return visit_continue;
     48 }
     49 
     50 ir_visitor_status
     51 ir_rvalue_base_visitor::rvalue_visit(ir_texture *ir)
     52 {
     53    handle_rvalue(&ir->coordinate);
     54    handle_rvalue(&ir->projector);
     55    handle_rvalue(&ir->shadow_comparitor);
     56    handle_rvalue(&ir->offset);
     57 
     58    switch (ir->op) {
     59    case ir_tex:
     60       break;
     61    case ir_txb:
     62       handle_rvalue(&ir->lod_info.bias);
     63       break;
     64    case ir_txf:
     65    case ir_txl:
     66    case ir_txs:
     67       handle_rvalue(&ir->lod_info.lod);
     68       break;
     69    case ir_txd:
     70       handle_rvalue(&ir->lod_info.grad.dPdx);
     71       handle_rvalue(&ir->lod_info.grad.dPdy);
     72       break;
     73    }
     74 
     75    return visit_continue;
     76 }
     77 
     78 ir_visitor_status
     79 ir_rvalue_base_visitor::rvalue_visit(ir_swizzle *ir)
     80 {
     81    handle_rvalue(&ir->val);
     82    return visit_continue;
     83 }
     84 
     85 ir_visitor_status
     86 ir_rvalue_base_visitor::rvalue_visit(ir_dereference_array *ir)
     87 {
     88    /* The array index is not the target of the assignment, so clear the
     89     * 'in_assignee' flag.  Restore it after returning from the array index.
     90     */
     91    const bool was_in_assignee = this->in_assignee;
     92    this->in_assignee = false;
     93    handle_rvalue(&ir->array_index);
     94    this->in_assignee = was_in_assignee;
     95 
     96    handle_rvalue(&ir->array);
     97    return visit_continue;
     98 }
     99 
    100 ir_visitor_status
    101 ir_rvalue_base_visitor::rvalue_visit(ir_dereference_record *ir)
    102 {
    103    handle_rvalue(&ir->record);
    104    return visit_continue;
    105 }
    106 
    107 ir_visitor_status
    108 ir_rvalue_base_visitor::rvalue_visit(ir_assignment *ir)
    109 {
    110    handle_rvalue(&ir->rhs);
    111    handle_rvalue(&ir->condition);
    112 
    113    return visit_continue;
    114 }
    115 
    116 ir_visitor_status
    117 ir_rvalue_base_visitor::rvalue_visit(ir_call *ir)
    118 {
    119    foreach_iter(exec_list_iterator, iter, *ir) {
    120       ir_rvalue *param = (ir_rvalue *)iter.get();
    121       ir_rvalue *new_param = param;
    122       handle_rvalue(&new_param);
    123 
    124       if (new_param != param) {
    125 	 param->replace_with(new_param);
    126       }
    127    }
    128    return visit_continue;
    129 }
    130 
    131 ir_visitor_status
    132 ir_rvalue_base_visitor::rvalue_visit(ir_return *ir)
    133 {
    134    handle_rvalue(&ir->value);;
    135    return visit_continue;
    136 }
    137 
    138 ir_visitor_status
    139 ir_rvalue_base_visitor::rvalue_visit(ir_if *ir)
    140 {
    141    handle_rvalue(&ir->condition);
    142    return visit_continue;
    143 }
    144 
    145 
    146 ir_visitor_status
    147 ir_rvalue_visitor::visit_leave(ir_expression *ir)
    148 {
    149    return rvalue_visit(ir);
    150 }
    151 
    152 ir_visitor_status
    153 ir_rvalue_visitor::visit_leave(ir_texture *ir)
    154 {
    155    return rvalue_visit(ir);
    156 }
    157 
    158 ir_visitor_status
    159 ir_rvalue_visitor::visit_leave(ir_swizzle *ir)
    160 {
    161    return rvalue_visit(ir);
    162 }
    163 
    164 ir_visitor_status
    165 ir_rvalue_visitor::visit_leave(ir_dereference_array *ir)
    166 {
    167    return rvalue_visit(ir);
    168 }
    169 
    170 ir_visitor_status
    171 ir_rvalue_visitor::visit_leave(ir_dereference_record *ir)
    172 {
    173    return rvalue_visit(ir);
    174 }
    175 
    176 ir_visitor_status
    177 ir_rvalue_visitor::visit_leave(ir_assignment *ir)
    178 {
    179    return rvalue_visit(ir);
    180 }
    181 
    182 ir_visitor_status
    183 ir_rvalue_visitor::visit_leave(ir_call *ir)
    184 {
    185    return rvalue_visit(ir);
    186 }
    187 
    188 ir_visitor_status
    189 ir_rvalue_visitor::visit_leave(ir_return *ir)
    190 {
    191    return rvalue_visit(ir);
    192 }
    193 
    194 ir_visitor_status
    195 ir_rvalue_visitor::visit_leave(ir_if *ir)
    196 {
    197    return rvalue_visit(ir);
    198 }
    199 
    200 ir_visitor_status
    201 ir_rvalue_enter_visitor::visit_enter(ir_expression *ir)
    202 {
    203    return rvalue_visit(ir);
    204 }
    205 
    206 ir_visitor_status
    207 ir_rvalue_enter_visitor::visit_enter(ir_texture *ir)
    208 {
    209    return rvalue_visit(ir);
    210 }
    211 
    212 ir_visitor_status
    213 ir_rvalue_enter_visitor::visit_enter(ir_swizzle *ir)
    214 {
    215    return rvalue_visit(ir);
    216 }
    217 
    218 ir_visitor_status
    219 ir_rvalue_enter_visitor::visit_enter(ir_dereference_array *ir)
    220 {
    221    return rvalue_visit(ir);
    222 }
    223 
    224 ir_visitor_status
    225 ir_rvalue_enter_visitor::visit_enter(ir_dereference_record *ir)
    226 {
    227    return rvalue_visit(ir);
    228 }
    229 
    230 ir_visitor_status
    231 ir_rvalue_enter_visitor::visit_enter(ir_assignment *ir)
    232 {
    233    return rvalue_visit(ir);
    234 }
    235 
    236 ir_visitor_status
    237 ir_rvalue_enter_visitor::visit_enter(ir_call *ir)
    238 {
    239    return rvalue_visit(ir);
    240 }
    241 
    242 ir_visitor_status
    243 ir_rvalue_enter_visitor::visit_enter(ir_return *ir)
    244 {
    245    return rvalue_visit(ir);
    246 }
    247 
    248 ir_visitor_status
    249 ir_rvalue_enter_visitor::visit_enter(ir_if *ir)
    250 {
    251    return rvalue_visit(ir);
    252 }
    253