From 648b45c83072e5cb93eea804f24ca10af3ffa545 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Sat, 22 Sep 2018 05:34:37 -0700 Subject: systemc: Add some error checks to sc_export. Change-Id: Ib0c14a5c7dad37b33d61c9b406f6b84121d94e46 Reviewed-on: https://gem5-review.googlesource.com/c/12965 Reviewed-by: Gabe Black Maintainer: Gabe Black --- src/systemc/ext/core/sc_export.hh | 50 +++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 5 deletions(-) (limited to 'src/systemc/ext/core') diff --git a/src/systemc/ext/core/sc_export.hh b/src/systemc/ext/core/sc_export.hh index e8bf0d911..e36e34ae9 100644 --- a/src/systemc/ext/core/sc_export.hh +++ b/src/systemc/ext/core/sc_export.hh @@ -30,6 +30,7 @@ #ifndef __SYSTEMC_EXT_CORE_SC_EXPORT_HH__ #define __SYSTEMC_EXT_CORE_SC_EXPORT_HH__ +#include "../utils/sc_report_handler.hh" #include "sc_module.hh" // for sc_gen_unique_name #include "sc_object.hh" @@ -71,19 +72,58 @@ class sc_export : public sc_export_base virtual const char *kind() const { return "sc_export"; } void operator () (IF &i) { bind(i); } - virtual void bind(IF &i) { interface = &i; } - operator IF & () { return *interface; } + virtual void + bind(IF &i) + { + if (interface) { + SC_REPORT_ERROR("(E126) sc_export instance already bound", name()); + return; + } + interface = &i; + } + operator IF & () + { + if (!interface) { + SC_REPORT_ERROR("(E120) sc_export instance has no interface", + name()); + } + return *interface; + } operator const IF & () const { return *interface; } - IF *operator -> () { return interface; } - const IF *operator -> () const { return interface; } + IF * + operator -> () + { + if (!interface) { + SC_REPORT_ERROR("(E120) sc_export instance has no interface", + name()); + } + return interface; + } + const IF * + operator -> () const + { + if (!interface) { + SC_REPORT_ERROR("(E120) sc_export instance has no interface", + name()); + } + return interface; + } sc_interface *get_iterface() override { return interface; } const sc_interface *get_interface() const override { return interface; } protected: void before_end_of_elaboration() {} - void end_of_elaboration() {} + void + end_of_elaboration() + { + if (!interface) { + std::string msg = "export not bound: export '"; + msg = msg + name() + "' (" + kind() + ")"; + SC_REPORT_ERROR("(E109) complete binding failed", msg.c_str()); + } + } void start_of_simulation() {} void end_of_simulation() {} -- cgit v1.2.3