Commit Graph

13 Commits

Author SHA1 Message Date
Tyson Dowd
416ca83320 Merge changes to add attributes to the HLDS, MLDS and ILDS from the
Estimated hours taken: 2
Branches: main

Merge changes to add attributes to the HLDS, MLDS and ILDS from the
dotnet-foreign branch.  We don't merge the changes to add syntax for
attributes, as the syntax is still very experimental.

compiler/hlds_pred.m:
compiler/prog_data.m:
	Add attributes to the pred_info (they are a bit like markers,
	but are more than just boolean flags).

compiler/ilasm.m:
	Add custom attributes to appropriate positions (on assemblies,
	IL types and methods).

compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/ml_type_gen.m:
compiler/ml_util.m:
compiler/mlds.m:
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
	Add mlds__attributes, which are the MLDS version of custom attributes.
	Convert hlds_pred__attributes into mlds__attributes.
	Add a list of mlds__attributes to the mlds__function defn.

compiler/mlds_to_il.m:
	Convert MLDS attributes to IL custom attributes.
2001-08-24 15:44:57 +00:00
Tyson Dowd
bf0ed70782 Use a new mlds__function_body type to represent function bodies, as the old
Estimated hours taken: 0.75
Branches: main

Use a new mlds__function_body type to represent function bodies, as the old
usage of maybe/1 was error prone ("no" meant the function had been declared
using :- pragma external, not merely that the body was missing).

compiler/mlds.m:
	Add mlds__function_body type.

compiler/ml_code_gen.m:
compiler/ml_code_util.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_csharp.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
	Handle this change.
2001-07-12 15:44:58 +00:00
Peter Ross
a6d5d61cb5 Refactor the top level of mlds_to_il so that we only do one pass over
Estimated hours taken: 40
Branches: main

Refactor the top level of mlds_to_il so that we only do one pass over
the MLDS to generate the ILDS.  As a side effect of this change nondet
code now works again.

compiler/mlds_to_il.m:
    Do a MLDS to MLDS transformation which places all the procedures and
    data into the mercury_code class.  Then modify all the qualifiers to
    take account of this change to the code.
    Rewrite the top level so that it only does one pass over the MLDS
    data structure.
    Examine the flags when deciding which attributes to place on a
    method, field or class.

compiler/mlds.m:
    Add a new field to mlds__class_defn which is the list of
    defns which are constructors for this class.
    Add the functions mlds__append_mercury_code and mlds__append_name
    which append either "mercury_code" or an arbitary string to the
    module qualifier of a name.

compiler/ml_elim_nested.m:
    Rather then hardcoding the generation of the constructor for the
    environment class, we generate it here as an MLDS method.
    On the IL backend the mercury code is placed in a seperate class to
    the environment data, so the env_type decls must be public so as to
    be accessible from the code.

compiler/ml_code_util.m:
    Wrapper functions should be static methods not instance methods.
    Fix ml_gen_label_func_decl_flags to make this true.

compiler/rtti_to_mlds.m:
    Rtti data structures should be one_copy (ie static) not per_instance.

compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/ml_type_gen.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_java.m:
    Misc changes to handle the additon of a list of constructors to the
    mlds__class_defn.

compiler/mlds_to_csharp.m:
compiler/mlds_to_mcpp.m:
    Use the function class_name rather then mercury_module_name_to_mlds.
2001-07-09 15:55:07 +00:00
Peter Ross
5c2103005e The .NET backend requires that names are not only qualified with their
Estimated hours taken: 4
Branches: main

The .NET backend requires that names are not only qualified with their
namespace but the source package the name comes from.  In this change we
back out a previous solution to this problem and implement a much
neater solution where we hide the package name in the abstract type
mlds_module_name.

This solution is neater because the package name shouldn't change once
the name is defined.  All that we may have to change is the qualifiers
to the name.

compiler/mlds.m:
    Add the package name to the abstract type mlds_module_name.

compiler/ml_call_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
compiler/rtti_to_mlds.m:
    Back out previous solution.
2001-06-22 09:14:39 +00:00
Peter Ross
f092670758 The .NET backend requires that names are not only qualified with their
Estimated hours taken: 16
Branches: main

The .NET backend requires that names are not only qualified with their
namespace but the source package the name comes from.  In this change we
add to the name type the name of the source package which this name is
defined in.  This change will be needed for implementing foreign_class
in the .NET backend where it will no longer be possible to determine
the package name from the fully qualified name.

compiler/mlds.m:
    Add the new field to the mlds__fully_qualified_name type.

compiler/ml_call_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
compiler/rtti_to_mlds.m:
    Propogate the changes around.
2001-06-08 09:13:45 +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
eda6dba133 Address juliensf's review comments on my recent change to add an MLDS
Estimated hours taken: 0.25

Address juliensf's review comments on my recent change to add an MLDS
optimization to convert assignments into initializers.

compiler/ml_optimize.m:
doc/user_guide.texi:
	Fix some typos.

compiler/options.m:
	Wrap some long lines.
2001-02-12 04:39:58 +00:00
Fergus Henderson
0e8f55be3e Add an MLDS optimization to convert assignments into
Estimated hours taken: 1.5

Add an MLDS optimization to convert assignments into
initializers.

compiler/options.m:
doc/user_guide.texi:
	Add new option `--optimize-initializations'.

compiler/ml_optimize.m:
	Implement the new optimization.

compiler/ml_elim_nested.m:
compiler/ml_util.m:
	Move initializer_contains_var, rval_contains_var and related
	predicates from ml_elim_nested.m to ml_util.m, for use by
	ml_optimize.m.
2001-02-08 12:54:12 +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
dd43cdab61 Get the MLDS back-end to generate better code for switches.
Estimated hours taken: 8

Get the MLDS back-end to generate better code for switches.
It now compiles Mercury switches on int/char/enums into C switches.

compiler/mlds.m:
	Add `switch' as a new alternative in the `mlds__stmt' type.

compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/ml_util.m:
	Minor changes to handle the new `switch' statement.

compiler/ml_code_gen.m:
	Move the code for handling switches to ml_switch_gen.m.
	Export `ml_gen_goal', for use in ml_switch_gen.m.

compiler/ml_switch_gen.m:
compiler/ml_dense_switch.m:
	New files, adapted from switch_gen.m and dense_switch.m, but
	with significant changes.  These now handle three forms of switch:
	    - dense switches, implemented as computed gotos;
	    - "direct mapped" switches, which get implemented using the
	      MLDS switch statement, which in turn gets mapped to the
	      target language's switch statement;
	    - if-then-else chains

compiler/ml_code_util.m:
	Add a label counter to the ml_gen_info, and define predicates
	for allocating new labels.

compiler/mlds_to_c.m:
	Output switch statements.  Also fix a layout bug in the output:
	make sure we output newlines at the end of comments.

compiler/mlds_to_il.m:
	Call error/1 for MLDS switch statements.  The code generator
	will generate MLDS computed_gotos (which map to IL `switch'
	instructions) rather than MLDS switch statements, so we should
	never get MLDS switch statements here.

compiler/options.m:
	Add a new option `--prefer-switch', defaulting to enabled,
	which says to generate switches rather than computed gotos
	where possible.
2000-11-08 07:23:11 +00:00
Tyson Dowd
d00bd76219 Various fixes for problems fjh pointed out in a review.
Estimated hours taken: 0.5

Various fixes for problems fjh pointed out in a review.

compiler/ml_code_util.m:
	Fix a typo.

compiler/ml_optimize.m:
compiler/mlds_to_c.m:
	Move some comments from mlds_output_assign_args to
	generate_assign_args.
	Remove mlds_output_assign_args as it is now dead code.

compiler/options.m:
	Fix a typo, llds-optimize should be mlds-optimize.

doc/user_guide.texi:
	Document --no-mlds-optimize.
2000-09-17 09:19:12 +00:00
Tyson Dowd
a14671ce14 Do the transformation of self-tailcalls into loops as an MLDS->MLDS
Estimated hours taken: 5

Do the transformation of self-tailcalls into loops as an MLDS->MLDS
transformation (instead of during mlds_to_c.m).  Both the IL and C
backends for MLDS use this transformation.

Also, we transform into label/goto instead of for/continue.  This is
because IL doesn't have a for/continue construct.  It may be worth
revisiting this decision in future and performing benchmarks.

compiler/mercury_compile.m:
	Add an optimization phase to the MLDS end of the compiler.

compiler/ml_optimize.m:
	New file that performs MLDS->MLDS optimizations such as turning
	self-tail calls into loops.

compiler/ml_tailcall.m:
	Use ml_util.

compiler/ml_util.m:
	New file containing generic MLDS utilities.
	Contents are can_optimize_tailcall and statements_contain_statements.
	This code was in mlds_to_c but will be used by more than just
	this backend.

compiler/mlds_to_c.m:
	Delete old tailcall transformation code (it is either moved into
	ml_optimize, ml_util or it is no longer needed).
	Only handle general tailcalls.
2000-08-31 03:00:23 +00:00