Add some methods to the C++ wrapper API.

gcc/jit/
	* libgccjit++.h: Include <ostream> rather than <iostream>, since
	the former gets us std::ostream, and the latter may introduce
	startup-time overhead for constructing std::cout et al.
	(gccjit::context::new_child_context): New.
	(gccjit::context::release): New.
	(gccjit::context::compile): New.
	(gccjit::context::set_int_option): New.
	(gccjit::context::set_bool_option): New.
Update TODO.rst

gcc/jit/
	* TODO.rst: Update.
Use default arguments to eliminate half of the methods in the C++ wrapper API.

Consolidate the with/without source location pairs of methods in the
C++ wrapper API into individual methods.  This should all compile down to
just the equivalent of supplying a NULL (gcc_jit_location *) where the
client code doesn't provide a gccjit::location.

gcc/jit/
	* libgccjit++.h (gccjit::object, gccjit::location): Move
	these declarations to before that of gccjit::context so that
	the various methods of context taking a location can have a
	default location value.
	(gccjit::context::new_array_type): Consolidate two methods,
	one accepting a gccjit::location, the other without, by
	providing a default argument (which thus has to be moved to the
	end of the argument list).
	(gccjit::context::new_field): Likewise.
	(gccjit::context::new_struct_type): Likewise.
	(gccjit::context::new_param): Likewise.
	(gccjit::context::new_function): Likewise.
	(gccjit::context::new_unary_op): Likewise.
	(gccjit::context::new_binary_op): Likewise.
	(gccjit::context::new_comparison): Likewise.
	(gccjit::context::new_call): Likewise.
	(gccjit::context::new_array_access): Likewise.
	(gccjit::function::new_local): Likewise.
	(gccjit::function::add_eval): Likewise.
	(gccjit::function::add_assignment): Likewise.
	(gccjit::function::add_assignment_op): Likewise.
	(gccjit::function::add_comment): Likewise.
	(gccjit::function::add_conditional): Likewise.
	(gccjit::function::add_label): Likewise.
	(gccjit::function::place_forward_label): Likewise.
	(gccjit::function::add_jump): Likewise.
	(gccjit::function::add_return): Likewise.
	(gccjit::rvalue::access_field): Likewise.
	(gccjit::rvalue::dereference_field): Likewise.
	(gccjit::rvalue::dereference): Likewise.
	(gccjit::lvalue::access_field): Likewise.
	(gccjit::lvalue::get_address): Likewise.
Use std::string rather than const char * in C++ wrapper API.

gcc/jit/
	* libgccjit++.h (gccjit::context::new_location): Update filename
	arg from a const char * to a const std::string &.
	(gccjit::context::new_field): Likewise for "name" arg.
	(gccjit::context::new_struct_type): Likewise.
	(gccjit::context::new_param): Likewise.
	(gccjit::context::new_function): Likewise.
	(gccjit::function::new_local): Likewise.
	(gccjit::context::new_rvalue): Likewise for "value" arg.
	(gccjit::function::add_comment): Likewise for "text" arg.
	(gccjit::function::new_forward_label): Likewise for "name" arg; add
	variant taking no args for anonymous labels.
	(gccjit::function::add_label): Likewise.
Pass std::vector by reference within the C++ wrapper API

gcc/jit/
	* libgccjit++.h (gccjit::context::new_struct_type): Pass std::vector
	"fields" argument by reference rather than by value.
	(gccjit::context::new_function): Likewise, for "params" arg.
	(gccjit::context::new_call): Likewise, for "args" arg.

gcc/testsuite/
	* jit.dg/test-quadratic.cc (make_test_quadratic): Update for
	change to gccjit::context::new_call to pass args by reference
	rather than by value.
Provide a more terse C++ wrapper API.

Add some more methods to the C++ wrapper API to reduce the amount of
typing needed when performing specific operations, albeit it without going
all the way to using operator overloading, since the latter is often too
"magical" for some people's taste, and may make it impossible to specify
the context within which the resulting object lives.

We retain the more general wrapper APIs, since having both generic and
specialized methods seems to be useful (based on my ongoing experiments
porting GNU Octave's existing JIT compiler to libgccjit).

gcc/jit/
	* libgccjit++.h (gccjit::context::new_minus): New method,
	providing a way to do a specific unary op with less typing.
	(gccjit::context::new_bitwise_negate): Likewise.
	(gccjit::context::new_logical_negate): Likewise.

	(gccjit::context::new_plus): Likewise, for binary op.
	(gccjit::context::new_minus): Likewise.
	(gccjit::context::new_mult): Likewise.
	(gccjit::context::new_divide): Likewise.
	(gccjit::context::new_modulo): Likewise.
	(gccjit::context::new_bitwise_and): Likewise.
	(gccjit::context::new_bitwise_xor): Likewise.
	(gccjit::context::new_bitwise_or): Likewise.
	(gccjit::context::new_logical_and): Likewise.
	(gccjit::context::new_logical_or): Likewise.

	(gccjit::context::new_eq): Likewise, for comparison.
	(gccjit::context::new_ne): Likewise.
	(gccjit::context::new_lt): Likewise.
	(gccjit::context::new_le): Likewise.
	(gccjit::context::gccjit::context::new_gt): Likewise.
	(gccjit::context::gccjit::context::new_ge): Likewise.

	(gccjit::context::new_call): Add a series of overloaded methods
	for specific numbers of args (from 0 - 6), to avoid the need for
	client code to manually build a std::vector (or requiring C++11).

gcc/testsuite/
	* jit.dg/test-quadratic.cc (make_calc_discriminant): Make use of
	new methods of the C++ wrapper API to shorten the example code.
	(make_test_quadratic): Likewise.
Add operator overloading to the C++ API.

gcc/jit/
	* libgccjit++.h (gccjit::object::get_context): New method.
	(gccjit::function): Add overloaded operator () for various
	numbers of arguments as a very terse way of creating function calls.
	(gccjit::rvalue::get_type): New method.

	(operator-): New overloaded unary op for rvalues.
	(operator~): Likewise.
	(operator!): Likewise.

	(operator+): New overloaded binary op for rvalues.
	(operator-): Likewise.
	(operator*): Likewise.
	(operator/): Likewise.
	(operator%): Likewise.
	(operator&): Likewise.
	(operator^): Likewise.
	(operator|): Likewise.
	(operator&&): Likewise.
	(operator||): Likewise.

	(operator==): New overloaded comparison for rvalues.
	(operator!=): Likewise.
	(operator<): Likewise.
	(operator<=): Likewise.
	(operator>): Likewise.
	(operator>=): Likewise.

	(operator*): New overloaded operator for dereferencing an
	rvalue representing a pointer.

	* libgccjit.c (gcc_jit_rvalue_get_type): New.
	* libgccjit.h (gcc_jit_rvalue_get_type): New.
	* libgccjit.map (gcc_jit_rvalue_get_type): New.

gcc/testsuite/
	* jit.dg/test-operator-overloading.cc: New testcase, a
	rewrite of test-quadratic.cc to use operator overloading.
Mark "get_inner_" methods as const within C++ wrapper API.

gcc/jit/
	* libgccjit++.h (gccjit::object::get_inner_object): Make const.
	(gccjit::location::get_inner_location): Likewise.
	(gccjit::field::get_inner_field): Likewise.
	(gccjit::type::get_inner_type): Likewise.
	(gccjit::function::get_inner_function): Likewise.
	(gccjit::label::get_inner_label): Likewise.
	(gccjit::rvalue::get_inner_rvalue): Likewise.
	(gccjit::lvalue::get_inner_lvalue): Likewise.
	(gccjit::param::get_inner_param): Likewise.
Add gcc_jit_function_get_param

gcc/jit/
	* libgccjit.h (gcc_jit_function_get_param): New.
	* libgccjit.map (gcc_jit_function_get_param): New.
	* libgccjit.c (gcc_jit_function_get_param): New.
	* libgccjit++.h (gccjit::function::get_param): New.
Add the ability to get int types by size/signedness.

Provide a way to get a N-byte int with a given signedness.
Also, use template tricks in the C++ wrapper API so that one can
map types by writing e.g.

  gccjit::type index_t_gcc = ctxt.get_int_type <octave_idx_type> ();

and having the compiler figure out the details of the type and
call into libgccjit accordingly.

gcc/jit/
	* libgccjit.h (gcc_jit_context_get_int_type): New.
	* libgccjit.map (gcc_jit_context_get_int_type): New.
	* libgccjit.c (gcc_jit_context_get_int_type): New.

	* internal-api.h (gcc::jit::recording::context::get_int_type): New.
	(gcc::jit::recording::context::get_int_type<T>): New template.
	* internal-api.c (gcc::jit::recording::context::get_int_type): New.

	* libgccjit++.h: Include <limits> so we can use std::numeric_limits.
	(gccjit::context::get_int_type): New.
	(gccjit::context::get_int_type<T>): New.

gcc/testsuite/
	* jit.dg/test-types.c (struct zoo): Add field m_sized_int_type,
	to be populated by...
	(create_code): Use gcc_jit_context_get_int_type.
	(verify_code): Verify that type from gcc_jit_context_get_int_type
	works properly.
	* jit.dg/test-operator-overloading.cc (make_types): Use the
	template form of get_int_type.
	* jit.dg/test-quadratic.cc (make_types): Likewise.
Improvements to error-handling

gcc/jit/
	* internal-api.c (gcc::jit::recording::context::add_error_va): If
	GCC_JIT_STR_OPTION_PROGNAME is NULL, use "libgccjit.so", as per
	the comment in libgccjit.h
	(gcc::jit::recording::label::replay_into): When reporting on an
	unplaced label, include the name of the containing function in
	the error message.
	* libgccjit.c: Remove comment about "Functions for use within the
	code factory", as this distinction went away in commit
	96b218c9a1d5f39fb649e02c0e77586b180e8516.
	(RETURN_VAL_IF_FAIL_PRINTF4): New.
	(RETURN_NULL_IF_FAIL_PRINTF4): New.
	(jit_error): Invoke vfprintf with the correct format string in
	the NULL context case.
	(gcc_jit_context_new_call): Check for NULL entries within the
	array of arguments.
Fix error message in test

gcc/testsuite/
	* jit.dg/test-error-unplaced-label.c (verify_code): Update
	expected error message to reflect commit
	6cd4f82c5237cc328aea229cdaaa428ff09d6e98.
Add an explicit boolean type

gcc/jit/
	* libgccjit.h (enum gcc_jit_types): Add GCC_JIT_TYPE_BOOL.

	* internal-api.h (gcc::jit::recording::comparison::comparison): Use
	GCC_JIT_TYPE_BOOL as the types of comparisons, rather than
	GCC_JIT_TYPE_INT.

	* internal-api.c (gcc::jit::recording::memento_of_get_type::
	dereference): Handle GCC_JIT_TYPE_BOOL (with an error).
	(get_type_strings): Add GCC_JIT_TYPE_BOOL.
	(get_tree_node_for_type): Handle GCC_JIT_TYPE_BOOL.

gcc/testsuite/
	* jit.dg/test-types.c: Add test coverage for getting type
	GCC_JIT_TYPE_BOOL.
	* jit.dg/test-expressions.c (make_test_of_comparison): Convert
	return type from int to bool.
	(verify_comparisons): Likewise.
For now, require function names to be valid C identifiers

gcc/jit/
	* libgccjit.c (IS_ASCII_ALPHA): New macro.
	(IS_ASCII_DIGIT): New macro.
	(IS_ASCII_ALNUM): New macro.
	(gcc_jit_context_new_function): Require that function names be valid
	C identifiers for now, to avoid later problems in the assembler.
add missing gcc/jit/ChangeLog.jit entry
New API entrypoint: gcc_jit_context_get_builtin_function

This commit adds the ability for client code to look up GCC builtins by
name, potentially allowing GCC to optimize the resulting function usage
based on what it knows about the behavior of each builtin.

Note that if the optimizer can't eliminate the call, the generated caller
code will still require machine code for the callee, and thus may need
the DSO implementing the "builtin" to already be linked into the client
process, or you'll get a linker error - so perhaps "builtin" is a bad
name?

Implementing this required creating function types (to handle
builtin-types.def), which are used internally by the new builtins_manager.
They're not yet exposed to client code.

gcc/jit/
	* libgccjit.h (gcc_jit_context_get_builtin_function): New.
	* libgccjit.map (gcc_jit_context_get_builtin_function): New.
	* libgccjit++.h (gccjit::context::get_builtin_function): New method.

	* Make-lang.in (jit_OBJS): Add jit/jit-builtins.o
	* jit-builtins.c: New source file, for managing builtin functions
	and their types.
	* jit-builtins.h: Likewise.

	* libgccjit.c (gcc_jit_context_new_function): Pass BUILT_IN_NONE for
	the new argument of new_function
	(gcc_jit_context_get_builtin_function): New.

	* internal-api.h: Add idempotency guards.
	(gcc::jit::recording::context::new_function): Add parameter
	for builtin functions.
	(gcc::jit::recording::context::get_builtin_function): New method.
	(gcc::jit::recording::context::m_builtins_manager): New field.
	(gcc::jit::recording::type::as_a_function_type): New virtual function.
	(gcc::jit::recording::function_type): New subclass of type.
	(gcc::jit::recording::function::function): Add parameter for
	builtin functions.
	(gcc::jit::recording::function::m_builtin_id): New field.
	(gcc::jit::recording::function::new_function_type): New method.
	(gcc::jit::playback::function::function):  Add parameter for
	builtin functions.
	* internal-api.c (gcc::jit::recording::context::context):
	NULL-initialize new field m_builtins_manager.
	(gcc::jit::recording::context::~context): Clean up the builtins
	manager, if one has been created.
	(gcc::jit::recording::context::new_function): Add parameter
	(gcc::jit::recording::context::get_builtin_function): New method.
	(gcc::jit::recording::function_type::function_type): Implement
	constructor for new subclass.
	(gcc::jit::recording::function_type::dereference): Implement
	method for new subclass.
	(gcc::jit::recording::function_type::replay_into): Likewise.
	(gcc::jit::recording::function_type::make_debug_string): Likewise.
	(gcc::jit::recording::function::function): Add parameter for
	builtin functions.
	(gcc::jit::recording::function::replay_into): Likewise for
	creation of playback object.
	(gcc::jit::recording::function::new_function_type): New method.
	(gcc::jit::playback::function::new_function):  Add parameter for
	builtin functions, using it to set up the fndecl accordingly.

gcc/testsuite/
	* jit.dg/harness.h (CHECK_DOUBLE_VALUE): New macro.
	(CHECK): New macro.
	* jit.dg/test-functions.c: New testcase, exercising
	gcc_jit_context_get_builtin_function.
	* jit.dg/test-combination.c: Add test-functions.c to the combined
	test.
Add some syntactic sugar to C++ wrapper API

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.
Avoid using a NULL context when reporting errors

gcc/jit/
	* libgccjit.c (gcc_jit_function_new_local): Use the context of the
	function when reporting errors.
	(gcc_jit_function_place_forward_label): Likewise.
	(gcc_jit_function_add_eval): Likewise.
	(gcc_jit_function_add_assignment_op): Likewise.
	(gcc_jit_function_add_comment): Likewise.
	(gcc_jit_function_add_jump): Likewise.
Support self-referential data structures (API changes).

New API type:
  - gcc_jit_struct

New API entrypoints:
  - gcc_jit_context_new_opaque_struct
  - gcc_jit_struct_as_type
  - gcc_jit_struct_set_fields
  - gcc_jit_context_null: get the NULL value for a pointer type.

Changed API entrypoint:
  - gcc_jit_context_new_struct_type: changed return type from
    (gcc_jit_type *) to (gcc_jit_struct *).

Internally, split out populating the fields of a struct from the creation
of said struct.

Also, require conditionals to be of boolean type (so that conversions must,
for now, be explicit), since the implicit behavior of passing in a pointer
didn't match that of C.

gcc/jit/
	* libgccjit.h (gcc_jit_struct): New.
	(gcc_jit_context_new_struct_type): Change return type from gcc_jit_type
	to gcc_jit_struct.
	(gcc_jit_context_new_opaque_struct): New.
	(gcc_jit_struct_as_type): New.
	(gcc_jit_struct_set_fields): New.
	(gcc_jit_context_null): New.

	* libgccjit.map (gcc_jit_context_new_opaque_struct): New.
	(gcc_jit_context_null): New.
	(gcc_jit_struct_as_type): New.
	(gcc_jit_struct_set_fields): New.

	* libgccjit++.h (gccjit::context::new_struct_type): Return a
	struct_ rather than a type.
	(gccjit::context::new_opaque_struct_type): New.
	(gccjit::struct_): New subclass of type.

	* libgccjit.c (gcc_jit_struct): New.
	(RETURN_VAL_IF_FAIL_PRINTF1): New.
	(RETURN_VAL_IF_FAIL_PRINTF2): New.
	(RETURN_NULL_IF_FAIL_PRINTF1): New.
	(RETURN_IF_FAIL_PRINTF1): New.
	(RETURN_IF_FAIL_PRINTF2): New.
	(gcc_jit_context_new_struct_type): Return a gcc_jit_struct rather
	than a gcc_jit_type; implement by creating the struct, then
	setting the fields in it.
	(gcc_jit_context_new_opaque_struct): New.
	(gcc_jit_struct_as_type): New.
	(gcc_jit_struct_set_fields): New.
	(gcc_jit_context_null): New.
	(gcc_jit_lvalue_access_field): Use the struct's context when
	reporting on a NULL field; verify that the field has been placed
	in a struct.
	(gcc_jit_rvalue_access_field): Likewise.
	(is_bool): New.
	(gcc_jit_function_add_conditional): Use the function's context
	when reporting errors; verify that boolval's type is indeed
	boolean.
	(gcc_jit_function_new_loop): Likewise.

	* internal-api.h (gcc::jit::recording::context::new_struct_type):
	Don't accept fields, and return a struct_ rather than a type_, so
	that fields can be set later.
	(gcc::jit::recording::struct_::struct_): Store a (fields *) rather
	than a vec of fields.
	(gcc::jit::recording::struct_::as_type): New.
	(gcc::jit::recording::struct_::get_fields): New.
	(gcc::jit::recording::struct_::set_fields): New.
	(gcc::jit::recording::struct_::playback_struct): New.
	(gcc::jit::recording::fields): New class.
	(gcc::jit::playback::context::new_struct_type): Don't accept
	fields, and return a struct_ rather than a type_, so that fields
	can be set later.
	(gcc::jit::playback::struct_): New subclass of type.

	* internal-api.c (gcc::jit::recording::context::get_type): With
	nested contexts, create basic types within the ultimate parent
	context, allowing for a fast check for the boolean type using
	pointer equality.
	(gcc::jit::recording::context::new_struct_type): Don't accept
	fields, and return a struct_ rather than a type_, so that fields
	can be set later.
	(gcc::jit::recording::context::get_opaque_FILE_type): Update for
	struct-creation changes.
	(gcc::jit::recording::struct_::struct_): Store a (fields *) rather
	than a vec of fields.
	(gcc::jit::recording::struct_::set_fields): New.
	(gcc::jit::recording::struct_::replay_into): Don't playback the
	fields, as this is now done by a fields instance.
	(gcc::jit::recording::fields::fields): New.
	(gcc::jit::recording::fields::replay_into): New.
	(gcc::jit::recording::fields::make_debug_string): New.
	(gcc::jit:: playback::context::new_struct_type): Don't accept
	fields, and return a struct_ rather than a type_, so that fields
	can be set later.
	(gcc::jit::playback::struct_::set_fields): New.

	* TODO.rst: Update.

gcc/testsuite/
	* jit.dg/test-accessing-struct.c (create_code): Update for change to
	return type of gcc_jit_context_new_struct_type.
	* jit.dg/test-arrays.c (create_code): Likewise.
	* jit.dg/test-error-accessing-field-in-other-struct.c (create_code):
	Likewise.
	* jit.dg/test-error-dereference-field-of-non-pointer.c (create_code):
	Likewise.
	* jit.dg/test-fuzzer.c (make_random_type): Likewise.
	* jit.dg/test-nested-contexts.c (make_types): Likewise.
	* jit.dg/test-quadratic.c (make_types): Likewise.
	* jit.dg/test-reading-struct.c (create_code): Likewise.
	* jit.dg/test-types.c (create_code): Likewise.

	* jit.dg/test-linked-list.c: New selftest, exercising
	gcc_jit_context_new_opaque_struct, gcc_jit_type_get_pointer, and
	gcc_jit_context_null.
	* jit.dg/test-combination.c: Add test-linked-list.c
Add some type-checking to parameters requiring pointers

gcc/jit/
	* libgccjit.c (gcc_jit_context_new_rvalue_from_ptr): Verify that
	pointer_type is indeed a pointer type.
	(gcc_jit_context_null): Likewise.
	(gcc_jit_context_new_array_access): Verify that ptr is indeed a
	pointer.

	* TODO.rst: Update