Created
July 3, 2018 12:49
-
-
Save shtaxxx/de0b406cb0a9b8dcf71af9431cff2249 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import absolute_import | |
from __future__ import print_function | |
import sys | |
import os | |
import re | |
pairs = { | |
# main | |
'axi_datawidth=32, silent=False):': | |
"""axi_datawidth=32, silent=False, | |
memimg_name=None):""", | |
'memimg=mem)': | |
'memimg=mem, memimg_name=memimg_name)', | |
"filename=None, simtype='iverilog'):": | |
"""filename=None, simtype='iverilog', outputfile=None): | |
if outputfile is None: | |
outputfile = os.path.splitext(os.path.basename(__file__))[0] + '.out' | |
memimg_name = 'memimg_' + outputfile | |
""", | |
'axi_datawidth, silent)': | |
'axi_datawidth, silent, memimg_name)', | |
"rslt = sim.run(outputfile=simtype + '.out')": | |
"rslt = sim.run(outputfile=outputfile)", | |
# test | |
'filename=None, simtype=simtype)': | |
"""filename=None, simtype=simtype, | |
outputfile=os.path.splitext(os.path.basename(__file__))[0] + '.out')""", | |
"filename='tmp.v')": | |
"""filename='tmp.v', | |
outputfile=os.path.splitext(os.path.basename(__file__))[0] + '.out')""" | |
} | |
new_lines = [] | |
with open(sys.argv[1], 'r') as f: | |
lines = f.readlines() | |
for line in lines: | |
for key, val in pairs.items(): | |
if line.count(key): | |
new_lines.append(line.replace(key, val)) | |
break | |
else: | |
new_lines.append(line) | |
with open(sys.argv[1], 'w') as f: | |
f.writelines(new_lines) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment