From 9a3ecba0102c2912c6f8387fab23d00b85ea4605 Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Tue, 23 Feb 2021 20:05:17 -0700 Subject: [PATCH] scripts: Add coccinelle file to use BIT macro --- scripts/coccinelle/bit-macro.cocci | 14 ++++++++++++++ scripts/coccinelle/macros.h | 9 +++++++++ scripts/spatch.sh | 11 +++++++++++ 3 files changed, 34 insertions(+) create mode 100644 scripts/coccinelle/bit-macro.cocci create mode 100644 scripts/coccinelle/macros.h create mode 100755 scripts/spatch.sh diff --git a/scripts/coccinelle/bit-macro.cocci b/scripts/coccinelle/bit-macro.cocci new file mode 100644 index 0000000..bfaf5da --- /dev/null +++ b/scripts/coccinelle/bit-macro.cocci @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-3.0-only +// Replace shifts with BIT macro + +@@ expression val; @@ +-(1 << val) ++BIT(val) + +@@ expression val; @@ +-(1U << val) ++BIT(val) + +@@ expression val; @@ +-1 << val ++BIT(val) diff --git a/scripts/coccinelle/macros.h b/scripts/coccinelle/macros.h new file mode 100644 index 0000000..c5e5493 --- /dev/null +++ b/scripts/coccinelle/macros.h @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-3.0-only +// SDCC extenstions that need to be defined away for spatch + +#define __at(x) +#define __code +#define __critical +#define __data +#define __reentrant +#define ___ diff --git a/scripts/spatch.sh b/scripts/spatch.sh new file mode 100755 index 0000000..817f67b --- /dev/null +++ b/scripts/spatch.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-3.0-only + +spatch \ + --sp-file ./scripts/coccinelle/bit-macro.cocci \ + --macro-file ./scripts/coccinelle/macros.h \ + --no-includes \ + --include-headers \ + --preprocess \ + --in-place \ + --dir src/