Major API change: blocks rather than labels

In the old API, statements were added to functions, with an implicit
insertion position within each function.  Control flow was expressed by
creating and placing labels.

With this commit, the API changes to using basic blocks instead: blocks
are created within functions, and statements are added to blocks, rather
than to functions.

The old API worked, but I found it to be error-prone: in my ongoing
attempts to port GNU Octave's JIT compiler to libgccjit, long debugging
sessions indicated places where I'd created functions incorrectly, leading
to bogus code being created.  The block-based API can detect such mistakes
at JIT-compile time, failing fast with a clear error message for:
  * unterminated blocks (which will catch some kinds of missing return value)
  * missing return value (a function with a non-void return with no blocks)
  * unreachable blocks
  * adding something to a terminated block
  * jump to a block in another function

This commit also eliminates the loop part of the API: I haven't seen it
used in real code, only in testcases - the C++ wrapper API didn't support
it, and I hadn't noticed that it didn't.  I ported the three testcases
that used the loop API to instead directly work with blocks, and the result
seems clearer.

gcc/jit/
	* libgccjit.h (gcc_jit_label): Delete in favor of...
	(gcc_jit_block): New type.
	(gcc_jit_loop): Delete.

	(gcc_jit_function_new_forward_label): Delete in favor of...
	(gcc_jit_function_new_block): New.

	(gcc_jit_label_as_object): Delete in favor of...
	(gcc_jit_block_as_object): New.

	(gcc_jit_function_add_eval): Delete in favor of...
	(gcc_jit_block_add_eval): New.

	(gcc_jit_function_add_assignment): Delete in favor of...
	(gcc_jit_block_add_assignment): New.

	(gcc_jit_function_add_assignment_op): Delete in favor of...
	(gcc_jit_block_add_assignment_op): New.

	(gcc_jit_function_add_comment): Delete in favor of...
	(gcc_jit_block_add_comment): New.

	(gcc_jit_label_as_object): Delete in favor of...
	(gcc_jit_block_as_object): New.

	(gcc_jit_function_add_conditional): Delete in favor of...
	(gcc_jit_block_end_with_conditional): New.

	(gcc_jit_function_add_jump): Delete in favor of...
	(gcc_jit_block_end_with_jump): New.

	(gcc_jit_function_add_return): Delete in favor of...
	(gcc_jit_block_end_with_return): New.

	(gcc_jit_function_add_void_return): Delete in favor of...
	(gcc_jit_block_end_with_void_return): New.

	(gcc_jit_function_new_loop): Delete.
	(gcc_jit_function_new_loop_over_range): Delete.
	(gcc_jit_loop_as_object): Delete.
	(gcc_jit_loop_end): Delete.

	* libgccjit.map (gcc_jit_function_add_assignment): Delete in favor of...
	(gcc_jit_block_add_assignment): New.

	(gcc_jit_function_add_assignment_op): Delete in favor of...
	(gcc_jit_block_add_assignment_op): New.

	(gcc_jit_function_add_comment): Delete in favor of...
	(gcc_jit_block_add_comment): New.

	(gcc_jit_function_add_eval): Delete in favor of...
	(gcc_jit_block_add_eval): New.

	(gcc_jit_label_as_object): Delete in favor of...
	(gcc_jit_block_as_object): New.

	(gcc_jit_function_add_conditional): Delete in favor of...
	(gcc_jit_block_end_with_conditional): New.

	(gcc_jit_function_add_jump): Delete in favor of...
	(gcc_jit_block_end_with_jump): New.

	(gcc_jit_function_add_return): Delete in favor of...
	(gcc_jit_block_end_with_return): New.

	(gcc_jit_function_add_void_return): Delete in favor of...
	(gcc_jit_block_end_with_void_return): New.

	(gcc_jit_function_add_label): Delete in favor of...
	(gcc_jit_function_new_block): New.
	(gcc_jit_function_new_forward_label): Delete.
	(gcc_jit_function_place_forward_label): Delete.

	(gcc_jit_function_new_loop): Delete.
	(gcc_jit_function_new_loop_over_range): Delete.
	(gcc_jit_loop_as_object): Delete.
	(gcc_jit_loop_end): Delete.

	* libgccjit.c (gcc_jit_label): Delete in favor of...
	(gcc_jit_block): New type.
	(gcc_jit_loop): Delete.

	(RETURN_IF_NOT_FUNC_DEFINITION): Delete in favor of...
	(RETURN_IF_NOT_VALID_BLOCK): New macro.
	(RETURN_NULL_IF_NOT_FUNC_DEFINITION): Delete in favor of...
	(RETURN_NULL_IF_NOT_VALID_BLOCK): New macro.

	(gcc_jit_function_new_forward_label): Delete in favor of...
	(gcc_jit_function_new_block): New.

	(gcc_jit_label_as_object): Delete in favor of...
	(gcc_jit_block_as_object): New.

	(gcc_jit_rvalue_dereference_field): Ensure that field has been
	placed.

	(gcc_jit_function_add_label): Delete
	(gcc_jit_function_place_forward_label): Delete.

	(gcc_jit_function_add_eval): Delete in favor of...
	(gcc_jit_block_add_eval): New.

	(gcc_jit_function_add_assignment): Delete in favor of...
	(gcc_jit_block_add_assignment): New.

	(gcc_jit_function_add_assignment_op): Delete in favor of...
	(gcc_jit_block_add_assignment_op): New.

	(gcc_jit_function_add_conditional): Delete in favor of...
	(gcc_jit_block_end_with_conditional): New.

	(gcc_jit_function_add_comment): Delete in favor of...
	(gcc_jit_block_add_comment): New.

	(gcc_jit_function_add_jump): Delete in favor of...
	(gcc_jit_block_end_with_jump): New.

	(gcc_jit_function_add_return): Delete in favor of...
	(gcc_jit_block_end_with_return): New.

	(gcc_jit_function_add_void_return): Delete in favor of...
	(gcc_jit_block_end_with_void_return): New.

	(gcc_jit_function_new_loop): Delete.
	(gcc_jit_function_new_loop_over_range): Delete.
	(gcc_jit_loop_as_object): Delete.
	(gcc_jit_loop_end): Delete.

	* internal-api.h (gcc::jit::recording::label): Delete class in
	favor of...
	(gcc::jit::recording::block): New class.
	(gcc::jit::recording::loop): Delete class.
	(gcc::jit::recording::loop_end): Delete class.

	(gcc::jit::playback::label): Delete class in favor of...
	(gcc::jit::playback::block): New class.

	(gcc::jit::playback::loop): Delete class.

	(gcc::jit::recording::playback_label): Delete function in favor of...
	(gcc::jit::recording::playback_block): New function.

	(gcc::jit::recording::context::validate): New.

	(gcc::jit::recording::function::new_forward_label): Delete method.
	(gcc::jit::recording::function::add_eval): Delete method in favor
	of method of new gcc::jit::recording::block class.
	(gcc::jit::recording::function::add_assignment): Likewise.
	(gcc::jit::recording::function::add_assignment_op): Likewise.
	(gcc::jit::recording::function::add_comment): Likewise.
	(gcc::jit::recording::function::add_conditional): Likewise.
	(gcc::jit::recording::function::place_forward_label): Likewise.
	(gcc::jit::recording::function::add_jump): Likewise.
	(gcc::jit::recording::function::add_return): Likewise.

	(gcc::jit::recording::function::add_label): Delete method in favor of...
	(gcc::jit::recording::function::new_block): New method.

	(gcc::jit::recording::function::new_loop): Delete method.

	(gcc::jit::recording::function::validate): New method.
	(gcc::jit::recording::function::m_activity): Delete field in favor of...
	(gcc::jit::recording::function::m_blocks): New field.

	(gcc::jit::recording::statement::get_successor_blocks): New method.
	(gcc::jit::recording::statement::write_to_dump): Make public.
	(gcc::jit::recording::statement::statement): Accept a block rather
	than a function.
	(gcc::jit::recording::statement::playback_function): Delete.
	(gcc::jit::recording::statement::get_block): New.
	(gcc::jit::recording::statement::m_func): Delete in favor of...
	(gcc::jit::recording::statement::m_block): ...this.

	(gcc::jit::recording::eval::eval): Accept a block rather than a
	function.
	(gcc::jit::recording::assignment::assignment): Likewise.
	(gcc::jit::recording::assignment_op::assignment_op): Likewise.
	(gcc::jit::recording::comment::comment): Likewise.
	(gcc::jit::recording::return::return): Likewise.
	(gcc::jit::recording::conditional::conditional): Likewise; accept
	blocks rather than labels.
	(gcc::jit::recording::jump::jump): Likewise.
	(gcc::jit::recording::conditional::get_successor_blocks): New.
	(gcc::jit::recording::jump::get_successor_blocks): New.

	(gcc::jit::playback::function::new_forward_label): Delete method
	in favor of...
	(gcc::jit::playback::function::new_block): New method.
	(gcc::jit::playback::function::build_stmt_list): New method.
	(gcc::jit::playback::function::m_blocks): New field.

	* libgccjit++.h (gccjit::label): Delete class in favor of...
	(gccjit::block): New class.
	(gccjit::function::new_forward_label): Delete methods in favor of...
	(gccjit::function::new_block): New methods.
	(gccjit::function::add_comment): Delete methods in favor of methods
	of new class gccjit::block.
	(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::function::add_call): Likewise.

	* internal-api.c (gcc::jit::recording::playback_label): Delete in
	favor of...
	(gcc::jit::recording::playback_block): New.
	(gcc::jit::recording::context::compile): Validate.
	(gcc::jit::recording::context::validate): New.
	(gcc::jit::recording::function::function): Update.
	(gcc::jit::recording::function::new_forward_label): Delete.
	(gcc::jit::recording::function::add_eval): Delete.
	(gcc::jit::recording::function::add_assignment): Delete.
	(gcc::jit::recording::function::add_assignment_op): Delete.
	(gcc::jit::recording::function::new_block): New.
	(gcc::jit::recording::function::add_comment): Delete.
	(gcc::jit::ecording::function::add_conditional): Delete.
	(gcc::jit::recording::function::add_label): Delete.
	(gcc::jit::recording::function::place_forward_label): Delete.
	(gcc::jit::recording::function::add_jump): Delete.
	(gcc::jit::recording::function::add_return): Delete.
	(gcc::jit::recording::function::new_loop): Delete.
	(gcc::jit::recording::function::write_to_dump): Port to block-based
	representation.
	(gcc::jit::recording::function::validate): New.
	(gcc::jit::recording::block::add_eval): New.
	(gcc::jit::recording::block::add_assignment): New.
	(gcc::jit::recording::label::replay_into): Delete.
	(gcc::jit::recording::block::add_assignment_op): New.
	(gcc::jit::recording::block::add_comment): New.
	(gcc::jit::recording::block::end_with_conditional): New.
	(gcc::jit::recording::block::end_with_jump): New.
	(gcc::jit::recording::block::end_with_return): New.
	(gcc::jit::recording::block::write_to_dump): New.
	(gcc::jit::recording::block::validate): New.
	(gcc::jit::recording::block::get_last_statement): New.
	(gcc::jit::recording::block::get_successor_blocks): New.
	(gcc::jit::recording::block::replay_into): New.
	(gcc::jit::recording::label::make_debug_string): Delete.
	(gcc::jit::recording::block::make_debug_string): New.
	(gcc::jit::recording::statement::get_successor_blocks): New.
	(gcc::jit::recording::eval::replay_into): Port to block-based
	representation.
	(gcc::jit::recording::assignment::replay_into): Likewise.
	(gcc::jit::recording::assignment_op::replay_into): Likewise.
	(gcc::jit::recording::comment::replay_into): Likewise.
	(gcc::jit::recording::conditional::replay_into): Likewise.
	(gcc::jit::recording::jump::replay_into): Likewise.
	(gcc::jit::recording::return_::replay_into): Likewise.

	(gcc::jit::recording::conditional::get_successor_blocks): New.
	(gcc::jit::recording::place_label::place_label): Delete.
	(gcc::jit::recording::place_label::replay_into): Delete.
	(gcc::jit::recording::place_label::make_debug_string): Delete.
	(gcc::jit::recording::place_label::write_to_dump): Delete.

	(gcc::jit::recording::jump::get_successor_blocks): New.
	(gcc::jit::recording::return_::get_successor_blocks): New.

	(gcc::jit::recording::loop::replay_into): Delete.
	(gcc::jit::recording::loop::make_debug_string): Delete.
	(gcc::jit::recording::loop::end): Delete.
	(gcc::jit::recording::loop_end::replay_into): Delete.
	(gcc::jit::recording::loop_end::make_debug_string): Delete.

	(gcc::jit::playback::function::new_forward_label): Delete.
	(gcc::jit::playback::function::new_block): New.
	(gcc::jit::playback::function::build_stmt_list): New.
	(gcc::jit::playback::function::add_eval): Replace with...
	(gcc::jit::playback::block::add_eval): New.
	(gcc::jit::playback::function::add_assignment): Replace with...
	(gcc::jit::playback::block::add_assignment): New.
	(gcc::jit::playback::function::add_comment): Replace with...
	(gcc::jit::playback::block::add_comment): New, reimplementing,
	given that we no longer have labels.
	(gcc::jit::playback::function::add_conditional): Replace with...
	(gcc::jit::playback::block::add_conditional): New, reworking,
	given that on_false can no longer be NULL.
	(gcc::jit::playback::function::add_label): Delete.
	(gcc::jit::playback::function::place_forward_label): Delete.
	(gcc::jit::playback::function::add_jump): Replace with...
	(gcc::jit::playback::block::add_jump): New.
	(gcc::jit::playback::function::add_return): Replace with...
	(gcc::jit::playback::block::add_return): New.
	(gcc::jit::playback::function::new_loop): Delete.
	(gcc::jit::playback::label::label): Replace with...
	(gcc::jit::playback::block::block): ...this.

	(gcc::jit::playback::loop::loop): Delete.
	(gcc::jit::playback::loop::end): Delete.

	(gcc::jit::playback::context::replay): Call each function's
	build_stmt_list.

	* TODO.rst: Update

gcc/testsuite/
	* jit.dg/test-accessing-struct.c (create_code): Port to
	block-based API.
	* jit.dg/test-calling-external-function.c (create_code): Likewise.
	* jit.dg/test-error-accessing-field-in-other-struct.c (create_code):
	Likewise.
	* jit.dg/test-error-call-with-mismatching-args.c (create_code):
	Likewise.
	* jit.dg/test-error-call-with-not-enough-args.c (create_code):
	Likewise.
	* jit.dg/test-error-call-with-too-many-args.c (create_code):
	Likewise.
	* jit.dg/test-error-dereference-field-of-non-pointer.c (create_code):
	Likewise.
	* jit.dg/test-error-dereference-read: Likewise.
	* jit.dg/test-error-mismatching-types-in-assignment.c: Likewise.
	* jit.dg/test-error-return-within-void-function.c: Likewise.
	* jit.dg/test-expressions.c: Likewise.
	* jit.dg/test-factorial.c: Likewise.
	* jit.dg/test-functions.c: Likewise.
	* jit.dg/test-fuzzer.c: Likewise.
	* jit.dg/test-hello-world.c (create_code): Likewise.
	* jit.dg/test-nested-contexts.c: Likewise.
	* jit.dg/test-operator-overloading.cc: Likewise.
	* jit.dg/test-quadratic.c: Likewise.
	* jit.dg/test-quadratic.cc: Likewise.
	* jit.dg/test-reading-struct.c (create_code): Likewise.
	* jit.dg/test-string-literal.c (create_code): Likewise.
	* jit.dg/test-sum-of-squares.c (create_code): Likewise.
	* jit.dg/test-types.c (create_code): Likewise.
	* jit.dg/test-using-global.c (create_code): Likewise.

	* jit.dg/test-arrays.c (create_code): Likewise, eliminating use of
	loop API.
	* jit.dg/test-dot-product.c (create_code): Likewise.
	* jit.dg/test-linked-list.c (create_code): Likewise.

	* jit.dg/test-error-adding-to-terminated-block.c: New testcase.
	* jit.dg/test-error-block-in-wrong-function.c: Likewise.
	* jit.dg/test-error-missing-return.c: Likewise.
	* jit.dg/test-error-unreachable-block.c: Likewise.
	* jit.dg/test-error-unterminated-block.c: Likewise.

	* jit.dg/test-error-label-already-placed.c: Delete obsolete testcase.
	* jit.dg/test-error-unplaced-label.c: Likewise.
New API entrypoint: gcc_jit_block_get_function

gcc/jit/
	* libgccjit.h (gcc_jit_block_get_function): New.
	* libgccjit.map (gcc_jit_block_get_function): New.
	* libgccjit++.h (gccjit::block::get_function): New method.
	* libgccjit.c (gcc_jit_block_get_function): New.
New API entrypoint: gcc_jit_context_new_cast

gcc/jit/
	* libgccjit.h (gcc_jit_context_new_cast): New.
	* libgccjit.map (gcc_jit_context_new_cast): New.
	* libgccjit++.h (gccjit::context::new_cast): New method.
	* libgccjit.c (gcc_jit_context_new_cast): New.

	* internal-api.h (gcc::jit::recording::context::new_cast): New method.
	(gcc::jit::recording::cast): New subclass of rvalue.
	(gcc::jit::playback::context::new_cast): New method.
	(gcc::jit::playback::context::build_cast): New method.

	* internal-api.c (convert): New.
	(gcc::jit::recording::context::new_cast): New.
	(gcc::jit::recording::cast::replay_into): New.
	(gcc::jit::recording::cast::make_debug_string): New.
	(gcc::jit::playback::context::build_cast): New.
	(gcc::jit::playback::context::new_cast): New.

	* TODO.rst: Update.

gcc/testsuite/
	* jit.dg/test-expressions.c (make_test_of_cast): New, to test new
	entrypoint gcc_jit_context_new_cast.
	(make_tests_of_casts): New.
	(create_code): Add call to make_tests_of_casts.
	(verify_code): Add call to verify_casts.
Add typechecking to binary ops and comparisons

gcc/jit/
	* libgccjit.c (gcc_jit_context_new_binary_op): Check that the
	operands have the same type.
	(gcc_jit_context_new_comparison): Likewise.
Add more syntactic sugar to C++ wrapper API

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.
New API entrypoint: gcc_jit_type_get_volatile

gcc/jit/
	* libgccjit.h (gcc_jit_type_get_volatile): New.
	* libgccjit.map (gcc_jit_type_get_volatile): New.
	* libgccjit.c (gcc_jit_type_get_volatile): New.
	* libgccjit++.h (gccjit::type::get_volatile): New.
	* internal-api.c (gcc::jit::recording::type::get_volatile): New.
	(gcc::jit::recording::memento_of_get_volatile::replay_into): New.
	(gcc::jit::recording::memento_of_get_volatile::make_debug_string): New.
	* internal-api.h (gcc::jit::recording::type::get_volatile): New.
	(gcc::jit::recording::type::accepts_writes_from): Strip off
	qualifiers such as "const" and "volatile" from the source type.
	(gcc::jit::recording::memento_of_get_volatile): New class.
	(gcc::jit::playback::type::get_volatile): New.
	* TODO.rst: Update.

gcc/testsuite/
	* jit.dg/test-volatile.c: New testcase, to exercise
	gcc_jit_type_get_volatile, and show a way to work with pre-existing
	global variables.
Fixes to type-checking

gcc/jit/
	* internal-api.c (gcc::jit::recording::memento_of_get_pointer::
	accepts_writes_from): Avoid segfaulting when the argument is not
	of pointer type.
	* internal-api.h (gcc::jit::recording::accepts_writes_from): Add
	an assertion.
	* libgccjit.c (gcc_jit_context_new_comparison): Strip away const
	and volatile when comparing input types.

gcc/testsuite/
	* jit.dg/test-error-mismatching-types-in-call.c: New test case,
	to ensure that a (struct foo *) vs (struct foo) type error is
	gracefully handled.