From patchwork Thu Jun 1 09:34:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 687693 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d8a:0:0:0:0:0 with SMTP id b10csp235167wru; Thu, 1 Jun 2023 02:36:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5C9tWVH0MImcPhRJ0Vhwuy6nW20iki7xLLJYc32dQFXLn8Ff1tbzhfEHR+S+UtdBEKQ4Ib X-Received: by 2002:a05:620a:3f0c:b0:75b:23a0:de86 with SMTP id tx12-20020a05620a3f0c00b0075b23a0de86mr7184882qkn.4.1685612171550; Thu, 01 Jun 2023 02:36:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685612171; cv=none; d=google.com; s=arc-20160816; b=DpKYMIsm2aXEp4TT4Ei0jkQNwlNaLIm4ilg/Ktx5tRp107mdmEi9VZJ/Hxs/Jv4akE sOh+K+DLMzPCW0PkUx/0l3fgDN7EUsjS4ToHWEeDQfl49nbhM4D6w7YDs4OifFxLG4wY JMfxRrK+zR0uDJhKwn0kM+/HvYsqek2U6AuC1swlPbRPLAZGvKxTny0w4GIscykN9pvm z9PtziwlkcY/703hq+MKIopbm04zS2pO2rRrFJr9OsexfgCKqq0BYztF+gWjmFRC1A9E SoilITlxOm4WJZjukVW/JwKnO4qtjTE0OlOUu3rxkMST6i6dbIsaLj7fk9tqhri46GWD wkYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=iBmRFGSCUyWrpqUCkJ9/kvAcmY0X7VBtc3pe1bAu4Nw=; b=tjhegEWEA9QQOw36dA8zOvxSzJVWjDr234PLn7DmTTO9mdgMz2mk6eIury56Q7466E rUpUZKwuzdb23BbApPhJAlnYxkCPmHfv286OCT/Gkc/PRriJ4yRUdd8j1rf3QibytVKI 0w0/zZYJkDwX6XIeeDMrNDbsYAO10/1LGLnpHAfkV4cd8zheD0ICRtX2gqBYDa6OpvpG Eg2LIFLlR3FuGlu5m5EpT6GBoAYOnizDsLNGvZfX479lNtSsZzQIQf1nbZXmiWOMnA0O VmjwiNLdc/2hN/msf+TeUSVXjuRLV8eiDwWNFpAwIWkRe9etS8nS1xZxd6cMut1fb+xl zEXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=m+53Rqw4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i7-20020a05620a144700b0075cceb751a3si6954246qkl.547.2023.06.01.02.36.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 01 Jun 2023 02:36:11 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=m+53Rqw4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4eiJ-0007iu-E7; Thu, 01 Jun 2023 05:35:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q4eiF-0007hL-TJ for qemu-devel@nongnu.org; Thu, 01 Jun 2023 05:35:20 -0400 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q4ei0-0008Sy-5V for qemu-devel@nongnu.org; Thu, 01 Jun 2023 05:35:09 -0400 Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-4f3b9e54338so704596e87.0 for ; Thu, 01 Jun 2023 02:35:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1685612100; x=1688204100; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iBmRFGSCUyWrpqUCkJ9/kvAcmY0X7VBtc3pe1bAu4Nw=; b=m+53Rqw4BvkMKcWgY8ijZYQZ3MvEhO4yd3IBzpmQXtgmat8Fuijcn8ZNKPpJQyO2Gq hnDP6OQNh8fYfyAERrj1toGGmwNqkcH+wCrSBrd42VH5mOcu/Vdu+o0XRK7A4hNcGKMj IPCUt2is3km3TLvkvpkm4lGzDT8Zt0xNmxY2p5LZTPxptADt+xXkYnrWK/9YSCozNVwc W7USHT5gnm1ZZZvkd3g0HcmgKdckwmcPnyzv/L1da5lC4ambnmmDTI50z0MrV8PveJ2L YUl7HbEO3LWXKanfwJ+Vvx5R2BidfMjvOx7XOWj/mT1VdtapjSkwy/sedFUscRS0gQQ5 R0tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685612100; x=1688204100; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iBmRFGSCUyWrpqUCkJ9/kvAcmY0X7VBtc3pe1bAu4Nw=; b=ejcVYuO8/53YLpmd5n3WHmG7VUNxG+h+7lt1Ef1h+vqvonJbmiyvChOgULULiBgDzN 43bj8VxWfEQevUUbZLZnoeXIhx6IeZ1iQOzsHr0pHCPlTvNd88yrXG9zN6q+5ZqChJJC irtr78Vgth9c9pNGWzB2dieDccD4tTX8V0OeFczUIZgvVFtcT0qruXcFTn8v5w72KW2p E0gK9aar8VL8gp4vIfw65sCjspkGDud2gx86DJLBsFf2O+vbWfG9dkJIQ1TsZKTyuy0+ 2SYmF3tsznvo0csn2EmJY1fQEzDQ923Vs2S8BDGbQFbUJhqF8KFs2+GIaq1/Kqb9T+Oq 6eRQ== X-Gm-Message-State: AC+VfDxCBaP27Uvz5xxllj1cWNYve+EMGUOVDEItoU/ZxyEFSbbL6AY0 t1U/OG4DeT7Z4qveM7xg7A5XXFwCn0uC9geC3tI= X-Received: by 2002:ac2:5505:0:b0:4f3:b221:558c with SMTP id j5-20020ac25505000000b004f3b221558cmr914245lfk.43.1685612099981; Thu, 01 Jun 2023 02:34:59 -0700 (PDT) Received: from localhost.localdomain ([176.176.141.224]) by smtp.gmail.com with ESMTPSA id n16-20020a1c7210000000b003f60119ee08sm1658709wmc.43.2023.06.01.02.34.58 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 01 Jun 2023 02:34:59 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Markus Armbruster , Eduardo Habkost Cc: qemu-riscv@nongnu.org, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, Thomas Huth , qemu-block@nongnu.org, =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= Subject: [PATCH 1/2] scripts: Add qom-cast-macro-clean-cocci-gen.py Date: Thu, 1 Jun 2023 11:34:51 +0200 Message-Id: <20230601093452.38972-2-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230601093452.38972-1-philmd@linaro.org> References: <20230601093452.38972-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::12a; envelope-from=philmd@linaro.org; helo=mail-lf1-x12a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Add a script to generate Coccinelle semantic patch removing all pointless QOM cast macro uses. Suggested-by: Markus Armbruster Signed-off-by: Philippe Mathieu-Daudé --- MAINTAINERS | 1 + scripts/qom-cast-macro-clean-cocci-gen.py | 49 +++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 scripts/qom-cast-macro-clean-cocci-gen.py diff --git a/MAINTAINERS b/MAINTAINERS index 4b025a7b63..37a2412011 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3044,6 +3044,7 @@ F: include/qom/ F: qapi/qom.json F: qapi/qdev.json F: scripts/coccinelle/qom-parent-type.cocci +F: scripts/qom-cast-macro-clean-cocci-gen.py F: softmmu/qdev-monitor.c F: stubs/qdev.c F: qom/ diff --git a/scripts/qom-cast-macro-clean-cocci-gen.py b/scripts/qom-cast-macro-clean-cocci-gen.py new file mode 100644 index 0000000000..2fa8438a14 --- /dev/null +++ b/scripts/qom-cast-macro-clean-cocci-gen.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 +# +# Generate a Coccinelle semantic patch to remove pointless QOM cast. +# +# Usage: +# +# $ qom-cast-macro-clean-cocci-gen.py $(git ls-files) > qom_pointless_cast.cocci +# $ spatch \ +# --macro-file scripts/cocci-macro-file.h \ +# --sp-file qom_pointless_cast.cocci \ +# --keep-comments \ +# --use-gitgrep \ +# --in-place \ +# --dir . +# +# SPDX-FileContributor: Philippe Mathieu-Daudé +# SPDX-FileCopyrightText: 2023 Linaro Ltd. +# SPDX-License-Identifier: GPL-2.0-or-later + +import re +import sys + +assert len(sys.argv) > 0 + +def print_cocci_rule(qom_typedef, qom_cast_macro): + print(f'''@@ +typedef {qom_typedef}; +{qom_typedef} *obj; +@@ +- {qom_cast_macro}(obj) ++ obj +''') + +patterns = [ + r'DECLARE_INSTANCE_CHECKER\((\w+),\W*(\w+),\W*TYPE_\w+\)', + r'DECLARE_OBJ_CHECKERS\((\w+),\W*\w+,\W*(\w+),\W*TYPE_\w+\)', + r'OBJECT_DECLARE_TYPE\((\w+),\W*\w+,\W*(\w+)\)', + r'OBJECT_DECLARE_SIMPLE_TYPE\((\w+),\W*(\w+)\)', + r'INTERFACE_CHECK\((\w+),\W*\(\w+\),\W*TYPE_(\w+)\)', +] + +for fn in sys.argv[1:]: + try: + content = open(fn, 'rt').read() + except: + continue + for pattern in patterns: + for match in re.findall(pattern, content): + print_cocci_rule(match[0], match[1])