[m-rev.] for review: More robust compile-time evaluation of `int' operations.

Julien Fischer jfischer at opturion.com
Wed Mar 18 22:14:48 AEDT 2015

Hi Peter,

On Tue, 17 Mar 2015, Peter Wang wrote:

> More robust compile-time evaluation of `int' operations.
> Compile-time evaluation of `int' operations previously required that
> the target have the same number of bits per int as the host compiler.
> In other cases, the user would have to pass `--cross-compiling' to avoid
> the compiler silently producing a different result at compile time to
> what would be produced at run time.
> This change makes the compiler aware of the target's `int' width when
> evaluating operations at compile-time.
> Passing `--cross-compiling' is no longer required to avoid the problems
> that this change addresses, but it MAY still be required for other reasons.
> As of now, the one problem it would avoid is generating incorrect trie
> string switches containing non-ASCII strings when targeting a high-level
> C grade from a compiler built in Java or C# grades (not really
> supported, but something we can fix anyway).

Modulo a bunch of build system issues and a (probably) incorrect stack
size setting a compiler built in the Java grade should be able to target
the high-level C grade.

> I have not removed any
> references to the `--cross-compiling' option in the documentation.
> compiler/libs.m:
> compiler/int_emu.m:
> 	Add new module to emulate `int' operations for the target
> 	bits-per-int.  The predicates will only succeed if the result
> 	would be well-defined (including no overflow), and the result
> 	fits in the host's `int' type (no truncation).
> compiler/const_prop.m:
> 	Evaluate `int' operations at compile time using `int_emu'
> 	predicates.
> 	Delete now unnecessary checks for cross_compiling=no.
> 	Delete comment about checking for overflow, now done.
> compiler/simplify_goal_call.m:
> 	Use the target's value of bits-per-int in relevant
> 	simplifications.
> 	Delete check for cross_compiling=no.
> compiler/handle_options.m:
> 	Don't imply `--cross-compiling' when targeting java, csharp and
> 	erlang grades.  This was a temporary workaround in case the
> 	Mercury compiler itself uses 64-bit ints.
> tests/hard_coded/Mercury.options:
> tests/hard_coded/Mmakefile:
> tests/hard_coded/constant_prop_int.exp:
> tests/hard_coded/constant_prop_int.exp2:
> tests/hard_coded/constant_prop_int.m:
> 	Add test case.
> diff --git a/compiler/int_emu.m b/compiler/int_emu.m


> new file mode 100644
> index 0000000..d0562c5
> --- /dev/null
> +++ b/compiler/int_emu.m
> @@ -0,0 +1,180 @@
> +%----------------------------------------------------------------------------%
> +% vim: ft=mercury ts=4 sw=4 et
> +%----------------------------------------------------------------------------%
> +% Copyright (C) 2015 The University of Melbourne.

s/The University of Melbourne/The Mercury team/

The diff looks fine otherwise.


More information about the reviews mailing list