Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fixes for monitor generation #31

Merged
merged 3 commits into from Oct 22, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Handle nested ifdef in generate.py

This is required to properly handle the BEQ instruction with compressed
instructions disabled. Currently in this case invalid verilog output
is produced.
  • Loading branch information
Joshua Leahy
Joshua Leahy committed Sep 18, 2019
commit 40e6d917a42f46aec31ee58a868a0138d5a6e8af
@@ -590,77 +590,42 @@ def usage():
insn_list.append(insn)
replace_db.append((" rvfi_insn_%s " % insn, " %s_insn_%s " % (prefix, insn)))

expected_flags = {
"RISCV_FORMAL_COMPRESSED": compressed,
"RISCV_FORMAL_ALIGNED_MEM": aligned,
}

def print_rewrite_file(filename):
with open(filename) as f:
flag_compressed_ifdef = False
flag_compressed_ifndef = False
flag_aligned_ifdef = False
flag_aligned_ifndef = False
flag_ifdef = False
flag_ifndef = False
flag_stack = []
flags = {}

for line in f:
if line.startswith("`ifdef RISCV_FORMAL_COMPRESSED"):
flag_compressed_ifdef = True
flag_compressed_ifndef = False
continue

if line.startswith("`ifndef RISCV_FORMAL_COMPRESSED"):
flag_compressed_ifdef = False
flag_compressed_ifndef = True
continue

if line.startswith("`ifdef RISCV_FORMAL_ALIGNED_MEM"):
flag_aligned_ifdef = True
flag_aligned_ifndef = False
continue

if line.startswith("`ifndef RISCV_FORMAL_ALIGNED_MEM"):
flag_aligned_ifdef = False
flag_aligned_ifndef = True
continue

if line.startswith("`ifdef "):
flag_ifdef = True
flag_ifndef = False
flag_name = line.split()[1]
assert flag_name not in flags, (filename, flag_name, flags)
flag_stack.append(flag_name)
flags[flag_name] = True
continue

if line.startswith("`ifndef "):
flag_ifdef = False
flag_ifndef = True
flag_name = line.split()[1]
assert flag_name not in flags
flag_stack.append(flag_name)
flags[flag_name] = False
continue

if line.startswith("`else"):
flag_compressed_ifdef, flag_compressed_ifndef = flag_compressed_ifndef, flag_compressed_ifdef
flag_aligned_ifdef, flag_aligned_ifndef = flag_aligned_ifndef, flag_aligned_ifdef
flag_ifdef, flag_ifndef = flag_ifndef, flag_ifdef
flag_name = flag_stack[-1]
flags[flag_name] = not flags[flag_name]
continue

if line.startswith("`endif"):
flag_compressed_ifdef = False
flag_compressed_ifndef = False
flag_aligned_ifdef = False
flag_aligned_ifndef = False
flag_ifdef = False
flag_ifndef = False
continue

if flag_compressed_ifdef and not compressed:
continue

if flag_compressed_ifndef and compressed:
continue

if flag_aligned_ifdef and not aligned:
continue

if flag_aligned_ifndef and aligned:
continue

if flag_ifdef and True:
flag_name = flag_stack.pop()
del flags[flag_name]
continue

if flag_ifndef and False:
if any(expected_flags.get(name, False) != val for name, val in flags.items()):
continue

for a, b in replace_db:
ProTip! Use n and p to navigate between commits in a pull request.