Re: [PATCH 17/27] New file: gcc/jit/libgccjit++.h

2014-11-03 Thread Jeff Law

On 10/31/14 11:02, David Malcolm wrote:

This adds a C++ wrapper API, with syntactic sugar for reducing the
verbosity compared to the C API.

gcc/jit/
* libgccjit++.h: New.

OK.
Jeff



[PATCH 17/27] New file: gcc/jit/libgccjit++.h

2014-10-31 Thread David Malcolm
This adds a C++ wrapper API, with syntactic sugar for reducing the
verbosity compared to the C API.

gcc/jit/
* libgccjit++.h: New.
---
 gcc/jit/libgccjit++.h | 1574 +
 1 file changed, 1574 insertions(+)
 create mode 100644 gcc/jit/libgccjit++.h

diff --git a/gcc/jit/libgccjit++.h b/gcc/jit/libgccjit++.h
new file mode 100644
index 000..67ed5d5
--- /dev/null
+++ b/gcc/jit/libgccjit++.h
@@ -0,0 +1,1574 @@
+/* A C++ API for libgccjit, purely as inline wrapper functions.
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+http://www.gnu.org/licenses/.  */
+
+#ifndef LIBGCCJIT_PLUS_PLUS_H
+#define LIBGCCJIT_PLUS_PLUS_H
+
+#include libgccjit.h
+
+#include limits
+#include ostream
+#include vector
+
+/
+ C++ API
+ /
+
+namespace gccjit
+{
+  class context;
+  class location;
+  class field;
+  class type;
+  class struct_;
+  class param;
+  class function;
+  class block;
+  class rvalue;
+  class lvalue;
+
+  /* Errors within the API become C++ exceptions of this class.  */
+  class error
+  {
+  };
+
+  class object
+  {
+  public:
+context get_context () const;
+
+std::string get_debug_string () const;
+
+  protected:
+object ();
+object (gcc_jit_object *obj);
+
+gcc_jit_object *get_inner_object () const;
+
+  private:
+gcc_jit_object *m_inner_obj;
+  };
+
+  inline std::ostream operator  (std::ostream stream, const object obj);
+
+  /* Some client code will want to supply source code locations, others
+ won't.  To avoid doubling the number of entrypoints, everything
+ accepting a location also has a default argument.  To do this, the
+ other classes need to see that location has a default constructor,
+ hence we need to declare it first.  */
+  class location : public object
+  {
+  public:
+location ();
+location (gcc_jit_location *loc);
+
+gcc_jit_location *get_inner_location () const;
+  };
+
+  class context
+  {
+  public:
+static context acquire ();
+context ();
+context (gcc_jit_context *ctxt);
+
+gccjit::context new_child_context ();
+
+gcc_jit_context *get_inner_context () { return m_inner_ctxt; }
+
+void release ();
+
+gcc_jit_result *compile ();
+
+void dump_to_file (const std::string path,
+  bool update_locations);
+
+void set_int_option (enum gcc_jit_int_option opt,
+int value);
+
+void set_bool_option (enum gcc_jit_bool_option opt,
+ int value);
+
+location
+new_location (const std::string filename,
+ int line,
+ int column);
+
+type get_type (enum gcc_jit_types kind);
+type get_int_type (size_t num_bytes, int is_signed);
+
+/* A way to map a specific int type, using the compiler to
+   get the details automatically e.g.:
+ gccjit::type type = get_int_type my_int_type_t ();  */
+template typename T
+type get_int_type ();
+
+type new_array_type (type element_type, int num_elements,
+location loc = location ());
+
+field new_field (type type_, const std::string name,
+location loc = location ());
+
+struct_ new_struct_type (const std::string name,
+std::vectorfield fields,
+location loc = location ());
+
+struct_ new_opaque_struct_type (const std::string name,
+   location loc = location ());
+
+param new_param (type type_,
+const std::string name,
+location loc = location ());
+
+function new_function (enum gcc_jit_function_kind kind,
+  type return_type,
+  const std::string name,
+  std::vectorparam params,
+  int is_variadic,
+  location loc = location ());
+
+function get_builtin_function (const std::string name);
+
+lvalue new_global (type type_,
+  const std::string name,
+  location loc = location ());
+
+rvalue new_rvalue (type numeric_type,
+  int value) const;
+rvalue