Skip to content

Commit

Permalink
Tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
rmrf committed Dec 23, 2019
1 parent 61e11b8 commit d4eb3c9
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 66 deletions.
9 changes: 6 additions & 3 deletions src/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,28 +128,31 @@ Model::eventMapType Model::getEventMapType() { return event_map_; }
unsigned int Model::getNumEvents() { return (event_map_.size() - 3); }

void Model::dump(llvm::raw_ostream &os) {
os << "\n# Number of modules : " << modules_.size();
os << "-- Number of sc_module instances: " << modules_.size();
os << "\n";

for (const auto & mod : modules_ ) {
// <string, ModuleDecl*>
os << "Instance name " << mod.first ;
os << "-- Instance name: " << mod.first ;
mod.second->dump(os);
}
/*
for (Model::moduleMapType::iterator mit = modules_.begin();
mit != modules_.end(); mit++) {
// Second is the ModuleDecl type.
os << "\n";
vector<ModuleDecl *> instanceVec = module_instance_map_[mit->second];
os << "\n# Module " << mit->first << ": " << instanceVec.size()
os << " Module " << mit->first << ": " << instanceVec.size()
<< " instances.";
for (size_t i = 0; i < instanceVec.size(); i++) {
// os <<", instance: " << i + 1 << " ";
instanceVec.at(i)->dump(os);
}
}
os << "\n\n";
*/

os << "# Global events:\n";
for (Model::eventMapType::iterator it = event_map_.begin(),
Expand Down
7 changes: 4 additions & 3 deletions src/SystemCClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ bool SystemCConsumer::fire() {
module_decl_instances);
}

/*
////////////////////////////////////////////////////////////////
// Figure out the module map.
////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -330,6 +331,7 @@ bool SystemCConsumer::fire() {
}
// systemcModel_->addModuleDeclInstances(mainmd, moduleDeclVec);
}
*/

/*
FindSCMain scmain(tu, os_);
Expand All @@ -349,7 +351,6 @@ bool SystemCConsumer::fire() {
FindNetlist findNetlist(scmain.getSCMainFunctionDecl());
findNetlist.dump();
systemcModel_->addNetlist(findNetlist);
*/
// Only do this if SAUTO flag is set.
#ifdef USE_SAUTO
Expand Down Expand Up @@ -384,8 +385,8 @@ bool SystemCConsumer::fire() {
}
#endif
os_ << "\n";
os_ << "\n## SystemC model\n";
*/
os_ << "[Parsed SystemC model from systemc-clang] \n";
systemcModel_->dump(os_);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ file(COPY data DESTINATION ${CMAKE_BINARY_DIR}/tests/ )
file(COPY ../examples/llnl-examples DESTINATION ${CMAKE_BINARY_DIR}/tests/data )

set( UNIT_TEST_LIST
# t1
t1
t2
t3
sreg-test
Expand Down
109 changes: 50 additions & 59 deletions tests/t1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ int sc_main(int argc, char *argv[]) {
test_instance.in_out(double_sig);
test_instance.out1(sig1);
simple_module simple("simple_module");
simple_module simple("simple_module_instance");
simple.one(sig1);
return 0;
Expand All @@ -98,66 +98,57 @@ int sc_main(int argc, char *argv[]) {
// model->dump(llvm::outs());
auto module_decl{model->getModuleDecl()};

SECTION("Found sc_modules", "[modules]") {
auto test_module{std::find_if(
module_decl.begin(), module_decl.end(), [](const auto &element) {
return element.second->getInstanceName() == "testing";
})};

auto simple_module{std::find_if(
module_decl.begin(), module_decl.end(), [](const auto &element) {
return element.second->getInstanceName() == "simple_module_instance";
})};

SECTION("Found sc_module instances", "[instances]") {
// There should be 2 modules identified.
INFO( "ERROR: number of sc_module declarations found: " << module_decl.size() );
REQUIRE(module_decl.size() == 2);
INFO("ERROR: number of sc_module declarations found: "
<< module_decl.size());

// Check their names, and that their pointers are not nullptr.

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.

// The module instances have all the information.
// 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{
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.
REQUIRE(test_module->getIPorts().size() == 3);
REQUIRE(test_module->getOPorts().size() == 2);
REQUIRE(test_module->getIOPorts().size() == 1);
REQUIRE(test_module->getSignals().size() == 1);
REQUIRE(test_module->getOtherVars().size() == 1);
REQUIRE(test_module->getInputStreamPorts().size() == 0);
REQUIRE(test_module->getOutputStreamPorts().size() == 0);
}
REQUIRE(module_decl.size() == 2);

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{
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.
REQUIRE(test_module->getIPorts().size() == 3);
REQUIRE(test_module->getOPorts().size() == 1);
REQUIRE(test_module->getIOPorts().size() == 0);
REQUIRE(test_module->getSignals().size() == 0);
REQUIRE(test_module->getOtherVars().size() == 1);
REQUIRE(test_module->getInputStreamPorts().size() == 0);
REQUIRE(test_module->getOutputStreamPorts().size() == 0);
}
REQUIRE(test_module != module_decl.end());
REQUIRE(simple_module != module_decl.end());

INFO("Checking member ports for test instance.");
// These checks should be performed on the declarations.

// The module instances have all the information.
// 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 test_module_inst{test_module->second};

// Check if the proper number of ports are found.
REQUIRE(test_module_inst->getIPorts().size() == 3);
REQUIRE(test_module_inst->getOPorts().size() == 2);
REQUIRE(test_module_inst->getIOPorts().size() == 1);
REQUIRE(test_module_inst->getSignals().size() == 1);
REQUIRE(test_module_inst->getOtherVars().size() == 1);
REQUIRE(test_module_inst->getInputStreamPorts().size() == 0);
REQUIRE(test_module_inst->getOutputStreamPorts().size() == 0);

INFO("Checking member ports for simple module instance.");
auto simple_module_inst{simple_module->second};

// Check if the proper number of ports are found.
REQUIRE(simple_module_inst->getIPorts().size() == 3);
REQUIRE(simple_module_inst->getOPorts().size() == 1);
REQUIRE(simple_module_inst->getIOPorts().size() == 0);
REQUIRE(simple_module_inst->getSignals().size() == 0);
REQUIRE(simple_module_inst->getOtherVars().size() == 1);
REQUIRE(simple_module_inst->getInputStreamPorts().size() == 0);
REQUIRE(simple_module_inst->getOutputStreamPorts().size() == 0);
}
}

0 comments on commit d4eb3c9

Please sign in to comment.