]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
Target FP printing: Simplify and fix ui_printf
authorUlrich Weigand <ulrich.weigand@de.ibm.com>
Tue, 24 Oct 2017 16:00:50 +0000 (18:00 +0200)
committerUlrich Weigand <ulrich.weigand@de.ibm.com>
Tue, 24 Oct 2017 16:00:50 +0000 (18:00 +0200)
commit16e812b29e68c4a6fcad73b033716c4f385ce94f
tree843a021ac8fdc67e80c71575ffd435c98fd7131d
parentfdf0cbc2b710cb5e01249e18f5a377a55eddc39b
Target FP printing: Simplify and fix ui_printf

This patch adds support for handling format strings to both
floatformat_to_string and decimal_to_string, and then uses
those routines to implement ui_printf formatted printing.

There is already a subroutine printf_decfloat that ui_printf uses to
handle decimal FP.  This is renamed to printf_floating and updated
to handle both binary and decimal FP.  This includes the following
set of changes:

- printf_decfloat currently parses the format string again to determine
  the intended target format.  This seems superfluous since the common
  parsing code in parse_format_string already did this, but then did
  not pass the result on to its users.  Fixed by splitting the decfloat_arg
  argument class into three distinct classes, and passing them through.

- Now we can rename printf_decfloat to printf_floating and also call it
  for the argument classes representing binary FP types.

- The code will now use the argclass to detect the type the value should
  be printed at, and converts the input value to this type if necessary.
  To remain compatible with current behavior, for binary FP the code
  instead tries to re-interpret the input value as a FP type of the
  same size if that exists.  (Maybe this behavior is more confusing
  than useful -- but this can be changed later if we want to ...)

- Finally, we can use floatformat_to_string / decimal_to_string passing
  the format string to perform the formatted output using the desired
  target FP type.

Note that we no longer generate different code depending on whether or not
the host supports "long double" -- this check is obsolete anyway since C++11
mandates "long double", and in any case a %lg format string is intended to
refer to the *target* long double type, not the host version.

Note also that formatted printing of DFP numbers may not work correctly,
since it attempts to use the host printf to do so (and makes unwarranted
assumptions about the host ABI while doing so!).  This is no change to
the current behavior -- I simply moved the code from printf_decfloat to
the decimal_to_string routine in dfp.c.  If we want to fix it in the
future, that is a more appropriate place anyway.

ChangeLog:
2017-10-24  Ulrich Weigand  <uweigand@de.ibm.com>

* common/format.h (enum argclass): Replace decfloat_arg by
dec32float_arg, dec64float_arg, and dec128float_arg.
* common/format.c (parse_format_string): Update to return
new decimal float argument classes.

* printcmd.c (printf_decfloat): Rename to ...
(printf_floating): ... this.  Add argclass argument, and use it
instead of parsing the format string again.  Add support for
binary floating-point values, using floatformat_to_string.
Convert value to the target format if it doesn't already match.
(ui_printf): Call printf_floating instead of printf_decfloat,
also for double_arg / long_double_arg.  Pass argclass.

* dfp.c (decimal_to_string): Add format string argument.
* dfp.h (decimal_to_string): Likewise.

* doublest.c (floatformat_to_string): Add format string argument.
* doublest.h (floatformat_to_string): Likewise.
gdb/ChangeLog
gdb/common/format.c
gdb/common/format.h
gdb/dfp.c
gdb/dfp.h
gdb/doublest.c
gdb/doublest.h
gdb/printcmd.c