diff --git a/gcc/jit/libgccjit++.h b/gcc/jit/libgccjit++.h index 8dc2112367b..5a7bf8e2c43 100644 --- a/gcc/jit/libgccjit++.h +++ b/gcc/jit/libgccjit++.h @@ -40,6 +40,7 @@ namespace gccjit class field; class type; class struct_; + class union_; class function; class block; class rvalue; @@ -158,6 +159,10 @@ namespace gccjit struct_ new_opaque_struct_type (const std::string &name, location loc = location ()); + union_ new_union_type (const std::string &name, + std::vector &fields, + location loc = location ()); + param new_param (type type_, const std::string &name, location loc = location ()); @@ -346,6 +351,16 @@ namespace gccjit gcc_jit_struct *get_inner_struct () const; }; + class union_ : public type + { + public: + union_ (); + union_ (gcc_jit_type *inner); + + gcc_jit_type *get_inner_union () const; + }; + + class function : public object { public: @@ -773,6 +788,26 @@ context::new_opaque_struct_type (const std::string &name, name.c_str ())); } +inline union_ +context::new_union_type (const std::string &name, + std::vector &fields, + location loc) +{ + /* Treat std::vector as an array, relying on it not being resized: */ + field *as_array_of_wrappers = &fields[0]; + + /* Treat the array as being of the underlying pointers, relying on + the wrapper type being such a pointer internally. */ + gcc_jit_field **as_array_of_ptrs = + reinterpret_cast (as_array_of_wrappers); + + return union_ (gcc_jit_context_new_union_type (m_inner_ctxt, + loc.get_inner_location (), + name.c_str (), + fields.size (), + as_array_of_ptrs)); +} + inline param context::new_param (type type_, const std::string &name, @@ -1317,6 +1352,13 @@ struct_::get_inner_struct () const return reinterpret_cast (get_inner_object ()); } +// class union_ +inline union_::union_ () : type (NULL) {} +inline union_::union_ (gcc_jit_type *inner) : + type (inner) +{ +} + // class function inline function::function () : object () {} inline function::function (gcc_jit_function *inner)