101e04c3fSmrg/* -*- c++ -*- */
201e04c3fSmrg/*
301e04c3fSmrg * Copyright © 2010 Intel Corporation
401e04c3fSmrg *
501e04c3fSmrg * Permission is hereby granted, free of charge, to any person obtaining a
601e04c3fSmrg * copy of this software and associated documentation files (the "Software"),
701e04c3fSmrg * to deal in the Software without restriction, including without limitation
801e04c3fSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
901e04c3fSmrg * and/or sell copies of the Software, and to permit persons to whom the
1001e04c3fSmrg * Software is furnished to do so, subject to the following conditions:
1101e04c3fSmrg *
1201e04c3fSmrg * The above copyright notice and this permission notice (including the next
1301e04c3fSmrg * paragraph) shall be included in all copies or substantial portions of the
1401e04c3fSmrg * Software.
1501e04c3fSmrg *
1601e04c3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1701e04c3fSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1801e04c3fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1901e04c3fSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2001e04c3fSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2101e04c3fSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2201e04c3fSmrg * DEALINGS IN THE SOFTWARE.
2301e04c3fSmrg */
2401e04c3fSmrg
2501e04c3fSmrg#ifndef IR_VISITOR_H
2601e04c3fSmrg#define IR_VISITOR_H
2701e04c3fSmrg
2801e04c3fSmrg#ifdef __cplusplus
2901e04c3fSmrg/**
3001e04c3fSmrg * Abstract base class of visitors of IR instruction trees
3101e04c3fSmrg */
3201e04c3fSmrgclass ir_visitor {
3301e04c3fSmrgpublic:
3401e04c3fSmrg   virtual ~ir_visitor()
3501e04c3fSmrg   {
3601e04c3fSmrg      /* empty */
3701e04c3fSmrg   }
3801e04c3fSmrg
3901e04c3fSmrg   /**
4001e04c3fSmrg    * \name Visit methods
4101e04c3fSmrg    *
4201e04c3fSmrg    * As typical for the visitor pattern, there must be one \c visit method for
4301e04c3fSmrg    * each concrete subclass of \c ir_instruction.  Virtual base classes within
4401e04c3fSmrg    * the hierarchy should not have \c visit methods.
4501e04c3fSmrg    */
4601e04c3fSmrg   /*@{*/
4701e04c3fSmrg   virtual void visit(class ir_rvalue *) { assert(!"unhandled error_type"); }
4801e04c3fSmrg   virtual void visit(class ir_variable *) = 0;
4901e04c3fSmrg   virtual void visit(class ir_function_signature *) = 0;
5001e04c3fSmrg   virtual void visit(class ir_function *) = 0;
5101e04c3fSmrg   virtual void visit(class ir_expression *) = 0;
5201e04c3fSmrg   virtual void visit(class ir_texture *) = 0;
5301e04c3fSmrg   virtual void visit(class ir_swizzle *) = 0;
5401e04c3fSmrg   virtual void visit(class ir_dereference_variable *) = 0;
5501e04c3fSmrg   virtual void visit(class ir_dereference_array *) = 0;
5601e04c3fSmrg   virtual void visit(class ir_dereference_record *) = 0;
5701e04c3fSmrg   virtual void visit(class ir_assignment *) = 0;
5801e04c3fSmrg   virtual void visit(class ir_constant *) = 0;
5901e04c3fSmrg   virtual void visit(class ir_call *) = 0;
6001e04c3fSmrg   virtual void visit(class ir_return *) = 0;
6101e04c3fSmrg   virtual void visit(class ir_discard *) = 0;
627ec681f3Smrg   virtual void visit(class ir_demote *) = 0;
6301e04c3fSmrg   virtual void visit(class ir_if *) = 0;
6401e04c3fSmrg   virtual void visit(class ir_loop *) = 0;
6501e04c3fSmrg   virtual void visit(class ir_loop_jump *) = 0;
6601e04c3fSmrg   virtual void visit(class ir_emit_vertex *) = 0;
6701e04c3fSmrg   virtual void visit(class ir_end_primitive *) = 0;
6801e04c3fSmrg   virtual void visit(class ir_barrier *) = 0;
6901e04c3fSmrg   /*@}*/
7001e04c3fSmrg};
7101e04c3fSmrg
7201e04c3fSmrg/* NOTE: function calls may never return due to discards inside them
7301e04c3fSmrg * This is usually not an issue, but if it is, keep it in mind
7401e04c3fSmrg */
7501e04c3fSmrgclass ir_control_flow_visitor : public ir_visitor {
7601e04c3fSmrgpublic:
7701e04c3fSmrg   virtual void visit(class ir_variable *) {}
7801e04c3fSmrg   virtual void visit(class ir_expression *) {}
7901e04c3fSmrg   virtual void visit(class ir_texture *) {}
8001e04c3fSmrg   virtual void visit(class ir_swizzle *) {}
8101e04c3fSmrg   virtual void visit(class ir_dereference_variable *) {}
8201e04c3fSmrg   virtual void visit(class ir_dereference_array *) {}
8301e04c3fSmrg   virtual void visit(class ir_dereference_record *) {}
8401e04c3fSmrg   virtual void visit(class ir_assignment *) {}
8501e04c3fSmrg   virtual void visit(class ir_constant *) {}
8601e04c3fSmrg   virtual void visit(class ir_call *) {}
877ec681f3Smrg   virtual void visit(class ir_demote *) {}
8801e04c3fSmrg   virtual void visit(class ir_emit_vertex *) {}
8901e04c3fSmrg   virtual void visit(class ir_end_primitive *) {}
9001e04c3fSmrg   virtual void visit(class ir_barrier *) {}
9101e04c3fSmrg};
9201e04c3fSmrg#endif /* __cplusplus */
9301e04c3fSmrg
9401e04c3fSmrg#endif /* IR_VISITOR_H */
95