Skip to content

Commit

Permalink
Merge pull request #162 from nanocoh/main
Browse files Browse the repository at this point in the history
coverage
  • Loading branch information
nanocoh authored Nov 28, 2024
2 parents 6826791 + 8bad237 commit c3ac936
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 5 deletions.
40 changes: 35 additions & 5 deletions src/najaeda/najaeda/netlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ def __init__(self, inst_term):
)
self.equi = snl.SNLEquipotential(ito)

def __eq__(self, value):
return self.equi == value.equi

def get_inst_terms(self):
for term in self.equi.getInstTermOccurrences():
yield InstTerm(
Expand Down Expand Up @@ -50,6 +53,32 @@ def __init__(self, path, net):
def __eq__(self, value):
return self.net == value.net and self.path == value.path

def __ne__(self, value):
return not self == value

def __lt__(self, value):
if self.path != value.path:
return self.path < value.path
return self.net < value.net

def __le__(self, value):
if self.path != value.path:
return self.path < value.path
return self.net <= value.net

def __gt__(self, value):
if self.path != value.path:
return self.path > value.path
return self.net > value.net

def __ge__(self, value):
if self.path != value.path:
return self.path > value.path
return self.net >= value.net

def __str__(self):
return str(self.net)

def get_name(self) -> str:
return self.net.getName()

Expand All @@ -67,7 +96,7 @@ def __init__(self, term):
self.term = term

def __eq__(self, other) -> bool:
return self.path == other.path and self.term == other.term
return self.term == other.term

def __ne__(self, other) -> bool:
return not self == other
Expand Down Expand Up @@ -151,11 +180,9 @@ def get_net(self) -> Net:
return Net(self.path, self.term.getNet())

def get_instance(self):
inst = self.term.getInstance()
path = snl.SNLPath(self.path, inst)
return Instance(path, inst)
return Instance(self.path, self.term.getInstance())

def get_flat_fanout(self) -> Equipotential:
def get_flat_fanout(self):
return self.get_equipotential().get_all_leaf_readers()

def get_equipotential(self) -> Equipotential:
Expand Down Expand Up @@ -233,6 +260,9 @@ def __init__(self, path, inst):
def __eq__(self, other) -> bool:
return self.inst == other.inst and self.path == other.path

def __str__(self) -> str:
return str(self.inst) + " " + str(self.path)

def get_child_instance(self, name: str):
return Instance(
snl.SNLPath(self.path, self.inst.getModel().getInstance(name)),
Expand Down
79 changes: 79 additions & 0 deletions test/najaeda/test_najaeda_netlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,85 @@ def test_equipotential(self):
instance.get_inst_term("I0").connect(netlist.Net(path0, i0_net))
self.assertTrue(instance.get_inst_term("I0").get_net() == netlist.Net(path1, i0_net))

netlistNet1 = netlist.Net(path1, i0_net)
netlistNet2 = netlist.Net(path2, i0_net_sub)
self.assertTrue(netlistNet1 != netlistNet2)
self.assertTrue(netlistNet2 == netlistNet2)
self.assertTrue(netlistNet1 == netlist.Net(path1, i0_net))
self.assertTrue(netlistNet2 == netlist.Net(path2, i0_net_sub))
self.assertTrue(netlistNet1 < netlistNet2)
self.assertTrue(netlistNet1 <= netlistNet2)
self.assertTrue(netlistNet2 > netlistNet1)
self.assertTrue(netlistNet2 >= netlistNet1)
print(netlistNet1)

def testTopTerm(self):
universe = snl.SNLUniverse.create()
db = snl.SNLDB.create(universe)
lib = snl.SNLLibrary.create(db)
self.primitives = snl.SNLLibrary.createPrimitives(db)
self.top = snl.SNLDesign.create(lib)
universe.setTopDesign(self.top)
self.i0 = snl.SNLScalarTerm.create(self.top, snl.SNLTerm.Direction.Input, "I0")
self.i1 = snl.SNLScalarTerm.create(self.top, snl.SNLTerm.Direction.Input, "I1")

top_term = netlist.TopTerm(self.i0)
top_term2 = netlist.TopTerm(self.i1)

self.assertTrue(top_term == top_term)
self.assertTrue(top_term != top_term2)
self.assertTrue(top_term < top_term2)
self.assertTrue(top_term <= top_term2)
self.assertTrue(top_term2 > top_term)
self.assertTrue(top_term2 >= top_term)
print(top_term)

def testInstTerm(self):
universe = snl.SNLUniverse.create()
db = snl.SNLDB.create(universe)
lib = snl.SNLLibrary.create(db)
self.primitives = snl.SNLLibrary.createPrimitives(db)
self.top = snl.SNLDesign.create(lib)
universe.setTopDesign(self.top)
self.model = snl.SNLDesign.create(lib, "model")
self.submodel = snl.SNLDesign.createPrimitive(self.primitives, "submodel")
self.i0 = snl.SNLScalarTerm.create(self.model, snl.SNLTerm.Direction.Input, "I0")
self.i1 = snl.SNLBusTerm.create(self.model, snl.SNLTerm.Direction.Input, 4, 0, "I1")
self.o = snl.SNLScalarTerm.create(self.model, snl.SNLTerm.Direction.Output, "O")
self.i0sub = snl.SNLScalarTerm.create(self.submodel, snl.SNLTerm.Direction.Input, "I0")
self.i1sub = snl.SNLBusTerm.create(self.submodel, snl.SNLTerm.Direction.Input, 4, 0, "I1")
self.osub = snl.SNLScalarTerm.create(self.submodel, snl.SNLTerm.Direction.Output, "O")
ins2 = snl.SNLInstance.create(self.model, self.submodel, "ins2")
ins1 = snl.SNLInstance.create(self.top, self.model, "ins1")

path0 = snl.SNLPath()
path1 = snl.SNLPath(path0, ins1)
path2 = snl.SNLPath(path1, ins2)
instance = netlist.Instance(path1, ins1)
instTerm0 = instance.get_inst_term("I0")
instTerm1 = instance.get_inst_term("I1")
instance2 = netlist.Instance(path2, ins2)
inst2Term0 = instance2.get_inst_term("I0")
inst2Term1 = instance2.get_inst_term("I1")

self.assertTrue(instTerm0 == instTerm0)
self.assertTrue(instTerm0 != instTerm1)
self.assertTrue(instTerm0 < instTerm1)
self.assertTrue(instTerm0 <= instTerm1)
self.assertTrue(instTerm1 > instTerm0)
self.assertTrue(instTerm1 >= instTerm0)
self.assertTrue(instTerm0.get_instance().inst == instance.inst)
count = 0
for to in instTerm1.get_flat_fanout():
count += 1
self.assertTrue(count == 0)
self.assertTrue(instTerm0.get_equipotential() == netlist.Equipotential(instTerm0))
self.assertTrue(instTerm0.is_input())
self.assertFalse(instTerm0.is_output())





if __name__ == '__main__':
faulthandler.enable()
Expand Down

0 comments on commit c3ac936

Please sign in to comment.