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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.