tools/reg_filter.py: Decode trivial values into BIT()

Signed-off-by: Hector Martin <marcan@marcan.st>
This commit is contained in:
Hector Martin 2022-06-27 18:17:44 +09:00
parent d9c1ef7d49
commit e00e9574d0

View file

@ -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)