From e00e9574d03341b59005b5fd55066e2af2e7cc11 Mon Sep 17 00:00:00 2001 From: Hector Martin Date: Mon, 27 Jun 2022 18:17:44 +0900 Subject: [PATCH] tools/reg_filter.py: Decode trivial values into BIT() Signed-off-by: Hector Martin --- tools/reg_filter.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/reg_filter.py b/tools/reg_filter.py index 7c905a05..81591d5a 100644 --- a/tools/reg_filter.py +++ b/tools/reg_filter.py @@ -1,4 +1,4 @@ -import json, sys, re +import json, sys, re, math import argparse parser = argparse.ArgumentParser() @@ -18,6 +18,18 @@ def reg_lookup(m): s = m.group(0) return name_map.get(s, s) +def hex_parse(m): + v = int(m.group(0), 0) + if v and (v & (v - 1)) == 0: + bit = int(math.log2(v)) + return f"BIT({bit})" + v ^= 0xffff_ffff_ffff_ffff + if v and (v & (v - 1)) == 0: + bit = int(math.log2(v)) + return f"~BIT({bit})" + return m.group(0) + for line in sys.stdin: line = re.sub(r"s(\d+)_(\d+)_c(\d+)_c(\d+)_(\d+)", reg_lookup, line) + line = re.sub(r"\b0x[0-9a-f]+\b", hex_parse, line) sys.stdout.write(line)