Jump to content
maarten

SystemC 2.3.3 using MSVC causes read access violation

Recommended Posts

I'm trying to use Accellera's SystemC on Windows 10, using Visual Studio 15 2017.
I'm using the systemc package from conan. So systemc is built using cmake.

Using the simple systemc module at the bottom of this post, a read access violation is thrown.
At the crash site, the following code is executed:

        (m_semantics_host_p->*m_semantics_method_p)();

 

Some advice about how to fix this problem would be appreciated.
This code runs fine on mingw, so I assume the problem is MSVC specific.

 

The call stack is:

>	main.exe!sc_core::sc_process_b::semantics() Line 685	C++
 	main.exe!sc_core::sc_method_process::run_process() Line 306	C++
 	main.exe!sc_core::sc_simcontext::crunch(bool once) Line 486	C++
 	main.exe!sc_core::sc_simcontext::simulate(const sc_core::sc_time & duration) Line 888	C++
 	main.exe!sc_core::sc_start(const sc_core::sc_time & duration, sc_core::sc_starvation_policy p) Line 1722	C++
 	main.exe!sc_core::sc_start(int duration, sc_core::sc_time_unit unit, sc_core::sc_starvation_policy p) Line 106	C++
 	main.exe!sc_main(int argc, char * * argv) Line 27	C++
 	main.exe!sc_elab_and_sim(int argc, char * * argv) Line 89	C++
 	main.exe!main(int argc, char * * argv) Line 37	C++
 	[External Code]	

simple module:

#include <systemc.h>

#include <iostream>

SC_MODULE(Not1) {
    sc_in<bool> in;
    sc_out<bool> out;
    SC_CTOR(Not1) : in("in"), out("out") {
        SC_METHOD(behaviors);
        sensitive << in;
    }
    void behaviors() {
        out.write(!in);
    }
};

int sc_main (int argc, char* argv[]) {
    sc_signal<bool> in;
    sc_signal<bool> out;
    Not1 notm("not");
    notm.in(in);
    notm.out(out);

    for (unsigned i = 4; i; --i) {
        in = false;
        sc_start(1, SC_NS);
        std::cout << "@" << sc_time_stamp() <<" in = " << in << " out = " << out << "\n";
        in = true;
        sc_start(1, SC_NS);
        std::cout << "@" << sc_time_stamp() <<" in = " << in << " out = " << out << "\n";
    }
    return 0;
 }

 

 

Share this post


Link to post
Share on other sites

@Philipp A Hartmann
Many thanks! That fixed the problem!

@Eyck
The systemc package is available for the conan package manager.
Since conan is a simple python package, it can be installed as

python -m pip install --user conan

I'll create a very simple project to show you how easy it is to use.

Create a conanfile.txt file:

[requires]
systemc/2.3.3
[generators]
cmake
cmake_find_package

Create a simple systemc model, systemc_example.cpp:

#include <systemc.h>

#include <iostream>

SC_MODULE(Not1) {
    sc_in<bool> in;
    sc_out<bool> out;
    SC_CTOR(Not1) : in("in"), out("out") {
        SC_METHOD(behaviors);
        sensitive << in;
    }
    void behaviors() {
        out.write(!in);
    }
};

int sc_main (int argc, char* argv[]) {
    sc_signal<bool> in;
    sc_signal<bool> out;
    Not1 notm("not");
    notm.in(in);
    notm.out(out);

    for (unsigned i = 4; i; --i) {
        in = false;
        sc_start(1, SC_NS);
        std::cout << "@" << sc_time_stamp() <<" in = " << in << " out = " << out << "\n";
        in = true;
        sc_start(1, SC_NS);
        std::cout << "@" << sc_time_stamp() <<" in = " << in << " out = " << out << "\n";
    }
    return 0;
 }

Create a CMakeLists.txt build script:

cmake_minimum_required(VERSION 3.0)
project(systemc_conan)

# Include and run file generated by 'cmake' generator:
# this makes sure your compiler is the same as conan thinks it is
include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
conan_basic_setup(TARGETS)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_BINARY_DIR}")

# Find systemc using the 'cmake_find_package' generator
find_package(SystemC REQUIRED)

add_executable(systemc_example systemc_example.cpp)
target_link_libraries(systemc_example SystemC::SystemC)

Run the following commands to install/download the dependencies and build the project.

mkdir build && cd build
conan install ..
cmake ..

# We can run the example
bin/systemc_example

Installing a dependency using conan, means downloading them and saving them to a path in the user directory.
On Linux, this is ~/.conan/data/systemc/2.3.3/_/_/package.

 

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...