diff --git a/.gitignore b/.gitignore index 959b5eb..0329c82 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,7 @@ /.settings /*.vcd /*.png -/*.dot \ No newline at end of file +/*.dot +/*.fst +/*.ftr +/.venv \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..98acc30 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,29 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python Debugger: router_example.py", + "type": "debugpy", + "request": "launch", + "program": "${workspaceFolder}/router_example.py", + "console": "integratedTerminal" + }, + { + "name": "Python Debugger: router_example2.py", + "type": "debugpy", + "request": "launch", + "program": "${workspaceFolder}/router_example2.py", + "console": "integratedTerminal" + }, + { + "name": "Python Debugger: modules.py", + "type": "debugpy", + "request": "launch", + "program": "${workspaceFolder}/modules.py", + "console": "integratedTerminal" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..879f973 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,14 @@ +{ + "editor.rulers": [ + { + "column": 140, + "comment": "clang-format" + } + ], + "editor.formatOnSave": true, + "editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd", + "cmake.buildDirectory": "${workspaceFolder}/build", + "[jsonc]": { + "editor.defaultFormatter": "vscode.json-language-features" + } +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..c287503 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,32 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "router_example", + "type": "shell", + "command": "python3 router_example.py", + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [] + }, + { + "label": "router_example2", + "type": "shell", + "command": "python3 router_example2.py", + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [] + }, + { + "label": "modules", + "type": "shell", + "command": "python3 modules.py", + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [] + } + ] +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 0976948..6a9f3fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.3) +cmake_minimum_required(VERSION 3.12) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_CURRENT_SOURCE_DIR}/scc/cmake) project(pysysc-sc) @@ -9,10 +9,10 @@ include(GNUInstallDirs) include(BuildType) include(clang-format) -set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_POSITION_INDEPENDENT_CODE ON) +set(CMAKE_CXX_STANDARD 17) include(CheckCXXCompilerFlag) CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE) @@ -51,17 +51,44 @@ if(EXISTS /etc/redhat-release) endif() # Boost on CentOS quirks end endif() -set(CONAN_PACKAGE_LIST fmt/8.0.1 spdlog/1.9.2 zlib/1.2.11 boost/1.75.0 yaml-cpp/0.7.0 lz4/1.9.3) +set(BOOST_OPTIONS +boost:fPIC=True +boost:shared=True +boost:header_only=False +boost:without_context=True +boost:without_contract=True +boost:without_coroutine=True +boost:without_fiber=True +boost:without_graph=True +boost:without_graph_parallel=True +boost:without_iostreams=True +boost:without_json=True +boost:without_locale=True +boost:without_log=True +boost:without_math=True +boost:without_mpi=True +boost:without_nowide=True +boost:without_python=True +boost:without_random=True +boost:without_regex=True +boost:without_serialization=True +boost:without_stacktrace=True +boost:without_test=True +boost:without_timer=True +boost:without_type_erasure=True +boost:without_wave=True +) +set(CONAN_PACKAGE_LIST fmt/8.0.1 spdlog/1.9.2 zlib/1.2.11 boost/1.75.0 yaml-cpp/0.7.0 jsoncpp/1.9.5 lz4/1.9.3) if(BUILD_SCC_DOCUMENTATION) list(APPEND CONAN_PACKAGE_LIST doxygen/1.9.2) endif() -set(CONAN_PACKAGE_OPTIONS fmt:header_only=True spdlog:header_only=True boost:without_stacktrace=True boost:shared=False boost:header_only=False) +set(CONAN_PACKAGE_OPTIONS fmt:header_only=True spdlog:header_only=True ${BOOST_OPTIONS}) if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") list(APPEND CONAN_PACKAGE_OPTIONS boost:fPIC=True) endif() if(NOT USE_CWR_SYSTEMC AND NOT USE_NCSC_SYSTEMC AND NOT DEFINED ENV{SYSTEMC_HOME}) - set(CONAN_PACKAGE_LIST ${CONAN_PACKAGE_LIST} systemc/2.3.3 systemc-cci/1.0.0) - set(CONAN_PACKAGE_OPTIONS ${CONAN_PACKAGE_OPTIONS} systemc-cci:shared=False) + set(CONAN_PACKAGE_LIST ${CONAN_PACKAGE_LIST} systemc/2.3.4) + set(CONAN_PACKAGE_OPTIONS ${CONAN_PACKAGE_OPTIONS} systemc:shared=True) endif() conan_configure(REQUIRES ${CONAN_PACKAGE_LIST} GENERATORS cmake_find_package OPTIONS ${CONAN_PACKAGE_OPTIONS}) @@ -81,12 +108,11 @@ find_package(spdlog REQUIRED) find_package(lz4 REQUIRED) find_package(fmt REQUIRED) find_package(yaml-cpp REQUIRED) - include(SystemCPackage) add_subdirectory(scc) add_subdirectory(vp_components) -add_subdirectory(top) +#add_subdirectory(top) # CTest is a testing tool that can be used to test your project. # enable_testing() diff --git a/README.md b/README.md index cf0c91d..d9e0f4a 100644 --- a/README.md +++ b/README.md @@ -4,16 +4,29 @@ A simple C++/SystemC/CMake project to test pysysc # How to build -> Currently only Linux and MacOS are tested +> Currently only Linux and MacOS are tested. +The install instruction below assume using bash. ``` +git clone --recursive -b develop https://git.minres.com/SystemC/PySysC-SC.git cd PySysC-SC -mkdir build -cd build -conan install .. --build=missing -cmake -DBUILD_SHARED_LIBS=ON .. -cmake --build . +python3 -mvenv .venv +. .venv/bin/activate +pip install "conan<2.0" +cmake -S . -B build -DBUILD_SHARED_LIBS=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON +cmake --build build -j24 +export SYSTEMC_HOME=$(grep -A1 rootpath_systemc\] build/conanbuildinfo.txt | tail -1) +export STDCXX=17 +pip install "cppyy<3.0" +pip install https://github.com/Minres/PySysC/tarball/master +pip install scc/contrib/pysysc/ +python3 router_example.py +python3 router_example2.py +python3 modules.py ``` - +These steps clone the PySysC-SC repository and builds the shared libraries using conan 1.x. +This also downloads and builds SYSTEMC (as a conan package). +Then it installs the python packages cppyy, PySysC, and PySysC.SCC using the same settings as the cmake build. +Eventually it runs the 3 examples. diff --git a/modules.py b/modules.py index f202049..e526b5b 100644 --- a/modules.py +++ b/modules.py @@ -4,48 +4,43 @@ # SPDX-License-Identifier: Apache-2.0 # -import os.path import logging -import cppyy -from cppyy import gbl as cpp +import os.path + import pysysc +import pysysc.scc as scc +from cppyy import gbl as cpp from pysysc.structural import Connection, Module, Signal, Simulation ############################################################################### # setup and load ############################################################################### logging.basicConfig(level=logging.DEBUG) -build_type='Debug' ############################################################################### -myDir = os.path.dirname( os.path.realpath(__file__)) -pysysc.read_config_from_conan(os.path.join(myDir, 'build/%s/conanfile.txt'%build_type), build_type) -pysysc.load_systemc() +myDir = os.path.dirname(os.path.realpath(__file__)) +pysysc.load_systemc(17) ############################################################################### logging.debug("Loading SC-Components lib") -# pysysc.add_include_path(os.path.join(myDir, 'scc/incl')) -# pysysc.add_library('scc.h', os.path.join(myDir, 'build/%s/lib/libscc.so'%build_type)) -pysysc.add_include_path(os.path.join(myDir, 'scc/src/common')) -pysysc.add_library('scc_util.h', os.path.join(myDir, 'build/%s/scc/src/common/libscc-util.so'%build_type)) -pysysc.add_include_path(os.path.join(myDir, 'scc/third_party')) -pysysc.add_include_path(os.path.join(myDir, 'scc/third_party/scv-tr/src')) -pysysc.add_library('scv-tr.h', os.path.join(myDir, 'build/%s/scc/third_party/scv-tr/src/libscv-tr.so'%build_type)) -pysysc.add_include_path(os.path.join(myDir, 'scc/src/sysc')) -pysysc.add_library('scc_sysc.h', os.path.join(myDir, 'build/%s/scc/src/sysc/libscc-sysc.so'%build_type)) -pysysc.add_include_path(os.path.join(myDir, 'scc/src/components')) -cppyy.include('scc_components.h') +scc.load_lib(myDir) ############################################################################### logging.debug("Loading Components lib") -pysysc.add_include_path(os.path.join(myDir, 'vp_components')) -pysysc.add_library('components.h', os.path.join(myDir, 'build/%s/vp_components/libvp_components.so'%build_type)) - +pysysc.add_include_path(os.path.join(myDir, "vp_components")) +pysysc.add_library("components.h", "libvp_components.so", myDir) +############################################################################### +# configure +############################################################################### +scc.setup(logging.root.level) +scc.configure(enable_trace=False) ############################################################################### # define toplevel class ############################################################################### num_of_mem = 4 from pysysc.sysc import ScModule + + class TopModule(ScModule): - + def __init__(self, name): ScModule.__init__(self, name) ############################################################################### @@ -54,47 +49,62 @@ class TopModule(ScModule): self.clk_gen = Module(cpp.ClkGen).create("clk_gen") self.rst_gen = Module(cpp.ResetGen).create("rst_gen") self.initiator = Module(cpp.Initiator).create("initiator") - self.memories = [Module(cpp.Memory).create("mem%d"%idx) for idx in range(0,num_of_mem)] + self.memories = [ + Module(cpp.Memory).create("mem%d" % idx) for idx in range(0, num_of_mem) + ] self.router = Module(cpp.Router[num_of_mem]).create("router") ############################################################################### # connect them ############################################################################### - self.clk = Signal("clk").src(self.clk_gen.clk_o).sink(self.initiator.clk_i).sink(self.router.clk_i) + self.clk = ( + Signal("clk") + .src(self.clk_gen.clk_o) + .sink(self.initiator.clk_i) + .sink(self.router.clk_i) + ) [self.clk.sink(m.clk_i) for m in self.memories] - self.rst = Signal("rst").src(self.rst_gen.reset_o).sink(self.initiator.reset_i).sink(self.router.reset_i) + self.rst = ( + Signal("rst") + .src(self.rst_gen.reset_o) + .sink(self.initiator.reset_i) + .sink(self.router.reset_i) + ) [self.rst.sink(m.reset_i) for m in self.memories] Connection().src(self.initiator.socket).sink(self.router.target_socket) - [Connection().src(self.router.initiator_socket.at(idx)).sink(m.socket) for idx,m in enumerate(self.memories)] + [ + Connection().src(self.router.initiator_socket.at(idx)).sink(m.socket) + for idx, m in enumerate(self.memories) + ] self.ScThread("RunThread") - + def EndOfElaboration(self): print("Elaboration finished") - + def StartOfSimulation(self): print("Simulation started") - + def EndOfSimulation(self): print("Simulation finished") def RunThread(self): print("Starting RunThread") - while(cpp.sc_core.sc_time_stamp()