diff --git a/README.md b/README.md index dec0e63..86d41e6 100644 --- a/README.md +++ b/README.md @@ -13,3 +13,6 @@ STDCXX=11 MAKE_NPROCS=32 pip install --verbose --force-reinstall --ignore-instal pip install conan ``` +## TODO + +* pythonize `sc_module` with iteration protocol (`__next__` and `StopIteration` exception) \ No newline at end of file diff --git a/pysysc/sccppyy.py b/pysysc/sccppyy.py index e8ab4e9..b12e6b7 100644 --- a/pysysc/sccppyy.py +++ b/pysysc/sccppyy.py @@ -111,8 +111,7 @@ def _pythonizor(klass, name): # install the pythonizor as a callback on namespace 'Math' (default is the global namespace) cppyy.py.add_pythonization(_pythonizor, 'sc_core') - - + # reflection methods def get_members(sc_object): def is_cpp_data_type(name, module): diff --git a/pysysc/structural.py b/pysysc/structural.py new file mode 100644 index 0000000..7c6e779 --- /dev/null +++ b/pysysc/structural.py @@ -0,0 +1,81 @@ +''' +Created on 02.01.2019 + +@author: eyck +''' +from cppyy import gbl as cpp +from builtins import getattr +import re + +class Module(object): + ''' + classdocs + ''' + + def __init__(self, clazz): + self.cppclazz=clazz + self.instance=None + + def __getattr__(self, attr): + if self.instance is None: + raise AttributeError + return getattr(self.instance, attr) + + def create(self, name): + self.instance = self.cppclazz(cpp.sc_core.sc_module_name(str(name))) + return self + +class Signal(object): + ''' + classdocs + ''' + + _sc_inout_re = re.compile(r'^sc_core::sc_(?:_in)?out<(.*)>$') + _sc_port_re = re.compile(r'^sc_core::sc_port<[^<]*<(.*)>>$') + + + def __init__(self, name=None): + self.name=name + self.source=None + self.targets=[] + self.signal=None + self.sig_data_type=None + + def src(self, module_port): + self.source=module_port + port_class_name=type(module_port).__cppname__ + match = self._sc_inout_re.match(port_class_name) + if match: + self.sig_data_type=match.group(1) + else: + match = self._sc_port_re.match(port_class_name) + if match: + self.sig_data_type=match.group(1) + if self.sig_data_type is None: + raise AttributeError; + py_dt_name=self.sig_data_type.replace("::", ".").replace("<", "[").replace(">", "]") + self.signal = eval("cpp.sc_core.sc_signal[cpp.%s](self.name)" % py_dt_name) + module_port.bind(self.signal) + return self + + def sink(self, module_port): + self.targets.append(module_port) + module_port.bind(self.signal) + return self + +class Connection(object): + ''' + classdocs + ''' + def __init__(self): + self.source=None + self.targets=[] + + def src(self, module_port): + self.source=module_port + return self + + def sink(self, module_port): + self.targets.append(module_port) + self.source.bind(module_port) + return self \ No newline at end of file diff --git a/setup.py b/setup.py index 55bf85a..196431f 100644 --- a/setup.py +++ b/setup.py @@ -12,9 +12,9 @@ setup(name='PySysC', long_description=readme(), classifiers=[ 'Development Status :: 3 - Alpha', - 'License :: OSI Approved :: Apache 2.0 License', + 'License :: OSI Approved :: Apache Software License', 'Programming Language :: Python :: 3.6', - 'Topic :: Engineering :: Simulation' + 'Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)' ], keywords='SystemC simulation', url='https://git.minres.com/SystemC/PySysC', diff --git a/tests/router_example.py b/tests/router_example.py index fb59d21..24ed012 100644 --- a/tests/router_example.py +++ b/tests/router_example.py @@ -22,6 +22,25 @@ intors = scpy.get_inititator_sockets(initiator) tgts = scpy.get_target_sockets(initiator) childs = scpy.get_submodules(initiator) +cppyy.cppdef(""" +class my_module: public sc_core::sc_module { +public: + sc_core::sc_out> port; + my_module(sc_core::sc_module_name nm):sc_core::sc_module(nm), port("port"){} +}; +void bind_port(sc_core::sc_signal>& s, sc_core::sc_out>& p){p(s);} +""") + +class MyMod(cpp.sc_core.sc_module): + def __init__(self, name): + cpp.sc_core.sc_module.sc_module() + +mod = cpp.my_module(cpp.sc_core.sc_module_name("module")) +sig = cpp.sc_core.sc_signal[cpp.sc_dt.sc_uint[32]]("signal") +mod.port(sig) + +mod2 = MyMod("Blah") + initiator.socket.bind(router.target_socket) for idx,m in enumerate(memories): router.initiator_socket.at(idx).bind(m.socket)