Some general improvements

This commit is contained in:
Eyck Jentzsch 2019-01-04 15:46:55 +01:00
parent a8738defea
commit c8c2c3918c
2 changed files with 108 additions and 42 deletions

View File

@ -31,7 +31,7 @@ class NullLogger(object):
self.buffer+=message self.buffer+=message
def read_config_from_conan(conanfile): def read_config_from_conan(conanfile, build_type='Release'):
global lang_level global lang_level
sys.stdout = NullLogger() sys.stdout = NullLogger()
#read conan configuration #read conan configuration
@ -39,7 +39,7 @@ def read_config_from_conan(conanfile):
conan_api, client_cache, user_io = conan.Conan.factory() conan_api, client_cache, user_io = conan.Conan.factory()
install_info = conan_api.install(path=conanfile, install_info = conan_api.install(path=conanfile,
generators=['json'], generators=['json'],
settings=['build_type=Debug'], settings=['build_type=%s'%build_type],
install_folder=tmpdirname) install_folder=tmpdirname)
for e in install_info['installed']: for e in install_info['installed']:
@ -62,6 +62,8 @@ def read_config_from_conan(conanfile):
sys.stdout=sys.stdout.terminal sys.stdout=sys.stdout.terminal
return msg return msg
systemc_loaded=False
def load_systemc(): def load_systemc():
if 'SYSTEMC_HOME' in os.environ: if 'SYSTEMC_HOME' in os.environ:
add_sys_include_path(os.path.join(os.environ['SYSTEMC_HOME'], 'include')) add_sys_include_path(os.path.join(os.environ['SYSTEMC_HOME'], 'include'))
@ -73,7 +75,10 @@ def load_systemc():
#define SC_CPLUSPLUS %s #define SC_CPLUSPLUS %s
#include "systemc" #include "systemc"
#include "tlm" #include "tlm"
""" % lang_symbols[lang_level]) """
% lang_symbols[lang_level])
systemc_loaded=True
cppyy.gbl.sc_core.sc_in_action=True
return True return True
return False return False
@ -168,3 +173,23 @@ def get_submodules(module):
res.append(attr) res.append(attr)
return res 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

View File

@ -6,7 +6,48 @@ Created on 02.01.2019
from cppyy import gbl as cpp from cppyy import gbl as cpp
from builtins import getattr from builtins import getattr
import re 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): class Module(object):
''' '''
classdocs classdocs
@ -25,44 +66,6 @@ class Module(object):
self.instance = self.cppclazz(cpp.sc_core.sc_module_name(str(name))) self.instance = self.cppclazz(cpp.sc_core.sc_module_name(str(name)))
return self 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): class Connection(object):
''' '''
classdocs classdocs
@ -78,4 +81,42 @@ class Connection(object):
def sink(self, module_port): def sink(self, module_port):
self.targets.append(module_port) self.targets.append(module_port)
self.source.bind(module_port) self.source.bind(module_port)
return self 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