Commit Graph

18 Commits

Author SHA1 Message Date
Zoltan Somogyi
6554ef7daa Replace "is" with "=".
Estimated hours taken: 2
Branches: main

Replace "is" with "=".
Add field names where relevant.
Replace integers with counters where relevant.
2003-05-26 09:01:46 +00:00
Zoltan Somogyi
c698ab3a88 Start using the flags in type_ctor_infos to improve effificiency.
Estimated hours taken: 1
Branches: main

Start using the flags in type_ctor_infos to improve effificiency.

runtime/*.c:
	Replace uses of the old, expensive macros for testing whether a
	type_ctor is variable arity or of some kind of discriminated union
	type with uses of the macros that do the same job by testing
	type_ctor_info flags.

runtime/mercury_type_info.h:
	Delete the old, expensive macros.

	Set the minimum RTTI version number to the one that implements
	their newer versions.

runtime/mercury_grade.h:
	Increment the version compatibility number accordingly.

configure.in:
	Require the RTTI system to have flags.

compiler/c_util.m:
	Don't emit the macro that used to cause type_ctor_infos to have
	flags; the version of mercury_type_info.h that doesn't need the flag
	has been installed on all our machines.
2003-03-21 08:00:31 +00:00
Simon Taylor
82a950c0d9 Make Aditi work with `--highlevel-code'.
Estimated hours taken: 80
Branches: main

Make Aditi work with `--highlevel-code'.

(Note that this doesn't work with the current CVS version
of Aditi. The Aditi developers have rewritten the Aditi client
API, and haven't maintained the old version of the API, so Mercury
queries don't work at the moment. extras/aditi will be updated to
use the new interface as a separate change.)

extras/aditi/aditi_private_builtin.m:
extras/aditi/aditi.m:
	Move code to implement Aditi calls and updates into
	a aditi_private_builtin.m. These operations are now
	implemented using ordinary Mercury foreign procedures,
	rather than hand-coded C modules.

compiler/magic.m:
	Use calls to ordinary calls to predicates defined in
	extras/aditi/aditi_private_builtin.m to implement the
	procedures which interface between top-down Mercury
	code and Aditi procedures.

compiler/aditi_backend.pp:
compiler/aditi_builtin_ops.m:
compiler/mercury_compile.m:
compiler/notes/compiler_design.html:
	Add a pass to convert Aditi builtins (calls and updates)
	into ordinary calls to predicates defined in
	extras/aditi/aditi_private_builtin.m.

compiler/hlds_goal.m:
compiler/hlds_pred.m:
	Add a new generic_call type -- `unsafe_cast'.
	aditi_builtin_ops.m needs to be able to cast
	closures from one type and inst to another.

	Delete the `aditi_call' alternative for `aditi_builtin',
	which is not needed after the change to magic.m described
	above.

	Add predicates `construct_tuple' and `deconstruct_tuple'.

compiler/*hlds.*.m:
compiler/call_gen.m:
compiler/ml_call_gen.m:
	Handle unsafe cast goals.

compiler/common.m:
compiler/higher_order.m:
compiler/unify_proc.m:
	Generate unsafe_cast goals instead of calls to
	private_builtin.unsafe_type_cast.

compiler/purity.m:
compiler/notes/compiler_design.html:
	Convert calls to private_builtin.unsafe_type_cast into
	unsafe_cast goals.

compiler/ml_code_gen.m:
	Don't attempt to generate code for Aditi procedures.

	Remove special case handling of calls to
	private_builtin.unsafe_type_cast -- such
	calls are now transformed away.

compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/maybe_mlds_to_gcc.m:
	Add the RL code to the generated C file.

compiler/llds_out.m:
compiler/c_util.m:
compiler/compile_target_code.m:
	Move code to generate a `.rlo' file and work out the
	name of the RL constant embeeded in the C file for
	a module into c_util.m, for use by the MLDS backend.

compiler/modules.m:
	Automatically import aditi_private_builtin when compiling
	with `--aditi'.

	We generate a C constant for the RL code for each module,
	so modules compiled with `--aditi' need to be treated
	by the build system as if they contain foreign code.

compiler/polymorphism.m:
	Tuple insertion and deletion no longer need special treatment.

compiler/llds.m:
compiler/ll_backend.*.m:
	Delete the Aditi alternatives of the `code_addr' type.

compiler/mode_util.m:
	Add function versions of in_mode, out_mode, etc.

compiler/prog_util.m:
	Add aditi_public_builtin_module (returns `aditi') and
	aditi_private_builtin_module (returns `aditi_private_builtin').

tests/valid/aditi_private_builtin.m:
tests/invalid/aditi_private_builtin.m:
tests/valid/Mercury.options:
tests/invalid/Mercury.options:
	Add a cut down version of extras/aditi/aditi_private_builtin.m
	for use in running the tests.
2003-03-18 02:43:52 +00:00
Zoltan Somogyi
1cb657b998 Reduce inappropriate dependencies on ll_backend modules.
Estimated hours taken: 3
Branches: main

Reduce inappropriate dependencies on ll_backend modules. Except for
simplification of unnecessarily complicated logic in dependency_graph.m,
this change only moves functionality around.

compiler/llds_out.m:
compiler/c_util.m:
compiler/name_mangle.m:
	Move predicates that are used by multiple backends from
	ll_backend__llds_out to backend_libs__c_util and to a new module
	backend_libs__name_mangle. Make the relevant ones functions,
	and give some of them more meaningful names.

compiler/trace.m:
compiler/hlds_goal.m:
	Move a backend-independent predicate from ll_backend__trace
	to hlds__hlds_goal.

compiler/llds.m:
compiler/trace_params.m:
	Move the definition of the trace_port type from ll_backend__llds
	to libs__trace_params to avoid having libs__trace_params depend on
	ll_backend.

compiler/exprn_aux.m:
compiler/globals.m:
	Move the definition of the imported_is_constant from
	ll_backend__exprn_aux to libs__globals to avoid having libs__globals
	depend on ll_backend.

compiler/*.m:
	Conform to the above changes. This removes many inappropriate
	dependencies on the LLDS backend.
2003-03-16 08:01:31 +00:00
Zoltan Somogyi
9551640f55 Import only one compiler module per line. Sort the blocks of imports.
Estimated hours taken: 2
Branches: main

compiler/*.m:
	Import only one compiler module per line. Sort the blocks of imports.
	This makes it easier to merge in changes.

	In a couple of places, remove unnecessary imports.
2003-03-15 03:09:14 +00:00
Fergus Henderson
476e40c7f1 Change set_line_num so that if we do not have a valid context,
Estimated hours taken: 0.5
Branches: main

compiler/c_util.m:
	Change set_line_num so that if we do not have a valid context,
	it calls reset_line_num.

	Previous it would just not emit any #line directive, but that is wrong,
	because it causes the C compiler to assume that such lines come from
	the next line in the source file after wherever the previous line
	in the C file came from.  This is incorrect and can lead to confusing
	results.
2003-03-15 00:08:51 +00:00
Fergus Henderson
0c07d69c89 Reorganize the code in the compiler to centralize the code which handles
Estimated hours taken:
Branches: main, release

Reorganize the code in the compiler to centralize the code which handles
output of floating point literals.

compiler/c_util.m:
	Add new routines make_float_literal and output_float_literal.
	These output to 17 digits precision.
	Also add some comments.

compiler/mlds_to_c.m:
compiler/llds_out.m:
compiler/mlds_to_java.m:
compiler/ilasm.m:
	Use the new routines.
	Also add some comments.

tests/hard_coded/Mmakefile:
tests/hard_coded/float_consistency.m:
tests/hard_coded/float_consistency.exp:
	A regression test.
2002-11-24 03:57:36 +00:00
Fergus Henderson
8c6f60daba Fix a bug where we were generating C code that contained special
Estimated hours taken: 2
Branches: main

Fix a bug where we were generating C code that contained special
characters in string literals.  This generated code was relying on
the implementation-specific behaviour of GCC, and unfortunately
that behaviour changed in GCC versions 2.96 and later.
The symptom was that printing "\r\n" came out as "\n\n"
when using GCC versions >= 2.96.

compiler/c_util.m:
	Change the code used to implement quote_char, quote_string,
	and quote_multi_string so that these routines properly escape
	all special characters, rather than just \" \' \n \b and \t.
	(This required changing the output argument type for quote_char
	from a character to a string.)
	Add output_quoted_char, for use by layout_out.m.

compiler/layout_out.m:
	Use c_util__output_quoted_char, rather than duplicating the
	logic in c_util.m.

tests/hard_coded/Mmakefile:
tests/hard_coded/special_char.m:
tests/hard_coded/special_char.exp:
	Regression test.

tests/hard_coded/Mmakefile:
tests/hard_coded/null_char.m:
tests/hard_coded/null_char.exp:
tests/hard_coded/null_char.exp2:
	Add a test of outputting strings containing null characters.
	Note that currently we don't handle this correctly;
	we ignore everything after the first null character.
	So the ".exp2" file for this test case allows that output.
	If/when this is fixed, the ".exp2" file for this
	test case should be removed.
2002-08-06 00:30:52 +00:00
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
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
Julien Fischer
efe77ccbb0 Converts MLDS to Java source code. The following features
Estimated hours taken: 200

Converts MLDS to Java source code.  The following features
do not work/have not yet been implemented:
	* RTTI
	* foreign language interface
	* multidet and nondet predicates
	* higher order predicates
	* enforced usage of Java coding conventions

compiler/mlds_to_java.m:
	Replaces existing file.
compiler/java_util.m:
	New file.  Contains utility predicates that are used
	by the Java backend.
compiler/c_util.m:
	Added comment about Java backend.
2001-03-01 15:52:35 +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
Zoltan Somogyi
1c8cb6faf2 Get the compiler to bootstrap with -DMR_NO_BACKWARDS_COMPAT.
Estimated hours taken: 2

Get the compiler to bootstrap with -DMR_NO_BACKWARDS_COMPAT.

compiler/c_util.m:
compiler/rtti_out.m:
	Add MR_ prefixes to various type names in generated code.

compiler/*.m:
browser/*.m:
library/*.m:
	Add MR_prefixes to various type and function names in pragma C code.

runtime/*.[ch]:
trace/*.[ch]:
	Add MR_prefixes to various type and function names in
	hand-written code.
2000-10-16 01:34:14 +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
Peter Ross
151c2bae2b Bootstrap the none.gc.debug grade using MSVC as the C compiler.
Estimated hours taken: 2

Bootstrap the none.gc.debug grade using MSVC as the C compiler.

compiler/c_util.m:
	Avoid a limitation in MSVC where string literals are not allowed
	to be longer then 2048 chars.
	Error C2026 is now avoided by instead of outputing a string as
	"a very long string" chunk it up into "a very " "long string"
	where each chunk is 512 characters long.
	Redefine c_util__output_quoted_string to call
	c_util__output_quoted_multi_string, so as to avoid some code
	duplication.

compiler/llds_out.m:
	The definitions of any types used in the module need to be
	output before they are used, so output them first.
2000-08-14 09:08:44 +00:00
Fergus Henderson
31a8b91e0a Add `MR_' prefix to hash_string().
Estimated hours taken: 0.1

compiler/c_util.m:
        Add `MR_' prefix to hash_string().
2000-05-09 11:23:20 +00:00
Fergus Henderson
eefc022da7 Add support for generation of builtins to the MLDS backend.
Estimated hours taken: 2

Add support for generation of builtins to the MLDS backend.

compiler/ml_code_gen.m:
	Add support for generating builtins (mostly copied
	from call_gen.m and code_util.m, but with a few
	changes).

compiler/code_util.m:
	Add a comment warning about the code duplication.

compiler/c_util.m:
compiler/llds_out.m:
compiler/mlds_to_c.m:
	Move (most of) the code from llds_out__binary_op_to_string
	into a new routine c_util__binary_infix_op/2, and change
	llds_out.m and mlds_to_c.m to use it.

compiler/mlds_to_c.m:
        (An unrelated change:)
	Don't output any comments for "public" access,
	since such comments end up being just noise.
1999-09-17 16:22:27 +00:00
Fergus Henderson
de27cd9bbb A batch of changes related to the development of the new MLDS back-end.
Estimated hours taken: 30

A batch of changes related to the development of the new MLDS back-end.

compiler/notes/compiler_design.html:
	Reorganize the documentation to reflect the multi-target /
	multiple back-end nature of the compiler.
	Document mlds.m and the new modules c_util.m and mlds_to_c.m.

compiler/mlds_to_c.m:
	New module.  This converts MLDS to C/C++ code.
	This version compiles, but it is still quite incomplete;
	there's lots of parts which are still not yet implemented.

compiler/llds_out.m:
compiler/c_util.m:
	Move some procedures from llds_out.m into a new module c_util.m,
	so that they can also be used by mlds_to_c.m.

compiler/mlds.m:
	- Add new functions for use by mlds_to_c.m:
		* get_prog_context/1, for getting the prog_context from an
		  mlds__context
		* get_module_name/1, for getting the module name from the mlds
		* module_name_to_sym_name/1, for converting an mlds_module_name
		  to a sym_name
	- Change the mlds__func_signature type to
		* allow multiple return values, for consistency with the
		  MLDS `return' statement;
	        * include the names of the parameters.
	- Undo the premature over-optimization of making the `constness'
	  and `finality' flags share the same flag bit.
1999-08-05 11:57:42 +00:00