MEM: Pass the ports from Python to C++ using the Swig params
This patch adds basic information about the ports in the parameter classes to be passed from the Python world to the corresponding C++ object. Currently, the only information passed is the number of connected peers, which for a Port is either 0 or 1, and for a VectorPort reflects the size of the VectorPort. The default port of the bus had to be renamed to avoid using the name "default" as a field in the parameter class. It is possible to extend the Swig'ed information further and add e.g. a pair with a description and size.
This commit is contained in:
@@ -1349,6 +1349,11 @@ class PortRef(object):
|
||||
def __str__(self):
|
||||
return '%s.%s' % (self.simobj, self.name)
|
||||
|
||||
def __len__(self):
|
||||
# Return the number of connected ports, i.e. 0 is we have no
|
||||
# peer and 1 if we do.
|
||||
return int(self.peer != None)
|
||||
|
||||
# for config.ini, print peer's name (not ours)
|
||||
def ini_str(self):
|
||||
return str(self.peer)
|
||||
@@ -1462,6 +1467,11 @@ class VectorPortRef(object):
|
||||
def __str__(self):
|
||||
return '%s.%s[:]' % (self.simobj, self.name)
|
||||
|
||||
def __len__(self):
|
||||
# Return the number of connected peers, corresponding the the
|
||||
# length of the elements.
|
||||
return len(self.elements)
|
||||
|
||||
# for config.ini, print peer's name (not ours)
|
||||
def ini_str(self):
|
||||
return ' '.join([el.ini_str() for el in self.elements])
|
||||
@@ -1525,6 +1535,17 @@ class Port(object):
|
||||
def connect(self, simobj, ref):
|
||||
self.makeRef(simobj).connect(ref)
|
||||
|
||||
# No need for any pre-declarations at the moment as we merely rely
|
||||
# on an unsigned int.
|
||||
def cxx_predecls(self, code):
|
||||
pass
|
||||
|
||||
# Declare an unsigned int with the same name as the port, that
|
||||
# will eventually hold the number of connected ports (and thus the
|
||||
# number of elements for a VectorPort).
|
||||
def cxx_decl(self, code):
|
||||
code('unsigned int port_${{self.name}}_connection_count;')
|
||||
|
||||
class MasterPort(Port):
|
||||
# MasterPort("description")
|
||||
def __init__(self, *args):
|
||||
|
||||
Reference in New Issue
Block a user