1b8e80941Smrg/* -*- c++ -*- */ 2b8e80941Smrg/* 3b8e80941Smrg * Copyright © 2010 Intel Corporation 4b8e80941Smrg * 5b8e80941Smrg * Permission is hereby granted, free of charge, to any person obtaining a 6b8e80941Smrg * copy of this software and associated documentation files (the "Software"), 7b8e80941Smrg * to deal in the Software without restriction, including without limitation 8b8e80941Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9b8e80941Smrg * and/or sell copies of the Software, and to permit persons to whom the 10b8e80941Smrg * Software is furnished to do so, subject to the following conditions: 11b8e80941Smrg * 12b8e80941Smrg * The above copyright notice and this permission notice (including the next 13b8e80941Smrg * paragraph) shall be included in all copies or substantial portions of the 14b8e80941Smrg * Software. 15b8e80941Smrg * 16b8e80941Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17b8e80941Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18b8e80941Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19b8e80941Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20b8e80941Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21b8e80941Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22b8e80941Smrg * DEALINGS IN THE SOFTWARE. 23b8e80941Smrg */ 24b8e80941Smrg 25b8e80941Smrg#ifndef IR_VISITOR_H 26b8e80941Smrg#define IR_VISITOR_H 27b8e80941Smrg 28b8e80941Smrg#ifdef __cplusplus 29b8e80941Smrg/** 30b8e80941Smrg * Abstract base class of visitors of IR instruction trees 31b8e80941Smrg */ 32b8e80941Smrgclass ir_visitor { 33b8e80941Smrgpublic: 34b8e80941Smrg virtual ~ir_visitor() 35b8e80941Smrg { 36b8e80941Smrg /* empty */ 37b8e80941Smrg } 38b8e80941Smrg 39b8e80941Smrg /** 40b8e80941Smrg * \name Visit methods 41b8e80941Smrg * 42b8e80941Smrg * As typical for the visitor pattern, there must be one \c visit method for 43b8e80941Smrg * each concrete subclass of \c ir_instruction. Virtual base classes within 44b8e80941Smrg * the hierarchy should not have \c visit methods. 45b8e80941Smrg */ 46b8e80941Smrg /*@{*/ 47b8e80941Smrg virtual void visit(class ir_rvalue *) { assert(!"unhandled error_type"); } 48b8e80941Smrg virtual void visit(class ir_variable *) = 0; 49b8e80941Smrg virtual void visit(class ir_function_signature *) = 0; 50b8e80941Smrg virtual void visit(class ir_function *) = 0; 51b8e80941Smrg virtual void visit(class ir_expression *) = 0; 52b8e80941Smrg virtual void visit(class ir_texture *) = 0; 53b8e80941Smrg virtual void visit(class ir_swizzle *) = 0; 54b8e80941Smrg virtual void visit(class ir_dereference_variable *) = 0; 55b8e80941Smrg virtual void visit(class ir_dereference_array *) = 0; 56b8e80941Smrg virtual void visit(class ir_dereference_record *) = 0; 57b8e80941Smrg virtual void visit(class ir_assignment *) = 0; 58b8e80941Smrg virtual void visit(class ir_constant *) = 0; 59b8e80941Smrg virtual void visit(class ir_call *) = 0; 60b8e80941Smrg virtual void visit(class ir_return *) = 0; 61b8e80941Smrg virtual void visit(class ir_discard *) = 0; 62b8e80941Smrg virtual void visit(class ir_if *) = 0; 63b8e80941Smrg virtual void visit(class ir_loop *) = 0; 64b8e80941Smrg virtual void visit(class ir_loop_jump *) = 0; 65b8e80941Smrg virtual void visit(class ir_emit_vertex *) = 0; 66b8e80941Smrg virtual void visit(class ir_end_primitive *) = 0; 67b8e80941Smrg virtual void visit(class ir_barrier *) = 0; 68b8e80941Smrg /*@}*/ 69b8e80941Smrg}; 70b8e80941Smrg 71b8e80941Smrg/* NOTE: function calls may never return due to discards inside them 72b8e80941Smrg * This is usually not an issue, but if it is, keep it in mind 73b8e80941Smrg */ 74b8e80941Smrgclass ir_control_flow_visitor : public ir_visitor { 75b8e80941Smrgpublic: 76b8e80941Smrg virtual void visit(class ir_variable *) {} 77b8e80941Smrg virtual void visit(class ir_expression *) {} 78b8e80941Smrg virtual void visit(class ir_texture *) {} 79b8e80941Smrg virtual void visit(class ir_swizzle *) {} 80b8e80941Smrg virtual void visit(class ir_dereference_variable *) {} 81b8e80941Smrg virtual void visit(class ir_dereference_array *) {} 82b8e80941Smrg virtual void visit(class ir_dereference_record *) {} 83b8e80941Smrg virtual void visit(class ir_assignment *) {} 84b8e80941Smrg virtual void visit(class ir_constant *) {} 85b8e80941Smrg virtual void visit(class ir_call *) {} 86b8e80941Smrg virtual void visit(class ir_emit_vertex *) {} 87b8e80941Smrg virtual void visit(class ir_end_primitive *) {} 88b8e80941Smrg virtual void visit(class ir_barrier *) {} 89b8e80941Smrg}; 90b8e80941Smrg#endif /* __cplusplus */ 91b8e80941Smrg 92b8e80941Smrg#endif /* IR_VISITOR_H */ 93