Gabe Black has submitted this change and it was merged. (
https://gem5-review.googlesource.com/c/public/gem5/+/12262 )
Change subject: systemc: Use sc_assert to check the number of interfaces.
......................................................................
systemc: Use sc_assert to check the number of interfaces.
The sc_port code had been using the .at() function of the vector class,
but when that failed it threw an exception, and it was very difficult
to tell where the exception came from from how gem5 crashed. This
change switches to sc_assert (the systemc version of assert) which
makes the cause/location of failures much more obvious.
Change-Id: I1cd51c86f47b314be551c304b014c44cfa030175
Reviewed-on: https://gem5-review.googlesource.com/12262
Reviewed-by: Gabe Black <[email protected]>
Maintainer: Gabe Black <[email protected]>
---
M src/systemc/ext/core/sc_port.hh
1 file changed, 42 insertions(+), 7 deletions(-)
Approvals:
Gabe Black: Looks good to me, approved; Looks good to me, approved
diff --git a/src/systemc/ext/core/sc_port.hh
b/src/systemc/ext/core/sc_port.hh
index 73f5362..f9e50da 100644
--- a/src/systemc/ext/core/sc_port.hh
+++ b/src/systemc/ext/core/sc_port.hh
@@ -105,14 +105,44 @@
virtual void bind(IF &i) { sc_port_base::bind(i); }
virtual void bind(sc_port_b<IF> &p) { sc_port_base::bind(p); }
- IF *operator -> () { return _interfaces.at(0); }
- const IF *operator -> () const { return _interfaces.at(0); }
+ IF *
+ operator -> ()
+ {
+ sc_assert(!_interfaces.empty());
+ return _interfaces[0];
+ }
+ const IF *
+ operator -> () const
+ {
+ sc_assert(!_interfaces.empty());
+ return _interfaces[0];
+ }
- IF *operator [] (int n) { return _interfaces.at(n); }
- const IF *operator [] (int n) const { return _interfaces.at(n); }
+ IF *
+ operator [] (int n)
+ {
+ sc_assert(_interfaces.size() > n);
+ return _interfaces[n];
+ }
+ const IF *
+ operator [] (int n) const
+ {
+ sc_assert(_interfaces.size() > n);
+ return _interfaces[n];
+ }
- sc_interface *get_interface() { return _interfaces.at(0); }
- const sc_interface *get_interface() const { return _interfaces.at(0); }
+ sc_interface *
+ get_interface()
+ {
+ sc_assert(!_interfaces.empty());
+ return _interfaces[0];
+ }
+ const sc_interface *
+ get_interface() const
+ {
+ sc_assert(!_interfaces.empty());
+ return _interfaces[0];
+ }
protected:
void before_end_of_elaboration() {}
@@ -151,7 +181,12 @@
private:
std::vector<IF *> _interfaces;
- sc_interface *_gem5Interface(int n) const { return _interfaces.at(n); }
+ sc_interface *
+ _gem5Interface(int n) const
+ {
+ sc_assert(_interfaces.size() > n);
+ return _interfaces[n];
+ }
void
_gem5AddInterface(sc_interface *i)
{
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/12262
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I1cd51c86f47b314be551c304b014c44cfa030175
Gerrit-Change-Number: 12262
Gerrit-PatchSet: 8
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Giacomo Travaglini <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Matthias Jung <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev