diff options
author | Tom Tromey <tromey@adacore.com> | 2022-02-16 10:07:18 -0700 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2022-03-07 08:27:38 -0700 |
commit | 63fc2437deda87a566059444630ccc402945ae99 (patch) | |
tree | ff778d7fab7aea1716f23f4c36c5553d9c5c1449 /gdb/testsuite/gdb.ada/float-bits/prog.adb | |
parent | c9bfa277e9e6467dad91641357e09bf0a7ac0dc2 (diff) | |
download | binutils-63fc2437deda87a566059444630ccc402945ae99.zip binutils-63fc2437deda87a566059444630ccc402945ae99.tar.gz binutils-63fc2437deda87a566059444630ccc402945ae99.tar.bz2 |
Implement real literal extension for Ada
Sometimes it is convenient to be able to specify the exact bits of a
floating-point literal. For example, you may want to set a
floating-point register to a denormalized value, or to a particular
NaN.
In C, you can do this by combining the "{}" cast with an array
literal, like:
(gdb) p {double}{0x576488BDD2AE9FFE}
$1 = 9.8765449999999996e+112
This patch adds a somewhat similar idea to Ada. It extends the lexer
to allow "l" and "f" suffixes in a based literal. The "f" indicates a
floating-point literal, and the "l"s control the size of the
floating-point type.
Note that this differs from Ada's based real literals. I believe
those can also be used to control the bits of a floating-point value,
but they are a bit more cumbersome to use (simplest is binary but
that's also very lengthy). Also, these aren't implemented in GDB.
I chose not to allow this extension to work with based integer
literals with exponents. That didn't seem very useful.
Diffstat (limited to 'gdb/testsuite/gdb.ada/float-bits/prog.adb')
-rw-r--r-- | gdb/testsuite/gdb.ada/float-bits/prog.adb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.ada/float-bits/prog.adb b/gdb/testsuite/gdb.ada/float-bits/prog.adb new file mode 100644 index 0000000..0d8c18f --- /dev/null +++ b/gdb/testsuite/gdb.ada/float-bits/prog.adb @@ -0,0 +1,22 @@ +-- Copyright 2022 Free Software Foundation, Inc. +-- +-- 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/>. + +procedure Prog is + Val_Float : Float := 23.0; + Val_Double : Long_Float := -2.0e-19; + Val_Long_Double : Long_Long_Float := 5.0e+25; +begin + null; -- BREAK +end Prog; |