Skip to content

Commit

Permalink
feat: --btable print breakpoints table
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuajack committed Sep 5, 2022
1 parent 81d0db4 commit 10cc2e4
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 55 deletions.
20 changes: 0 additions & 20 deletions .vscode/launch.json

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ Reloading a saved query:
sootty -R "save.txt"
```

Add breakpoints at time 9, 11, and 17 - 18:
Add breakpoints at time 9, 11, and 16 - 17 and print wire values at breakpoints:

```bash
sootty "example/example1.vcd" -b "time 9 || time 11 || after time 16 && before time 18"
sootty "example/example5.evcd" -b "time 9 || time 11 || after time 15 && before time 18" --btable
```

How to run in python (using the repl):
Expand Down
25 changes: 17 additions & 8 deletions sootty/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import argparse
import os
import yaml
import sys
from sootty.exceptions import SoottyError
from .save import save_query, reload_query
from .storage import WireTrace
Expand All @@ -17,7 +16,7 @@ def parse_args():
default=None,
metavar="FILENAME",
type=str,
help="input .vcd file (required unless -R flag is provided)",
help="input .vcd or .evcd file (required unless -R flag is provided)",
)
parser.add_argument(
"-s",
Expand Down Expand Up @@ -47,7 +46,17 @@ def parse_args():
help="formula for the points in time to be highlighted",
)
parser.add_argument(
"-l", "--length", type=int, dest="length", help="number of cycles to display"
'--btable',
action="store_true",
required='-b' in sys.argv,
help="print a breakpoint table to stdout",
)
parser.add_argument(
"-l",
"--length",
type=int,
dest="length",
help="number of cycles to display",
)
parser.add_argument(
"-o",
Expand Down Expand Up @@ -102,6 +111,7 @@ def parse_args():
args.filename,
args.wires,
args.breakpoints,
args.btable,
args.length,
args.start,
args.end,
Expand All @@ -111,7 +121,7 @@ def parse_args():


def main():
filename, wires, breakpoints, length, start, end, output, radix = parse_args()
filename, wires, breakpoints, btable, length, start, end, output, radix = parse_args()

if filename is None:
raise SoottyError("Input file is required. See --help for more info.")
Expand Down Expand Up @@ -161,12 +171,11 @@ def main():

if not output:
image.display() # Show image in terminal (works in kitty, iterm)
if breakpoints is not None:
wiretrace.print(breakpoints)

else:
print(image.source)

if btable:
wiretrace.print_breakpoints(breakpoints)

if __name__ == "__main__":
main()
1 change: 0 additions & 1 deletion sootty/storage/valuechange.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sys
from vcd.reader import *
from itertools import islice
from sortedcontainers import SortedDict, SortedList, SortedSet
Expand Down
1 change: 0 additions & 1 deletion sootty/storage/wire.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sys
from itertools import compress, chain

from ..exceptions import *
Expand Down
32 changes: 20 additions & 12 deletions sootty/storage/wiregroup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import sys

from ..exceptions import *
from .wire import Wire

Expand Down Expand Up @@ -40,17 +38,27 @@ def find(self, name: str):

def get_names(self):
"""Returns list of all wire names."""
names = dict()
names[self.name] = list()
for wire in self.wires:
names[self.name].append(wire.name)
for group in self.groups:
names[group.name] = group.get_names()
if self.groups:
names = dict()
if self.wires:
names[self.name] = list()
for wire in self.wires:
names[self.name].append(wire.name)
for group in self.groups:
names[group.name] = group.get_names()
else:
names = list()
for wire in self.wires:
names.append(wire.name)
return names

def get_wires(self):
wires = dict()
wires[self.name] = self.wires
for group in self.groups:
wires[group.name] = group.get_wires()
if self.groups:
wires = dict()
if self.wires:
wires[self.name] = self.wires
for group in self.groups:
wires[group.name] = group.get_wires()
else:
wires = self.wires
return wires
23 changes: 17 additions & 6 deletions sootty/storage/wiretrace.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import json, sys
import sys
from vcd.reader import *

from ..exceptions import *
Expand Down Expand Up @@ -291,11 +291,22 @@ def compute_limits(self, start_expr: str, end_expr: str):
end = ends[0] if len(ends) else self.length()
return (start, end)

def print(self, breakpoints: list):
def print_breakpoints(self, breakpoints: list):
"""
Print a table of wires and their values.
"""
wires = self.root.get_wires()
col_widths = [len(str(max(wires.keys())))]
for i in range(len(wires)):
col_widths.append(max(wires))
def rec_print(wires):
for scope, sub in wires.items():
if type(sub) is dict:
print("scope\t" + scope)
rec_print(sub)
else: # is list
print("scope\t" + scope)
for wire in sub:
print(wire.name, end="\t")
for breakpoint in breakpoints:
print(str(wire._data.get(breakpoint)), end="\t")
print()

print("time", *breakpoints, sep="\t")
rec_print(self.root.get_wires())
8 changes: 4 additions & 4 deletions sootty/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def dec2anybase(input, base, width):
res += chr(rem + ord("0"))
else:
res += chr(rem - 10 + ord("A"))
input = int(input / base)
input = input // base

return res[::-1].zfill(ceil(log(2**width - 1, base)))

Expand Down Expand Up @@ -129,12 +129,12 @@ def evcd2vcd(stream):
while True:
# Basic formatter and syntax checker
if tok == b'$comment' or tok == b'$date' or tok == b'$timescale' or tok == b'$version':
vcd.write(tok + b' ')
vcd.write(tok + b'\n ')
body = next(tokit)
while body != b'$end':
vcd.write(body + b' ')
vcd.write(b' ' + body)
body = next(tokit)
vcd.write(b'$end\n') # body + \n
vcd.write(b'\n$end\n') # body + \n
tok = next(tokit)
elif tok == b'$enddefinitions':
if next(tokit) != b'$end':
Expand Down
2 changes: 1 addition & 1 deletion sootty/visualizer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import sys, html
import html
from enum import Enum

from .display import VectorImage
Expand Down

0 comments on commit 10cc2e4

Please sign in to comment.