Mesa (master): glsl: Factor out code which emits a new function into the IR stream.

Kenneth Graunke kwg at kemper.freedesktop.org
Mon Dec 6 23:24:42 UTC 2010


Module: Mesa
Branch: master
Commit: 6fae1e4c4d33769e2f255d50907b5aa0ab80edd4
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=6fae1e4c4d33769e2f255d50907b5aa0ab80edd4

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Mon Dec  6 10:54:05 2010 -0800

glsl: Factor out code which emits a new function into the IR stream.

A future commit will use the newly created function in a second place.

---

 src/glsl/ast.h          |    4 ++++
 src/glsl/ast_to_hir.cpp |   40 ++++++++++++++++++++++------------------
 2 files changed, 26 insertions(+), 18 deletions(-)

diff --git a/src/glsl/ast.h b/src/glsl/ast.h
index e5aa5c1..a77b522 100644
--- a/src/glsl/ast.h
+++ b/src/glsl/ast.h
@@ -714,4 +714,8 @@ _mesa_ast_field_selection_to_hir(const ast_expression *expr,
 				 exec_list *instructions,
 				 struct _mesa_glsl_parse_state *state);
 
+void
+emit_function(_mesa_glsl_parse_state *state, exec_list *instructions,
+	      ir_function *f);
+
 #endif /* AST_H */
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index f5b1120..d24a7bb 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -2477,6 +2477,27 @@ ast_parameter_declarator::parameters_to_hir(exec_list *ast_parameters,
 }
 
 
+void
+emit_function(_mesa_glsl_parse_state *state, exec_list *instructions,
+	      ir_function *f)
+{
+   /* Emit the new function header */
+   if (state->current_function == NULL) {
+      instructions->push_tail(f);
+   } else {
+      /* IR invariants disallow function declarations or definitions nested
+       * within other function definitions.  Insert the new ir_function
+       * block in the instruction sequence before the ir_function block
+       * containing the current ir_function_signature.
+       */
+      ir_function *const curr =
+	 const_cast<ir_function *>(state->current_function->function());
+
+      curr->insert_before(f);
+   }
+}
+
+
 ir_rvalue *
 ast_function::hir(exec_list *instructions,
 		  struct _mesa_glsl_parse_state *state)
@@ -2588,24 +2609,7 @@ ast_function::hir(exec_list *instructions,
 	 return NULL;
       }
 
-      /* Emit the new function header */
-      if (state->current_function == NULL)
-	 instructions->push_tail(f);
-      else {
-	 /* IR invariants disallow function declarations or definitions nested
-	  * within other function definitions.  Insert the new ir_function
-	  * block in the instruction sequence before the ir_function block
-	  * containing the current ir_function_signature.
-	  *
-	  * This can only happen in a GLSL 1.10 shader.  In all other GLSL
-	  * versions this nesting is disallowed.  There is a check for this at
-	  * the top of this function.
-	  */
-	 ir_function *const curr =
-	    const_cast<ir_function *>(state->current_function->function());
-
-	 curr->insert_before(f);
-      }
+      emit_function(state, instructions, f);
    }
 
    /* Verify the return type of main() */




More information about the mesa-commit mailing list