summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2018-10-03 16:17:50 -0700
committerGabe Black <gabeblack@google.com>2018-10-16 00:49:44 +0000
commit8946c9d52fc2d789844586867d047be69651ddd6 (patch)
treec69ec75842f42cacfe8fe7570e6aa000763aa17e /src
parentd45caee43e10c50d837aadc56b385f6340366cae (diff)
downloadgem5-8946c9d52fc2d789844586867d047be69651ddd6.tar.xz
systemc: Change how errors are handled in some constructors slightly.
Because SC_REPORT_ERROR usually causes an exception to be thrown, it's easy to assume it will be the last thing executed in a function. It might, however, be set up to do nothing, in which case the function will continue to execute. This change makes sure sc_prim will be set up properly even if errors about the time a channel can be set up are ignored. Also, if an exception is thrown while sc_port is being set up, the corresponding Port object needs to be cleaned up. Rather than try to intercept exceptions in the constructor and clean up properly, we'll just make the allocation of the Port object be the last thing it does. If the function exits early, then the Port pointer will still be nullptr and nothing will need to be done. Change-Id: If8f6f6b7e6830235fee3cd75625240b99e87dfbe Reviewed-on: https://gem5-review.googlesource.com/c/13289 Reviewed-by: Gabe Black <gabeblack@google.com> Maintainer: Gabe Black <gabeblack@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/systemc/core/sc_port.cc3
-rw-r--r--src/systemc/core/sc_prim.cc12
2 files changed, 8 insertions, 7 deletions
diff --git a/src/systemc/core/sc_port.cc b/src/systemc/core/sc_port.cc
index 3a31e411d..50a67a3b6 100644
--- a/src/systemc/core/sc_port.cc
+++ b/src/systemc/core/sc_port.cc
@@ -56,7 +56,7 @@ reportError(const char *id, const char *add_msg,
}
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))
+ sc_object(n), _gem5Port(nullptr)
{
if (sc_is_running()) {
reportError("(E110) insert port failed", "simulation running",
@@ -74,6 +74,7 @@ sc_port_base::sc_port_base(const char *n, int max_size, sc_port_policy p) :
} else {
m->ports.push_back(this);
}
+ _gem5Port = new ::sc_gem5::Port(this, max_size);
}
sc_port_base::~sc_port_base()
diff --git a/src/systemc/core/sc_prim.cc b/src/systemc/core/sc_prim.cc
index 216bd78f9..099e5d8bf 100644
--- a/src/systemc/core/sc_prim.cc
+++ b/src/systemc/core/sc_prim.cc
@@ -48,12 +48,12 @@ 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()) {
+ }
+ if (::sc_gem5::scheduler.elaborationDone()) {
SC_REPORT_ERROR("(E113) insert primitive channel failed",
"elaboration done");
- } else {
- _gem5_channel = new sc_gem5::Channel(this);
}
+ _gem5_channel = new sc_gem5::Channel(this);
}
sc_prim_channel::sc_prim_channel(const char *_name) :
@@ -62,12 +62,12 @@ sc_prim_channel::sc_prim_channel(const char *_name) :
if (sc_is_running()) {
SC_REPORT_ERROR("(E113) insert primitive channel failed",
"simulation running");
- } else if (::sc_gem5::scheduler.elaborationDone()) {
+ }
+ if (::sc_gem5::scheduler.elaborationDone()) {
SC_REPORT_ERROR("(E113) insert primitive channel failed",
"elaboration done");
- } else {
- _gem5_channel = new sc_gem5::Channel(this);
}
+ _gem5_channel = new sc_gem5::Channel(this);
}
sc_prim_channel::~sc_prim_channel() { delete _gem5_channel; }