forked from Ceasar/xilinx_sucks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.py
33 lines (26 loc) · 1.05 KB
/
scripts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from itertools import chain
import sys
from wires import get_inputs, get_outputs, get_wires
def generate_debug(filename):
"""Generate print statements for every wire in a file."""
for wire in chain(get_inputs(filename), get_outputs(filename), get_wires(filename)):
# try to automatically format pc wires to use hex values
if "pc" in wire and "opcode" not in wire:
print '$display("%s: %%h", %s);' % (wire, wire)
else:
print '$display("%s: %%b", %s);' % (wire, wire)
def pc_trace(filename):
with open(filename) as f:
for line in f:
tokens = line.strip().split(":")
if tokens[0] == "time":
print "TIME", tokens[1]
elif tokens[0] == "m_pc_plus_one":
print "PC+1", tokens[1]
elif tokens[0] == "m_imem_out":
print "INSN", tokens[1]
if __name__ == "__main__":
if sys.argv[1] == 'debug':
sys.exit(generate_debug(sys.argv[2]))
elif sys.argv[1] == 'trace':
sys.exit(pc_trace(sys.argv[2]))