Commit Graph

8 Commits

Author SHA1 Message Date
Fergus Henderson
40e37d11cf Add compiler support for deciding when to use reserved addresses,
Estimated hours taken: 18
Branches: main

Add compiler support for deciding when to use reserved addresses,
and for generating code appropriately when they are used.

compiler/options.m:
doc/user_guide.texi:
	Add new options `--num-reserved-addresses'
	and `--num-reserved-objects'.

compiler/hlds_data.m:
	Add new type `reserved_address ---> null_pointer ; small_pointer(int) ;
	reserved_object(sym_name, arity)'.
	Add new cons_tag alternatives `reserved_address(reserved_address)'
	and `shared_with_reserved_address(list(reserved_address), cons_tag)'.
	Also add get_secondary_tag, for use by ml_type_gen.m.

compiler/ml_type_gen.m:
	Don't generate types for constructors represented using reserved
	addresses.  For constructors represented using reserved_object,
	generate the reserved object.
	Also, use get_secondary_tag, rather than just unifying with
	shared_remote/2, so that it works for
	shared_with_reserved_tag(_, shared_remote(_, _)).

compiler/make_tags.m:
	If --tags none and --num-reserved-addresses are both set,
	then assign null_pointer and small_pointer(int) representations
	to constants up to the value set in num-reserved-addresses.
	If --tags none and --high-level-code are both set,
	and more constants remain unassigned, then assign reserved_object
	representations for those constants, and generate static member
	variable declarations for the reserved_objects.

compiler/make_hlds.m:
	Pass down the type_id to assign_constructor_tags in make_tags.m,
	since it is needed for reserved_object representations.

compiler/ml_unify_gen.m:
compiler/unify_gen.m:
	Handle construction, deconstruction, and tag tests for
	types represented using reserved tags.
	(In unify_gen.m, only null_pointer and small_pointer(int)
	are supported; for reserved_object we call sorry/2).

compiler/ml_switch_gen.m:
compiler/switch_gen.m:
compiler/switch_util.m:
	Handle switches on types represented using reserved tags.
	XXX Currently we always use if-then-else chains for such
	    switches; this may not be efficient.

compiler/ml_code_util.m:
	Add ml_format_reserved_object_name.
	Also add accessibility parameter to ml_gen_static_const_defn,
	so that it can be used for generating the class member
	static constants used for reserved_objects.

compiler/ml_string_switch.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
	Handle the new parameter to ml_gen_static_const_defn.

compiler/bytecode_gen.m:
	Call sorry/2 if types represented using reserved addresses are
	encountered.
2001-10-24 07:10:18 +00:00
Fergus Henderson
befb329aaf Add type information to the array_index operator.
Estimated hours taken: 8
Branches: main

Add type information to the array_index operator.
This is needed for both the GCC back-end and the IL back-end.

compiler/builtin_ops.m:
	In the array_index constructor for the unary_op type,
	add the array element type as a field.

compiler/ml_string_switch.m:
compiler/string_switch.m:
compiler/mlds_to_java.m:
	When generating array_index operators, generate the new field.

compiler/bytecode.m:
compiler/llds.m:
compiler/llds_out.m:
compiler/mlds_to_c.m:
compiler/mlds_to_java.m:
	When consuming array_index operators, ignore the new field.

compiler/mlds_to_gcc.m:
	When consuming array_index operators, use the array element type,
	rather than wrongly assuming the element type is always 'MR_Integer'.

compiler/mlds_to_il.m:
	Add code to handle the array_index operator,
	rather than calling `throw_unimplemented'.

compiler/bytecode.m:
	Delete the reverse mode of binop_code.  This was not used,
	it was just there to get the compiler to check that we didn't
	map two different binary operators to the same code.  This
	mode no longer works, since we map array_index operators to
	the same code regardless of the the array element type.

compiler/rtti_to_mlds.m:
compiler/ml_string_switch.m:
compiler/ml_code_util.m:
	To avoid code duplication, move ml_string_type, which was defined in
	both rtti_to_mlds.m and ml_string_switch.m, into ml_code_util.m.

compiler/ml_string_switch.m:
	Minor changes to avoid some code duplication.

compiler/mlds_to_java.m:
	Fix a bug where it was using the wrong type for the `args' variable.
	Add an XXX comment about what looks to me like another bug.
2001-07-08 16:40:11 +00:00
Tyson Dowd
76ac44335d Implement a C# interface for the .NET backend.
Estimated hours taken: 45
Branches: main

Implement a C# interface for the .NET backend.

To use it, you currently need to set
	--backend-foreign-language csharp --use-foreign-language csharp
in your MCFLAGS.

The C# foreign language interface works by introducing a new sort of
MLDS statement called outline_foreign_proc.  outline_foreign_proc is expected
to be turned into a separate procedure in a separate file.  This is
quite different to normal foreign code which has been renamed as inline
target code, as it is really intended to be generated inline, inside the
generated code.

Because outline_foreign_proc is expected to be generated outside the
normal code, we don't need to generate variable renamings,
initializations, casts and other complicated interfacing code.

Any marshalling is done by the backend, which knows how to marshall
arguments across the boundary into the outline code and back.  In the
case of marshalling to C# from the .NET backend, we currently don't do
anything special (part of the point of .NET is that data
representation don't have to change very often just because you are
using different languages, so this is a property we should try to
preserve).

The actual implementation of the foreign code is therefore very simple.
Simply generate an appropriate procedure, and insert the user's code in
the middle.

The bulk of this change to delay the mangling of MLDS var names, so we
can still use the original user's var name when we output the outline
procedure (since the user's foreign code will refer to these var names,
it's important to keep them around).

compiler/foreign.m:
	Handle the csharp foreign language.

compiler/globals.m:
	Fix an XXX about converting to lowercase to do language name
	comparisons.
	Add new predicates to make conversion of foreign languages
	to strings more uniform.

compiler/handle_options.m:
	Don't set backend_foreign_language to the default if it has
	already been set by hand.

compiler/ml_call_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
	Delay the mangling of MLDS var names by keeping the variable
	number around until the output phase.

	Slightly generalize the handling of foreign language interfacing.
	Handle C# foreign language interfacing.

	Add value_output_vars to the ml_gen_info, which are the variables
	returned rather than passed by reference.  We need to know
	these variables for C# interfacing so that we can handle the return
	value of the forwarding function.

	Mark the beginning and end of the MLDS foreign language processing as
	a "sub-module" (in comments at least).  Later I may put this code
	into a separate module.

	Rename some predicates from c_code to foreign_code.

compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_string_switch.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/rtti_to_mlds.m:
	Handle the new var_name type, and the new target_code constructors.

compiler/mlds.m:
	Add outline_foreign_proc which is handled differently to the old
	target_code (which has been renamed inline_target_code).

	Change the definiton for mlds__var_name.

compiler/mlds_to_c.m:
	Factor out mlds_output_to_file.
	Handle the new var_name type, and the new target_code constructors.

compiler/mlds_to_csharp.m:
	A new module to generate C# code suitable for foreign language
	interfacing.  This is largely lifted from the MC++ code, with a few
	changes to the output syntax.

compiler/mlds_to_il.m:
	Return the set of foreign languages processed instead of a bool
	saying wither MC++ was present.  This is so we can generate the
	appropriate output .cs or .cpp files, and because we need to keep
	track of all the external assembly references we need to put in the
	.il file.

	Handle the inline_target_code and mlds__var_name changes.

compiler/mlds_to_ilasm.m:
	Output .cpp and .cs files conditionally.
	Factor out output_to_file.
	Move MC++ output code to mlds_to_mcpp.m

compiler/mlds_to_java.m:
	Factor out output_to_file.
	Handle the new var_name type, and the new target_code constructors.

compiler/mlds_to_mcpp.m:
	New file to handle generating MC++ code suitable for foreign language
	interfacing.

compiler/options.m:
	Add a way of setting the backend-foreign-language option.

compiler/passes_aux.m:
	Add output_to_file which is used by the MLDS backend to generate
	output files.

compiler/prog_data.m:
	Uncomment csharp as a foreign language.
2001-05-02 11:36:41 +00:00
Julien Fischer
00d8243570 General improvements and bug fixes to the MLDS backend, most
Estimated hours taken: 20

General improvements and bug fixes to the MLDS backend, most
of which were prompted by working on the Java backend.

The definition of mlds__lval now includes type information for
variables.  This is necessary because if enumerations are treated
as objects (as in the Java backend) rather than integers we need to know
when to create new objects.  At the level this occurs there was
previously no way to distinguish between an integer that is an integer,
and one that represents an enumeration.

Added the access specifier `local' to the declaration flags.  This fixes
a bug in which the local variables of a function were being declared
`private'.

Redefined ctor_name so that they are fully qualified.  This was necessary
because the Java backend represents discriminated unions as nested
classes and we need to be able to determine the fully qualified name of
the constructor in order to call it, do casts, etc.

Added `mlds__unknown_type' to `mlds__type'.  This is due to the change
in the definition of mlds_lval above.  In ml_code_util.m, env_ptr's are
created as dangling references.  The new definition of mlds__lval expects
there to be a type as well, but at this point it hasn't been
generated (and won't be until the ml_elim_nested pass).  Rather than just
guess the type we should declare the type to be unknown and print out an
error message if an unknown type makes it through to one of the backends.

Fixed a bug in the `--det-copy-out' option.

Shifted code for detecting entry point to main/2 from mercury_compile.m
to ml_util.m

compiler/mercury_compile.m:
compiler/ml_util.m:
	Shifted code for detecting entry point to main/2 from mercury_compile.m
	to ml_util.m
compiler/mlds.m:
	Added `local' as an access specifier.
	Extended definition of mlds__lval to include type information
	for variables.
	Added `mlds__unknown_type' to the mlds types so that when
	the compiler generates variables without yet knowing their
	type we can mark them as this, rather than hoping that the
	correct types eventually get added.
	Redefined ctor_name so that it is fully qualified.
	Made changes to comments to reflect above changes.

compiler/ml_code_gen.m:
	Mark the generated functions as `one_copy' rather than `per_instance',
	so that they get generated as static methods for the Java back-end.
	Fixed a bug with the --det-copy-out option.

compiler/ml_code_util.m:
	Fixed a bug that was causing the wrong declaration flags to be
	set for fields in du constructors.
	Changed the name of the predicate `ml_qualify_var' to
	`ml_gen_var_lval'.

compiler/ml_type_gen.m:
	Mark the generated types as `one_copy' rather than `per_instance',
	so that they get generated as static nested classes for the Java
	back-end.
	Changed comments to reflect that classes and enumeration constants
	should be static.
	Export functions that generate declaration flags because they
	are used in other modules as well.
	Added a new predicate `ml_gen_mlds_field_decl' that correctly
	generates fields of classes in discriminated unions.

compiler/ml_unify_gen.m:
	Changed the code that generates ctor_id's so that it generates
	the new sort.

compiler/ml_call_gen.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_string_switch.m:
compiler/ml_tailcall.m:
compiler/mlds_to_il.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_ilasm.m:
compiler/rtti_to_mlds.m:
	Fixed things so that they conform to the changes above.
2001-02-20 07:52:19 +00:00
Fergus Henderson
4be69fa961 Eliminated a lot of the dependencies on the the `code_model' type,
Estimated hours taken: 6

Eliminated a lot of the dependencies on the the `code_model' type,
and move that type from llds.m into a new module `code_model'.
The aim of this change is to improve the modularity of the compiler by
reducing the number of places in the compiler front-end that depend
on back-end concepts and the number of places in the MLDS back-end
which depend on the LLDS.

compiler/code_model.m:
	New module.  Contains the code_model type and associated
	procedures.

compiler/llds.m:
	Move the code_model type into code_model.m.

compiler/hlds_goal.m:
	Move the goal_info_get_code_model procedure into code_model.m,
	to avoid having the HLDS modules import code_model.

compiler/hlds_out.m:
	Delete `hlds_out__write_code_model', since it wasn't being used.

compiler/hlds_pred.m:
	Move the proc_info_interface_code_model procedure into code_model.m,
	to avoid having the HLDS modules import code_model.

compiler/goal_path.m:
	When computing the `maybe_cut' field for `some' goals,
	compute it by comparing the determinism rather than by
	comparing the goal_infos.

compiler/unique_modes.m:
	Use determinism and test for soln_count = at_most_many
	rather than using code_model and testing for model_non.

compiler/inlining.m:
	Test for determinism nondet/multi rather than testing
	for code_model model_non.

compiler/hlds_pred.m:
compiler/det_report.m:
	Change valid_code_model_for_eval_method, which succeeded unless
	the eval_method was minimal_model and the code_model was model_det,
	to valid_determinism_for_eval_method, which succeeds unless the
	eval_method is minimal_model and the determinism cannot fail.
	As well as avoiding a dependency on code_model in the HLDS
	modules, this also fixes a bug where det_report could give
	misleading error messages, saying that `multi' was a valid
	determinism for `minimal_model' predicates, when in fact the
	compiler will always report a determinism error if you declare
	a `minimal_model' predicate with determinism `multi'.
	(Actually the code in which this bug occurs is in fact
	unreachable, but this is no doubt also a bug... I'll address
	that one in a separate change.)

compiler/lookup_switch.m:
	Simplify the code a bit by using globals__lookup_*_option
	rather than globals__get_option and then getopt__lookup_option.

compiler/*.m:
	Add `import_module' declarations for `code_model', and in some
	cases remove `import_module' declarations for `llds'.
2000-11-23 04:32:51 +00:00
Fergus Henderson
258107eeac Add an MLDS to MLDS transformation that converts MLDS switches
Estimated hours taken: 16

Add an MLDS to MLDS transformation that converts MLDS switches
into computed gotos or if-then-else chains.  (Eventually we
should make this code also handle binary searches.)

This transformation should allow tag switch optimization to work for
the IL back-end.  It also replaces ml_dense_switch.m and lets us
simplify ml_string_switch.m.

compiler/mlds.m:
	Add a new `switch_range' field to the `switch' stmt.

compiler/ml_simplify_switch.m:
	The new transformation.  This converts MLDS switches into
	computed gotos or if-then-else chains.
	It uses the new `switch_range' field to determine how big
	it would need to make the jump table to cover all cases.

compiler/ml_switch_gen.m:
compiler/ml_string_switch.m:
compiler/ml_tag_switch.m:
compiler/ml_dense_switch.m:
	Generate the new field.
	Change the places that generate switches so that after
	generating the switch they invoke the new transformation.
	Delete ml_dense_switch.m, since it is now redundant,
	and significantly simplify ml_string_switch.m.

compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_il.m:
	Trivial changes to handle the new field.

compiler/switch_util.m:
compiler/dense_switch.m:
	Move most of the code from the `type_range' procedure from
	dense_switch.m to switch_util.m, so we can use it in
	ml_switch_gen.m for computing the switch range.
2000-11-21 13:37:45 +00:00
Fergus Henderson
d9c0475e4a Reorganize the code for handling switches in the MLDS and
Estimated hours taken: 2

Reorganize the code for handling switches in the MLDS and
LLDS back-ends to reduce code duplication.

compiler/switch_util.m:
	New file.  Contains stuff for switches that is shared
	between the MLDS and LLDS back-ends.

compiler/ml_switch_gen.m:
compiler/ml_string_switch.m:
compiler/ml_tag_switch.m:
compiler/switch_gen.m:
compiler/string_switch.m:
compiler/tag_switch.m:
	Move code that was duplicated in the LLDS and MLDS back-ends
	into string_util.m.  Change some names and import_module
	declarations to match the new organization.

compiler/notes/compiler_design.html:
	Document the new module switch_util.m.
	Also mention ml_tag_switch.m.
2000-11-16 08:45:48 +00:00
Fergus Henderson
612865de05 Get the MLDS back-end to generate better code for string switches.
Estimated hours taken: 8

Get the MLDS back-end to generate better code for string switches.

compiler/ml_code_util.m:
compiler/ml_unify_gen.m:
	Move the routines for generating static constants from
	ml_unify_gen.m to ml_code_util.m, for use by ml_string_switch.m.

compiler/ml_string_switch.m:
	New file, adapted from string_switch.m.
	This handles generation of string switches for the MLDS back-end.
	It generates string switches using string hashing and either
	computed gotos or int switches.

compiler/ml_switch_gen.m:
	Add support for string switches.
	Export the target_supports_* predicates, for use in ml_string_switch.m.
	(Perhaps these predicates should be moved into a different module?)
	Add `target_supports_goto'.

compiler/notes/compiler_design.html:
	Mention the new module.  Also mention other MLDS modules that
	have been recently added and not yet documented here.
2000-11-09 04:08:31 +00:00