Commit Graph

11 Commits

Author SHA1 Message Date
Fergus Henderson
7597790760 Use sub-modules to structure the modules in the Mercury compiler directory.
The main aim of this change is to make the overall, high-level structure
of the compiler clearer, and to encourage better encapsulation of the
major components.

compiler/libs.m:
compiler/backend_libs.m:
compiler/parse_tree.m:
compiler/hlds.m:
compiler/check_hlds.m:
compiler/transform_hlds.m:
compiler/bytecode_backend.m:
compiler/aditi_backend.m:
compiler/ml_backend.m:
compiler/ll_backend.m:
compiler/top_level.m:
	New files.  One module for each of the major components of the
	Mercury compiler.  These modules contain (as separate sub-modules)
	all the other modules in the Mercury compiler, except gcc.m and
	mlds_to_gcc.m.

Mmakefile:
compiler/Mmakefile:
	Handle the fact that the top-level module is now `top_level',
	not `mercury_compile' (since `mercury_compile' is a sub-module
	of `top_level').

compiler/Mmakefile:
	Update settings of *FLAGS-<modulename> to use the appropriate
	nested module names.

compiler/recompilation_check.m:
compiler/recompilation_version.m:
compiler/recompilation_usage.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
compiler/recompilation.version.m:
	Convert the `recompilation_*' modules into sub-modules of the
	`recompilation' module.

compiler/*.m:
compiler/*.pp:
	Module-qualify the module names in `:- module', `:- import_module',
	and `:- use_module' declarations.

compiler/base_type_info.m:
compiler/base_type_layout.m:
	Deleted these unused empty modules.

compiler/prog_data.m:
compiler/globals.m:
	Move the `foreign_language' type from prog_data to globals.

compiler/mlds.m:
compiler/ml_util.m:
compiler/mlds_to_il.m:
	Import `globals', for `foreign_language'.

Mmake.common.in:
trace/Mmakefile:
runtime/Mmakefile:
	Rename the %.check.c targets as %.check_hdr.c,
	to avoid conflicts with compiler/recompilation.check.c.
2002-03-20 12:37:56 +00:00
Simon Taylor
f02edca36e Add a clause for `int__rem/2' which throws an exception if
Estimated hours taken: 0.25

library/int.m:
	Add a clause for `int__rem/2' which throws an exception if
	the right operand is zero.

	Add declarations for the `int__unchecked_rem/2', which
	does not perform any checking.

compiler/builtin_ops.m:
	`int__rem/2' is no longer a builtin.

compiler/const_prop.m:
	Handle `int__unchecked_rem/2'.

NEWS:
	Document the changes.
2001-11-03 17:35:00 +00:00
Simon Taylor
b221ce448c I missed `int__rem/2' in my change to make the arithmetic functions
Estimated hours taken: 0.25
Branches: main

I missed `int__rem/2' in my change to make the arithmetic functions
throw exceptions rather than abort for domain erors.

`int__rem/2' will be made non-builtin. The code for `int__rem/2'
will call `int__unchecked_rem/2' after checking that the right
operand is not zero.

compiler/builtin_ops.m:
	Add a translation for `int__unchecked_rem/2'.

compiler/make_hlds.m:
	Disable warnings about clauses for builtins. This
	is needed to bootstrap the change to make `int__rem/2'
	non-builtin.
2001-10-24 06:51:06 +00:00
Simon Taylor
34c6b77b3c Generate exceptions rather than program aborts for domain errors
Estimated hours taken: 6
Branches: main

Generate exceptions rather than program aborts for domain errors
and out of bounds array accesses.

Improve the handling of the arithmetic functions.

library/float.m:
library/int.m:
compiler/builtin_ops.m:
	Handle division by zero with an exception rather than a
	program abort.

	Add int__unchecked_quotient and float__unchecked_quotient,
	which don't check for division by zero.

	Remove reverse modes of the arithmetic functions in float.m.
	Richard O'Keefe pointed out a while ago that they don't work
	because of rounding errors.

	Remove the long obsolete `int__builtin_*' and
	`float__builtin_float_*' predicates.

library/math.m:
library/array.m:
	Generate exceptions rather than program aborts.
	The bounds and domain checks are now implemented in
	Mercury, so they do not need to be duplicated for each
	target language.

library/exception.m:
	Remove predicate throw_string/1, which was used to throw
	exceptions from array.m across the C interface, which would
	not work in LLDS grades.

NEWS:
	Document the changes.

tests/general/float_test.m:
tests/general/string_format_test.m:
tests/hard_coded/ho_solns.m:
tests/hard_coded/ho_univ_to_type.m:
tests/hard_coded/qual_strang.m:
tests/hard_coded/qual_strung.m:
	Rename occurrences of `builtin_*'.
2001-09-02 12:20:14 +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
Peter Ross
d89afe3839 Merge changes from the reuse branch back onto the main branch.
Estimated hours taken: 0.25
Branches: main

Merge changes from the reuse branch back onto the main branch.

compiler/ml_unify_gen.m:
    Handle the case where the tag on the cell to be reused is unknown.

compiler/hlds_goal.m:
    Add a field which records what possible cons_ids the cell to be
    reused can be tagged with.

compiler/builtin_ops.m:
    Add the unary builtin operator strip_tag.

compiler/bytecode.m:
compiler/c_util.m:
compiler/java_util.m:
compiler/llds.m:
compiler/mlds_to_il.m:
compiler/opt_debug.m:
bytecode/mb_disasm.c:
bytecode/mb_exec.c:
    Handle the strip_tag operator.
2001-03-13 12:40:19 +00:00
Fergus Henderson
9d453c5a7b Delete the `cast_to_unsigned' unary operator from builtin_ops, and
Estimated hours taken: 4

Delete the `cast_to_unsigned' unary operator from builtin_ops, and
replace it with an `unsigned_le' binary operator for doing unsigned
less-then-or-equal comparisons.

This change makes the semantics and typing of the builtin operators
more consistent.

compiler/builtin_ops.m:
	Delete the `cast_to_unsigned' unary_op.
	Add a new `unsigned_le' binary_op.

compiler/dense_switch.m:
compiler/lookup_switch.m:
compiler/ml_simplify_switch.m:
	Use `binop(unsigned_le, X, Y)' rather than
	`binop(<=, unop(cast_to_unsigned, X), Y)'.

compiler/bytecode.m:
compiler/c_util.m:
compiler/llds.m:
compiler/llds_out.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/opt_debug.m:
compiler/vn_util.m:
compiler/vn_cost.m:
	Delete code for handling `cast_to_unsigned'
	and instead add code for handling `unsigned_le'.

compiler/vn_cost.m:
	Also add `mktag' and `unmktag' as zero_cost_unops.

compiler/c_util.m:
	Add a new procedure `c_util__unsigned_comparison_op',
	for use by llds_out.m.
2001-01-20 15:42:48 +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
Peter Ross
35d1d914e7 Update the MLDS backend to handle structure reuse and compile time gc.
Estimated hours taken: 20

Update the MLDS backend to handle structure reuse and compile time gc.
Note that currently no pass on the main branch currently generates this
information yet.

mlds.m:
    Add a new instruction delete_object which is to be inserted
    whenever a lval can be compile time garbage collected.

ml_unify_gen.m:
    Handle the case where the HowToConstruct field of a construction
    is reuse_cell(_).
    Handle the case where a deconstruction can be compile time gc'd.

hlds_goal.m:
    Add a new field, can_cgc, to deconstruction unifications.  This
    field is `yes' if the deconstruction unification can be compile time
    garbage collected.

hlds_out.m:
    Output the can_cgc field.  Output unification information if we
    request the structure reuse information.

ml_elim_nested.m:
mlds_to_c.m:
    Handle the delete_object instruction.

builtin_ops.m:
    Fix a bug where body was an unary op instead of a binary op.

bytecode.m:
c_util.m:
llds.m:
opt_debug.m:
vn_cost.m:
    Changes to reflect that body is a binary op.

bytecode_gen.m:
code_aux.m:
common.m:
cse_detection.m:
dependency_graph.m:
det_analysis.m:
goal_util.m:
higher_order.m:
mark_static_terms.m:
mode_util.m:
modecheck_unify.m:
pd_cost.m:
pd_util.m:
prog_rep.m:
rl_exprn.m:
rl_key.m:
simplify.m:
switch_detection.m:
term_traversal.m:
unify_gen.m:
unused_args.m:
    Handle the can compile time gc field in deconstruction unifications.
2000-10-06 10:18:39 +00:00
Fergus Henderson
1f85335505 Refactor the handling of code generation for builtin
Estimated hours taken: 5

Refactor the handling of code generation for builtin
procedures to avoid code duplication and to reduce
dependencies between different sub-systems.

compiler/builtin_ops.m:
	Add a new `simple_expr' type.
	Add a new procedure `translate_builtin' that returns this type.
	This procedure is very similar to code_util__translate_builtin
	and ml_call_gen:ml_translate_builtin, but with a slightly
	simpler and somewhat safer interface.

compiler/ml_call_gen.m:
	Use builtin_ops__translate_builtin rather than ml_translate_builtin.

compiler/code_util.m:
compiler/call_gen.m:
compiler/bytecode_gen.m:
compiler/rl_exprn.m:
	Use builtin_ops__translate_builtin rather than
	code_util__translate_builtin.
2000-03-15 08:30:54 +00:00
Fergus Henderson
773bd702cc Some more changes to minimize the complexity of the intermodule dependencies.
Estimated hours taken: 2.5

Some more changes to minimize the complexity of the intermodule dependencies.
In particular, ensure that bytecode.m does not need to import llds.m.

compiler/llds.m:
compiler/builtin_ops.m:
	Move the definitions of the unary_op and binary_op types into
	a new module `builtin_ops'.  These types are used by three of the
	different back-ends (bytecode, llds, and mlds) and therefore deserve
	to be in their own module.

compiler/bytecode.m:
	Define a type `byte_reg_type' and use that instead of llds__reg_type.
	Delete the import of module llds.

compiler/notes/compiler_design.html:
	Document the new module builtin_ops.

compiler/rl_exprn.m:
	Add a comment explaining why we need to import llds (and builtin_ops).

compiler/base_type_layout.m:
compiler/bytecode.m:
compiler/code_util.m:
compiler/dense_switch.m:
compiler/ite_gen.m:
compiler/jumpopt.m:
compiler/llds_out.m:
compiler/lookup_switch.m:
compiler/middle_rec.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/rl_exprn.m:
compiler/string_switch.m:
compiler/tag_switch.m:
compiler/transform_llds.m:
compiler/unify_gen.m:
compiler/value_number.m:
compiler/vn_block.m:
compiler/vn_cost.m:
compiler/vn_flush.m:
compiler/vn_type.m:
compiler/vn_util.m:
compiler/vn_verify.m:
	Add imports of module builtin_ops to lots of modules that
	imported llds.
1999-07-10 07:20:09 +00:00