Initial bits for converting AST return nodes to IR return instructions
authorIan Romanick <ian.d.romanick@intel.com>
Fri, 19 Mar 2010 23:45:19 +0000 (16:45 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Fri, 19 Mar 2010 23:51:16 +0000 (16:51 -0700)
ast.h
ast_to_hir.cpp

diff --git a/ast.h b/ast.h
index 1bc38d355cb1f01b5310e6edc18a70f3faa71e8b..5fd69695c1aff2d8c35e986f6922928d64df220f 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -531,6 +531,9 @@ public:
    ast_jump_statement(int mode, ast_expression *return_value);
    virtual void print(void) const;
 
+   virtual ir_instruction *hir(exec_list *instructions,
+                              struct _mesa_glsl_parse_state *state);
+
    enum ast_jump_modes {
       ast_continue,
       ast_break,
index 63f0c82d3d62ca47a7ae63fca1cd37c6780a4e51..79d32165a19ed680299b12b671866b7b86f1e440 100644 (file)
@@ -1120,3 +1120,40 @@ ast_function_definition::hir(exec_list *instructions,
     */
    return NULL;
 }
+
+
+ir_instruction *
+ast_jump_statement::hir(exec_list *instructions,
+                       struct _mesa_glsl_parse_state *state)
+{
+
+   if (mode == ast_return) {
+      ir_return *inst;
+
+      if (opt_return_value) {
+        /* FINISHME: Make sure the enclosing function has a non-void return
+         * FINISHME: type.
+         */
+
+        ir_expression *const ret = (ir_expression *)
+           opt_return_value->hir(instructions, state);
+        assert(ret != NULL);
+
+        /* FINISHME: Make sure the type of the return value matches the return
+         * FINISHME: type of the enclosing function.
+         */
+
+        inst = new ir_return(ret);
+      } else {
+        /* FINISHME: Make sure the enclosing function has a void return type.
+         */
+        inst = new ir_return;
+      }
+
+      instructions->push_tail(inst);
+   }
+
+   /* Jump instructions do not have r-values.
+    */
+   return NULL;
+}