mirror of
https://github.com/AsahiLinux/m1n1
synced 2024-11-10 01:34:12 +00:00
tools/reg_filter.py: Decode trivial values into BIT()
Signed-off-by: Hector Martin <marcan@marcan.st>
This commit is contained in:
parent
d9c1ef7d49
commit
e00e9574d0
1 changed files with 13 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue