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 #include "ir.h"
     25 #include "ir_hierarchical_visitor.h"
     26 
     27 ir_hierarchical_visitor::ir_hierarchical_visitor()
     28 {
     29    this->base_ir = NULL;
     30    this->callback = NULL;
     31    this->data = NULL;
     32    this->in_assignee = false;
     33 }
     34 
     35 ir_visitor_status
     36 ir_hierarchical_visitor::visit(ir_variable *ir)
     37 {
     38    if (this->callback != NULL)
     39       this->callback(ir, this->data);
     40 
     41    return visit_continue;
     42 }
     43 
     44 ir_visitor_status
     45 ir_hierarchical_visitor::visit(ir_constant *ir)
     46 {
     47    if (this->callback != NULL)
     48       this->callback(ir, this->data);
     49 
     50    return visit_continue;
     51 }
     52 
     53 ir_visitor_status
     54 ir_hierarchical_visitor::visit(ir_loop_jump *ir)
     55 {
     56    if (this->callback != NULL)
     57       this->callback(ir, this->data);
     58 
     59    return visit_continue;
     60 }
     61 
     62 ir_visitor_status
     63 ir_hierarchical_visitor::visit(ir_dereference_variable *ir)
     64 {
     65    if (this->callback != NULL)
     66       this->callback(ir, this->data);
     67 
     68    return visit_continue;
     69 }
     70 
     71 ir_visitor_status
     72 ir_hierarchical_visitor::visit_enter(ir_loop *ir)
     73 {
     74    if (this->callback != NULL)
     75       this->callback(ir, this->data);
     76 
     77    return visit_continue;
     78 }
     79 
     80 ir_visitor_status
     81 ir_hierarchical_visitor::visit_leave(ir_loop *ir)
     82 {
     83    (void) ir;
     84    return visit_continue;
     85 }
     86 
     87 ir_visitor_status
     88 ir_hierarchical_visitor::visit_enter(ir_function_signature *ir)
     89 {
     90    if (this->callback != NULL)
     91       this->callback(ir, this->data);
     92 
     93    return visit_continue;
     94 }
     95 
     96 ir_visitor_status
     97 ir_hierarchical_visitor::visit_leave(ir_function_signature *ir)
     98 {
     99    (void) ir;
    100    return visit_continue;
    101 }
    102 
    103 ir_visitor_status
    104 ir_hierarchical_visitor::visit_enter(ir_function *ir)
    105 {
    106    if (this->callback != NULL)
    107       this->callback(ir, this->data);
    108 
    109    return visit_continue;
    110 }
    111 
    112 ir_visitor_status
    113 ir_hierarchical_visitor::visit_leave(ir_function *ir)
    114 {
    115    (void) ir;
    116    return visit_continue;
    117 }
    118 
    119 ir_visitor_status
    120 ir_hierarchical_visitor::visit_enter(ir_expression *ir)
    121 {
    122    if (this->callback != NULL)
    123       this->callback(ir, this->data);
    124 
    125    return visit_continue;
    126 }
    127 
    128 ir_visitor_status
    129 ir_hierarchical_visitor::visit_leave(ir_expression *ir)
    130 {
    131    (void) ir;
    132    return visit_continue;
    133 }
    134 
    135 ir_visitor_status
    136 ir_hierarchical_visitor::visit_enter(ir_texture *ir)
    137 {
    138    if (this->callback != NULL)
    139       this->callback(ir, this->data);
    140 
    141    return visit_continue;
    142 }
    143 
    144 ir_visitor_status
    145 ir_hierarchical_visitor::visit_leave(ir_texture *ir)
    146 {
    147    (void) ir;
    148    return visit_continue;
    149 }
    150 
    151 ir_visitor_status
    152 ir_hierarchical_visitor::visit_enter(ir_swizzle *ir)
    153 {
    154    if (this->callback != NULL)
    155       this->callback(ir, this->data);
    156 
    157    return visit_continue;
    158 }
    159 
    160 ir_visitor_status
    161 ir_hierarchical_visitor::visit_leave(ir_swizzle *ir)
    162 {
    163    (void) ir;
    164    return visit_continue;
    165 }
    166 
    167 ir_visitor_status
    168 ir_hierarchical_visitor::visit_enter(ir_dereference_array *ir)
    169 {
    170    if (this->callback != NULL)
    171       this->callback(ir, this->data);
    172 
    173    return visit_continue;
    174 }
    175 
    176 ir_visitor_status
    177 ir_hierarchical_visitor::visit_leave(ir_dereference_array *ir)
    178 {
    179    (void) ir;
    180    return visit_continue;
    181 }
    182 
    183 ir_visitor_status
    184 ir_hierarchical_visitor::visit_enter(ir_dereference_record *ir)
    185 {
    186    if (this->callback != NULL)
    187       this->callback(ir, this->data);
    188 
    189    return visit_continue;
    190 }
    191 
    192 ir_visitor_status
    193 ir_hierarchical_visitor::visit_leave(ir_dereference_record *ir)
    194 {
    195    (void) ir;
    196    return visit_continue;
    197 }
    198 
    199 ir_visitor_status
    200 ir_hierarchical_visitor::visit_enter(ir_assignment *ir)
    201 {
    202    if (this->callback != NULL)
    203       this->callback(ir, this->data);
    204 
    205    return visit_continue;
    206 }
    207 
    208 ir_visitor_status
    209 ir_hierarchical_visitor::visit_leave(ir_assignment *ir)
    210 {
    211    (void) ir;
    212    return visit_continue;
    213 }
    214 
    215 ir_visitor_status
    216 ir_hierarchical_visitor::visit_enter(ir_call *ir)
    217 {
    218    if (this->callback != NULL)
    219       this->callback(ir, this->data);
    220 
    221    return visit_continue;
    222 }
    223 
    224 ir_visitor_status
    225 ir_hierarchical_visitor::visit_leave(ir_call *ir)
    226 {
    227    (void) ir;
    228    return visit_continue;
    229 }
    230 
    231 ir_visitor_status
    232 ir_hierarchical_visitor::visit_enter(ir_return *ir)
    233 {
    234    if (this->callback != NULL)
    235       this->callback(ir, this->data);
    236 
    237    return visit_continue;
    238 }
    239 
    240 ir_visitor_status
    241 ir_hierarchical_visitor::visit_leave(ir_return *ir)
    242 {
    243    (void) ir;
    244    return visit_continue;
    245 }
    246 
    247 ir_visitor_status
    248 ir_hierarchical_visitor::visit_enter(ir_discard *ir)
    249 {
    250    if (this->callback != NULL)
    251       this->callback(ir, this->data);
    252 
    253    return visit_continue;
    254 }
    255 
    256 ir_visitor_status
    257 ir_hierarchical_visitor::visit_leave(ir_discard *ir)
    258 {
    259    (void) ir;
    260    return visit_continue;
    261 }
    262 
    263 ir_visitor_status
    264 ir_hierarchical_visitor::visit_enter(ir_if *ir)
    265 {
    266    if (this->callback != NULL)
    267       this->callback(ir, this->data);
    268 
    269    return visit_continue;
    270 }
    271 
    272 ir_visitor_status
    273 ir_hierarchical_visitor::visit_leave(ir_if *ir)
    274 {
    275    (void) ir;
    276    return visit_continue;
    277 }
    278 
    279 void
    280 ir_hierarchical_visitor::run(exec_list *instructions)
    281 {
    282    visit_list_elements(this, instructions);
    283 }
    284 
    285 
    286 void
    287 visit_tree(ir_instruction *ir,
    288 	   void (*callback)(class ir_instruction *ir, void *data),
    289 	   void *data)
    290 {
    291    ir_hierarchical_visitor v;
    292 
    293    v.callback = callback;
    294    v.data = data;
    295 
    296    ir->accept(&v);
    297 }
    298