Skip to content

Commit

Permalink
reverse_json.py: more flexible recognition of parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
ldoolitt committed Aug 23, 2024
1 parent e917542 commit 7c1a46b
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions build-tools/reverse_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
addr_found = {}
name_found = {}
fail = 0
verbose = False # can we have a command-line switch to control this?

# Bugs:
# brittle to variations in Verilog code formatting
Expand Down Expand Up @@ -117,7 +118,8 @@ def memorize(g):
alias = None
m1a = re.search(r";\s*//\s*alias:\s*(\w+)", line)
if m1a:
# stderr.write('INFO: alias "%s"\n' % m1a.group(1))
if verbose:
stderr.write('INFO: alias "%s"\n' % m1a.group(1))
alias = m1a.group(1)
tbank = m1.group(2)
if bank_state == "=armed=":
Expand All @@ -131,7 +133,8 @@ def memorize(g):
if "default" in line and ": reg_bank_" in line:
m1 = re.search(r"default:\s*reg_bank_(\w)\s*<=\s*32'h", line)
if m1:
# stderr.write('INFO: default %s\n' % line)
if verbose:
stderr.write('INFO: default %s\n' % line)
tbank = m1.group(1)
if bank_state != tbank:
stderr.write(ehead + ' bank %s assignment found in bank %s stanza\n' % (tbank, bank_state))
Expand All @@ -149,11 +152,21 @@ def memorize(g):
if m2:
memorize(m2.group)
if any(x in line for x in ["parameter", "localparam"]):
m3 = re.search(r"\b(?:parameter|localparam)\s+(\w+)\s*=\s*(\d+);", line)
# This logic can handle parameter as a statement, or in the header of a module.
# It does get tripped up by the _last_ parameter of a module,
# that doesn't have a trailing comma.
m3 = re.search(r"\b(?:parameter|localparam)\s+(\w+)\s*=\s*(\d+)[;,]", line)
if m3:
p, v = m3.group(1), int(m3.group(2))
param_db[p] = v
# stderr.write('INFO: found parameter "%s" with value %d\n' % (p, v))
if verbose:
stderr.write('INFO: found parameter "%s" with value %d\n' % (p, v))
m3 = re.search(r"\b(?:parameter|localparam)\s+integer\s+(\w+)\s*=\s*(\d+)[;,]", line)
if m3:
p, v = m3.group(1), int(m3.group(2))
param_db[p] = v
if verbose:
stderr.write('INFO: found parameter "%s" with value %d\n' % (p, v))
if "endcase" in line:
bank_state = None
if "case" in line and "addr" in line:
Expand Down

0 comments on commit 7c1a46b

Please sign in to comment.