summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2019-03-06 18:03:50 -0800
committerGabe Black <gabeblack@google.com>2019-03-15 18:14:25 +0000
commitb5046b2e512ccf3ffdbba85b169b1adcba6c4443 (patch)
treed5bedb1a6614f185fa3d44bc7efda2ea5858853a
parentb482cff6c3330d1c43d5c8d18d25731f552f02ee (diff)
downloadgem5-b5046b2e512ccf3ffdbba85b169b1adcba6c4443.tar.xz
python: Simplify connectPorts() around EtherObject/EtherDevice.
EtherDevice now inherits EtherObject and shares the same getEthPort virtual function, so there's no need to treat them separately any more. Change-Id: Ia6c147fd97fece4a281c296521a7b095f793d32e Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/17030 Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com> Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
-rw-r--r--src/python/pybind11/pyobject.cc35
1 files changed, 6 insertions, 29 deletions
diff --git a/src/python/pybind11/pyobject.cc b/src/python/pybind11/pyobject.cc
index bb2635ae5..a2da96d3b 100644
--- a/src/python/pybind11/pyobject.cc
+++ b/src/python/pybind11/pyobject.cc
@@ -55,24 +55,6 @@
namespace py = pybind11;
-static EtherInt *
-lookupEthPort(SimObject *so, const std::string &name, int i)
-{
- EtherObject *eo = dynamic_cast<EtherObject *>(so);
- EtherDevice *ed = dynamic_cast<EtherDevice *>(so);
- if (eo == NULL && ed == NULL) {
- warn("error casting SimObject %s", so->name());
- return NULL;
- }
-
- EtherInt *p = NULL;
- if (eo)
- p = eo->getEthPort(name, i);
- else
- p = ed->getEthPort(name, i);
- return p;
-}
-
/**
* Connect the described MemObject ports. Called from Python.
* The indices i1 & i2 will be -1 for regular ports, >= 0 for vector ports.
@@ -82,19 +64,14 @@ static int
connectPorts(SimObject *o1, const std::string &name1, int i1,
SimObject *o2, const std::string &name2, int i2)
{
- EtherObject *eo1, *eo2;
- EtherDevice *ed1, *ed2;
- eo1 = dynamic_cast<EtherObject*>(o1);
- ed1 = dynamic_cast<EtherDevice*>(o1);
- eo2 = dynamic_cast<EtherObject*>(o2);
- ed2 = dynamic_cast<EtherDevice*>(o2);
-
- if ((eo1 || ed1) && (eo2 || ed2)) {
- EtherInt *p1 = lookupEthPort(o1, name1, i1);
- EtherInt *p2 = lookupEthPort(o2, name2, i2);
+ auto *eo1 = dynamic_cast<EtherObject*>(o1);
+ auto *eo2 = dynamic_cast<EtherObject*>(o2);
- if (p1 != NULL && p2 != NULL) {
+ if (eo1 && eo2) {
+ EtherInt *p1 = eo1->getEthPort(name1, i1);
+ EtherInt *p2 = eo2->getEthPort(name2, i2);
+ if (p1 && p2) {
p1->setPeer(p2);
p2->setPeer(p1);