diff mbox

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

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

Commit Message

David Malcolm Feb. 14, 2014, 9:54 p.m. UTC
Committed to branch dmalcolm/jit:

gcc/jit/
	* libgccjit++.h (gccjit::type::zero): New method.
	(gccjit::type::one): New method.
	(gccjit::function::add_call): New family of overloaded methods.

gcc/testsuite/
	* jit.dg/test-operator-overloading.cc (make_test_quadratic): Use
	the new "zero" and "one" methods of gccjit::type.
	* jit.dg/test-quadratic.cc (make_test_quadratic): Use the new
	"add_call" method of gccjit::function.
---
 gcc/jit/ChangeLog.jit                             |  6 +++
 gcc/jit/libgccjit++.h                             | 65 +++++++++++++++++++++++
 gcc/testsuite/ChangeLog.jit                       |  7 +++
 gcc/testsuite/jit.dg/test-operator-overloading.cc |  4 +-
 gcc/testsuite/jit.dg/test-quadratic.cc            |  3 +-
 5 files changed, 81 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/gcc/jit/ChangeLog.jit b/gcc/jit/ChangeLog.jit
index 603dd96..39706f6 100644
--- a/gcc/jit/ChangeLog.jit
+++ b/gcc/jit/ChangeLog.jit
@@ -1,3 +1,9 @@ 
+2014-02-14  David Malcolm  <dmalcolm@redhat.com>
+
+	* libgccjit++.h (gccjit::type::zero): New method.
+	(gccjit::type::one): New method.
+	(gccjit::function::add_call): New family of overloaded methods.
+
 2014-02-13  David Malcolm  <dmalcolm@redhat.com>
 
 	* libgccjit.h (gcc_jit_context_get_builtin_function): New.
diff --git a/gcc/jit/libgccjit++.h b/gcc/jit/libgccjit++.h
index 897b262..a718d0c 100644
--- a/gcc/jit/libgccjit++.h
+++ b/gcc/jit/libgccjit++.h
@@ -259,6 +259,9 @@  namespace gccjit
 
     type get_pointer ();
 
+    // Shortcuts for getting values of numeric types:
+    rvalue zero ();
+    rvalue one ();
  };
 
   class function : public object
@@ -311,6 +314,20 @@  namespace gccjit
     void add_return (rvalue rvalue,
 		     location loc = location ());
 
+    /* A way to add a function call to the body of a function being
+       defined, with various numbers of args.  */
+    rvalue add_call (function other,
+		     location loc = location ());
+    rvalue add_call (function other,
+		     rvalue arg0,
+		     location loc = location ());
+    rvalue add_call (function other,
+		     rvalue arg0, rvalue arg1,
+		     location loc = location ());
+    rvalue add_call (function other,
+		     rvalue arg0, rvalue arg1, rvalue arg2,
+		     location loc = location ());
+
     /* A series of overloaded operator () with various numbers of arguments
        for a very terse way of creating a call to this function.  The call
        is created within the same context as the function itself, which may
@@ -991,6 +1008,18 @@  type::get_pointer ()
   return type (gcc_jit_type_get_pointer (get_inner_type ()));
 }
 
+inline rvalue
+type::zero ()
+{
+  return get_context ().new_rvalue (*this, 0);
+}
+
+inline rvalue
+type::one ()
+{
+  return get_context ().new_rvalue (*this, 1);
+}
+
 // class function
 inline function::function () : object (NULL) {}
 inline function::function (gcc_jit_function *inner)
@@ -1136,6 +1165,42 @@  function::add_return (rvalue rvalue,
 }
 
 inline rvalue
+function::add_call (function other,
+		    location loc)
+{
+  rvalue c = get_context ().new_call (other, loc);
+  add_eval (c);
+  return c;
+}
+inline rvalue
+function::add_call (function other,
+		    rvalue arg0,
+		    location loc)
+{
+  rvalue c = get_context ().new_call (other, arg0, loc);
+  add_eval (c);
+  return c;
+}
+inline rvalue
+function::add_call (function other,
+		    rvalue arg0, rvalue arg1,
+		    location loc)
+{
+  rvalue c = get_context ().new_call (other, arg0, arg1, loc);
+  add_eval (c);
+  return c;
+}
+inline rvalue
+function::add_call (function other,
+		    rvalue arg0, rvalue arg1, rvalue arg2,
+		    location loc)
+{
+  rvalue c = get_context ().new_call (other, arg0, arg1, arg2, loc);
+  add_eval (c);
+  return c;
+}
+
+inline rvalue
 function::operator() (location loc)
 {
   return get_context ().new_call (*this, loc);
diff --git a/gcc/testsuite/ChangeLog.jit b/gcc/testsuite/ChangeLog.jit
index 1aa8082..ec1d76a 100644
--- a/gcc/testsuite/ChangeLog.jit
+++ b/gcc/testsuite/ChangeLog.jit
@@ -1,3 +1,10 @@ 
+2014-02-14  David Malcolm  <dmalcolm@redhat.com>
+
+	* jit.dg/test-operator-overloading.cc (make_test_quadratic): Use
+	the new "zero" and "one" methods of gccjit::type.
+	* jit.dg/test-quadratic.cc (make_test_quadratic): Use the new
+	"add_call" method of gccjit::function.
+
 2014-02-13  David Malcolm  <dmalcolm@redhat.com>
 
 	* jit.dg/harness.h (CHECK_DOUBLE_VALUE): New macro.
diff --git a/gcc/testsuite/jit.dg/test-operator-overloading.cc b/gcc/testsuite/jit.dg/test-operator-overloading.cc
index 1124d9c..226cb22 100644
--- a/gcc/testsuite/jit.dg/test-operator-overloading.cc
+++ b/gcc/testsuite/jit.dg/test-operator-overloading.cc
@@ -253,11 +253,11 @@  make_test_quadratic (quadratic_test &testcase)
   test_quadratic.add_assignment (*r1, minus_b / two_a);
 
   /* "return 1;" */
-  test_quadratic.add_return (testcase.ctxt.one (testcase.int_type));
+  test_quadratic.add_return (testcase.int_type.one ());
 
   /* else return 0; */
   test_quadratic.place_forward_label (on_negative_discriminant);
-  test_quadratic.add_return (testcase.ctxt.zero (testcase.int_type));
+  test_quadratic.add_return (testcase.int_type.zero ());
 
   /* Verify that output stream operator << works.  */
   std::ostringstream os;
diff --git a/gcc/testsuite/jit.dg/test-quadratic.cc b/gcc/testsuite/jit.dg/test-quadratic.cc
index ba58c18..f7333e5 100644
--- a/gcc/testsuite/jit.dg/test-quadratic.cc
+++ b/gcc/testsuite/jit.dg/test-quadratic.cc
@@ -208,8 +208,7 @@  make_test_quadratic (quadratic_test &testcase)
   test_quadratic.add_assignment (q.access_field (testcase.c), c);
   /* calc_discriminant (&q); */
   gccjit::rvalue address_of_q = q.get_address ();
-  test_quadratic.add_eval (
-    testcase.ctxt.new_call (testcase.calc_discriminant, address_of_q));
+  test_quadratic.add_call (testcase.calc_discriminant, address_of_q);
 
   gccjit::label on_positive_discriminant
     = test_quadratic.new_forward_label ("positive_discriminant");