Files
mercury/trace
Peter Ross 2e66995c01 Fix the I/O routines for floats so that can roundtrip.
Estimated hours taken: 8
Branches: main

Fix the I/O routines for floats so that can roundtrip.

library/string.m:
    Ensure that string__float_to_string returns a float that is
    round-trippable.  On the C backend we do that by starting at the min
    precision required and increasing it until the float roundtrips.
    This functionality is provided by ML_sprintf_float, so that it can
    be reused in io.m. On the IL backend the R flag guarantees that a
    double will be round-trippable, so we just use that.
    Change string__to_float so that it uses the format string for the
    precision float that we are using, and export this predicate for use
    by the trace system.
    Delete the unused string__float_to_f_string.

library/io.m:
    Print round-tripable floats in io__write_float.
    For the C backend use ML_sprintf_float to avoid unnecessary string
    allocation.  For other backends use string__float_to_string to
    generate a valid float.

trace/mercury_trace_util.c:
    Rather than duplicating the code from the library, call the code in
    the library.

tests/general/Mmakefile:
tests/general/float_roundtrip.exp:
tests/general/float_roundtrip.m:
    Test that floats roundtrip for different required miniumum
    precisions.
2002-11-21 08:00:58 +00:00
..

This directory holds the trace subsystem,
i.e. the part of the Mercury debugger that is written in C code.


Notes on interfacing with other subsystems
------------------------------------------

If tracing is enabled, the compiler includes calls to MR_trace() in the
generated C code.  The trace subsystem in this directory is therefore
called directly from Mercury code, via MR_trace() in
runtime/mercury_trace_base.c.

One of the first things it does is to save the original values
of the Mercury registers in a variable called `saved_regs'.
The reason it needs to do this is that the code here may
modify registers, e.g. by allocating memory using incr_hp
or by calling Mercury code.  Once the original values of
the registers have been saved, the trace subsystem is free
to modify the Mercury registers.

So for all code in this directory, the usual convention is that the
original values of the Mercury registers are in `saved_regs',
while the current (scratch) values for the normal non-transient
Mercury registers etc. are in their normal locations, not in the
fake_reg copies, and the transient (register window) registers,
if any, are in the fake_reg copies.

Any code which uses macros such as incr_hp(), list_cons(),
make_aligned_string(), etc. that modify the heap pointer must call
restore_transient_regs() beforehand and must call save_transient_regs()
afterwards.  The simplest way to do this is to use the macro
MR_TRACE_USE_HP() in trace/mercury_trace_util.h.

The tracer may invoke Mercury code defined in the browser or library
directories if that code is exported to C using `pragma export'.
But any calls from functions here to code defined in Mercury
and exported using `pragma export', i.e. functions starting with `ML_'
prefixes, must be preceded by a call to save_registers() and
followed by a call to restore_registers().
The simplest way to do this is to use the macro
MR_TRACE_CALL_MERCURY() in trace/mercury_trace_util.h.