From f39a68fcca3643a0bda2ca965c432ad70402fbd9 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Thu, 4 Oct 2018 16:41:32 -0700 Subject: systemc: Fill out some error reporting in sc_port. Rather than just asserting some invariants are true, report errors if they aren't. Change-Id: Id361b8a13011e1a75289ddddb6b41c1d09dbf794 Reviewed-on: https://gem5-review.googlesource.com/c/13296 Reviewed-by: Gabe Black Maintainer: Gabe Black --- src/systemc/core/sc_port.cc | 12 ++++++++++++ src/systemc/ext/core/sc_port.hh | 43 ++++++++++++++++++++++++++++++++--------- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/systemc/core/sc_port.cc b/src/systemc/core/sc_port.cc index 50a67a3b6..60911f8e1 100644 --- a/src/systemc/core/sc_port.cc +++ b/src/systemc/core/sc_port.cc @@ -27,6 +27,8 @@ * Authors: Gabe Black */ +#include + #include "base/logging.hh" #include "systemc/core/module.hh" #include "systemc/core/port.hh" @@ -88,6 +90,16 @@ sc_port_base::warn_unimpl(const char *func) const warn("%s not implemented.\n", func); } +void +sc_port_base::report_error(const char *id, const char *add_msg) const +{ + std::ostringstream ss; + if (add_msg) + ss << add_msg << ": "; + ss << "port '" << name() << "' (" << kind() << ")"; + SC_REPORT_ERROR(id, ss.str().c_str()); +} + int sc_port_base::maxSize() const { return _gem5Port->maxSize(); } int sc_port_base::size() const { return _gem5Port->size(); } diff --git a/src/systemc/ext/core/sc_port.hh b/src/systemc/ext/core/sc_port.hh index 904d35b8e..915b11f08 100644 --- a/src/systemc/ext/core/sc_port.hh +++ b/src/systemc/ext/core/sc_port.hh @@ -101,6 +101,8 @@ class sc_port_base : public sc_object virtual void start_of_simulation() = 0; virtual void end_of_simulation() = 0; + void report_error(const char *id, const char *add_msg) const; + private: friend class ::sc_gem5::Port; friend class ::sc_gem5::Kernel; @@ -125,39 +127,53 @@ class sc_port_b : public sc_port_base IF * operator -> () { - sc_assert(!_interfaces.empty()); + if (_interfaces.empty()) { + report_error("(E112) get interface failed", "port is not bound"); + sc_abort(); + } return _interfaces[0]; } const IF * operator -> () const { - sc_assert(!_interfaces.empty()); + if (_interfaces.empty()) { + report_error("(E112) get interface failed", "port is not bound"); + sc_abort(); + } return _interfaces[0]; } IF * operator [] (int n) { - sc_assert(_interfaces.size() > n); + if (n < 0 || n >= size()) { + report_error("(E112) get interface failed", "index out of range"); + return NULL; + } return _interfaces[n]; } const IF * operator [] (int n) const { - sc_assert(_interfaces.size() > n); + if (n < 0 || n >= size()) { + report_error("(E112) get interface failed", "index out of range"); + return NULL; + } return _interfaces[n]; } sc_interface * get_interface() { - sc_assert(!_interfaces.empty()); + if (_interfaces.empty()) + return NULL; return _interfaces[0]; } const sc_interface * get_interface() const { - sc_assert(!_interfaces.empty()); + if (_interfaces.empty()) + return NULL; return _interfaces[0]; } @@ -201,14 +217,23 @@ class sc_port_b : public sc_port_base sc_interface * _gem5Interface(int n) const { - sc_assert(_interfaces.size() > n); + if (n < 0 || n >= size()) { + report_error("(E112) get interface failed", "index out of range"); + return NULL; + } return _interfaces[n]; } void - _gem5AddInterface(sc_interface *i) + _gem5AddInterface(sc_interface *iface) { - IF *interface = dynamic_cast(i); + IF *interface = dynamic_cast(iface); sc_assert(interface); + for (int i = 0; i < _interfaces.size(); i++) { + if (interface == _interfaces[i]) { + report_error("(E107) bind interface to port failed", + "interface already bound to port"); + } + } _interfaces.push_back(interface); } -- cgit v1.2.3