systemc: Implement port binding policies.
authorGabe Black <gabeblack@google.com>
Fri, 5 Oct 2018 00:46:55 +0000 (17:46 -0700)
committerGabe Black <gabeblack@google.com>
Tue, 16 Oct 2018 00:55:15 +0000 (00:55 +0000)
Change-Id: I585e34c4a666103af16ff1675701b61122822b55
Reviewed-on: https://gem5-review.googlesource.com/c/13299
Reviewed-by: Gabe Black <gabeblack@google.com>
Maintainer: Gabe Black <gabeblack@google.com>

src/systemc/core/port.cc
src/systemc/ext/core/sc_port.hh
src/systemc/tests/systemc/communication/sc_port_policy/test03/expected_returncode [new file with mode: 0644]
src/systemc/tests/systemc/communication/sc_port_policy/test04/expected_returncode [new file with mode: 0644]

index b7120efa435843cd7fa433c8b07e1a10787056d9..c1d77d9d0e743c80e68f5cb6b1ed7cad97eeec3e 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "systemc/core/port.hh"
 
+#include "base/logging.hh"
 #include "systemc/core/process.hh"
 #include "systemc/core/sensitivity.hh"
 #include "systemc/ext/channel/sc_signal_in_if.hh"
@@ -123,6 +124,27 @@ Port::finalize()
         finalizeReset(r);
 
     resets.clear();
+
+    switch (portBase->_portPolicy()) {
+      case sc_core::SC_ONE_OR_MORE_BOUND:
+        if (size() == 0)
+            portBase->report_error(
+                    "(E109) complete binding failed", "port not bound");
+        break;
+      case sc_core::SC_ALL_BOUND:
+        if (size() < maxSize() || size() < 1) {
+            std::stringstream ss;
+            ss << size() << " actual binds is less than required " <<
+                maxSize();
+            portBase->report_error(
+                    "(E109) complete binding failed", ss.str().c_str());
+        }
+        break;
+      case sc_core::SC_ZERO_OR_MORE_BOUND:
+        break;
+      default:
+        panic("Unrecognized port policy %d.", portBase->_portPolicy());
+    }
 }
 
 void
index 915b11f0883d9a0d489f30939c9917f8f29b4602..aa9a322b8ee3c6981df8e1fc2975f49fda2fe802 100644 (file)
@@ -112,6 +112,7 @@ class sc_port_base : public sc_object
 
     ::sc_gem5::Port *_gem5Port;
     virtual const char *_ifTypeName() const = 0;
+    virtual sc_port_policy _portPolicy() const = 0;
 };
 
 template <class IF>
@@ -299,6 +300,8 @@ class sc_port : public sc_port_b<IF>
     // Disabled
     sc_port(const sc_port<IF, N, P> &) {}
     sc_port<IF, N, P> &operator = (const sc_port<IF, N, P> &) { return *this; }
+
+    virtual sc_port_policy _portPolicy() const { return P; }
 };
 
 } // namespace sc_core
diff --git a/src/systemc/tests/systemc/communication/sc_port_policy/test03/expected_returncode b/src/systemc/tests/systemc/communication/sc_port_policy/test03/expected_returncode
new file mode 100644 (file)
index 0000000..d00491f
--- /dev/null
@@ -0,0 +1 @@
+1
diff --git a/src/systemc/tests/systemc/communication/sc_port_policy/test04/expected_returncode b/src/systemc/tests/systemc/communication/sc_port_policy/test04/expected_returncode
new file mode 100644 (file)
index 0000000..d00491f
--- /dev/null
@@ -0,0 +1 @@
+1