Skip to content

Commit

Permalink
added index and port information to pin str(), added get_pin(name, in…
Browse files Browse the repository at this point in the history
…dex) to instance
  • Loading branch information
jacobdbrown4 committed Oct 31, 2023
1 parent dcb5e15 commit 6225228
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
20 changes: 20 additions & 0 deletions spydrnet/ir/innerpin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ def port(self):
This object cannot be modified directly by the end user."""
return self._port

@property
def index(self):
"""Returns the index of the pin
This property cannot be modified directly by the end user."""
return self._port.pins.index(self)

def _clone_rip_and_replace(self, memo):
"""Remove from its current environment and place it into the new cloned environment with
references held in the memo dictionary"""
Expand Down Expand Up @@ -64,3 +71,16 @@ def clone(self):
c = self._clone({})
c._clone_rip()
return c

def __str__(self):
"""Re-define the print function so it is easier to read"""
rep = str(type(self))
rep = rep[:-1] + "; "
rep+= "Index: " + str(self.index) + "; "
rep+= "Port: " + str(self.port) + "; "
if self.wire is None:
rep += "Wire connected undefined"
else:
rep += "connected to'" + str(self.wire) + "'"
rep += ">"
return rep
11 changes: 11 additions & 0 deletions spydrnet/ir/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ def get_ports(self, *args, **kwargs):

return get_ports(self, *args, **kwargs)

def get_pin(self, name, index=0):
"""Returns the pin connected to a port of the specified name and
at the specified index. Returns None if no pin is found"""
for pin in self.pins:
if pin.inner_pin.port.name != name:
continue
if pin.index != index:
continue
return pin
return None

@property
def pins(self):
"""Get the pins on this instance.
Expand Down
21 changes: 19 additions & 2 deletions spydrnet/ir/outerpin.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ def instance(self):
"""Return the instance with which this pin is associated"""
return self._instance

@property
def index(self):
"""Returns the index of the pin
This property cannot be modified directly by the end user."""
return self._inner_pin.index

@property
def inner_pin(self):
"""get the inner pin associated with this outer pin"""
Expand Down Expand Up @@ -106,5 +113,15 @@ def clone(self):
c._clone_rip()
return c

def index(self):
return self._inner_pin.port.pins.index(self._inner_pin)
def __str__(self):
"""Re-define the print function so it is easier to read"""
rep = str(type(self))
rep = rep[:-1] + "; "
rep+= "Index: " + str(self.index) + "; "
rep+= "Port: " + str(self.inner_pin.port) + "; "
if self.wire is None:
rep += "Wire connected undefined"
else:
rep += "connected to'" + str(self.wire) + "'"
rep += ">"
return rep
17 changes: 17 additions & 0 deletions tests/spydrnet/ir/tests/test_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,20 @@ def test_instance_is_unique(self):
instance_2.reference = definition
self.assertFalse(instance_1.is_unique())
self.assertFalse(instance_2.is_unique())

def test_get_pin(self):
definition = sdn.Definition()
self.instance.reference = definition
port = definition.create_port("Port_A")
pin0 = port.create_pin()
pin1 = port.create_pin()

outer_pin0 = self.instance.pins[pin0]
outer_pin1 = self.instance.pins[pin1]

self.assertEqual(self.instance.get_pin("Port_A", 0), outer_pin0)
self.assertEqual(self.instance.get_pin("Port_A", 1), outer_pin1)
self.assertIsNone(self.instance.get_pin("Port_A", 2))
self.assertIsNone(self.instance.get_pin("Fake Name", 0))
self.assertIsNone(self.instance.get_pin("Fake Name", 10))

0 comments on commit 6225228

Please sign in to comment.