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_visitor::visit_leave(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_visitor::visit_leave(ir_texture *ir)
     52 {
     53    handle_rvalue(&ir->coordinate);
     54    handle_rvalue(&ir->projector);
     55    handle_rvalue(&ir->shadow_comparitor);
     56 
     57    switch (ir->op) {
     58    case ir_tex:
     59       break;
     60    case ir_txb:
     61       handle_rvalue(&ir->lod_info.bias);
     62       break;
     63    case ir_txf:
     64    case ir_txl:
     65       handle_rvalue(&ir->lod_info.lod);
     66       break;
     67    case ir_txd:
     68       handle_rvalue(&ir->lod_info.grad.dPdx);
     69       handle_rvalue(&ir->lod_info.grad.dPdy);
     70       break;
     71    }
     72 
     73    return visit_continue;
     74 }
     75 
     76 ir_visitor_status
     77 ir_rvalue_visitor::visit_leave(ir_swizzle *ir)
     78 {
     79    handle_rvalue(&ir->val);
     80    return visit_continue;
     81 }
     82 
     83 ir_visitor_status
     84 ir_rvalue_visitor::visit_leave(ir_dereference_array *ir)
     85 {
     86    /* The array index is not the target of the assignment, so clear the
     87     * 'in_assignee' flag.  Restore it after returning from the array index.
     88     */
     89    const bool was_in_assignee = this->in_assignee;
     90    this->in_assignee = false;
     91    handle_rvalue(&ir->array_index);
     92    this->in_assignee = was_in_assignee;
     93 
     94    handle_rvalue(&ir->array);
     95    return visit_continue;
     96 }
     97 
     98 ir_visitor_status
     99 ir_rvalue_visitor::visit_leave(ir_dereference_record *ir)
    100 {
    101    handle_rvalue(&ir->record);
    102    return visit_continue;
    103 }
    104 
    105 ir_visitor_status
    106 ir_rvalue_visitor::visit_leave(ir_assignment *ir)
    107 {
    108    handle_rvalue(&ir->rhs);
    109    handle_rvalue(&ir->condition);
    110 
    111    return visit_continue;
    112 }
    113 
    114 ir_visitor_status
    115 ir_rvalue_visitor::visit_leave(ir_call *ir)
    116 {
    117    foreach_iter(exec_list_iterator, iter, *ir) {
    118       ir_rvalue *param = (ir_rvalue *)iter.get();
    119       ir_rvalue *new_param = param;
    120       handle_rvalue(&new_param);
    121 
    122       if (new_param != param) {
    123 	 param->replace_with(new_param);
    124       }
    125    }
    126    return visit_continue;
    127 }
    128 
    129 ir_visitor_status
    130 ir_rvalue_visitor::visit_leave(ir_return *ir)
    131 {
    132    handle_rvalue(&ir->value);;
    133    return visit_continue;
    134 }
    135 
    136 ir_visitor_status
    137 ir_rvalue_visitor::visit_leave(ir_if *ir)
    138 {
    139    handle_rvalue(&ir->condition);
    140    return visit_continue;
    141 }
    142