Skip to content

Commit

Permalink
Added changes to prepare for systemc 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
janweinstock committed Jan 6, 2024
1 parent 7bd7a43 commit 303af41
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
fail-fast: false
matrix:
systemc: [2.3.0a, 2.3.1a, 2.3.2, 2.3.3]
systemc: [2.3.0a, 2.3.1a, 2.3.2, 2.3.3, 2.3.4]
os: [ubuntu-20.04, ubuntu-22.04]
include:
- systemc: 2.3.3
Expand Down
2 changes: 2 additions & 0 deletions include/vcml/core/systemc.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#define SYSTEMC_VERSION_2_3_1a 20140417 // NOLINT
#define SYSTEMC_VERSION_2_3_2 20171012 // NOLINT
#define SYSTEMC_VERSION_2_3_3 20181013 // NOLINT
#define SYSTEMC_VERSION_2_3_4 20221128 // NOLINT
#define SYSTEMC_VERSION_3_0_0 20231124 // NOLINT

#if SYSTEMC_VERSION < SYSTEMC_VERSION_2_3_1a
inline sc_core::sc_time operator%(const sc_core::sc_time& t1,
Expand Down
58 changes: 51 additions & 7 deletions src/vcml/core/systemc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,21 @@ void hierarchy_push(sc_module* mod) {
sc_module* hierarchy_pop() {
sc_simcontext* simc = sc_get_curr_simcontext();
VCML_ERROR_ON(!simc, "no simulation context");
#if SYSTEMC_VERSION < SYSTEMC_VERSION_3_0_0
return simc->hierarchy_pop();
#else
return dynamic_cast<sc_module*>(simc->hierarchy_pop());
#endif
}

sc_module* hierarchy_top() {
sc_simcontext* simc = sc_get_curr_simcontext();
VCML_ERROR_ON(!simc, "no simulation context");
#if SYSTEMC_VERSION < SYSTEMC_VERSION_3_0_0
return simc->hierarchy_curr();
#else
return dynamic_cast<sc_module*>(simc->active_object());
#endif
}

bool is_parent(const sc_object* obj, const sc_object* child) {
Expand Down Expand Up @@ -172,7 +180,8 @@ string tlm_transaction_to_str(const tlm_generic_payload& tx) {
return ss.str();
}

#if SYSTEMC_VERSION >= SYSTEMC_VERSION_2_3_1a
#if SYSTEMC_VERSION >= SYSTEMC_VERSION_2_3_1a && \
SYSTEMC_VERSION < SYSTEMC_VERSION_3_0_0
static inline bool test_kernel_has_phase_callbacks() {
class callbacks_tester : public sc_object
{
Expand Down Expand Up @@ -203,16 +212,20 @@ static inline bool test_kernel_has_phase_callbacks() {
#endif

bool kernel_has_phase_callbacks() {
#if SYSTEMC_VERSION < SYSTEMC_VERSION_2_3_1a
#if SYSTEMC_VERSION >= SYSTEMC_VERSION_3_0_0
return true;
#elif SYSTEMC_VERSION < SYSTEMC_VERSION_2_3_1a
return false;
#else
static bool has_callbacks = test_kernel_has_phase_callbacks();
return has_callbacks;
#endif
}

// we just need this class to have something that is called every cycle...
class helper_module : public sc_core::sc_trace_file,
#if SYSTEMC_VERSION >= SYSTEMC_VERSION_3_0_0
public sc_core::sc_stage_callback_if,
#endif
public sc_core::sc_prim_channel
{
public:
Expand Down Expand Up @@ -359,6 +372,9 @@ class helper_module : public sc_core::sc_trace_file,

helper_module(const char* nm):
sc_core::sc_trace_file(),
#if SYSTEMC_VERSION >= SYSTEMC_VERSION_3_0_0
sc_core::sc_stage_callback_if(),
#endif
sc_core::sc_prim_channel(nm),
sim_running(true),
use_phase_callbacks(kernel_has_phase_callbacks()),
Expand All @@ -370,14 +386,22 @@ class helper_module : public sc_core::sc_trace_file,
tsteps(),
timeout_event("timeout_ev"),
timers() {
#if SYSTEMC_VERSION >= SYSTEMC_VERSION_2_3_1a
#if SYSTEMC_VERSION >= SYSTEMC_VERSION_2_3_1a && \
SYSTEMC_VERSION < SYSTEMC_VERSION_3_0_0
if (use_phase_callbacks) {
register_simulation_phase_callback(sc_core::SC_END_OF_UPDATE |
sc_core::SC_BEFORE_TIMESTEP);
}
#endif
#if SYSTEMC_VERSION < SYSTEMC_VERSION_3_0_0
if (!use_phase_callbacks)
simcontext()->add_trace_file(this);
#endif

#if SYSTEMC_VERSION >= SYSTEMC_VERSION_3_0_0
sc_core::sc_register_stage_callback(
*this, sc_core::SC_POST_UPDATE | sc_core::SC_PRE_TIMESTEP);
#endif

sc_spawn_options opts;
opts.spawn_method();
Expand All @@ -386,7 +410,8 @@ class helper_module : public sc_core::sc_trace_file,
sc_spawn([&]() -> void { run_timer(); }, "$$$$vcml_timer$$$$", &opts);
}

#if SYSTEMC_VERSION >= SYSTEMC_VERSION_2_3_1a
#if SYSTEMC_VERSION >= SYSTEMC_VERSION_2_3_1a && \
SYSTEMC_VERSION < SYSTEMC_VERSION_3_0_0
virtual void simulation_phase_callback() override {
switch (simcontext()->get_status()) {
case sc_core::SC_END_OF_UPDATE:
Expand All @@ -396,16 +421,35 @@ class helper_module : public sc_core::sc_trace_file,
cycle(false);
break;

default:
break;
}
}
#elif SYSTEMC_VERSION >= SYSTEMC_VERSION_3_0_0
virtual void stage_callback(const sc_core::sc_stage& stage) override {
switch (stage) {
case sc_core::SC_POST_UPDATE:
cycle(true);
break;
case sc_core::SC_PRE_TIMESTEP:
cycle(false);
break;

default:
break;
}
}
#endif

virtual ~helper_module() {
#if SYSTEMC_VERSION >= SYSTEMC_VERSION_2_3_1a
#if SYSTEMC_VERSION >= SYSTEMC_VERSION_2_3_1a && \
SYSTEMC_VERSION < SYSTEMC_VERSION_3_0_0
if (!use_phase_callbacks)
sc_get_curr_simcontext()->remove_trace_file(this);
#endif
#if SYSTEMC_VERSION >= SYSTEMC_VERSION_3_0_0
sc_core::sc_unregister_stage_callback(
*this, sc_core::SC_POST_UPDATE | sc_core::SC_PRE_TIMESTEP);
#endif
while (!timers.empty()) {
delete timers.top();
Expand Down Expand Up @@ -746,7 +790,7 @@ string call_origin() {
return parent ? parent->name() : proc->name();
}

sc_module* module = simc->hierarchy_curr();
sc_module* module = hierarchy_top();
if (module)
return module->name();
}
Expand Down
55 changes: 34 additions & 21 deletions utils/setup-systemc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

root="$(cd $(dirname $(dirname ${BASH_SOURCE[0]} )) &>/dev/null && pwd)"

url="https://www.accellera.org/images/downloads/standards/systemc"

prefix=$PWD
version=2.3.3
debug=no
Expand All @@ -40,24 +38,27 @@ while [[ "$#" -gt 0 ]]; do
shift
done

case $version in
2.3.0a);;
2.3.1a);;
2.3.2);;
2.3.3);;
*) echo "Unknown SystemC version: $version"; exit 1;;
esac

mkdir -p $prefix

prefix=$(realpath $prefix)
home=$prefix/systemc/$version
build=$home/BUILD
src=systemc-$version
flags="--enable-static --disable-shared"
aconf_flags="--enable-static --disable-shared"
cmake_flags="-DBUILD_SHARED_LIBS=OFF"

mkdir -p $prefix

case $version in
2.3.0a) url=https://www.accellera.org/images/downloads/standards/systemc/$src.tar.gz;;
2.3.1a) url=https://www.accellera.org/images/downloads/standards/systemc/$src.tar.gz;;
2.3.2) url=https://www.accellera.org/images/downloads/standards/systemc/$src.tar.gz;;
2.3.3) url=https://www.accellera.org/images/downloads/standards/systemc/$src.tar.gz;;
2.3.4) url=https://github.com/accellera-official/systemc/archive/refs/tags/2.3.4.tar.gz;;
*) echo "Unknown SystemC version: $version"; exit 1;;
esac

echo ""
echo "+----------------------------------------------------------------------"
echo "| source: " $url
echo "| prefix: " $prefix
echo "| build: " $build
echo "| version: " $version
Expand All @@ -67,15 +68,23 @@ echo "+----------------------------------------------------------------------"
echo ""

if [ $debug == "yes" ]; then
flags+=" --enable-debug"
aconf_flags+=" --enable-debug"
cmake_build="DEBUG"
else
flags+=" --disable-debug"
aconf_flags+=" --disable-debug"
cmake_build="RELEASE"
fi

if [ $optimize == "yes" ]; then
flags+=" --enable-optimize"
aconf_flags+=" --enable-optimize"
cmake_build="RELEASE"
else
flags+=" --disable-optimize"
aconf_flags+=" --disable-optimize"
cmake_build="DEBUG"
fi

if [ $optimize == "yes" ] && [ $debug == "yes" ]; then
cmake_build="RelWithDebInfo"
fi

if [ -n "$(find /usr/include -name 'valgrind.h' 2>/dev/null)" ]; then
Expand All @@ -85,18 +94,22 @@ fi
mkdir -p $home && cd $home

if [ ! -d $src ]; then
test -f $src.tar.gz || curl -O $url/$src.tar.gz
tar -xzf $src.tar.gz
test -f $(basename $url) || wget $url
tar -xzf $(basename $url)

for p in $(ls $root/patches/systemc-$version-*.patch); do
for p in $(ls $root/patches/systemc-$version-*.patch 2>/dev/null); do
echo "applying $p"
(cd $src && patch -p1 <$p)
done
fi

if [ ! -d $build ]; then
mkdir -p $build && cd $build
../$src/configure --prefix=$home $flags
if [ -f ../$src/CMakeLists.txt ]; then
cmake -DCMAKE_INSTALL_PREFIX=$home -DCMAKE_BUILD_TYPE=$cmake_build ../$src
else
../$src/configure --prefix=$home $flags
fi
fi

make -C $build -j $(nproc)
Expand Down

0 comments on commit 303af41

Please sign in to comment.