Added PyScModule to forward simulation phase callbacks

This commit is contained in:
2019-06-08 14:31:23 +00:00
parent b1334a0689
commit 4381c9be32
5 changed files with 120 additions and 9 deletions

View File

@ -1,6 +1,7 @@
import json
import cppyy
import os.path
from pathlib import Path
import sys
import tempfile
import conans.client.conan_api as conan
@ -13,8 +14,6 @@ lang_symbols = {
14:'201402L',
17:'201703L'}
lang_level=11
'''
'''
sysIncludeDirs = set()
@ -92,6 +91,7 @@ namespace sc_core { extern void pln(); }
if systemc_loaded: break;
if not interactive: cppyy.gbl.sc_core.pln()
cppyy.gbl.sc_core.sc_in_action=True
_load_pythonization_lib()
return True
return False
@ -120,7 +120,17 @@ def _load_systemc_cci():
cci_loaded=True
return True
return False
def _load_pythonization_lib():
import pysysc
path = os.path.dirname(os.path.dirname(pysysc.__file__))
for file in os.listdir(path):
if file.endswith(".so"):
cppyy.load_library(os.path.join(path, file))
cppyy.include(os.path.join(path, "PyScModule.h"))
return
def add_library(file, lib):
buf = io.StringIO()
with redirect_stdout(buf), redirect_stderr(buf):
@ -150,8 +160,6 @@ def _pythonizor(clazz, name):
clazz.__repr__ = lambda self: repr(self.name())
elif len(name) > 10 and name[:9] == 'sc_export<':
clazz.__repr__ = lambda self: repr(self.name())
# else:
# print('not pythonizing', name)
# install the pythonizor as a callback on namespace 'Math' (default is the global namespace)
cppyy.py.add_pythonization(_pythonizor, 'sc_core')

View File

@ -8,7 +8,6 @@ from builtins import getattr
import re
from enum import Enum
import logging
import pysysc
class Mode(Enum):
SIM = 1
@ -21,6 +20,8 @@ class Simulation(object):
@staticmethod
def run():
cpp.sc_core.sc_start()
if not cpp.sc_core.sc_end_of_simulation_invoked():
cpp.sc_core.sc_stop()
@staticmethod
def setup(log_level = logging.WARNING):