From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway33.websitewelcome.com (gateway33.websitewelcome.com [192.185.146.130]) by sourceware.org (Postfix) with ESMTPS id 4D7C0389366A for ; Fri, 1 Jan 2021 21:48:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4D7C0389366A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tom@tromey.com Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway33.websitewelcome.com (Postfix) with ESMTP id EB48BEEF2D0 for ; Fri, 1 Jan 2021 15:48:14 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id vSHOkZEnroE4DvSHOkuHDD; Fri, 01 Jan 2021 15:48:14 -0600 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=s/O5hs365kd6h3FH1iA73Pv3F0/QbnjQHGL/nCwApBk=; b=qRpaFHlcmqUKIMLFThCTDMQOOq ffjjtTguaZqIYugaxefw0LgyhWw+GRUfup91dUzfNvI0DqPAfFfB3+KwVoA+rU8XNa3e9YApvUjHE Ufd+CJp5mBcSyoN17WeFL5217; Received: from 97-122-81-39.hlrn.qwest.net ([97.122.81.39]:60400 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1kvSHO-0029XH-Nz for gdb-patches@sourceware.org; Fri, 01 Jan 2021 14:48:14 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH 104/203] Implement some unary operations Date: Fri, 1 Jan 2021 14:45:44 -0700 Message-Id: <20210101214723.1784144-105-tom@tromey.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210101214723.1784144-1-tom@tromey.com> References: <20210101214723.1784144-1-tom@tromey.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.81.39 X-Source-L: No X-Exim-ID: 1kvSHO-0029XH-Nz X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-81-39.hlrn.qwest.net (localhost.localdomain) [97.122.81.39]:60400 X-Source-Auth: tom+tromey.com X-Email-Count: 105 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3030.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_ABUSEAT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Jan 2021 21:48:17 -0000 This introduces a couple of new template classes and then uses them to implement some simple unary operations. gdb/ChangeLog 2021-01-01 Tom Tromey * expop.h (unary_ftype): New typedef. (unop_operation, usual_ax_binop_operation): New templates. (unary_plus_operation, unary_neg_operation) (unary_complement_operation, unary_logical_not_operation): New typedefs. * eval.c (eval_op_plus, eval_op_neg, eval_op_complement) (eval_op_lognot): No longer static. * ax-gdb.c (gen_expr_unop): New function. --- gdb/ChangeLog | 11 ++++++++ gdb/ax-gdb.c | 47 +++++++++++++++++++++++++++++++ gdb/eval.c | 8 +++--- gdb/expop.h | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 139 insertions(+), 4 deletions(-) diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c index 8d5e4fff903..c87b290397d 100644 --- a/gdb/ax-gdb.c +++ b/gdb/ax-gdb.c @@ -2694,6 +2694,53 @@ gen_expr_structop (struct expression *exp, internal_error (__FILE__, __LINE__, _("gen_expr: unhandled struct case")); } + +/* A helper function that emits a unary operation. */ + +void +gen_expr_unop (struct expression *exp, + enum exp_opcode op, + expr::operation *lhs, + struct agent_expr *ax, struct axs_value *value) +{ + struct axs_value value1, value2; + + switch (op) + { + case UNOP_NEG: + gen_int_literal (ax, &value1, 0, + builtin_type (ax->gdbarch)->builtin_int); + gen_usual_unary (ax, &value1); /* shouldn't do much */ + lhs->generate_ax (exp, ax, &value2); + gen_usual_unary (ax, &value2); + gen_usual_arithmetic (ax, &value1, &value2); + gen_binop (ax, value, &value1, &value2, aop_sub, aop_sub, 1, "negation"); + break; + + case UNOP_PLUS: + /* + FOO is equivalent to 0 + FOO, which can be optimized. */ + lhs->generate_ax (exp, ax, value); + gen_usual_unary (ax, value); + break; + + case UNOP_LOGICAL_NOT: + lhs->generate_ax (exp, ax, value); + gen_usual_unary (ax, value); + gen_logical_not (ax, value, builtin_type (ax->gdbarch)->builtin_int); + break; + + case UNOP_COMPLEMENT: + lhs->generate_ax (exp, ax, value); + gen_usual_unary (ax, value); + gen_integral_promotions (ax, value); + gen_complement (ax, value); + break; + + default: + gdb_assert_not_reached ("invalid case in gen_expr_unop"); + } +} + /* Given a single variable and a scope, generate bytecodes to trace diff --git a/gdb/eval.c b/gdb/eval.c index 06f4c67e1d7..60e065cb0de 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -1739,7 +1739,7 @@ eval_op_repeat (struct type *expect_type, struct expression *exp, /* A helper function for UNOP_PLUS. */ -static struct value * +struct value * eval_op_plus (struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1) @@ -1757,7 +1757,7 @@ eval_op_plus (struct type *expect_type, struct expression *exp, /* A helper function for UNOP_NEG. */ -static struct value * +struct value * eval_op_neg (struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1) @@ -1775,7 +1775,7 @@ eval_op_neg (struct type *expect_type, struct expression *exp, /* A helper function for UNOP_COMPLEMENT. */ -static struct value * +struct value * eval_op_complement (struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1) @@ -1793,7 +1793,7 @@ eval_op_complement (struct type *expect_type, struct expression *exp, /* A helper function for UNOP_LOGICAL_NOT. */ -static struct value * +struct value * eval_op_lognot (struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1) diff --git a/gdb/expop.h b/gdb/expop.h index 67b265ca8f0..aae42f201bc 100644 --- a/gdb/expop.h +++ b/gdb/expop.h @@ -40,6 +40,10 @@ extern void gen_expr_structop (struct expression *exp, expr::operation *lhs, const char *name, struct agent_expr *ax, struct axs_value *value); +extern void gen_expr_unop (struct expression *exp, + enum exp_opcode op, + expr::operation *lhs, + struct agent_expr *ax, struct axs_value *value); extern struct value *eval_op_scope (struct type *expect_type, struct expression *exp, @@ -139,6 +143,24 @@ extern struct value *eval_op_repeat (struct type *expect_type, enum noside noside, enum exp_opcode op, struct value *arg1, struct value *arg2); +extern struct value *eval_op_plus (struct type *expect_type, + struct expression *exp, + enum noside noside, enum exp_opcode op, + struct value *arg1); +extern struct value *eval_op_neg (struct type *expect_type, + struct expression *exp, + enum noside noside, enum exp_opcode op, + struct value *arg1); +extern struct value *eval_op_complement (struct type *expect_type, + struct expression *exp, + enum noside noside, + enum exp_opcode op, + struct value *arg1); +extern struct value *eval_op_lognot (struct type *expect_type, + struct expression *exp, + enum noside noside, + enum exp_opcode op, + struct value *arg1); namespace expr { @@ -1228,6 +1250,61 @@ class comma_operation override; }; +typedef struct value *unary_ftype (struct type *expect_type, + struct expression *exp, + enum noside noside, enum exp_opcode op, + struct value *arg1); + +/* Base class for unary operations. */ +template +class unop_operation + : public maybe_constant_operation +{ +public: + + using maybe_constant_operation::maybe_constant_operation; + + value *evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) override + { + value *val = std::get<0> (m_storage)->evaluate (nullptr, exp, noside); + return FUNC (expect_type, exp, noside, OP, val); + } + + enum exp_opcode opcode () const override + { return OP; } +}; + +/* Unary operations that can also be turned into agent expressions in + the "usual" way. */ +template +class usual_ax_unop_operation + : public unop_operation +{ + using unop_operation::unop_operation; + +protected: + + void do_generate_ax (struct expression *exp, + struct agent_expr *ax, + struct axs_value *value, + struct type *cast_type) + override + { + gen_expr_unop (exp, OP, + std::get<0> (this->m_storage).get (), + ax, value); + } +}; + +using unary_plus_operation = usual_ax_unop_operation; +using unary_neg_operation = usual_ax_unop_operation; +using unary_complement_operation + = usual_ax_unop_operation; +using unary_logical_not_operation + = usual_ax_unop_operation; + } /* namespace expr */ #endif /* EXPOP_H */ -- 2.26.2