Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/xtofalex/naja
Browse files Browse the repository at this point in the history
  • Loading branch information
xtofalex committed Nov 28, 2024
2 parents 2951f15 + 331c925 commit 70f605b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/najaeda/najaeda/netlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,11 @@ def __str__(self) -> str:
return str(self.inst) + " " + str(self.path)

def get_child_instance(self, name: str):
childInst = self.inst.getModel().getInstance(name)
if childInst is None:
return None
return Instance(
snl.SNLPath(self.path, self.inst.getModel().getInstance(name)),
self.inst.getModel().getInstance(name)
)
snl.SNLPath(self.path, childInst), childInst)

def get_child_instances(self):
for inst in self.inst.getModel().getInstances():
Expand All @@ -294,10 +295,15 @@ def get_inst_term(self, name: str) -> InstTerm:
def is_primitive(self) -> bool:
return self.inst.getModel().isPrimitive()

def get_input_inst_terms(self):
for term in self.inst.getInstTerms():
if term.getDirection() == snl.SNLTerm.Direction.Input:
yield InstTerm(self.path, term)

def get_output_inst_terms(self):
for term in self.inst.getInstTerms():
if term.getDirection() == snl.SNLTerm.Direction.Output:
yield InstTerm(self.path.getHeadPath(), term)
yield InstTerm(self.path, term)

def delete_instance(self, name: str):
path = snl.SNLPath(self.path, self.inst.getModel().getInstance(name))
Expand Down Expand Up @@ -406,16 +412,16 @@ def create_net(self, name: str) -> Net:
uniq = snl.SNLUniquifier(self.path)
uniq_path = uniq.getPathUniqCollection()
self.inst = tuple(uniq_path)[len(tuple(uniq_path)) - 1]
design = self.inst.getModel()
newSNLNet = snl.SNLScalarNet.create(design, name)
model = self.inst.getModel()
newSNLNet = snl.SNLScalarNet.create(model, name)
return Net(self.path, newSNLNet)

def create_bus_net(self, name: str, width: int, offset: int) -> list:
uniq = snl.SNLUniquifier(self.path)
uniq_path = uniq.getPathUniqCollection()
self.inst = tuple(uniq_path)[len(tuple(uniq_path)) - 1]
design = self.inst.getModel()
newSNLNet = snl.SNLBusNet.create(design, width, offset, name)
model = self.inst.getModel()
newSNLNet = snl.SNLBusNet.create(model, width, offset, name)
list = []
for i in range(width):
list.append(Net(self.path, newSNLNet.getBit(i)))
Expand All @@ -429,9 +435,9 @@ def get_term_list_for_bus(self, name: str) -> list:
return list

def get_net(self, name: str) -> Net:
for term in self.inst.getInstTerms():
if term.getBitTerm().getName() == name:
return Net(self.path, term.getNet())
net = self.inst.getModel().getNet(name)
if net is not None:
return Net(self.path, net)
return None

def get_net_list_for_bus(self, name: str) -> list:
Expand Down
38 changes: 38 additions & 0 deletions test/najaeda/test_najaeda_netlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def test_instance(self):

instance.create_child_instance(self.submodel, "ins2")
self.assertTrue(instance.get_number_of_child_instances() == 1)
self.assertIsNotNone(instance.get_child_instance("ins2"))
self.assertTrue(instance.get_child_instance("ins2").inst.getName() == "ins2")

#Test bus term creation connection and disconnection
instance3 = instance.create_child_instance(self.submodel, "ins3")
Expand All @@ -95,8 +97,44 @@ def test_instance(self):
self.assertTrue(len(netBitsForBus) == 5)
for i in range(4):
termsForBus[i].connect(netBitsForBus[i])

inputCount = 0
for input in instance.get_input_inst_terms():
self.assertTrue(input.is_input())
self.assertFalse(input.is_output())
inputCount += 1

self.assertTrue(inputCount == 6)

outputCount = 0
for output in instance.get_output_inst_terms():
self.assertTrue(output.is_output())
self.assertFalse(output.is_input())
outputCount += 1

instance.create_input_term("I3")
instance.create_input_bus_term("I4", 4, -1)
instance.create_output_term("O2")

inputCount = 0
for input in instance.get_input_inst_terms():
self.assertTrue(input.is_input())
self.assertFalse(input.is_output())
inputCount += 1

self.assertTrue(inputCount == 13)

outputCount = 0
for output in instance.get_output_inst_terms():
self.assertTrue(output.is_output())
self.assertFalse(output.is_input())
outputCount += 1

self.assertTrue(outputCount == 2)

self.assertIsNone(instance.get_net("created_net"))
instance.create_net("created_net")
self.assertIsNotNone(instance.get_net("created_net"))

def test_equipotential(self):
universe = snl.SNLUniverse.create()
Expand Down

0 comments on commit 70f605b

Please sign in to comment.