7 parser
= argparse
.ArgumentParser(description
='Convert vcd2txt output to tikz-timing line.')
8 parser
.add_argument('filename', metavar
='FILE', help='input txt file')
9 parser
.add_argument('signame', metavar
='SIG', help='Signal name')
10 parser
.add_argument('-s', metavar
='scale', default
=1.0, type=float, help='Scale all time spans with this factor')
11 parser
.add_argument('-l', action
='store_true', help='Logic signal (high/low)')
12 parser
.add_argument('-b', action
='store_true', help='Display binary value')
13 parser
.add_argument('-x', action
='store_true', help='Display hex value')
14 parser
.add_argument('-d', action
='store_true', help='Display decimal value')
15 args
= parser
.parse_args()
21 def value_to_logic(value
):
28 return "U" if found_x
else "L"
30 def value_to_binary(value
):
31 return "D{%s}" % value
33 def value_to_hex(value
):
36 while len(value
) % 4 != 0:
38 while len(value
) != 0:
39 bin_digits
= value
[0:4]
44 hex_digit
= hex_digit
* 2
46 hex_digit
= hex_digit
* 2 + 1
53 hex_string
+= "0123456789abcdef"[hex_digit
]
56 return "D{%s}" % hex_string
58 def value_to_decimal(value
):
66 val
= val
*2 + int(digit
)
75 for line
in fileinput
.input(args
.filename
):
76 (node
, time
, name
, value
) = line
.strip().split('\t')
78 if start_time
is None or start_time
> time
:
80 if stop_time
is None or stop_time
< time
:
82 if name
== args
.signame
:
84 time_val
[+time
] = value_to_logic(value
)
86 time_val
[+time
] = value_to_binary(value
)
88 time_val
[+time
] = value_to_hex(value
)
90 time_val
[+time
] = value_to_decimal(value
)
92 time_val
[+time
] = value
94 if start_time
not in time_val
:
95 time_val
[start_time
] = "S"
99 for t
in sorted(time_val
.keys()):
100 if last_time
is not None:
101 print("%f%s" % ((t
- last_time
)*args
.s
, last_value
), end
='')
102 (last_time
, last_value
) = (t
, time_val
[t
])
103 if last_time
< stop_time
:
104 print("%f%s" % ((stop_time
- last_time
)*args
.s
, last_value
), end
='')