Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import os
- os.system("fgrep output\ reg *.v | grep = > init.txt")
- f = open("init.txt","r")
- lines = {}
- def getSize(line):
- if line[0] == "[":
- sizeStr = line[1:line.find("]")]
- sarray = sizeStr.split(":")
- return int(sarray[0])- int(sarray[1]) + 1
- else:
- return 1
- def insertContents(fileName, contents):
- f2 = open(fileName, "r")
- original = f2.readlines()
- f2.close()
- newlines = []
- for line in original:
- if line.startswith("output reg"):
- eqPos = line.find(" =")
- cmPos = line.find(",",eqPos)
- line = line[:eqPos] + line[cmPos:]
- newlines.append(line)
- original = newlines
- for line in original:
- if line.startswith("initial"):
- return
- index = 0
- for line in original:
- if line.startswith("endmodule"):
- original.insert(index, contents)
- f2 = open(fileName, "w")
- contents = "".join(original)
- f2.write(contents)
- f2.close()
- return
- index=index+1
- for line in f:
- splitPos = line.find(":")
- fileName = line[:splitPos]
- lineData = line[splitPos+1:]
- if not fileName in lines:
- lines[fileName] = []
- lines[fileName].append(lineData.strip())
- for fileName in lines.keys():
- print fileName
- contents = "initial begin\n\n"
- for line in lines[fileName]:
- l = line.replace("output reg ","")
- l = l.replace(",",";")
- size = getSize(l)
- l = l.replace(" 'd", " %i'd" % (size,))
- if size > 1:
- l = l[l.find("]")+1:]
- contents = contents+"\t"+l.strip()+"\n"
- contents = contents+"\n\nend\n"
- insertContents(fileName, contents)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement