-
Notifications
You must be signed in to change notification settings - Fork 160
Make argument order of imap_go
's black box consistent with #2543
#2946
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
Conversation
1568209
to
bb6bb7a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm right about this, it's worrying that the test doesn't catch the mistakes. It is unclear to me, without more investigation, how this black box works. For a proper review, maybe I ought to read up on its workings...
I've renamed everything with a dumb Python script now: #!/usr/bin/env python3
import random
import re
import string
from ruamel.yaml import YAML
TYPE_SIG = "imap_go :: (Index n -> a -> b) -> Vec m a -> Index n -> Vec m b"
PRIM_NAME = "Clash.Sized.Vector.imap_go"
PRIM_FILES = [
"clash-lib/prims/systemverilog/Clash_Sized_Vector.primitives.yaml",
"clash-lib/prims/verilog/Clash_Sized_Vector.primitives.yaml",
"clash-lib/prims/vhdl/Clash_Sized_Vector.primitives.yaml",
]
TAGS = [
(r"~OUTPUTUSAGE\[{n}\]", r"~OUTPUTUSAGE[{n}]"),
(r"~TYP\[{n}\]", r"~TYP[{n}]"),
(r"~ARG\[{n}\]", r"~ARG[{n}]"),
(r"~INST {n}", r"~INST {n}"),
(r"~VAR\[(\w+)\]\[{n}\]", r"~VAR[\1][{n}]"),
]
MAX_INDEX = 100
def rename_index(n):
if n == 0:
return 2
return n - 1
def find(haystack, needle_func):
for item in haystack:
if needle_func(item):
return item
raise ValueError(f"Could not find needle in {haystack}")
def generate_random_string(length):
return ''.join(random.choice(string.ascii_letters) for i in range(length))
def replace_tag(template, pattern, replacement):
random_strings = [generate_random_string(20) for _ in range(MAX_INDEX)]
for i in range(MAX_INDEX):
template = re.sub(
pattern.format(n=i),
replacement.format(n=random_strings[i]),
template
)
for i in range(MAX_INDEX):
template = re.sub(
pattern.format(n=random_strings[i]),
replacement.format(n=rename_index(i)),
template
)
return template
def replace_tags(template):
for tag, replacement in TAGS:
template = replace_tag(template, tag, replacement)
return template
def replace_in_prim_file(prim_file):
yaml = YAML()
with open(prim_file, "r") as f:
parsed = yaml.load(f)
prim = find(parsed, lambda x: x["BlackBox"]["name"] == PRIM_NAME)
prim["BlackBox"]["type"] = TYPE_SIG
prim["BlackBox"]["template"] = replace_tags(prim["BlackBox"]["template"])
with open(prim_file, "w") as f:
yaml.dump(parsed, f)
def main():
for prim_file in PRIM_FILES:
replace_in_prim_file(prim_file)
if __name__ == "__main__":
main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've played around with it a bit and it looks fine now!
Fixes #2904
Still TODO:
master
.Check copyright notices are up to date in edited files