systemc: Add some additional error checks.

Change-Id: I19c5e6f1795c2777dbe7d210cfa01f6ced2020f3
Reviewed-on: https://gem5-review.googlesource.com/c/12815
Reviewed-by: Gabe Black <gabeblack@google.com>
Maintainer: Gabe Black <gabeblack@google.com>
This commit is contained in:
Gabe Black
2018-09-15 16:04:34 -07:00
parent 56b5284bee
commit 170b9f90c2
4 changed files with 45 additions and 15 deletions

View File

@@ -58,17 +58,17 @@ sc_export_base::sc_export_base(const char *n) : sc_object(n)
{
if (sc_is_running()) {
reportError("(E121) insert sc_export failed", "simulation running",
n, kind());
name(), kind());
}
if (::sc_gem5::scheduler.elaborationDone()) {
reportError("(E121) insert sc_export failed", "elaboration done",
n, kind());
name(), kind());
}
::sc_gem5::Module *m = ::sc_gem5::currentModule();
if (!m) {
reportError("(E122) sc_export specified outside of module",
nullptr, n, kind());
nullptr, name(), kind());
} else {
m->exports.push_back(this);
}

View File

@@ -30,14 +30,24 @@
#include "base/logging.hh"
#include "systemc/core/module.hh"
#include "systemc/core/scheduler.hh"
#include "systemc/ext/core/sc_main.hh"
#include "systemc/ext/core/sc_module_name.hh"
#include "systemc/ext/utils/sc_report_handler.hh"
namespace sc_core
{
sc_module_name::sc_module_name(const char *name) :
_name(name), _gem5_module(new sc_gem5::Module(name)), _on_the_stack(true)
{}
_name(name), _gem5_module(nullptr), _on_the_stack(true)
{
if (sc_is_running())
SC_REPORT_ERROR("(E529) insert module failed", "simulation running");
else if (::sc_gem5::scheduler.elaborationDone())
SC_REPORT_ERROR("(E529) insert module failed", "elaboration done");
else
_gem5_module = new sc_gem5::Module(name);
}
sc_module_name::sc_module_name(const sc_module_name &other) :
_name(other._name), _gem5_module(other._gem5_module), _on_the_stack(false)

View File

@@ -55,22 +55,22 @@ reportError(const char *id, const char *add_msg,
}
sc_port_base::sc_port_base(const char *name, int n, sc_port_policy p) :
sc_object(name), _gem5Port(new ::sc_gem5::Port(this, n))
sc_port_base::sc_port_base(const char *n, int max_size, sc_port_policy p) :
sc_object(n), _gem5Port(new ::sc_gem5::Port(this, max_size))
{
if (sc_is_running()) {
reportError("(E110) insert port failed", "simulation running",
name, kind());
name(), kind());
}
if (::sc_gem5::scheduler.elaborationDone()) {
reportError("(E110) insert port failed", "elaboration done",
name, kind());
name(), kind());
}
::sc_gem5::Module *m = ::sc_gem5::currentModule();
if (!m) {
reportError("(E100) port specified outside of module",
nullptr, name, kind());
nullptr, name(), kind());
} else {
m->ports.push_back(this);
}

View File

@@ -30,6 +30,7 @@
#include "base/logging.hh"
#include "systemc/core/channel.hh"
#include "systemc/core/scheduler.hh"
#include "systemc/ext/core/sc_main.hh"
#include "systemc/ext/core/sc_prim.hh"
namespace sc_gem5
@@ -42,13 +43,32 @@ uint64_t getChangeStamp() { return scheduler.changeStamp(); }
namespace sc_core
{
sc_prim_channel::sc_prim_channel() :
_gem5_channel(new sc_gem5::Channel(this))
{}
sc_prim_channel::sc_prim_channel() : _gem5_channel(nullptr)
{
if (sc_is_running()) {
SC_REPORT_ERROR("(E113) insert primitive channel failed",
"simulation running");
} else if (::sc_gem5::scheduler.elaborationDone()) {
SC_REPORT_ERROR("(E113) insert primitive channel failed",
"elaboration done");
} else {
_gem5_channel = new sc_gem5::Channel(this);
}
}
sc_prim_channel::sc_prim_channel(const char *_name) :
sc_object(_name), _gem5_channel(new sc_gem5::Channel(this))
{}
sc_object(_name), _gem5_channel(nullptr)
{
if (sc_is_running()) {
SC_REPORT_ERROR("(E113) insert primitive channel failed",
"simulation running");
} else if (::sc_gem5::scheduler.elaborationDone()) {
SC_REPORT_ERROR("(E113) insert primitive channel failed",
"elaboration done");
} else {
_gem5_channel = new sc_gem5::Channel(this);
}
}
sc_prim_channel::~sc_prim_channel() { delete _gem5_channel; }