Skip to content

Commit

Permalink
Use appropriate macro for checking the calls to functions. Also fixed…
Browse files Browse the repository at this point in the history
… some other destructors.
  • Loading branch information
asrivast28 committed Dec 27, 2018
1 parent 81fb6e3 commit 38f44ff
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 27 deletions.
18 changes: 12 additions & 6 deletions Anml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Anml::loadMacro(
ap_macro_def_t macro;
int lineNumber = 0;
try {
APCALL_CHECK(AP_LoadAnmlMacro)(m_anml, &macro, &lineNumber, fileName.c_str(), static_cast<ap_cbinfo_t*>(0), AP_OPT_DEFAULT, static_cast<const char*>(0));
APCALL_CHECK_ZERO(AP_LoadAnmlMacro)(m_anml, &macro, &lineNumber, fileName.c_str(), static_cast<ap_cbinfo_t*>(0), AP_OPT_DEFAULT, static_cast<const char*>(0));
}
catch(std::runtime_error& e) {
throw std::runtime_error(std::string(e.what()) + " In " + fileName + " on line " + std::to_string(lineNumber) + ".");
Expand All @@ -83,7 +83,7 @@ Anml::createNetwork(
)
{
ap_anml_network_t network;
APCALL_CHECK(AP_CreateAutomataNetwork)(m_anml, &network, anmlId.c_str());
APCALL_CHECK_ZERO(AP_CreateAutomataNetwork)(m_anml, &network, anmlId.c_str());
return AnmlNetwork(network);
}

Expand All @@ -94,7 +94,7 @@ void
Anml::compileMacros(
) const
{
APCALL_CHECK(AP_CompileMacros)(m_anml, static_cast<ap_macro_def_t*>(0), static_cast<ap_anml_element_ref_t*>(0), static_cast<ap_cbinfo_t*>(0), AP_OPT_DEFAULT, 0);
APCALL_CHECK_ZERO(AP_CompileMacros)(m_anml, static_cast<ap_macro_def_t*>(0), static_cast<ap_anml_element_ref_t*>(0), static_cast<ap_cbinfo_t*>(0), AP_OPT_DEFAULT, 0);
}

/**
Expand All @@ -108,7 +108,7 @@ Anml::compileAnml(
{
ap_automaton_t automaton;
ap_element_map_t elementMap;
APCALL_CHECK(AP_CompileAnml)(m_anml, &automaton, &elementMap, static_cast<ap_anml_element_ref_t*>(0), static_cast<ap_cbinfo_t*>(0), AP_OPT_DEFAULT, 0);
APCALL_CHECK_ZERO(AP_CompileAnml)(m_anml, &automaton, &elementMap, static_cast<ap_anml_element_ref_t*>(0), static_cast<ap_cbinfo_t*>(0), AP_OPT_DEFAULT, 0);
return std::pair<Automaton, ElementMap>(Automaton(automaton), ElementMap(elementMap));
}

Expand All @@ -119,9 +119,15 @@ Anml::~Anml(
)
{
if (m_anml != 0) {
APCALL_CHECK(AP_DestroyAnml)(m_anml);
try {
APCALL_CHECK_ZERO(AP_DestroyAnml)(m_anml);
}
catch (const std::runtime_error& e) {
std::cerr << "Unable to destroy the ANML workspace because of errors." << std::endl;
std::cerr << e.what() << std::endl;
}
m_anml = 0;
}
m_anml = 0;
}

} // namespace ap
2 changes: 1 addition & 1 deletion AnmlMacro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void
AnmlMacro::setMacroDefToBeCompiled(
) const
{
APCALL_CHECK(AP_SetMacroDefToBeCompiled)(m_macro);
APCALL_CHECK_ZERO(AP_SetMacroDefToBeCompiled)(m_macro);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions AnmlNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ AnmlNetwork::addMacroRef(
element.id = anmlId.c_str();

ap_anml_element_ref_t elementRef;
APCALL_CHECK(AP_AddAnmlElement)(m_network, &elementRef, &element);
APCALL_CHECK_ZERO(AP_AddAnmlElement)(m_network, &elementRef, &element);
return ElementRef(elementRef);
}

Expand All @@ -73,7 +73,7 @@ AnmlNetwork::exportAnml(
const std::string& fileName
) const
{
APCALL_CHECK(AP_ExportAnml)(m_network, fileName.c_str(), static_cast<const char*>(0));
APCALL_CHECK_ZERO(AP_ExportAnml)(m_network, fileName.c_str(), static_cast<const char*>(0));
}

/**
Expand Down
18 changes: 12 additions & 6 deletions Automaton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Automaton::Automaton(
#else
//fd = CreateFileA(fileName.c_str(), GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
#endif
APCALL_CHECK(AP_Restore)(&m_automaton, fd);
APCALL_CHECK_ZERO(AP_Restore)(&m_automaton, fd);
#if defined(LINUX32) || defined(LINUX64)
close(fd);
#else
Expand All @@ -78,7 +78,7 @@ Automaton::Automaton(
const Automaton& that
) : m_automaton(0)
{
APCALL_CHECK(AP_Duplicate)(that.m_automaton, &m_automaton, 0);
APCALL_CHECK_ZERO(AP_Duplicate)(that.m_automaton, &m_automaton, 0);
}

/**
Expand Down Expand Up @@ -118,7 +118,7 @@ Automaton::setSymbol(
struct ap_symbol_change* allChanges = *changes;
size_t changeCount = changes.count();
for (size_t idx = 0; idx < changeCount; ++idx) {
APCALL_CHECK(AP_SetSymbol)(m_automaton, emap, &allChanges[idx], 1);
APCALL_CHECK_ZERO(AP_SetSymbol)(m_automaton, emap, &allChanges[idx], 1);
}
}

Expand All @@ -138,7 +138,7 @@ Automaton::save(
#else
fd = CreateFileA(fileName.c_str(), GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
#endif
APCALL_CHECK(AP_Save)(m_automaton, fd);
APCALL_CHECK_ZERO(AP_Save)(m_automaton, fd);
#if defined(LINUX32) || defined(LINUX64)
close(fd);
#else
Expand All @@ -154,7 +154,7 @@ Automaton::printInfo(
) const
{
struct ap_automaton_info info;
APCALL_CHECK(AP_GetInfo)(m_automaton, &info, 0);
APCALL_CHECK_ZERO(AP_GetInfo)(m_automaton, &info, 0);
std::cout << "blocks_rect = " << info.blocks_rect<< std::endl;
std::cout << "blocks_used = " << info.blocks_used<< std::endl;
std::cout << "ste_count = " << info.ste_count<< std::endl;
Expand Down Expand Up @@ -185,7 +185,13 @@ Automaton::~Automaton(
{
// Destroy the automaton only if it points to a valid instance.
if (m_automaton != 0) {
APCALL_CHECK(AP_Destroy)(m_automaton);
try {
APCALL_CHECK_ZERO(AP_Destroy)(m_automaton);
}
catch (const std::runtime_error& e) {
std::cerr << "Unable to destroy the automaton because of errors." << std::endl;
std::cerr << e.what() << std::endl;
}
m_automaton = 0;
}
}
Expand Down
16 changes: 11 additions & 5 deletions ElementMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ ElementMap::ElementMap(
#else
//fd = CreateFileA(fileName.c_str(), GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
#endif
APCALL_CHECK(AP_RestoreElementMap)(&m_elementMap, fd);
APCALL_CHECK_ZERO(AP_RestoreElementMap)(&m_elementMap, fd);
#if defined(LINUX32) || defined(LINUX64)
close(fd);
#else
Expand Down Expand Up @@ -108,7 +108,7 @@ ElementMap::getElementRef(
) const
{
ap_anml_element_ref_t elementRef;
APCALL_CHECK(AP_GetElementRefFromElementId)(m_elementMap, &elementRef, elementId.c_str());
APCALL_CHECK_ZERO(AP_GetElementRefFromElementId)(m_elementMap, &elementRef, elementId.c_str());
return ElementRef(elementRef);
}

Expand All @@ -119,7 +119,7 @@ ElementMap::getElementId(
{
unsigned bufSize = APCALL_CHECK(AP_GetElementIdFromElementRef)(m_elementMap, static_cast<char*>(0), 0, *elementRef);
std::vector<char> elementId(bufSize+1, 0);
APCALL_CHECK(AP_GetElementIdFromElementRef)(m_elementMap, &elementId[0], bufSize, *elementRef);
APCALL_CHECK_ZERO(AP_GetElementIdFromElementRef)(m_elementMap, &elementId[0], bufSize, *elementRef);
return std::string(&elementId[0]);
}

Expand All @@ -139,7 +139,7 @@ ElementMap::save(
#else
fd = CreateFileA(fileName.c_str(), GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
#endif
APCALL_CHECK(AP_SaveElementMap)(m_elementMap, fd);
APCALL_CHECK_ZERO(AP_SaveElementMap)(m_elementMap, fd);
#if defined(LINUX32) || defined(LINUX64)
close(fd);
#else
Expand Down Expand Up @@ -167,7 +167,13 @@ ElementMap::~ElementMap(
{
// Destroy the element map only if it points to a valid instance.
if (m_elementMap != 0) {
APCALL_CHECK(AP_DestroyElementMap)(m_elementMap);
try {
APCALL_CHECK_ZERO(AP_DestroyElementMap)(m_elementMap);
}
catch (const std::runtime_error& e) {
std::cerr << "Unable to destroy the element map because of errors." << std::endl;
std::cerr << e.what() << std::endl;
}
m_elementMap = 0;
}
}
Expand Down
14 changes: 7 additions & 7 deletions Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ calcLoadSize(
for ( const std::reference_wrapper<Automaton>& automaton : automataRefs ) {
automata.push_back(*(automaton.get()));
}
APCALL_CHECK(AP_CalcLoadSize)(&loadSize[0], &automata[0], automata.size());
APCALL_CHECK_ZERO(AP_CalcLoadSize)(&loadSize[0], &automata[0], automata.size());
return loadSize;
}

Expand All @@ -55,7 +55,7 @@ queryDeviceCount(
)
{
unsigned numDevices = 0;
APCALL_CHECK(AP_QueryDeviceCount)(&numDevices);
APCALL_CHECK_ZERO(AP_QueryDeviceCount)(&numDevices);
return numDevices;
}

Expand All @@ -72,7 +72,7 @@ queryDeviceMetrics(
)
{
std::vector<struct ap_device_metrics> deviceMetrics(queryDeviceCount());
APCALL_CHECK(AP_QueryDeviceMetrics)(&deviceMetrics[0], deviceName.c_str());
APCALL_CHECK_ZERO(AP_QueryDeviceMetrics)(&deviceMetrics[0], deviceName.c_str());
return deviceMetrics;
}

Expand All @@ -86,7 +86,7 @@ configureDevice(
const std::string& deviceName
)
{
APCALL_CHECK(AP_ConfigureDevice)(deviceName.c_str(), static_cast<struct ap_device_config*>(0));
APCALL_CHECK_ZERO(AP_ConfigureDevice)(deviceName.c_str(), static_cast<struct ap_device_config*>(0));
}

/**
Expand All @@ -101,9 +101,9 @@ queryDeviceConfig(
const std::string& deviceName
)
{
unsigned loadRegions;
loadRegions = APCALL_CHECK(AP_QueryDeviceConfig)(deviceName.c_str(), static_cast<struct ap_device_config*>(0));
return loadRegions;
struct ap_device_config config;
APCALL_CHECK_ZERO(AP_QueryDeviceConfig)(deviceName.c_str(), &config);
return config.load_region_count;
}

} // namespace runtime
Expand Down

0 comments on commit 38f44ff

Please sign in to comment.