From c8c2c3918cdf2524396e0ed627dd26f54c9b86b8 Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Fri, 4 Jan 2019 15:46:55 +0100 Subject: [PATCH] Some general improvements --- pysysc/sccppyy.py | 31 +++++++++-- pysysc/structural.py | 119 +++++++++++++++++++++++++++++-------------- 2 files changed, 108 insertions(+), 42 deletions(-) diff --git a/pysysc/sccppyy.py b/pysysc/sccppyy.py index b12e6b7..ea73ccb 100644 --- a/pysysc/sccppyy.py +++ b/pysysc/sccppyy.py @@ -31,7 +31,7 @@ class NullLogger(object): self.buffer+=message -def read_config_from_conan(conanfile): +def read_config_from_conan(conanfile, build_type='Release'): global lang_level sys.stdout = NullLogger() #read conan configuration @@ -39,7 +39,7 @@ def read_config_from_conan(conanfile): conan_api, client_cache, user_io = conan.Conan.factory() install_info = conan_api.install(path=conanfile, generators=['json'], - settings=['build_type=Debug'], + settings=['build_type=%s'%build_type], install_folder=tmpdirname) for e in install_info['installed']: @@ -62,6 +62,8 @@ def read_config_from_conan(conanfile): sys.stdout=sys.stdout.terminal return msg +systemc_loaded=False + def load_systemc(): if 'SYSTEMC_HOME' in os.environ: add_sys_include_path(os.path.join(os.environ['SYSTEMC_HOME'], 'include')) @@ -73,7 +75,10 @@ def load_systemc(): #define SC_CPLUSPLUS %s #include "systemc" #include "tlm" -""" % lang_symbols[lang_level]) + """ + % lang_symbols[lang_level]) + systemc_loaded=True + cppyy.gbl.sc_core.sc_in_action=True return True return False @@ -168,3 +173,23 @@ def get_submodules(module): res.append(attr) return res +import time + +class timewith(): + def __init__(self, name=''): + self.name = name + self.start = time.time() + + @property + def elapsed(self): + return time.time() - self.start + + def checkpoint(self, name=''): + return '{timer} {checkpoint} took {elapsed} seconds'.format(timer=self.name, checkpoint=name, elapsed=self.elapsed).strip() + + def __enter__(self): + return self + + def __exit__(self, mytype, value, traceback): + print(self.checkpoint('finished')) + pass diff --git a/pysysc/structural.py b/pysysc/structural.py index 7c6e779..304dc5a 100644 --- a/pysysc/structural.py +++ b/pysysc/structural.py @@ -6,7 +6,48 @@ Created on 02.01.2019 from cppyy import gbl as cpp from builtins import getattr import re +from enum import Enum +import logging +class Mode(Enum): + SIM = 1 + BUILD = 2 + +mode=Mode.SIM + +class Simulation(object): + + @staticmethod + def run(): + cpp.sc_core.sc_start() + + @staticmethod + def setup(log_level = logging.WARNING): + try: + if log_level >= logging.FATAL: + cpp.scc.init_logging(cpp.logging.FATAL, False) + elif log_level >= logging.ERROR: + cpp.scc.init_logging(cpp.logging.ERROR, False) + elif log_level >= logging.WARNING: + cpp.scc.init_logging(cpp.logging.WARNING, False) + elif log_level >= logging.INFO: + cpp.scc.init_logging(cpp.logging.INFO, False) + elif log_level >= logging.DEBUG: + cpp.scc.init_logging(cpp.logging.DEBUG, False) + except Exception: # fall back: use basic SystemC logging setup + verb_lut={ + logging.FATAL:100, #SC_LOW + logging.ERROR: 200, #SC_MEDIUM + logging.WARNING: 300, #SC_HIGH + logging.INFO: 400, #SC_FULL + logging.DEBUG: 500 #SC_DEBUG + } + cpp.sc_core.sc_report_handler.set_verbosity_level(verb_lut[log_level]); + cpp.sc_core.sc_report_handler.set_actions(cpp.sc_core.SC_ID_MORE_THAN_ONE_SIGNAL_DRIVER_, cpp.sc_core.SC_DO_NOTHING); + + def __init__(self): + pass + class Module(object): ''' classdocs @@ -25,44 +66,6 @@ class Module(object): 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 @@ -78,4 +81,42 @@ class Connection(object): def sink(self, module_port): self.targets.append(module_port) self.source.bind(module_port) - return self \ No newline at end of file + return self + +class Signal(Connection): + ''' + 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): + Connection.__init__(self) + self.name=name + self.signal=None + self.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.data_type=match.group(1) + else: + match = self._sc_port_re.match(port_class_name) + if match: + self.data_type=match.group(1) + if self.data_type is None: + raise AttributeError; + py_dt_name=self.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 +