Skip to content

Commit

Permalink
systemc: move tracefile registration into constructor
Browse files Browse the repository at this point in the history
The TraceFile object needs to be registered into the scheduler for
triggering its trace function. For now only the TraceFile created by
sc_create_vcd_trace_file is registered automatically. This design is not
good for users to implement their own TraceFile class.

In addition, some libraries, ex Verilator, implement thier own trace file.
To bridge them into gem5, we also need the ability to create customized
TraceFile class.

Change-Id: I38fe510048655c6a2cd848a0a1263a66a1778eee
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/52923
Reviewed-by: Earl Ou <[email protected]>
Reviewed-by: Gabe Black <[email protected]>
Maintainer: Gabe Black <[email protected]>
Tested-by: kokoro <[email protected]>
  • Loading branch information
wmin0 committed Nov 22, 2021
1 parent cdbeb07 commit 3b5a960
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 1 addition & 6 deletions src/systemc/utils/sc_trace_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

#include <vector>

#include "systemc/core/scheduler.hh"
#include "systemc/ext/channel/sc_signal_in_if.hh"
#include "systemc/ext/core/sc_event.hh"
#include "systemc/ext/core/sc_time.hh"
Expand All @@ -52,16 +51,12 @@ sc_trace_file::~sc_trace_file() {}
sc_trace_file *
sc_create_vcd_trace_file(const char *name)
{
auto tf = new ::sc_gem5::VcdTraceFile(name);
::sc_gem5::scheduler.registerTraceFile(tf);
return tf;
return new ::sc_gem5::VcdTraceFile(name);
}

void
sc_close_vcd_trace_file(sc_trace_file *tf)
{
::sc_gem5::scheduler.unregisterTraceFile(
static_cast<::sc_gem5::TraceFile *>(tf));
delete tf;
}

Expand Down
6 changes: 5 additions & 1 deletion src/systemc/utils/tracefile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <ctime>
#include <iomanip>

#include "systemc/core/scheduler.hh"
#include "systemc/core/time.hh"
#include "systemc/ext/core/sc_main.hh"
#include "systemc/ext/core/sc_time.hh"
Expand All @@ -41,10 +42,13 @@ namespace sc_gem5
TraceFile::TraceFile(const std::string &name) :
_os(gem5::simout.create(name, true, true)), timeUnitTicks(0),
timeUnitValue(0.0), timeUnitUnit(::sc_core::SC_PS), _traceDeltas(false)
{}
{
::sc_gem5::scheduler.registerTraceFile(this);
}

TraceFile::~TraceFile()
{
::sc_gem5::scheduler.unregisterTraceFile(this);
gem5::simout.close(_os);
}

Expand Down

0 comments on commit 3b5a960

Please sign in to comment.