diff mbox

[jit] Add more syntactic sugar to C++ wrapper API

Message ID 1393872521-21276-1-git-send-email-dmalcolm@redhat.com
State New
Headers show

Commit Message

David Malcolm March 3, 2014, 6:48 p.m. UTC
Committed to branch dmalcolm/jit:

gcc/jit/
	* libgccjit++.h (gccjit::function::operator()): Add overload for
	a call with 3 arguments.
	(gccjit::block::add_call): Likewise for 4 arguments.
	(gccjit::rvalue::cast_to): New method.
	(gccjit::rvalue::operator[]): New methods.
---
 gcc/jit/ChangeLog.jit |  8 ++++++++
 gcc/jit/libgccjit++.h | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 62 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/gcc/jit/ChangeLog.jit b/gcc/jit/ChangeLog.jit
index f2fea8c..dd4bf84 100644
--- a/gcc/jit/ChangeLog.jit
+++ b/gcc/jit/ChangeLog.jit
@@ -1,3 +1,11 @@ 
+2014-03-03  David Malcolm  <dmalcolm@redhat.com>
+
+	* libgccjit++.h (gccjit::function::operator()): Add overload for
+	a call with 3 arguments.
+	(gccjit::block::add_call): Likewise for 4 arguments.
+	(gccjit::rvalue::cast_to): New method.
+	(gccjit::rvalue::operator[]): New methods.
+
 2014-02-28  David Malcolm  <dmalcolm@redhat.com>
 
 	* libgccjit.c (gcc_jit_context_new_binary_op): Check that the
diff --git a/gcc/jit/libgccjit++.h b/gcc/jit/libgccjit++.h
index b77e82f..e7ff5ea 100644
--- a/gcc/jit/libgccjit++.h
+++ b/gcc/jit/libgccjit++.h
@@ -310,6 +310,8 @@  namespace gccjit
 		       location loc = location ());
     rvalue operator() (rvalue arg0, rvalue arg1,
 		       location loc = location ());
+    rvalue operator() (rvalue arg0, rvalue arg1, rvalue arg2,
+		       location loc = location ());
   };
 
   class block : public object
@@ -347,6 +349,9 @@  namespace gccjit
     rvalue add_call (function other,
 		     rvalue arg0, rvalue arg1, rvalue arg2,
 		     location loc = location ());
+    rvalue add_call (function other,
+		     rvalue arg0, rvalue arg1, rvalue arg2, rvalue arg3,
+		     location loc = location ());
 
     void add_comment (const std::string &text,
 		      location loc = location ());
@@ -381,7 +386,14 @@  namespace gccjit
 			      location loc = location ());
 
     lvalue dereference (location loc = location ());
- };
+
+    rvalue cast_to (type type_,
+		    location loc = location ());
+
+    /* Array access.  */
+    lvalue operator[] (rvalue index);
+    lvalue operator[] (int index);
+  };
 
   class lvalue : public rvalue
   {
@@ -1249,6 +1261,16 @@  block::add_call (function other,
 }
 
 inline rvalue
+block::add_call (function other,
+		 rvalue arg0, rvalue arg1, rvalue arg2, rvalue arg3,
+		 location loc)
+{
+  rvalue c = get_context ().new_call (other, arg0, arg1, arg2, arg3, loc);
+  add_eval (c);
+  return c;
+}
+
+inline rvalue
 function::operator() (location loc)
 {
   return get_context ().new_call (*this, loc);
@@ -1269,6 +1291,14 @@  function::operator() (rvalue arg0, rvalue arg1,
 				  arg0, arg1,
 				  loc);
 }
+inline rvalue
+function::operator() (rvalue arg0, rvalue arg1, rvalue arg2,
+		      location loc)
+{
+  return get_context ().new_call (*this,
+				  arg0, arg1, arg2,
+				  loc);
+}
 
 // class block
 inline block::block () : object (NULL) {}
@@ -1327,6 +1357,29 @@  rvalue::dereference (location loc)
 					     loc.get_inner_location ()));
 }
 
+inline rvalue
+rvalue::cast_to (type type_,
+		 location loc)
+{
+  return get_context ().new_cast (*this, type_, loc);
+}
+
+inline lvalue
+rvalue::operator[] (rvalue index)
+{
+  return get_context ().new_array_access (*this, index);
+}
+
+inline lvalue
+rvalue::operator[] (int index)
+{
+  context ctxt = get_context ();
+  type int_t = ctxt.get_int_type <int> ();
+  return ctxt.new_array_access (*this,
+				ctxt.new_rvalue (int_t,
+						 index));
+}
+
 // class lvalue : public rvalue
 inline lvalue::lvalue () : rvalue () {}
 inline lvalue::lvalue (gcc_jit_lvalue *inner)