From b74dbc2093191b10f4963f43ee570b54c9593404 Mon Sep 17 00:00:00 2001 From: Joel Brobecker Date: Sun, 15 Nov 2020 03:18:35 -0500 Subject: Add support for fixed-point type comparison operators This patch adds support for binary comparison operators with fixed-point type values. gdb/ChangeLog: * valarith.c (fixed_point_binop): Add BINOP_EQUAL and BINOP_LESS handling. (value_less): Add fixed-point handling. gdb/testsuite/ChangeLog: * gdb.ada/fixed_cmp.exp: Add -fgnat-encodings=minimal testing. * gdb.dwarf2/dw2-fixed-point.c (pck__fp1_var2): New global. (main): Add reference to pck__fp1_var2. * gdb.dwarf2/dw2-fixed-point.exp: Add comparison operator testing. --- gdb/valarith.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'gdb/valarith.c') diff --git a/gdb/valarith.c b/gdb/valarith.c index 65a6f13..f4497cd 100644 --- a/gdb/valarith.c +++ b/gdb/valarith.c @@ -890,7 +890,9 @@ fixed_point_binop (struct value *arg1, struct value *arg2, enum exp_opcode op) { struct type *type1 = check_typedef (value_type (arg1)); struct type *type2 = check_typedef (value_type (arg2)); + const struct language_defn *language = current_language; + struct gdbarch *gdbarch = get_type_arch (type1); struct value *val; gdb_assert (is_fixed_point_type (type1) || is_fixed_point_type (type2)); @@ -952,6 +954,16 @@ fixed_point_binop (struct value *arg1, struct value *arg2, enum exp_opcode op) INIT_VAL_WITH_FIXED_POINT_VAL (res); break; + case BINOP_EQUAL: + val = value_from_ulongest (language_bool_type (language, gdbarch), + mpq_cmp (v1.val, v2.val) == 0 ? 1 : 0); + break; + + case BINOP_LESS: + val = value_from_ulongest (language_bool_type (language, gdbarch), + mpq_cmp (v1.val, v2.val) < 0 ? 1 : 0); + break; + default: error (_("Integer-only operation on fixed point number.")); } @@ -1774,7 +1786,8 @@ value_less (struct value *arg1, struct value *arg2) is_int1 = is_integral_type (type1); is_int2 = is_integral_type (type2); - if (is_int1 && is_int2) + if ((is_int1 && is_int2) + || (is_fixed_point_type (type1) && is_fixed_point_type (type2))) return longest_to_int (value_as_long (value_binop (arg1, arg2, BINOP_LESS))); else if ((is_floating_value (arg1) || is_int1) -- cgit v1.1