Skip to content

Commit

Permalink
Change std::map to std::vector for module declarations.
Browse files Browse the repository at this point in the history
  • Loading branch information
rmrf committed Dec 16, 2019
1 parent ec95e87 commit e3fd372
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Model::~Model() {
Model::Model(const Model &from) { modules_ = from.modules_; }

void Model::addModuleDecl(ModuleDecl *md) {
modules_.insert(Model::modulePairType(md->getName(), md));
modules_.push_back(Model::modulePairType(md->getName(), md));
}

void Model::addModuleDeclInstances(ModuleDecl *md, vector<ModuleDecl *> mdVec) {
Expand Down
2 changes: 1 addition & 1 deletion src/Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ using namespace std;
class Model {
public:
typedef pair<string, ModuleDecl *> modulePairType;
typedef multimap<string, ModuleDecl *> moduleMapType;
typedef std::vector< modulePairType > moduleMapType;

typedef pair<string, EventContainer *> eventPairType;
typedef map<string, EventContainer *> eventMapType;
Expand Down
38 changes: 32 additions & 6 deletions tests/sreg-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,37 @@ TEST_CASE("sreg example",
SECTION("Found sc_modules", "[modules]") {
INFO( "ERROR: number of sc_module declarations found: " << module_decl.size() );
CHECK(module_decl.size() == 5);
REQUIRE(module_decl.find("test") != module_decl.end() );
REQUIRE(module_decl.find("sreg") != module_decl.end() );
auto test_module{
std::find_if(
module_decl.begin(), module_decl.end(),
[](const auto &element) { return element.first == "test"; })};

auto sreg_module{
std::find_if(
module_decl.begin(), module_decl.end(),
[](const auto &element) { return element.first == "sreg"; })};
REQUIRE(test_module != module_decl.end() );
REQUIRE(sreg_module != module_decl.end() );
}

SECTION("Found sreg instances", "[instances]") {
auto module_instances{model->getModuleInstanceMap()};
auto p_module{module_decl.find("sreg")};
//auto p_module{module_decl.find("sreg")};
auto p_module{
std::find_if(
module_decl.begin(), module_decl.end(),
[](const auto &element) { return element.first == "sreg"; })};
REQUIRE(module_instances[p_module->second].size() == 3);
}

SECTION("Checking sreg_bypass ports", "[ports]") {
auto module_instances{model->getModuleInstanceMap()};
auto p_module{module_decl.find("sreg")};
//auto p_module{module_decl.find("sreg")};
auto p_module{
std::find_if(
module_decl.begin(), module_decl.end(),
[](const auto &element) { return element.first == "sreg"; })};

auto sreg_bypass{module_instances[p_module->second][0]};

REQUIRE(sreg_bypass->getIPorts().size() == 2);
Expand All @@ -66,7 +84,11 @@ TEST_CASE("sreg example",

SECTION("Checking sreg_fwd ports", "[ports]") {
auto module_instances{model->getModuleInstanceMap()};
auto p_module{module_decl.find("sreg")};
//auto p_module{module_decl.find("sreg")};
auto p_module{
std::find_if(
module_decl.begin(), module_decl.end(),
[](const auto &element) { return element.first == "sreg"; })};
auto sreg_fwd{module_instances[p_module->second][1]};

REQUIRE(sreg_fwd->getIPorts().size() == 2);
Expand All @@ -80,7 +102,11 @@ TEST_CASE("sreg example",

SECTION("Checking sreg_fwd_rev ports", "[ports]") {
auto module_instances{model->getModuleInstanceMap()};
auto p_module{module_decl.find("sreg")};
//auto p_module{module_decl.find("sreg")};
auto p_module{
std::find_if(
module_decl.begin(), module_decl.end(),
[](const auto &element) { return element.first == "sreg"; })};
auto sreg_fwd_rev{module_instances[p_module->second][2]};

REQUIRE(sreg_fwd_rev->getIPorts().size() == 2);
Expand Down
26 changes: 22 additions & 4 deletions tests/t1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,17 @@ int sc_main(int argc, char *argv[]) {
REQUIRE(module_decl.size() == 2);

// Check their names, and that their pointers are not nullptr.
REQUIRE(module_decl.find("test") != module_decl.end() );
REQUIRE(module_decl.find("simple_module") != module_decl.end() );

auto test_module{
std::find_if(
module_decl.begin(), module_decl.end(),
[](const auto &element) { return element.first == "test"; })};
REQUIRE(test_module != module_decl.end() );
auto simple_module{
std::find_if(
module_decl.begin(), module_decl.end(),
[](const auto &element) { return element.first == "simple_module"; })};
REQUIRE(simple_module != module_decl.end() );

SECTION("Checking member ports for test instance", "[ports]") {
// These checks should be performed on the declarations.
Expand All @@ -114,7 +123,12 @@ int sc_main(int argc, char *argv[]) {
// This is necessary until the parsing code is restructured.
// There is only one module instance
auto module_instances{model->getModuleInstanceMap()};
auto p_module{module_decl.find("test")};
//auto p_module{module_decl.find("test")};

auto p_module{
std::find_if(
module_decl.begin(), module_decl.end(),
[](const auto &element) { return element.first == "test"; })};
auto test_module{module_instances[p_module->second].front()};

// Check if the proper number of ports are found.
Expand All @@ -129,7 +143,11 @@ int sc_main(int argc, char *argv[]) {

SECTION("Checking member ports for simple module instance", "[ports]") {
auto module_instances{model->getModuleInstanceMap()};
auto p_module{module_decl.find("simple_module")};
// auto p_module{module_decl.find("simple_module")};
auto p_module{
std::find_if(
module_decl.begin(), module_decl.end(),
[](const auto &element) { return element.first == "simple_module"; })};
auto test_module{module_instances[p_module->second].front()};

// Check if the proper number of ports are found.
Expand Down
7 changes: 6 additions & 1 deletion tests/t2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ int sc_main(int argc, char *argv[]) {

SECTION("No ports bound for test declaration", "[ports]") {
// The module instances have all the information.
auto test_module{module_decl.find("test")};
//auto test_module{module_decl.find("test")};

auto test_module{
std::find_if(
module_decl.begin(), module_decl.end(),
[](const auto &element) { return element.first == "test"; })};
// There is only one module instance

// Check if the proper number of ports are found.
Expand Down
8 changes: 6 additions & 2 deletions tests/t3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ TEST_CASE("Read SystemC model from file for testing", "[parsing]") {

SECTION("No ports bound for test declaration", "[ports]") {
// The module instances have all the information.
auto test_module{module_decl.find("test")};
//auto test_module{module_decl.find("test")};
auto test_module{
std::find_if(
module_decl.begin(), module_decl.end(),
[](const auto &element) { return element.first == "test"; })};
// There is only one module instance

// Check if the proper number of ports are found.
INFO(
"FAIL_TEST: A module must have a port bound for it to be "
"recognized.");
REQUIRE(test_module != module_decl.end() );
REQUIRE(test_module != module_decl.end());
}
}

0 comments on commit e3fd372

Please sign in to comment.