From: Andrew Burgess <andrew.burgess@embecosm.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <andrew.burgess@embecosm.com>
Subject: [PUSHED 10/11] gdb/fortran: Add support for the ABS intrinsic function
Date: Wed, 06 Mar 2019 18:16:00 -0000 [thread overview]
Message-ID: <739027546fc7a430867d9d6dd2bf6b8e34e04c94.1551895529.git.andrew.burgess@embecosm.com> (raw)
In-Reply-To: <cover.1551895528.git.andrew.burgess@embecosm.com>
In-Reply-To: <cover.1551895528.git.andrew.burgess@embecosm.com>
Adds support for the abs intrinsic function, this requires adding a
new pattern to the Fortran parser. Currently only float and integer
argument types are supported to ABS, complex is still not supported,
this can be added later if needed.
gdb/ChangeLog:
* f-exp.y: New token, UNOP_INTRINSIC.
(exp): New pattern using UNOP_INTRINSIC token.
(f77_keywords): Add 'abs' keyword.
* f-lang.c: Add 'target-float.h' and 'math.h' includes.
(value_from_host_double): New function.
(evaluate_subexp_f): Support UNOP_ABS.
gdb/testsuite/ChangeLog:
* gdb.fortran/intrinsics.exp: Extend to cover ABS.
---
gdb/ChangeLog | 11 +++++++++
gdb/f-exp.y | 8 ++++++-
gdb/f-lang.c | 39 ++++++++++++++++++++++++++++++++
gdb/testsuite/ChangeLog | 4 ++++
gdb/testsuite/gdb.fortran/intrinsics.exp | 9 ++++++++
5 files changed, 70 insertions(+), 1 deletion(-)
diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index d256ff14c1e..88c685a0af3 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -168,6 +168,7 @@ static int parse_number (struct parser_state *, const char *, int,
%token <voidval> DOLLAR_VARIABLE
%token <opcode> ASSIGN_MODIFY
+%token <opcode> UNOP_INTRINSIC
%left ','
%left ABOVE_COMMA
@@ -252,6 +253,10 @@ exp : exp '('
OP_F77_UNDETERMINED_ARGLIST); }
;
+exp : UNOP_INTRINSIC '(' exp ')'
+ { write_exp_elt_opcode (pstate, $1); }
+ ;
+
arglist :
;
@@ -945,7 +950,8 @@ static const struct token f77_keywords[] =
{ "real", REAL_KEYWORD, BINOP_END, true },
/* The following correspond to actual functions in Fortran and are case
insensitive. */
- { "kind", KIND, BINOP_END, false }
+ { "kind", KIND, BINOP_END, false },
+ { "abs", UNOP_INTRINSIC, UNOP_ABS, false }
};
/* Implementation of a dynamically expandable buffer for processing input
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index c329d602e24..24f0e61a46b 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -34,7 +34,9 @@
#include "cp-support.h"
#include "charset.h"
#include "c-lang.h"
+#include "target-float.h"
+#include <math.h>
/* Local functions */
@@ -239,6 +241,20 @@ f_collect_symbol_completion_matches (completion_tracker &tracker,
text, word, ":", code);
}
+/* Create and return a value object of TYPE containing the value D. The
+ TYPE must be of TYPE_CODE_FLT, and must be large enough to hold D once
+ it is converted to target format. */
+
+static struct value *
+value_from_host_double (struct type *type, double d)
+{
+ struct value *value = allocate_value (type);
+ gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLT);
+ target_float_from_host_double (value_contents_raw (value),
+ value_type (value), d);
+ return value;
+}
+
/* Special expression evaluation cases for Fortran. */
struct value *
evaluate_subexp_f (struct type *expect_type, struct expression *exp,
@@ -259,6 +275,29 @@ evaluate_subexp_f (struct type *expect_type, struct expression *exp,
*pos -= 1;
return evaluate_subexp_standard (expect_type, exp, pos, noside);
+ case UNOP_ABS:
+ arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
+ if (noside == EVAL_SKIP)
+ return eval_skip_value (exp);
+ type = value_type (arg1);
+ switch (TYPE_CODE (type))
+ {
+ case TYPE_CODE_FLT:
+ {
+ double d
+ = fabs (target_float_to_host_double (value_contents (arg1),
+ value_type (arg1)));
+ return value_from_host_double (type, d);
+ }
+ case TYPE_CODE_INT:
+ {
+ LONGEST l = value_as_long (arg1);
+ l = llabs (l);
+ return value_from_longest (type, l);
+ }
+ }
+ error (_("ABS of type %s not supported"), TYPE_SAFE_NAME (type));
+
case UNOP_KIND:
arg1 = evaluate_subexp (NULL, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
type = value_type (arg1);
diff --git a/gdb/testsuite/gdb.fortran/intrinsics.exp b/gdb/testsuite/gdb.fortran/intrinsics.exp
index 674f299c428..00396c74c2f 100644
--- a/gdb/testsuite/gdb.fortran/intrinsics.exp
+++ b/gdb/testsuite/gdb.fortran/intrinsics.exp
@@ -40,3 +40,12 @@ gdb_test "p kind (l2)" " = 2"
gdb_test "p kind (l4)" " = 4"
gdb_test "p kind (l8)" " = 8"
gdb_test "p kind (s1)" "argument to kind must be an intrinsic type"
+
+# Test ABS
+
+gdb_test "p abs (-11)" " = 11"
+gdb_test "p abs (11)" " = 11"
+# Use `$decimal` to match here as we depend on host floating point
+# rounding, which can vary.
+gdb_test "p abs (-9.1)" " = 9.$decimal"
+gdb_test "p abs (9.1)" " = 9.$decimal"
--
2.14.5
next prev parent reply other threads:[~2019-03-06 18:16 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-12 16:11 [PATCH 00/11] Fortran Parser Cleanup, KIND Support, and Intrinsic Functions Andrew Burgess
2019-02-12 16:11 ` [PATCH 02/11] gdb/fortran: Cleanup code for parsing logical constants Andrew Burgess
2019-02-12 16:11 ` [PATCH 10/11] gdb/fortran: Add support for the ABS intrinsic function Andrew Burgess
2019-02-12 16:11 ` [PATCH 08/11] gdb/fortran: Add builtin 8-byte integer type with (kind=8) support Andrew Burgess
2019-02-12 16:11 ` [PATCH 03/11] gdb/fortran: Simplify handling of Fortran dot operations and keywords Andrew Burgess
2019-02-12 16:11 ` [PATCH 06/11] gdb/fortran: Add Fortran 'kind' intrinsic and keyword Andrew Burgess
2019-02-12 16:11 ` [PATCH 01/11] gdb/fortran: Remove some duplicate tests Andrew Burgess
2019-02-12 16:11 ` [PATCH 09/11] gdb/fortran: Use TYPE_CODE_CHAR for character types Andrew Burgess
2019-02-12 16:11 ` [PATCH 07/11] gdb/fortran: Expand the set of types that support (kind=N) Andrew Burgess
2019-02-12 16:11 ` [PATCH 05/11] gdb/fortran: Enable debugging of the Fortran parser Andrew Burgess
2019-02-12 16:11 ` [PATCH 04/11] gdb/fortran: Add new function to evaluate Fortran expressions Andrew Burgess
2019-02-12 16:11 ` [PATCH 11/11] gdb/fortran: Handle older TYPE*SIZE typenames Andrew Burgess
2019-03-06 18:15 ` [PUSHED 00/11] Fortran Parser Cleanup, KIND Support, and Intrinsic Functions Andrew Burgess
2019-03-06 18:15 ` [PUSHED 01/11] gdb/fortran: Remove some duplicate tests Andrew Burgess
2019-03-06 18:15 ` [PUSHED 04/11] gdb/fortran: Add new function to evaluate Fortran expressions Andrew Burgess
2019-03-06 18:15 ` [PUSHED 02/11] gdb/fortran: Cleanup code for parsing logical constants Andrew Burgess
2019-03-06 18:16 ` [PUSHED 09/11] gdb/fortran: Use TYPE_CODE_CHAR for character types Andrew Burgess
2019-03-06 18:16 ` [PUSHED 05/11] gdb/fortran: Enable debugging of the Fortran parser Andrew Burgess
2019-03-06 18:16 ` [PUSHED 07/11] gdb/fortran: Expand the set of types that support (kind=N) Andrew Burgess
2019-03-06 18:16 ` [PUSHED 03/11] gdb/fortran: Simplify handling of Fortran dot operations and keywords Andrew Burgess
2019-03-06 18:16 ` [PUSHED 08/11] gdb/fortran: Add builtin 8-byte integer type with (kind=8) support Andrew Burgess
2019-03-06 18:16 ` Andrew Burgess [this message]
2019-03-06 19:11 ` [PUSHED 10/11] gdb/fortran: Add support for the ABS intrinsic function Tom Tromey
2019-03-07 15:23 ` [PATCH] gdb: Move value_from_host_double into value.c and make more use of it Andrew Burgess
2019-03-07 15:49 ` Tom Tromey
2019-03-06 18:16 ` [PUSHED 06/11] gdb/fortran: Add Fortran 'kind' intrinsic and keyword Andrew Burgess
2019-03-06 18:16 ` [PUSHED 11/11] gdb/fortran: Handle older TYPE*SIZE typenames Andrew Burgess
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=739027546fc7a430867d9d6dd2bf6b8e34e04c94.1551895529.git.andrew.burgess@embecosm.com \
--to=andrew.burgess@embecosm.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).