Commit Graph

177 Commits

Author SHA1 Message Date
Fergus Henderson
77b6a155cc Simplify the code for ml_gen_proc_defn a bit by moving some
Estimated hours taken: 0.5

compiler/ml_code_gen.m:
	Simplify the code for ml_gen_proc_defn a bit by moving some
	code into a new subroutine ml_det_copy_out_vars.
2001-02-28 12:54:28 +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
db238abc24 Fix a bug which caused an internal compiler error when compiling
Estimated hours taken: 4

Fix a bug which caused an internal compiler error when compiling
tests/hard_coded/cut_test.m with `-O5 --high-level-code'.

compiler/simplify.m:
	Document that simplify does NOT ensure that conditions
	of if-then-elses don't have determinism `det' or `failure'.

compiler/ml_code_gen.m:
	Handle if-then-elses with `det' conditions.
2001-02-03 22:39:28 +00:00
Fergus Henderson
247075bd3b Fix a bug that broke extras/trailed_update/samples/vqueens.m
Estimated hours taken: 3

Fix a bug that broke extras/trailed_update/samples/vqueens.m
when compiled with `-H -O4'.

compiler/ml_code_gen.m:
	Export ml_gen_wrap_goal, for use by ml_unify_gen.m.

compiler/ml_unify_gen.m:
	Handle deconstruct unifications where the goal_info determinism
	doesn't match the can_fail field of the deconstruct by calling
	ml_gen_wrap_goal, rather than aborting.
2001-01-23 06:01:05 +00:00
Fergus Henderson
452d9b27de Some efficiency improvements to the MLDS->C back-end.
Estimated hours taken: 8

Some efficiency improvements to the MLDS->C back-end.
In particular, use GCC's __builtin_setjmp/__builtin_longjmp(),
and generate better code for switches whose default case is
unreachable.

These changes also help to ensure that the MLDS->C back-end should
generate exactly the same assembler code as the MLDS->GCC back-end,
which makes it easier to debug the latter (by using `diff' on the
generated `.s' files).

compiler/mlds_to_c.m:
	For unreachable default cases, use `MR_assert(0)' rather than
	`assert(0)'.  This improves efficiency, since `MR_assert' is
	disabled unless you compile with -DMR_LOWLEVEL_DEBUG.
	These checks were useful in debugging the MLDS back-end, but
	it's probably not worth keeping them enabled by default now.

	Put the default case first, so that if it is empty (as it will
	be if the default is unreachable and MR_assert() is not enabled),
	it gets merged with.

	Replace an obsolete comment about a problem with setjmp() and
	volatile with a comment explaining how that problem was fixed.

	Generate calls to MR_builtin_setjmp() and MR_builtin_longjmp()
	rather than to setjmp() and longjmp().

runtime/mercury.h:
	Define MR_builtin_setjmp() and MR_builtin_longjmp().
	These expand to __builtin_setjmp()/__builtin_longjmp() for GNU C
	and to the standard setjmp()/longjmp() otherwise.

compiler/mlds.m:
compiler/ml_code_gen.m:
	Add some comments about __builtin_setjmp() and __builtin_longjmp().
2001-01-17 17:37:24 +00:00
Fergus Henderson
f1bfe5b6c5 Fix a bug in my previous change (I had the two arguments
Estimated hours taken: 0.5

compiler/ml_code_gen.m:
	Fix a bug in my previous change (I had the two arguments
	to unsafe_type_cast in the wrong order).
2000-12-14 08:02:18 +00:00
Fergus Henderson
0df51740ff Fix a problem with unsafe_type_cast that stopped the
Estimated hours taken: 2

Fix a problem with unsafe_type_cast that stopped the
compiler from bootstrapping in MLDS grades.

compiler/builtin_ops.m:
	Add a comment about unsafe_type_cast.

compiler/ml_code_gen.m:
	Generate code for unsafe_type_cast as an inline builtin.

compiler/mlds_to_c.m:
	Delete a hack that was previously needed for unsafe_type_cast.

library/private_builtin.m:
	Delete the `:- external' declaration for unsafe_type_cast;
	this is not needed, and could cause problems because it
	suppresses the definition for unsafe_type_cast,
	which could cause problems if you take its address.

runtime/mercury.h:
	Delete the definition of unsafe_type_cast, since it is
	no longer needed.
2000-12-14 02:04:59 +00:00
Fergus Henderson
ef91da404e Fix the handling of procedures declared `external' for the MLDS back-end.
Estimated hours taken: 3

Fix the handling of procedures declared `external' for the MLDS back-end.
This change fixes some problems that broke many of the test cases in
tests/valid in the hl*prof* grades.

compiler/hlds_pred.m:
	Add `external' as a new import_status, rather than using
	`imported'.

compiler/assertion.m:
compiler/higher_order.m:
compiler/hlds_out.m:
compiler/hlds_pred.m:
compiler/intermod.m:
compiler/make_hlds.m:
	Minor changes to handle the new import_status.

compiler/mlds.m:
	Add a comment about the handling of procedures declared
	`:- external'.

compiler/ml_code_gen.m:
	Generate MLDS function definitions, with no function body,
	for procedures declared `external'.

compiler/mlds_to_c.m:
	Declare private functions with no function body as `extern'
	rather than `static'.
2000-12-11 04:52:46 +00:00
Fergus Henderson
4e44dfb287 Fix a bug with the handling of commits in the high-level C back-end.
Estimated hours taken: 12

Fix a bug with the handling of commits in the high-level C back-end.

It was implementing commits via calls to setjmp()/longjmp(),
but ANSI/ISO C says that longjmp() is allowed to clobber the values
of any non-volatile local variables in the function that called setjmp()
which have been modified between the setjmp() and the longjmp().

The fix is that whenever we generate a commit, we put it in its own
nested function, with the local variables (e.g. `succeeded',
plus any outputs from the goal that we're committing over)
remaining in the containing function.  This ensures that
none of the variables which get modified between the setjmp()
and the longjmp() and which get referenced after the longjmp()
are local variables in the function containing the setjmp().

[The obvious alternative of declaring the local variables in the
function containing setjmp() as `volatile' doesn't work, since
the assignments to those output variables may be deep in some
function called indirectly from the goal that we're committing
across, and assigning to a volatile-qualified variable via a
non-volatile pointer is undefined behaviour.  The only way to
make it work would be to be to declare *every* output argument
that we pass by reference as `volatile T *'.  But that would
impose distributed fat and would make interoperability difficult.]

compiler/options.m:
	Add a new option `--put-commits-in-own-function'.

compiler/handle_options.m:
	If the target is high-level C, set the
	`--put-commits-in-own-function' option.

compiler/ml_code_util.m:
	Add a routine for accessing the new option.

compiler/ml_code_gen.m:
	If the new option is set, generate each commit in its own
	nested function.

tests/hard_coded/Mmakefile:
tests/hard_coded/setjmp_test.m:
tests/hard_coded/setjmp_test.exp:
	A regression test.
	Previous versions of the compiler generated code for this test
	case that did the wrong thing on *some* systems.
2000-12-10 07:39:47 +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
df5f31e072 Fix a bug that broke the `hlc.gc.memprof' grade when intermodule
Estimated hours taken: 1

Fix a bug that broke the `hlc.gc.memprof' grade when intermodule
optimization was enabled.  Also eliminate an XXX in ml_elim_nested.m.

compiler/ml_code_gen.m:
	Use the pred_id and proc_id of the current procedure,
	rather than the one from the `pragma foreign_code',
	for generating the name/1 used for MR_PROC_LABEL.
	Also, generate the fully qualified name rather than
	discarding the module name.

compiler/mlds.m:
	Make the argument of the name/1 target_code_component
	a fully qualified entity name, rather than an unqualified one.

compiler/mlds_to_c.m:
	Output the fully qualified name, rather than assuming that the
	name comes from the current module.

compiler/ml_elim_nested.m:
	Modify target_code_component_contains_var to handle the
	new type of name/1.  This allowed eliminating an XXX
	which was due to the name being unqualified.
2000-11-20 01:45:13 +00:00
Tyson Dowd
477ecb18f6 Implement pragma foreign_code for Managed C++.
Estimated hours taken: 60

Implement pragma foreign_code for Managed C++.

Currently you can only write MC++ code if your backend is capable of
generating use MC++ as its "native" foreign language.  The IL backend is
the only backend that does this at the moment (the other backends have C
as their "native" foreign language).

Most of the machinery is in place to call from C to (normal) C++
but there is little work done on actually spitting out the C++ code into
a separate file.  The IL backend does this step already with managed C++.
The intention is to turn foreign_code for C++ into a pragma import
(which imports the C++ function from a separate file) and
foreign_code for C (which calls the imported function).  The C++ code
will be inserted into a separate file that is compiled using C linkage.

The important improvement this change gives is that you can write a
module with a C and a MC++ implementations side-by-side.  The target
backend will select the most appropriate foreign language to use.
You can override its choice using --use-foreign-language.  Later on
we will probably want more flexibility than just a single language
selection option).

This change also implements :- pragma foreign_decl, which allows header
file style declarations to be written in languages other than C.

compiler/code_gen.m:
	Reject code that is not C when generating LLDS.

compiler/export.m:
	Start renaming C as foreign.
	Reject code that is not C when generating exports.

compiler/foreign.m:
	A new module to handle foreign language interfacing.
	The bulk of the code for pragma import has been moved here from
	make_hlds.

compiler/globals.m:
	Convert foreign language names to foreign_language.
	This code has been moved closer to the similar conversion we do
	for target language names.
	Add globals__io_lookup_foreign_language_option to make it easier
	to deterministically lookup the options relating to foreign
	languages.


compiler/hlds_module.m:
	Move module_add_foreign_decl and module_add_foreign_body_code
	from make_hlds.m (where they were called module_add_c_header and
	module_add_c_code).

compiler/hlds_out.m:
	Write the foreign language out in HLDS dumps.

compiler/llds.m:
	Change foreign_header_info to foreign_decl_info.
	Change definitions of foreign_decl_code and foreign_body_code to
	include the language.

compiler/llds_out.m:
	Reject code that is not C when writing out LLDS.

compiler/make_hlds.m:
	Add foreign language information to the bodys and decls when
	creating them.
	Update error messages to refer to foreign code instead of C
	code.
	Use foreign.m to generate interfaces from the backend language
	to the foreign language.
	Hardcode C as the language for fact tables.

compiler/mercury_compile.m:
	Collect the appropriate foreign language code together for
	output to the backend.

compiler/intermod.m:
compiler/mercury_to_mercury.m:
	Output the foreign language string.
	Change a few names to foreign_code instead of c_code.

compiler/ml_code_gen.m:
	Filter the foreign language bodys and decls so that we only get
	the ones we are in (given by the use-foreign-language option).

compiler/mlds_to_c.m:
	Abort if we are given non C foreign language code to output
	(we might handle it here in future, or we might handle it
	elsewhere).

compiler/mlds_to_ilasm.m:
	Abort if we are given non MC++ foreign language code to output
	(we might handle it here in future, or we might handle it
	elsewhere).

compiler/options.m:
compiler/handle_options.m:
	Add --use-foreign-language as a user option to control the
	preferred foreign language to use as the implementation of this
	module.
	Add backend_foreign_language as an internal option which stores
	the foreign language that the compiler will use as a default
	(e.g. the natural foreign language for the backend to use).
	Set the preferred backend foreign language depending on the
	target.

compiler/prog_data.m:
	Add managedcplusplus as a new alternative for the
	foreign_language type.
	Make c_header_code into foreign_decl.
	Give the foreign language for foreign_code as an attribute of
	the code.
	Write code to turn attributes into a list of strings (suitable
	for writing out by mercury_to_mercury).  This fixes what appears
	to be a bug in tabled_for_io -- the tabled_for_io attribute was not
	being written out.  Structure the code so this bug is
	difficult to repeat in future.

compiler/prog_io_pragma.m:
	Parse foreign_decl.
	Turn c_header_code into a special case of foreign_decl.

compiler/*.m:
	Remove the language field from pragma_foreign_code, it is now an
	attribute of the code.
	Various type and variable renamings.

tests/invalid/pragma_c_code_and_clauses1.err_exp:
tests/invalid/pragma_c_code_dup_var.err_exp:
tests/warnings/singleton_test.exp:
	Update the tests to reflect the new error messages talking
	about :- pragma foreign_code rather than :- pragma c_code.
2000-11-17 17:48:52 +00:00
Fergus Henderson
b8f181c7c2 In the initialization functions, output calls to MR_init_entry()
Estimated hours taken: 1

compiler/mlds_to_c.m:
	In the initialization functions, output calls to MR_init_entry()
	only if they are needed (i.e. if profiling is enabled).
	Likewise output the code that ensures that the initialization
	is only run once only if the initialization is non-empty.
	Use `bool', `TRUE', and `FALSE' rather than `int', 0, and 1
	for the `initialised' variable.
	The aim of all these changes is to improve the readability
	of the generated code.

compiler/ml_code_gen.m:
	Document the principle that the MLDS back-end should avoid
	relying on macros and conditional compilation, to improve
	readability and to make it easier to target languages like Java.

runtime/mercury_conf_param.h:
runtime/mercury_goto.h:
	Add some comments about the MLDS back-end.
2000-11-13 04:26:02 +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
Fergus Henderson
4fd150c78f Change the MLDS calling convention so that for model_det Mercury functions
Estimated hours taken: 6

Change the MLDS calling convention so that for model_det Mercury functions
with output mode results, the function results get mapped to MLDS function
return values rather than to by-ref parameters.  The rationale for this is
to make interoperability simpler (especially for the IL & Java back-ends).

compiler/lambda.m:
	Change the rules for compatibility of closures so that for
	MLDS grades function closures are not treated as compatible
	with predicate closures.

compiler/ml_code_util.m:
	Change ml_gen_params so that it takes a pred_or_func parameter, and
	for model_det functions it maps the output-moded function results
	to MLDS return values.

compiler/ml_code_gen.m:
	For model_det functions with output mode results,
	return the function result by value.
	Rename the `output_vars' field of the ml_gen_info as
	`byref_output_vars'.

compiler/ml_call_gen.m:
	Pass down the pred_or_func parameter to ml_gen_params.
	For calls to model_det functions with output mode results,
	return the function result by value.

compiler/hlds_goal.m:
	Add new predicate generic_call_pred_or_func, for use by ml_call_gen.m.

compiler/ml_unify_gen.m:
	Modify the code for generating wrapper functions for closures so
	that it reflects the new calling convention for Mercury functions.

compiler/mlds.m:
compiler/mlds_to_c.m:
compiler/ml_code_gen.m:
	Don't handle model_det functions with output mode results specially
	in `pragma export' anymore, since the internal MLDS form now
	has the same prototype as the exported one.
2000-10-30 07:09:04 +00:00
Fergus Henderson
9b850aeb86 Update the TODO list at the top of this module.
Estimated hours taken: 0.5

compiler/ml_code_gen.m:
	Update the TODO list at the top of this module.
2000-10-22 15:57:36 +00:00
Fergus Henderson
e823aa5838 Fix some bugs in the static ground term optimization for the MLDS
Estimated hours taken: 20

Fix some bugs in the static ground term optimization for the MLDS
back-end.

compiler/ml_code_util.m:
compiler/ml_code_gen.m:
	Ensure that declarations for a goal are generated in such a
	way that they scope over the C code generated for any
	following goals.  This is needed to ensure that we don't
	generate references to undeclared names in static constants.

compiler/ml_unify_gen.m:
compiler/ml_code_util.m:
	Ensure that all static consts get unique names, so that
	ml_elim_nested.m can hoist them to the top level.
	Also move ml_gen_static_const_decl_flags from ml_unify_gen.m
	to ml_code_util.m, for use by ml_code_gen.m.

compiler/ml_elim_nested.m:
	Hoist out the definitions of static constants to the top level
	in cases where they might be referenced from nested functions.
	Also change the name of the local_vars field of the ml_elim_info
	to local_data, to make it clear that it can hold constants too.

compiler/mark_static_terms.m:
	Fix some typos in the comments.

compiler/mlds_to_c.m:
	Fix an XXX: it was not outputting `static' in the right places.

tests/valid/Mmakefile:
tests/valid/static.m:
	Add some regression tests.
2000-10-22 13:57:55 +00:00
Tyson Dowd
169db1b8fd The .NET MSIL (Microsoft Intermediate Language) backend.
Estimated hours taken: 220

The .NET MSIL (Microsoft Intermediate Language) backend.

While not complete, this backend implements enough of Mercury to run
programs such as eliza (with an appropriate runtime, which is not part
of this change).  The IL backend TODO list is in mlds_to_il.m.

We generate IL "assembler" from MLDS.  The IL assembler (ILASM) then
turns this into bytecode in a .DLL or .EXE file.

Pragma C code is put into a separate .cpp file and compiled using the managed
C++ compiler.

compiler/il_peephole.m:
	Peephole optimize the IL.

compiler/ilasm.m:
	Generate IL assembler from IL.
	Also a representation of the entities in the IL assembler
	syntax.

compiler/ilds.m:
	The IL instruction set.

compiler/mercury_compile.m:
	Generate IL if --target il is set.
	Define mercury_compile__mlds_has_main/1.
	Assemble the IL if --target-code-only is not set.
	Use "target_debug" option instead of "c_debug".

compiler/ml_code_gen.m:
	If the target is IL and we are generating MLDS for foreign code
	that calls continuations (that is, model_non pragma C code),
	create a nested function (not implemented in foreign code) to
	call the continuation.  This is because in managed C++ it isn't
	possible to call a continuation, but it's fine to call a method
	written in IL that calls the continuation instead.

compiler/ml_code_util.m:
	Add unexpected/1 as another error message handler.
	Add code for generating indirect calls to success continutation
	(via a nested function).

compiler/ml_elim_nested.m:
	Generate slightly different code for IL environments.  We don't
	use the address of the environment variable (like in the C
	backend) but use the environment variable directly.  We also
	have to initialize the environment as a new object.
	This is because we use a class to represent the environment,
	whereas the C backend uses a struct.

	Also, if there is no environment required for nested functions
	(that is, the nested functions don't use any of the local
	variables of the parent), don't generate an environment.
	This is important for the nested functions generated in mangaged
	C++ -- otherwise have to be able to handle defining and
	initializing environments in managed C++ just to do the continuation
	calls for model non pragma C code.

	Add field names to elim_info.

compiler/mlds_to_il.m:
	The IL code generator.
	Also contains the mapping from MLDS type to IL types (which
	is useful when generating forieng language stubs to interface
	with IL).

compiler/options.m:
	Add a debugging option for IL assember -- it prints out each
	line of assembler before it executes.  This is very much a
	developer only option.
	Make a "target_debug" option -- the old "c_debug" option is just
	an alias for this option.  If the target it IL, "target_debug"
	can also turn on debugging for IL, allowing the IL debugger to
	display IL instructions as it traces execution.
2000-10-14 04:00:46 +00:00
Tyson Dowd
6d78224020 Add new options and grades for the IL back-end.
Estimated hours taken: 24	(by fjh)

Add new options and grades for the IL back-end.

Implement an option to handle output parameters for nondeterministic
procedures by passing the outputs (by value) to the continuation,
rather than using pass-by-reference.  This is needed for IL
because IL does not allow managed pointers (which we used to
implement pass-by-refernece) to be stored as fields of environment
structs.

Also add an option to return outputs by value in det/semidet code.
This is not yet tested, since none of our target languages support
returning multiple values.

(Note that the IL backend is not activated by these changes -- it
hasn't been checked in).

compiler/globals.m:
	Use field names for the globals structure.
	Add new `target' field to the globals.

compiler/options.m:
compiler/handle_options.m:
	Add new options `--target', `--target-only', `--il', and `--il-only'.
	`--target' specifies the output langauge (e.g. C or IL).
	`--target-only' says to only compile to the output language
	(e.g. similar to -C or --compile-to-c option).
	`--il' sets target to IL.
	`--il-only' sets target to IL and specifies --target-only.

	Add new grades `il' and `ilc'.
	These grades are used for compiling to il grades.  `il' is the
	normal `il' grade, while `ilc' uses low-level (C-like) data
	representations.

	Change `--compile-to-c' from a boolean option to an abbreviation
	for `--target c --target-only', and move it from the "Output options"
	section to the "Compilation model options" section.

	Comment out the documentation for `--generate-prolog' and
	`--prolog-dialect', since those options are not yet implemented.

	Document the `--infer-all' option.

compiler/mercury_compile.m:
	Check the `target_code_only' option rather than `compile_to_c',
	since the latter is just an abbreviation now, not a real option.

compiler/ml_call_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_unify_gen.m:
	Use the `--det-copy-out' option to decide whether to pass
	output arguments for model_det/model_semi procedures by
	reference, or whether to just return multiple values.
	Use the `--nondet-copy-out' option to decide whether to pass
	output arguments for model_non procedures by reference, or
	whether to just pass them to the continuation.

compiler/mlds.m:
        Change the mlds__cont_type so that it includes a list of
        the continuation's argument types (if any).

compiler/mlds_to_c.m:
        Update to reflect the change to mlds.m.

doc/user_guide.texi:
        Update the documentation to reflect the above changes.


scripts/parse_grade_options.sh-subr:
	Add new options `--target' and `--il'.

scripts/init_grade_options.sh-subr
        Add new grades `il' and `ilc'.

scripts/final_grade_options.sh-subr
        Make `--target il' imply `--high-level-code'.
2000-09-16 00:08:30 +00:00
Fergus Henderson
2006d7d21f Fix a bug in the MLDS back-end: handle `pragma export' of procedures
Estimated hours taken: 1.25

Fix a bug in the MLDS back-end: handle `pragma export' of procedures
defined in modules other than the current module.

compiler/mlds.m:
	Change the entity_name in the pragma_export type to a
	qualified_entity_name.

compiler/ml_code_util.m:
	Change ml_gen_proc_label so that it returns the module name too,
	not just the entity_name.

compiler/ml_code_gen.m:
compiler/mlds_to_c.m:
	Modify to reflect the changes described above.

tests/hard_coded/Mmakefile:
tests/hard_coded/pragma_export.m:
tests/hard_coded/pragma_export.exp:
	A regression test for the above-mentioned bug fix.
2000-08-24 10:01:55 +00:00
Tyson Dowd
c192d50143 Add preliminary support for a new pragma:
Estimated hours taken: 15

Add preliminary support for a new pragma:

:- pragma foreign_code(LanguageString, .... <same args as c_code>).

This is intended to be the eventual replacement of pragma c_code.
Presently the only valid language is "C".
The existing pragma c_code is simply turned into pragma foreign_code.

pragma foreign_code is not a supported pragma at the moment.  There are
several other changes that are intended (for example, foreign_code will
be impure by default).

This change also changes the HLDS goal pragma_c_code/7 to
pragma_foreign_code/8 where the extra argument is the foreign language.

Any code currently generating output for pragma C code simply checks
that the foreign language is set to "c".  Since this is the only
alternative of the type foreign_language, it will always succeed.
However when new alternatives are added it should be fairly easy to find
where the changes need to be made.

Some type names and predicate names have also been updated, however
there are many more that haven't yet been touched.

compiler/prog_io_pragma.m:
	Accept the new syntax.	Turn the old syntax into the new item.

compiler/hlds_goal.m:
	Change pragma_c_code/7 to pragma_foreign_code/8.
	Define the foreign_language type.

compiler/llds.m:
	Change user_c_code/2 to user_foreign_code/3.

compiler/*.m:
	Update the rest of the compiler to handle these types.
	Make a few small changes to update variable names, predicate
	names and type names.
2000-08-09 07:48:04 +00:00
Peter Ross
113dca2cad Bootstrap in the grade hlc.gc.memprof.
Estimated hours taken: 24

Bootstrap in the grade hlc.gc.memprof.
To analyse the generated Prof.* files you need to supply the option
--no-demangle to the profiler.

compiler/ml_code_gen.m:
    Define MR_PROC_LABEL in pragma c_code.

compiler/mlds.m:
    Add a new alternative to the type target_code_component which
    records a mlds_entity_name.  This information is needed when
    outputing the MR_PROC_LABEL #define.

compiler/ml_elim_nested.m:
    Changes due to the change to the type target_code_component.

compiler/mlds_to_c.m:
    Define a new predicate mlds_maybe_output_init_fn which outputs an
    initialisation function, if necessary.  This body of the
    initialisation function consists of calls to init_entry for each
    function in the src module.
    If profiling is turned on at each function call: call
    MR_prof_call_profile(callee, caller) to record the arc in the call
    graph.
    If profiling is turned on each heap allocation call
    MR_maybe_record_allocation().
    Changes due to the change to the type target_code_component.

library/array.m:
library/builtin.m:
library/exception.m:
library/private_builtin.m:
library/std_util.m:
    As c2init doesn't understand preprocessor directives we need to
    define some empty initialisation functions.

trace/mercury_trace_vars.c:
    Avoid a linking problem with MR_trace_ignored_type_ctors.
    Add a dummy member to MR_trace_ignored_type_ctors so that the array
    is never empty.

runtime/mercury.c:
    Call MR_init_entry for each hand defined procedure.

runtime/mercury.h:
    If profiling is turned on include the relevant header files.

runtime/mercury_goto.h:
    Define MR_init_entry.

runtime/mercury_prof.c:
runtime/mercury_prof.h:
    Make decl_fptr an extern global pointer so that mercury_wrapper.c
    can call fclose on it.

runtime/mercury_wrapper.c:
    Call fclose on decl_fptr.
2000-08-02 14:13:14 +00:00
Peter Ross
a48beedc9d Fix a bug where pragma imports of polymorphic predicates where not
Estimated hours taken: 16

Fix a bug where pragma imports of polymorphic predicates where not
having typeinfos prepended to the call.

compiler/prog_data.m:
    Add a the new functor import/4 to pragma_c_code impl.
    The functor stores all the information needed to constuct a C code
    fragment a pragma import.

compiler/make_hlds.m:
    Rather then constructing the C code fragment immediately, construct
    the sub-parts and store them in import/4.

compiler/polymorphism.m:
    Prepend the typeinfos to the list of variables passed to the
    imported C function.

compiler/ml_code_gen.m:
compiler/pragma_c_gen.m:
    Construct the C code fragment then call the routine which handles
    `ordinary' pragma c_code.

compiler/hlds_out.m:
compiler/mercury_to_mercury.m:
    Add code to recognise the import/4 functor.
2000-07-20 11:24:12 +00:00
Peter Ross
d38a833145 Implement `pragma export' for the MLDS backend.
Estimated hours taken: 30

Implement `pragma export' for the MLDS backend.

compiler/mlds.m:
    Add a new type mlds__pragma_export.  It records the exported name,
    the MLDS name of the exported procedure, the function parameters
    of the MLDS entity and the context of the export declaration.
    Add a new mlds_entity_name type export, for names which come from
    pragma export.

compiler/ml_code_gen.m:
    For every pragma export declaration, we associate the information
    used to generate the function prototype for the MLDS entity.  We
    also record whether or not the procedure is a det function in the
    forward mode.

compiler/mlds_to_c.m:
    Output a declaration for the exported procedure to the header file.
    Output a definition for the exported procedure to the source file.
    Providing that the procedure is not a det func in the forward mode
    the declaration is constructed by outputing the function prototype
    for the MLDS function, but using the exported name instead and
    the definition is constructed by defining a function which directly
    calls the MLDS function.
    If the procedure is a det func in the forward mode then the output
    argument is returned by the function instead of being passed in call
    by reference.  The signature of the exported function is changed to
    this new convention.  This change is required so the an exported
    procedure can by re-imported.
    Define in each header file MR_BOOTSTRAPPED_PRAGMA_EXPORT, this code
    should be removed once the compiler has bootstrapped.
    Move output_c_defns so that it comes after all the declarations.
    Modify mlds_output_params so that it takes a module name, not an
    entity name as all it needs is the module name.
    When outputing an mlds_entity_name of type export, don't module
    qualify the name and just output the string.

compiler/hlds_module.m:
    Add a prog_context field to the type pragma_exported_proc.

compiler/make_hlds.m:
    Record the context of the pragma export.

compiler/dead_proc_elim.m:
compiler/export.m:
    Ignore extra field added to pragma_exported_proc.

compiler/ml_elim_nested.m:
    In ml_env_name report error for export mlds__entity_name's.

library/io.m:
runtime/mercury.c:
runtime/mercury.h:
runtime/mercury_init.h:
    Check to see if MR_BOOTSTRAPPED_PRAGMA_EXPORT is defined when
    deciding whether hacks to get around the lack of pragma export need
    to turned on.  This code should be removed once the compiler has
    bootstrapped.
    This also required some definitions to be moved from mercury.c to
    io.m so that MR_BOOTSTRAPPED_PRAGMA_EXPORT is defined when the
    definition is reached.
2000-07-20 10:39:36 +00:00
Peter Ross
30e36b47f4 Avoid a fixed limit problem where only N (around 256) levels of block
Estimated hours taken: 4

Avoid a fixed limit problem where only N (around 256) levels of block
nesting is allowed in the MSVC compiler.

compiler/ml_code_gen.m:
    ml_join_decls creates block nesting proportional to the size of the
    disjunction when generating disjunctions in a model_non context.
    Now we always create a block for each arm of the disjunction.  This
    allows us to safely concatenate blocks together, and hence only nest
    blocks one level deeper.
2000-07-19 09:46:59 +00:00
Fergus Henderson
8bf0ca1ff6 Add a `\n' at the end of one of the strings that we generate
Estimated hours taken: 0.1

compiler/ml_code_gen.m:
	Add a `\n' at the end of one of the strings that we generate
	for `pragma c_code' goals.  This fixes a bug where we were
	generating `#line' directives that were not at the start of a line.
2000-06-06 06:21:22 +00:00
Fergus Henderson
9f56931a8b Mork work on implementing the `--high-level-data' option.
Estimated hours taken: 8

Mork work on implementing the `--high-level-data' option.  This change
fixes a problem with unify and compare procedures for equivalence types.

compiler/ml_code_gen.m:
	Generalize the code for boxing existentially typed output
	variables so that it now handles all cases where the procedure
	argument types don't match the types of the head variables in
	the body.  That can occur for unify and compare procedures
	for equivalence types too, not just for procedures with
	existentially typed outputs.

compiler/ml_code_util.m:
	Make several changes for use by ml_code_gen.m:
	- Add a new field to the ml_gen_info containing a map(prog_var, lval).
	- Change ml_gen_var so that it checks that map first, and if the
	  variable occurs in that map it uses the lval from the map.
	- Export a new procedure ml_gen_var_with_type.

compiler/ml_call_gen.m:
	Change ml_gen_box_or_unbox_lval so that it returns
	code to assign both to and from the lval, rather than
	just in one direction.
2000-06-05 00:27:24 +00:00
Fergus Henderson
c5caa01d8d When generating MLDS code for `pragma c_code' goals,
Estimated hours taken: 0.5

compiler/ml_code_gen.m:
	When generating MLDS code for `pragma c_code' goals,
	add some extra casts that are needed when you use --high-level-data.
2000-06-01 08:55:32 +00:00
Fergus Henderson
c92fe4cf7d Make a start towards implementing the `--high-level-data' option.
Estimated hours taken: 20

Make a start towards implementing the `--high-level-data' option.

XXX There are still quite a few places in the MLDS code generator,
specifically in ml_unify_gen.m, ml_call_gen.m, and ml_code_gen.m,
that assume `--no-high-level-data'.  For example, we still use
the MR_field() macro rather than using named fields.

XXX Equivalence types are not yet supported.

compiler/ml_type_gen.m:
	New module.  If --high-level-data is enabled, this module
	generates MLDS type definitions for HLDS types.

compiler/ml_code_gen.m:
	Import ml_type_gen.m, and delete the stub code for
	`ml_gen_types', since that is now defined in ml_type_gen.m.

compiler/mlds_to_c.m:
	- If --high-level-data is enabled, declare variables whose Mercury
	  types is user-defined using the MLDS types generated by
	  ml_type_gen.m, and declare closures with type `MR_ClosurePtr'
	  rather than `MR_Word'.
	- Output type definitions in the header file rather than
	  then `.c' file.
	- Add code to output `mlds__enum' classes as C enums,
	  and to handle static members and nested types in classes;
	  these changes are needed because ml_type_gen generates those
	  constructs.
	- Cast the argument of MR_tag() to `MR_Word'.
	- Cast the result of MR_new_object() to the appropriate type.

runtime/mercury.h:
	- Delete the cast to `MR_Word' in MR_new_object(), because it was
	  not right for the --high-level-data case; the necessary casts
	  are now generated by mlds_to_c.m.
	- Define the `MR_ClosurePtr' type.

compiler/mlds_to_c.m:
compiler/ml_elim_nested.m:
	Fully qualify struct member names.  This is needed to avoid
	name clashes for the enumeration constants and nested types
	that ml_type_gen generates, in particular for the case where
	the same constructor name and arity occurs in two or more
	different types in a single module.  It's also more consistent
	with our general approach of fully qualifying all references.

compiler/mlds.m:
	- Add a new field of type builtin_type to the mercury_type/2
	  MLDS type; this holds the type category (enumeration, etc.).
	  This required adding a module_info parameter to the
	  mercury_type_to_mlds function.
	- Similarly, add a new field of type mlds__class_kind to the
	  class_type/2 MLDS type.
	- Add a function `mlds__append_class_qualifier', for use by mlds_to_c.m
	  and ml_elim_nested.m.
	- Add field names to the `mlds__class_defn' struct.

compiler/ml_code_util.m:
	Add a new routine ml_gen_type for converting Mercury types to MLDS.
	This just extracts the module_info from the ml_gen_info and then
	calls mercury_type_to_mlds.

compiler/*ml*.m:
	Change lots of places to use ml_gen_type and/or to pass the
	module_info down to mercury_type_to_mlds, and to handle the
	new field of mercury_type/3.  Similarly, change quite a few
	places to handle the new field of class_type/3.

	In ml_code_util.m, passing the module_info down had the
	pleasant side-effect of enabling the elimination of an
	existing XXX: in ml_gen_proc_params_from_rtti,
	UseNestedFunctions was not being calculated correctly,
	because previously the globals where not easily available at
	that point.
2000-05-31 06:04:38 +00:00
Fergus Henderson
df725cdefb Clean up the handling of `pragma c_code' in the MLDS back-end.
Estimated hours taken: 2.5

Clean up the handling of `pragma c_code' in the MLDS back-end.

compiler/mlds.m:
	Change the representation of `target_code' statements,
	so that they can contain mlds__rvals and mlds__lvals.

compiler/ml_code_gen.m:
	Modify the code for compiling `pragma_c' HLDS goals so that
	it generates the new representation of `target_code' statements.
	This change also fixes the problem with handling "complicated"
	pragma c_code, i.e. cases which required boxing or unboxing.

compiler/ml_call_gen.m:
	Export `ml_box_or_unbox_lval', for use by ml_code_gen.m.

compiler/ml_elim_nested.m:
	Change `fixup_atomic_statement' to handle the new representation
	of `target_code' statements.

compiler/mlds_to_c.m:
	Change `mlds_output_statement' to handle the new representation
	of `target_code' statements.
2000-05-26 07:09:13 +00:00
Fergus Henderson
b85bdc6b5e Fix an XXX: don't output calls to the
Estimated hours taken: 0.25

compiler/ml_code_gen.m:
	Fix an XXX: don't output calls to the
	MR_OBTAIN_GLOBAL_LOCK() and MR_RELEASE_GLOBAL_LOCK()
	macros unless the module was compiled with `--parallel'.
	Also avoid some code duplication.
2000-05-25 01:05:20 +00:00
Fergus Henderson
4e3b02c23a Fix an XXX: don't output calls to the
Estimated hours taken: 0.25

compiler/ml_code_gen.m:
	Fix an XXX: don't output calls to the
	MR_OBTAIN_GLOBAL_LOCK() and MR_RELEASE_GLOBAL_LOCK()
	macros unless the module was compiled with `--parallel'.
2000-05-24 08:26:39 +00:00
Fergus Henderson
c038235650 Fix some bugs in my previous change to handle boxing of existentally
Estimated hours taken: 3

compiler/ml_code_gen.m:
	Fix some bugs in my previous change to handle boxing of existentally
	typed output arguments.

tests/hard_coded/Mmakefile:
tests/hard_coded/existential_float.m:
tests/hard_coded/existential_float.exp:
	Add some additional test cases testing model_non and model_semi
	procedures.
2000-05-17 21:59:44 +00:00
Fergus Henderson
56cd134c2a Fix a bug in the MLDS back-end that broke
Estimated hours taken: 4

Fix a bug in the MLDS back-end that broke
tests/typeclasses/typeclass_exist_method.m.

compiler/ml_code_gen.m:
compiler/ml_code_util.m:
	Add code to handle boxing of existentially typed output arguments.

tests/hard_coded/Mmakefile:
tests/hard_coded/existential_float.m:
tests/hard_coded/existential_float.exp:
	Add another test case which tests more specifically
	for this bug.
2000-05-17 18:02:24 +00:00
Fergus Henderson
d888d8ff49 Fix a problem with the Mmake dependencies generated for the MLDS
Estimated hours taken: 5

Fix a problem with the Mmake dependencies generated for the MLDS
back-end that broke intermodule optimization.

The problem was that the generated dependencies weren't taking
dependencies via `.opt' files into account.

compiler/modules.m:
	Change write_dependency_file so that takes AllDeps (which is
	used to calculate header file dependencies for the MLDS back-end)
	as an extra argument, rather than computing it here from the
	direct and indirect dependencies.  This allows AllDeps to
	include dependencies from `.opt' and `.trans_opt' files,
	rather than just those from the `.int*' files.
	Change generate_dependencies and generate_dependencies_write_d_files
	to compute AllDeps.  When generating dependencies, we don't
	know exactly which modules the `.opt' files will depend on, so
	the value computed here is a conservative (over-)aproximation.
	It doesn't matter much though, since the `.d' file will get
	rewritten every time the module is compiled, and the value
	for AllDeps computed then by mercury_compile.m will be exact,
	since the value is computed from the module_info after the
	`.opt' files have been read in.

compiler/ml_code_gen.m:
compiler/hlds_module.m:
	Move most of the code from ml_gen_imports (in ml_code_gen.m)
	to a new predicate module_info_get_all_deps (in hlds_module.m),
	for use by mercury_compile.m.

compiler/mercury_compile.m:
	Call module_info_get_all_deps, and pass the result of that
	to write_dependency_file.  This required changing things so that
	the `.d' file is only written after the initial HLDS is created.
2000-05-16 21:23:28 +00:00
Fergus Henderson
2aea0631ed Fix a bug in the handling of nested modules for the MLDS back-end.
Estimated hours taken: 0.25

Fix a bug in the handling of nested modules for the MLDS back-end.
This bug broke the test cases in tests/hard_coded/nested_modules.

compiler/ml_code_gen.m:
	Include the ancestor modules in the MLDS import list (which is
	used by mlds_to_c.m to determine which files to #include).

compiler/modules.m:
	Update the dependency calculation to reflect the above change.
2000-05-15 17:31:28 +00:00
Fergus Henderson
5890eda69d Fix the generation of `#include' directives for the MLDS back-end.
Estimated hours taken: 2

Fix the generation of `#include' directives for the MLDS back-end.

compiler/hlds_module.m:
	Add a new field `indirectly_imported_module_specifiers'
	to the module_info.

compiler/make_hlds.m:
	Add code to set up the appropriate values in the new field.

compiler/ml_code_gen.m:
	Include the indirectly imported modules in the mlds imports list.

runtime/mercury.h
	Delete some hacks that were work-arounds for this bug.
2000-05-13 13:56:15 +00:00
Fergus Henderson
16be071f93 Fix some typos in the comments that Erwan noticed when
Estimated hours taken: 0.1

compiler/ml_code_gen.m:
	Fix some typos in the comments that Erwan noticed when
	reviewing my recent change.
2000-05-10 07:12:49 +00:00
Fergus Henderson
af3a0a52c9 Fix a bug in the MLDS back-end's code generation for
Estimated hours taken: 2

Fix a bug in the MLDS back-end's code generation for
if-then-else goals with nondet conditions.

compiler/ml_code_gen.m:
	When generating code for if-then-elses with nondet conditions,
	allocate a fresh `cond_<N>' variable for each such
	if-then-else, rather than reusing the `succeeded' variable.
	This ensures that the boolean variable that we use to figure
	out if the condition succeeded won't be clobbered by the
	condition or the "then" part of the if-then-else.

compiler/ml_code_util.m:
	Add routines for generating `cond_<N>' variables.
	Add a new cond_var field to the ml_gen_info;
	this is a sequence number used to generate those
	variables.
2000-05-09 18:47:30 +00:00
Fergus Henderson
0c8b287d69 Improve the documentation a little, particularly with regard
Estimated hours taken: 0.5

compiler/ml_code_gen.m:
	Improve the documentation a little, particularly with regard
	to the declaration of the `succeeded' variable.
2000-05-09 17:32:30 +00:00
Fergus Henderson
336a772724 Fix a bug in the MLDS back-end that broke tests/valid/same_length_2.m.
Estimated hours taken: 0.5

Fix a bug in the MLDS back-end that broke tests/valid/same_length_2.m.

compiler/ml_code_gen.m:
	When generating code for conjunctions, ensure that we stop
	code generation once we reach a goal with at_most_zero
	solutions.  This is necessary to avoid getting internal
	errors when generating code for the `fail' goals
	that simplify__conj inserts after unreachable code,
	which can happen when the conjunction is model_det.

	Also update some of the documentation.
2000-05-09 10:05:32 +00:00
Fergus Henderson
6ba459bdaa Add some `MR_' prefixes.
Estimated hours taken: 0.75

Add some `MR_' prefixes.

runtime/mercury_string.h:
runtime/mercury_misc.h:
runtime/mercury_misc.c:
runtime/mercury_make_type_info_body.h:
runtime/mercury_type_info.c:
runtime/mercury.c:
extras/*/*.m:
extras/*/*/*.m:
library/*.m:
trace/*.c:
compiler/fact_table.m:
compiler/ml_code_gen.m:
compiler/stack_layout.m:
	Add `MR_' prefixes to fatal_error(), hash_string(),
	do_hash_string, and HASH_STRING_FUNC_BODY.

runtime/mercury_bootstrap.h:
	Add backwards compatibility macros for
	fatal_error() and hash_string().
2000-05-08 13:48:50 +00:00
Fergus Henderson
a1b02cfc47 More fixes for the MLDS back-end.
Estimated hours taken: 8

More fixes for the MLDS back-end.

compiler/ml_code_gen.m:
library/private_builtin.m:
runtime/mercury.h:
	Don't treat unsafe_type_cast as an inline builtin, since the
	code generated for it as an inline builtin is not type-correct.
	Instead, declare `unsafe_type_cast/2' as external in
	library/private_builtin.m, so that the generated code
	for this module does not try to declare or define it.
	And in runtime/mercury.h, define unsafe_type_cast/2 as a
	macro / inline function.

library/private_builtin.m:
	Fix a bug in my previous change: add a missing cast.

runtime/mercury_type_info.h:
	Declare the constants mercury_data___type_ctor_info_{pred,func}_0;
	used by the MR_TYPE_CTOR_INFO_HO_{FUNC,PRED} macros.
	Add some conditional code so that those macros do the right
	thing for the MLDS back-end.

runtime/mercury_deep_copy.c:
runtime/mercury_tabling.c:
library/std_util.m:
	Delete the now unnecessary declarations of
	mercury_data___type_ctor_info_{pred,func}_0;
	these are now declared in runtime/mercury_type_info.h.

library/std_util.m:
	Delete the redundant definitions of the MR_TYPE_CTOR_INFO_*()
	macros; these were defined identically in runtime/mercury_type_info.h.
	Also use MR_TYPE_CTOR_INFO_HO_{FUNC,PRED} rather than hard-coding
	their definitions.

runtime/mercury.h:
runtime/mercury.c:
	Update to reflect recent RTTI changes.
	In particular, use MR_TypeCtorInfo rather than MR_BaseTypeInfo,
	and delete the code for the index/2 predicate.

runtime/mercury_std.h:
runtime/mercury.h:
	Move the definition of MR_INLINE and MR_EXTERN_INLINE
	from mercury.h to mercury_std.h, since they're used in
	mercury_heap.h.

runtime/mercury.c:
	Wrap `#ifdef MR_HIGHLEVEL_CODE' around the whole of this file,
	so that it does the right thing in LLDS-based grades.

runtime/mercury_heap.h:
runtime/mercury_imp.h:
runtime/mercury_deep_copy.h:
runtime/mercury_layout_util.h:
	Add some missing `#include' directives.

runtime/Mmakefile:
	Add mercury.c and mercury.h to the respective file lists.
	Split the HDRS variable into HDRS and BODY_HDRS, so that
	`mmake check_headers' does not assume that *_body.h
	will be syntactically correct.
2000-05-05 10:14:50 +00:00
Fergus Henderson
f5623c632d Lots of bug fixes for the MLDS back-end.
Estimated hours taken: 10

Lots of bug fixes for the MLDS back-end.

compiler/ml_unify_gen.m:
	- Fix a bug where it was getting the field type and class type
	  in the wrong order when generating fields of closures.
	- When generating secondary tag test, ensure that we unbox
	  (i.e. cast) the secondary tag properly.
	- When generating code for deconstruction unifications,
	  generate the correct field types, and pass them down to
	  ml_gen_unify_arg...  but then ignore them, since currently
	  we store all fields as boxed (mlds__generic_type).

compiler/ml_unify_gen.m:
compiler/ml_call_gen.m:
	- Fix a bug where it was not properly boxing/unboxing/casting
	  things when generating unifications of no_tag types.

compiler/mlds.m:
	- Add some comments about the treatment of field types in
	  `new_object' statements and `field' lvals.

compiler/mlds_to_c.m:
	- Use llds_out__sym_name_mangle rather than prog_out__write_sym
	  to write out module names, since the latter was doing the wrong
	  thing for nested modules.
	- s/Word/MR_Word/g

compiler/ml_code_gen.m:
	- When generating pragma c_code, make sure to cast polymorphically
	  typed arguments from MR_Word to MR_Box or vice versa, since the
	  C interface uses MR_Word (for backwards compatiblity) while the
	  MLDS back-end uses MR_Box for the C type of variables which
	  in Mercury are polymorphically typed.
	- For semidet pragma c_code, add a `;' after the user's code,
	  like we do for the det and nondet cases, and like the LLDS
	  back-end does in all cases.

library/builtin.m:
	- Fix `gcc -Wmissing-prototypes' warning about
	  mercury__builtin__copy_2_p_{0,1} being defined
	  without having been first declared.
	- Avoid assuming that MR_Box is Word.
	- s/Word/MR_Word/g
	- Fix a bug: s/#ifdef HIGHLEVEL_CODE/#ifdef MR_HIGHLEVEL_CODE/
	                                            ^^^
library/private_builtin.m:
	- Add a missing #include.
	- If MR_HIGHLEVEL_CODE is defined, use MR_box_float() and
	  MR_unbox_float() rather than word_to_float() and float_to_word();
	  this is necessary because float_to_word() uses MR_hp.

library/std_util.m:
runtime/mercury.h:
	- Fix some code and documentation rot: s/type_info/type_desc/

library/std_util.m:
runtime/mercury_type_info.h:
	- Add `const' in various places, to avoid warnings that occur
	  when compiling with --high-level-code.

runtime/mercury.h:
	- Change `MR_Box' from `Word' to `void *'.
	  This is needed to avoid problems with casts to Word
	  in static initializers.  It is also better style,
	  since `MR_Box' is intended as a generic type
	  and C uses `void *' as its generic type.
	- Add a couple of nasty hacks to get things to compile.

runtime/mercury_type_info.h:
	- Use a different type for procedure addresses in the MLDS back-end.

runtime/mercury_heap.h:
	- Add definitions of create{1,2,3}{,_msg} for the MLDS back-end.
	  These are needed since they are used by the
	  MR_list_{empty,cons}{,_msg} macros in runtime/mercury_tags.h,
	  which are used in quite a few places in pragma c_code in the
	  standard library.
2000-05-01 17:43:13 +00:00
Fergus Henderson
018b0a57bb Implement RTTI support for the MLDS back-end using the rtti module.
Estimated hours taken: 10

Implement RTTI support for the MLDS back-end using the rtti module.

compiler/ml_base_type_info.m:
	Delete this file.

compiler/rtti_to_mlds.m:
	New file, replaces ml_base_type_info.
	This generates MLDS code from the RTTI data structures.

compiler/ml_code_gen.m:
	Don't call ml_base_type_info.

compiler/mercury_compile.m:
	Call rtti_to_mlds.
	Also add a few more comments to the list of
	imported modules.

compiler/mercury_compile.m:
compiler/type_ctor_info.m:
	Delete the unnecessary second `module_info' parameter from
	type_ctor_info_generate_rtti.

compiler/ml_code_util.m:
	Add ml_gen_proc_params_from_rtti, for use by gen_init_proc_id
	in rtti_to_mlds.
	Fix a bug where it was using Arity for both the PredArity
	and the TypeArity.

compiler/rtti.m:
compiler/rtti_out.m:
	Change the documentation for rtti_out.m to say that it
	_is_ intended to depend on LLDS.
	Move rtti_data_to_name from rtti_out.m to rtti.m,
	since that does not depend on the LLDS.
	Add rtti__name_is_exported/1, and implement
	rtti_name_linkage using that.
	Add some new fields to rtti_proc_label, for use by
	ml_gen_proc_params_from_rtti.

compiler/mlds.m:
	Add a new alternative `rtti_type(rtti_name)' to mlds__type type,
	and a new alternative `rtti_data(rtti_type_id, rtti_name)' to
	the mlds__data_name type, so we can represent the names and
	types of the RTTI data.
	Change the mlds__initializer type to make it a bit more expressive,
	so that it can represent e.g. initializers for arrays of structs,
	since this is needed for some of the RTTI data.

compiler/ml_code_util.m:
compiler/ml_elim_nested.m:
compiler/mlds_to_c.m:
	Handle the new definition of mlds__initializer,
	and the new alternatives in the rtti_name and
	mlds__data_name types.
2000-04-18 16:41:55 +00:00
Tyson Dowd
de40a0d018 Extend MLDS to cope with alternate backends, and hopefully to allow
Estimated hours taken: 16 (some work done in tandem with fjh)

Extend MLDS to cope with alternate backends, and hopefully to allow
easier implementation of high level data structures in the C backend.

Add type information that is required for more heavily typed backends
(with C you can just cast to void * to escape the type system when it is
inconvenient, with other systems this is impossible, e.g. a Java backend).

Introduce new "cast" unop, that does casts.

compiler/mercury_compile.m:
	Split the generation of MLDS from outputting high-level C code.
	MLDS can be connected up to other backends.

compiler/ml_base_type_info.m:
compiler/ml_call_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_tailcall.m:
compiler/ml_unify_gen.m:
	Add a type to code address constants (the type signature of the
	function).
	Add the type of the field and the type of the object to field
	instructions.
	Add a type to mem_ref (the type of the reference).
	Don't create local definitions if the locals are dummy types.

compiler/ml_elim_nested.m:
	Add types to code addresses, fields and mem_refs.
	Use cast where appropriate.

compiler/mlds.m:
	Add cast statement.
	Add types to code addresses, fields and mem_refs.

compiler/mlds_to_c.m:
	Output casts, generally ignore the types in code addresses,
	fields and mem_refs (high level C code doesn't really need them,
	although it might be nice to use them in future).
2000-03-30 05:41:52 +00:00
Zoltan Somogyi
6feb0b95f2 Make a separate enquiry function for each possible semantic test on
Estimated hours taken: 1

Make a separate enquiry function for each possible semantic test on
eval_methods. The answers are the same now, but will be different when
tabled I/O is implemented.

compiler/hlds_pred.m:
	Make a separate enquiry function for each possible semantic test on
	eval_methods.

compiler/code_gen.m:
compiler/ml_code_gen.m:
compiler/make_hlds.m:
compiler/modes.m:
compiler/table_gen.m:
	Use the new functions.
2000-03-13 02:23:08 +00:00
Fergus Henderson
4aee4cd2fb Update the TODO list.
Estimated hours taken: 0.25

compiler/ml_code_gen.m:
	Update the TODO list.
	Fix some typos in the comments.
2000-02-17 16:01:27 +00:00
Simon Taylor
2d8bc59951 Add an alternative method of computing the non-locals for
Estimated hours taken: 3

compiler/quantification.m:
	Add an alternative method of computing the non-locals for
	goals which do structure reuse, This is done to avoid unnecessary
	field extractions and variable saves for arguments of reused terms.
	The code-gen non-locals are the same as the ordinary non-locals
	except that arguments of a reconstruction which are taken
	from the reused cell are not included in the non-locals set.
	Mode analysis still uses the full non-locals set.

	Add a field to type quant_info to record which set
	of non-locals is being computed. Use record syntax
	for the access predicates.

compiler/hlds_goal.m:
	Add access predicates to extract and update the code_gen_nonlocals
	in a goal_info. When structure reuse is not performed, the nonlocals
	and the code-gen nonlocals will always be the same.

	Use record syntax for hlds_goal_info access predicates.

compiler/goal_util.m:
	Add a predicate `goal_contains_reconstruction', which
	succeeds if the goal does any structure reuse.
	This will always fail on the main branch.

	Add missing disjuncts for par_conj goals in `goal_calls' and
	`goal_calls_pred_id'.

compiler/liveness.m:
compiler/live_vars.m:
compiler/ml_code_gen.m:
compiler/par_conj_gen.m:
	Use the code_gen_nonlocals rather than the ordinary nonlocals.

configure.in:
	Add a test for record syntax.
2000-02-10 04:47:44 +00:00
Fergus Henderson
b2f565acf2 Some improvements to the MLDS back-end's handling
Estimated hours taken: 4

Some improvements to the MLDS back-end's handling
of `pragma c_code'.

compiler/ml_code_gen.m:
        Implement nondet pragma c_code.

compiler/ml_code_gen.m:
runtime/mercury_types.h:
        Fix some bugs with semidet pragma c_code.
        The `SUCCESS_INDICATOR' macro was not being
        correctly `#define'd and `#undef'ed.
2000-02-08 16:01:16 +00:00