From 94bb2b0cd8d2c89633b7e716dce7a72f487c8866 Mon Sep 17 00:00:00 2001 From: Riley Chou Date: Sat, 3 Feb 2024 12:45:39 -0800 Subject: [PATCH 1/3] add and find wires df --- sootty/__main__.py | 1 + sootty/storage/wiregroup.py | 23 +++++++++++++++++++++++ sootty/storage/wiretrace.py | 37 +++++++++++++++++++++++++++++++++++-- 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/sootty/__main__.py b/sootty/__main__.py index aa6ffae..58888f6 100644 --- a/sootty/__main__.py +++ b/sootty/__main__.py @@ -122,6 +122,7 @@ def parse_args(): def main(): + filename, wires, breakpoints, btable, length, start, end, output, radix = parse_args() if filename is None: diff --git a/sootty/storage/wiregroup.py b/sootty/storage/wiregroup.py index a82b5f2..95ed9d4 100644 --- a/sootty/storage/wiregroup.py +++ b/sootty/storage/wiregroup.py @@ -1,3 +1,5 @@ +import polars as pl + from ..exceptions import * from .wire import Wire @@ -8,9 +10,25 @@ def __init__(self, name: str): self.groups = [] self.wires = [] + self.groups_df = pl.DataFrame() + self.wires_df = pl.DataFrame([], schema={'name':pl.String, 'time': pl.Int64, 'value': pl.Int64, 'length': pl.Int64, 'width': pl.Int64}) + def add_wire(self, wire): self.wires.append(wire) + # this prints out null because time doesn't exist in the value change dictionary yet + + # print(wire.__getitem__('time')) + temp_wire_df = pl.DataFrame({ + 'name': wire.name, + 'time': wire.__getitem__('time'), + 'value': wire.__getitem__('value'), + 'length': wire.length(), + 'width': wire.width(), + }) + self.wires_df.extend(temp_wire_df) + print(self.wires_df) + def add_group(self, group): self.groups.append(group) @@ -29,12 +47,17 @@ def length(self): def find(self, name: str): """Returns the first wire object with the given name, if it exists.""" + """dataframe version""" + find_wires_df = self.wires_df.filter(pl.col("name") == name) + # print(find_wires_df) + for wire in self.wires: if wire.name == name: return wire for group in self.groups: return group.find(name) raise SoottyError(f"Wire '{name}' does not exist.") + def get_names(self): """Returns list of all wire names.""" diff --git a/sootty/storage/wiretrace.py b/sootty/storage/wiretrace.py index 9d178c1..d0a315b 100644 --- a/sootty/storage/wiretrace.py +++ b/sootty/storage/wiretrace.py @@ -1,6 +1,7 @@ import sys -from vcd.reader import * +import polars as pl +from vcd.reader import * from ..exceptions import * from ..parser import parser from .wiregroup import WireGroup @@ -11,6 +12,8 @@ class WireTrace: def __init__(self): self.root = WireGroup("__root__") + self.wires_df = pl.DataFrame() + self.wires_vc = pl.DataFrame() @classmethod def from_vcd(cls, filename): @@ -77,6 +80,11 @@ def from_vcd(cls, filename): this = cls() this.metadata = dict() # dictionary of vcd metadata wires = dict() # map from id_code to wire object + + wire_df_list = [] + wire_vc_dfs = [] + idx_count = 0 + stack = [this.root] # store stack of current group for scoping with open(filename, "rb") as stream: @@ -103,12 +111,26 @@ def from_vcd(cls, filename): stack.pop() elif token.kind is TokenKind.VAR: if token.var.id_code in wires: + # Used if wire is in multiple groups? + # wire_groups[token.var.id_code].append(stack[-1].name) stack[-1].add_wire(wires[token.var.id_code]) else: wire = Wire( name=token.var.reference, width=token.var.size, ) + + wire_dict = {"id": token.var.id_code, + "name": token.var.reference, + "size": token.var.size, + "df_idx": idx_count} + wire_df_list.append(wire_dict) + + # wire_groups[tokn.var.id_code].append(stack[-1].name) + vc_df = pl.DataFrame() + # wire_vc_dfs.append(vc_df) + idx_count = idx_count + 1 + wires[token.var.id_code] = wire stack[-1].add_wire(wire) elif token.kind is TokenKind.VERSION: @@ -123,6 +145,12 @@ def from_vcd(cls, filename): elif token.kind is TokenKind.CHANGE_SCALAR: value = token.scalar_change.value value = int(value) if value in ("0", "1") else value + + vc_dict = {"time": time, + "id": token.scalar_change.id_code, + "value": value} + wire_vc_dfs.append(vc_dict) + wires[token.scalar_change.id_code][time] = value elif token.kind is TokenKind.CHANGE_VECTOR: value = token.vector_change.value @@ -148,6 +176,11 @@ def from_vcd(cls, filename): else: raise SoottyError(f"Invalid vcd token when parsing: {token}") + this.wires_df = pl.from_dicts(wire_df_list) + this.wires_vc = pl.from_dicts(wire_vc_dfs) + print(this.wires_df) + print(this.wires_vc) + return this @classmethod @@ -319,4 +352,4 @@ def rec_print(wires): print() print("time", *breakpoints, sep="\t") - rec_print(self.root.get_wires()) + rec_print(self.root.get_wires()) \ No newline at end of file From a99e9fc31f9519e8afac79422f4b2b86a5662962 Mon Sep 17 00:00:00 2001 From: Riley Chou Date: Fri, 9 Feb 2024 09:38:23 -0800 Subject: [PATCH 2/3] add function (doens't work correctly) --- sootty/storage/wiregroup.py | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/sootty/storage/wiregroup.py b/sootty/storage/wiregroup.py index 95ed9d4..038f76e 100644 --- a/sootty/storage/wiregroup.py +++ b/sootty/storage/wiregroup.py @@ -10,6 +10,8 @@ def __init__(self, name: str): self.groups = [] self.wires = [] + self.all_wires_df = pl.DataFrame() + self.groups_df = pl.DataFrame() self.wires_df = pl.DataFrame([], schema={'name':pl.String, 'time': pl.Int64, 'value': pl.Int64, 'length': pl.Int64, 'width': pl.Int64}) @@ -17,7 +19,7 @@ def add_wire(self, wire): self.wires.append(wire) # this prints out null because time doesn't exist in the value change dictionary yet - + # print(wire.__getitem__('time')) temp_wire_df = pl.DataFrame({ 'name': wire.name, @@ -27,9 +29,38 @@ def add_wire(self, wire): 'width': wire.width(), }) self.wires_df.extend(temp_wire_df) - print(self.wires_df) + name_str = self.name + '.' + wire.name + + # TODO: try using the values in dumpvars for initial values + temp_all_wires_df = pl.DataFrame({ + name_str: [ + {'name': wire.name}, + {'time': wire.__getitem__('time')}, + {'value': wire.__getitem__('value')}, + {'length': wire.length()}, + {'width': wire.width()} + ] + }) + if self.all_wires_df.is_empty(): + self.all_wires_df = temp_all_wires_df + elif name_str in self.all_wires_df.columns: + #TODO: implement duplicate wire names + pass + + else: + self.all_wires_df = pl.concat( + [ + self.all_wires_df, + temp_all_wires_df + ], + how="horizontal") + + print(self.all_wires_df) + + def add_group(self, group): + # print(group) self.groups.append(group) def num_wires(self): From 3f2031503694ea98daa98643eaf102d150047e72 Mon Sep 17 00:00:00 2001 From: Riley Chou Date: Wed, 14 Feb 2024 23:02:28 -0800 Subject: [PATCH 3/3] made the group names work --- sootty/storage/wiregroup.py | 21 +++++++-------------- sootty/storage/wiretrace.py | 5 ++++- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/sootty/storage/wiregroup.py b/sootty/storage/wiregroup.py index 038f76e..8a71471 100644 --- a/sootty/storage/wiregroup.py +++ b/sootty/storage/wiregroup.py @@ -6,29 +6,19 @@ class WireGroup: def __init__(self, name: str): - self.name = name + self.name = name # e.g. Test_MIPS.core.alu self.groups = [] self.wires = [] self.all_wires_df = pl.DataFrame() - self.groups_df = pl.DataFrame() - self.wires_df = pl.DataFrame([], schema={'name':pl.String, 'time': pl.Int64, 'value': pl.Int64, 'length': pl.Int64, 'width': pl.Int64}) + # self.groups_df = pl.DataFrame() + # self.wires_df = pl.DataFrame([], schema={'name':pl.String, 'time': pl.Int64, 'value': pl.Int64, 'length': pl.Int64, 'width': pl.Int64}) def add_wire(self, wire): self.wires.append(wire) # this prints out null because time doesn't exist in the value change dictionary yet - - # print(wire.__getitem__('time')) - temp_wire_df = pl.DataFrame({ - 'name': wire.name, - 'time': wire.__getitem__('time'), - 'value': wire.__getitem__('value'), - 'length': wire.length(), - 'width': wire.width(), - }) - self.wires_df.extend(temp_wire_df) name_str = self.name + '.' + wire.name # TODO: try using the values in dumpvars for initial values @@ -79,7 +69,10 @@ def length(self): def find(self, name: str): """Returns the first wire object with the given name, if it exists.""" """dataframe version""" - find_wires_df = self.wires_df.filter(pl.col("name") == name) + # print("find") + # print(self.all_wires_df) + # # if not self.name == "__root__": + # find_wires_df = self.all_wires_df.select(self.name + '.' + name) # print(find_wires_df) for wire in self.wires: diff --git a/sootty/storage/wiretrace.py b/sootty/storage/wiretrace.py index d0a315b..93947d6 100644 --- a/sootty/storage/wiretrace.py +++ b/sootty/storage/wiretrace.py @@ -100,7 +100,9 @@ def from_vcd(cls, filename): elif token.kind is TokenKind.ENDDEFINITIONS: break # end of definitions elif token.kind is TokenKind.SCOPE: - group = WireGroup(token.scope.ident) + prepend_name = '' + prepend_name += stack[-1].name + '.' + token.scope.ident + group = WireGroup(prepend_name) stack[-1].add_group(group) stack.append(group) elif token.kind is TokenKind.TIMESCALE: @@ -113,6 +115,7 @@ def from_vcd(cls, filename): if token.var.id_code in wires: # Used if wire is in multiple groups? # wire_groups[token.var.id_code].append(stack[-1].name) + # PREPENDING THE NAME HERE BASED ON STACK[-1] Value is stack[-1].add_wire(wires[token.var.id_code]) else: wire = Wire(