diff --git a/sparta/sparta/ports/Port.hpp b/sparta/sparta/ports/Port.hpp index add667857d..8f09c8b2dc 100644 --- a/sparta/sparta/ports/Port.hpp +++ b/sparta/sparta/ports/Port.hpp @@ -127,6 +127,14 @@ namespace sparta return (bound_ports_.empty() == false); } + /** + * \brief How many ports are bound to this port? + * \return The number of bound ports + */ + size_t getNumBoundPorts() const { + return bound_ports_.size(); + } + /** * \brief The direction of the port * \return In or out diff --git a/sparta/sparta/utils/FastList.hpp b/sparta/sparta/utils/FastList.hpp index c74c45382c..37292da37b 100644 --- a/sparta/sparta/utils/FastList.hpp +++ b/sparta/sparta/utils/FastList.hpp @@ -189,6 +189,8 @@ namespace sparta::utils */ FastList(size_t size) { + sparta_assert(size != 0, + "Cannot create a sparta::utils::FastList of size 0"); int node_idx = 0; nodes_.reserve(size); for(size_t i = 0; i < size; ++i) { diff --git a/sparta/test/FastList/FastList_test.cpp b/sparta/test/FastList/FastList_test.cpp index 2e7f55c2ea..f3ffa71877 100644 --- a/sparta/test/FastList/FastList_test.cpp +++ b/sparta/test/FastList/FastList_test.cpp @@ -42,6 +42,9 @@ std::ostream & operator<<(std::ostream & os, const MyObj & obj) { void testFastList() { + + EXPECT_THROW(sparta::utils::FastList zero_fl(0)); + sparta::utils::FastList fl(10); std::cout << fl; diff --git a/sparta/test/Port/Port_test.cpp b/sparta/test/Port/Port_test.cpp index 1fb34339a5..5c028d2e58 100644 --- a/sparta/test/Port/Port_test.cpp +++ b/sparta/test/Port/Port_test.cpp @@ -105,6 +105,11 @@ int main () signal_out.bind(signal_in); delay1_out_non_continuing.bind(delay1_in_non_continuing); + EXPECT_EQUAL(delay0_out.getNumBoundPorts(), 1); + EXPECT_EQUAL(delay0_in.getNumBoundPorts(), 1); + EXPECT_EQUAL(signal_out.getNumBoundPorts(), 1); + EXPECT_EQUAL(signal_in.getNumBoundPorts(), 1); + // Try some binding rules sparta::SignalInPort signal_bind_in(&ps, "signal_bind_in"); sparta::SignalOutPort signal_bind_out(&ps, "signal_bind_out");