diff src/pt-jit.h @ 14961:903a5ee2cdde

Simplify the creation of error checks in jit * src/pt-jit.h (jit_convert::create_checked, jit_convert::create_checked_impl): New function. * src/pt-jit.cc (jit_convert::visit_binary_expression, jit_convert::visit_if_command, jit_convert::visit_index_expression): Use create_checked.
author Max Brister <max@2bass.com>
date Tue, 19 Jun 2012 13:10:10 -0500
parents c959136f8c3e
children 90a7a2af2cd5
line wrap: on
line diff
--- a/src/pt-jit.h	Tue Jun 19 12:36:53 2012 -0500
+++ b/src/pt-jit.h	Tue Jun 19 13:10:10 2012 -0500
@@ -2061,6 +2061,21 @@
     track_value (ret);
     return ret;
   }
+
+  template <typename ARG0, typename ARG1>
+  jit_call *create_checked (const ARG0& arg0, const ARG1& arg1)
+  {
+    jit_call *ret = create<jit_call> (arg0, arg1);
+    return create_checked_impl (ret);
+  }
+
+  template <typename ARG0, typename ARG1, typename ARG2>
+  jit_call *create_checked (const ARG0& arg0, const ARG1& arg1,
+                            const ARG2& arg2)
+  {
+    jit_call *ret = create<jit_call> (arg0, arg1, arg2);
+    return create_checked_impl (ret);
+  }
 private:
   typedef std::list<jit_block *> block_list;
   typedef block_list::iterator block_iterator;
@@ -2098,6 +2113,18 @@
     ablock->stash_location (--blocks.end ());
   }
 
+  jit_call *create_checked_impl (jit_call *ret)
+  {
+    block->append (ret);
+
+    jit_block *normal = create<jit_block> (block->name ());
+    block->append (create<jit_error_check> (ret, normal, final_block));
+    add_block (normal);
+    block = normal;
+
+    return ret;
+  }
+
   jit_variable *get_variable (const std::string& vname);
 
   jit_value *do_assign (const std::string& lhs, jit_value *rhs, bool print);