binutils-gdb/gdb/target-float.h
Ulrich Weigand 14ad931172 Target FP: Handle interfaces to scripting languages
The last remaing use for DOUBLEST is in the code that interfaces to the
scripting languages (Python and Guile).  The problem here is that we
expose interfaces to convert a GDB value to and from native values of
floating-point type in those languages, and those by definition use
the host floating-point format.

While we cannot completely eliminate conversions to/from the host
floating-point format here, we still need to get rid of the uses
of value_as_double / value_from_double, since those will go away.

This patch implements two new target-float.c routine:
 - target_float_to_host_double
 - target_float_from_host_double
which convert to/from a host "double".  Those should only ever be
used where a host "double" is mandated by an external interface.

gdb/ChangeLog:
2017-11-06  Ulrich Weigand  <uweigand@de.ibm.com>

	* target-float.c (floatformat_to_host_double): New function.
	(floatformat_from_host_double): Likewise.
	(target_float_to_host_double): Likewise.
	(target_float_from_host_double): Likewise.
	* target-float.h (target_float_to_host_double): Add prototype.
	(target_float_from_host_double): Likewise.

	* guile/scm-value.c: Include "target-float.h".
	(gdbscm_value_to_real): Use target_float_to_host_double.
	Handle integer source values via value_as_long.
	* guile/scm-math.c: Include "target-float.h".  Do not include
	"doublest.h", "dfp.h", and "expression.h".
	(vlscm_convert_typed_number): Use target_float_from_host_double.
	(vlscm_convert_number): Likewise.

	* python/py-value.c (valpy_float): Use target_float_to_host_double.
	(convert_value_from_python): Use target_float_from_host_double.
2017-11-06 16:00:47 +01:00

62 lines
2.2 KiB
C++

/* Floating point definitions for GDB.
Copyright (C) 1986-2017 Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifndef TYPED_FLOAT_H
#define TYPED_FLOAT_H
#include "expression.h"
extern bool target_float_is_valid (const gdb_byte *addr,
const struct type *type);
extern bool target_float_is_zero (const gdb_byte *addr,
const struct type *type);
extern std::string target_float_to_string (const gdb_byte *addr,
const struct type *type,
const char *format = nullptr);
extern bool target_float_from_string (gdb_byte *addr,
const struct type *type,
const std::string &string);
extern LONGEST target_float_to_longest (const gdb_byte *addr,
const struct type *type);
extern void target_float_from_longest (gdb_byte *addr,
const struct type *type,
LONGEST val);
extern void target_float_from_ulongest (gdb_byte *addr,
const struct type *type,
ULONGEST val);
extern double target_float_to_host_double (const gdb_byte *addr,
const struct type *type);
extern void target_float_from_host_double (gdb_byte *addr,
const struct type *type,
double val);
extern void target_float_convert (const gdb_byte *from,
const struct type *from_type,
gdb_byte *to, const struct type *to_type);
extern void target_float_binop (enum exp_opcode opcode,
const gdb_byte *x, const struct type *type_x,
const gdb_byte *y, const struct type *type_y,
gdb_byte *res, const struct type *type_res);
extern int target_float_compare (const gdb_byte *x, const struct type *type_x,
const gdb_byte *y, const struct type *type_y);
#endif