From: Ian Romanick Date: Fri, 19 Mar 2010 23:44:52 +0000 (-0700) Subject: Implement IR return instructions X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9578c87ce23a98472d52f15b0a7063f4df036c4d;p=mesa.git Implement IR return instructions --- diff --git a/ir.h b/ir.h index c7fd981200f..ab598ee0b08 100644 --- a/ir.h +++ b/ir.h @@ -323,6 +323,51 @@ private: }; +/** + * \name Jump-like IR instructions. + * + * These include \c break, \c continue, \c return, and \c discard. + */ +/*@{*/ +class ir_jump : public ir_instruction { +protected: + ir_jump() + : ir_instruction(ir_op_jump) + { + /* empty */ + } +}; + +class ir_return : public ir_jump { +public: + ir_return() + : value(NULL) + { + /* empty */ + } + + ir_return(ir_expression *value) + : value(value) + { + /* empty */ + } + + ir_expression *get_value() const + { + return value; + } + + virtual void accept(ir_visitor *v) + { + v->visit(this); + } + +private: + ir_expression *value; +}; +/*@}*/ + + struct ir_swizzle_mask { unsigned x:2; unsigned y:2; diff --git a/ir_print_visitor.cpp b/ir_print_visitor.cpp index b1c718d99ea..f9f3d3f17d8 100644 --- a/ir_print_visitor.cpp +++ b/ir_print_visitor.cpp @@ -142,3 +142,18 @@ ir_print_visitor::visit(ir_call *ir) printf("(call FINISHME: function name here\n"); printf(" (FINISHME: function paramaters here))\n"); } + + +void +ir_print_visitor::visit(ir_return *ir) +{ + printf("(return"); + + ir_expression *const value = ir->get_value(); + if (value) { + printf(" "); + value->accept(this); + } + + printf(")\n"); +} diff --git a/ir_print_visitor.h b/ir_print_visitor.h index b76de504617..121b7e8bb68 100644 --- a/ir_print_visitor.h +++ b/ir_print_visitor.h @@ -61,6 +61,7 @@ public: virtual void visit(ir_assignment *); virtual void visit(ir_constant *); virtual void visit(ir_call *); + virtual void visit(ir_return *); /*@}*/ }; diff --git a/ir_visitor.h b/ir_visitor.h index a2b2dd678b4..8ea416eb9f2 100644 --- a/ir_visitor.h +++ b/ir_visitor.h @@ -53,6 +53,7 @@ public: virtual void visit(class ir_assignment *) = 0; virtual void visit(class ir_constant *) = 0; virtual void visit(class ir_call *) = 0; + virtual void visit(class ir_return *) = 0; /*@}*/ };