From: Gabe Black Date: Sat, 15 Sep 2018 23:04:34 +0000 (-0700) Subject: systemc: Add some additional error checks. X-Git-Tag: v19.0.0.0~1581 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=170b9f90c2d2b40114da8b95fd0a2562013353cf;p=gem5.git systemc: Add some additional error checks. Change-Id: I19c5e6f1795c2777dbe7d210cfa01f6ced2020f3 Reviewed-on: https://gem5-review.googlesource.com/c/12815 Reviewed-by: Gabe Black Maintainer: Gabe Black --- diff --git a/src/systemc/core/sc_export.cc b/src/systemc/core/sc_export.cc index 252f8c0ff..0524ca8dc 100644 --- a/src/systemc/core/sc_export.cc +++ b/src/systemc/core/sc_export.cc @@ -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); } diff --git a/src/systemc/core/sc_module_name.cc b/src/systemc/core/sc_module_name.cc index ca568e2ad..c18c0f9b8 100644 --- a/src/systemc/core/sc_module_name.cc +++ b/src/systemc/core/sc_module_name.cc @@ -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) diff --git a/src/systemc/core/sc_port.cc b/src/systemc/core/sc_port.cc index 52f66b70d..ddfe39ff5 100644 --- a/src/systemc/core/sc_port.cc +++ b/src/systemc/core/sc_port.cc @@ -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); } diff --git a/src/systemc/core/sc_prim.cc b/src/systemc/core/sc_prim.cc index 0f4410161..216bd78f9 100644 --- a/src/systemc/core/sc_prim.cc +++ b/src/systemc/core/sc_prim.cc @@ -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; }