diff --git a/src/Memory/MemoryFactory.cpp b/src/Memory/MemoryFactory.cpp index 5614fb8..c378aed 100644 --- a/src/Memory/MemoryFactory.cpp +++ b/src/Memory/MemoryFactory.cpp @@ -24,14 +24,12 @@ std::unique_ptr makeSimpleSubArray(const NVM::Simulation::Config& conf) { SimpleConfigs configs; - ConfigParser parser; - parser.registerValue("PIMFaultRate", 0.0, &configs.pimFaultRate); - parser.registerValue("NumTries", 1, &configs.numTries); - parser.registerValue("NumCorrectableFaults", 0, - &configs.numCorrectableFaults); - parser.registerValue("WordSize", 64, &configs.wordSize); - - parser.parse(conf); + ConfigParser::registerValue("PIMFaultRate", 0.0, + &configs.pimFaultRate); + ConfigParser::registerValue("NumTries", 1, &configs.numTries); + ConfigParser::registerValue("NumCorrectableFaults", 0, + &configs.numCorrectableFaults); + ConfigParser::registerValue("WordSize", 64, &configs.wordSize); FaultModel model(configs.pimFaultRate, configs.wordSize, configs.numCorrectableFaults); diff --git a/src/Utils/CMakeLists.txt b/src/Utils/CMakeLists.txt index e1e7b63..d8eba8c 100644 --- a/src/Utils/CMakeLists.txt +++ b/src/Utils/CMakeLists.txt @@ -1,6 +1,7 @@ set(Utils_SOURCES Address.cpp - RowData.cpp) + RowData.cpp + ConfigParser.cpp) add_library(RTSim_Utils ${Utils_SOURCES}) target_include_directories(RTSim_Utils PUBLIC ${RTSIM_DIR}/include PRIVATE ${RTSIM_DIR}/src) diff --git a/src/Utils/ConfigParser.cpp b/src/Utils/ConfigParser.cpp new file mode 100644 index 0000000..75943df --- /dev/null +++ b/src/Utils/ConfigParser.cpp @@ -0,0 +1,8 @@ +#include "Utils/ConfigParser.h" + +using namespace NVM::Memory; + +bool ConfigParser::hasConfig = false; +NVM::Simulation::Config ConfigParser::config; +std::vector> + ConfigParser::parsers; \ No newline at end of file diff --git a/src/Utils/ConfigParser.h b/src/Utils/ConfigParser.h index f3a2aa9..4b64f0a 100644 --- a/src/Utils/ConfigParser.h +++ b/src/Utils/ConfigParser.h @@ -14,14 +14,14 @@ class ConfigParser { ConfigParser() {} template - void registerValue(std::string key, T defaultValue, T* destination) { + static void registerValue(std::string key, T defaultValue, T* destination) { using namespace NVM::Logging; log() << LogLevel::DEBUG << "Registering config value " << key << ", default is " << defaultValue << '\n'; - parsers.push_back([key, defaultValue, - destination](const NVM::Simulation::Config& conf) { + auto parseFunc = [key, defaultValue, + destination](const NVM::Simulation::Config& conf) { try { *destination = conf.get(key); log() << LogLevel::STAT << "Read config value " << key << " as " @@ -31,15 +31,27 @@ class ConfigParser { << key << " (" << defaultValue << ")\n"; *destination = defaultValue; } - }); + }; + + if (hasConfig) { + parseFunc(config); + } else { + parsers.push_back(parseFunc); + } } - void parse(const NVM::Simulation::Config& conf) { + static void setConfig(const NVM::Simulation::Config& conf) { + config = conf; for (auto p : parsers) p(conf); + hasConfig = true; } private: - std::vector> parsers; + static std::vector> + parsers; + + static NVM::Simulation::Config config; + static bool hasConfig; }; } // namespace NVM::Memory \ No newline at end of file diff --git a/src/main/simpleMain.cpp b/src/main/simpleMain.cpp index 2273261..c8b5387 100644 --- a/src/main/simpleMain.cpp +++ b/src/main/simpleMain.cpp @@ -23,29 +23,24 @@ ncycle_t getMaxCycles(char* arg) { } void setAddressScheme(const NVM::Simulation::Config& conf) { - ConfigParser parser; ComponentCounts counts; - parser.registerValue("DBCS", 64, &counts.rows); - parser.registerValue("DOMAINS", 512, &counts.cols); - parser.registerValue("RANKS", 1, &counts.ranks); - parser.registerValue("BANKS", 1, &counts.banks); - parser.registerValue("CHANNELS", 1, &counts.channels); + ConfigParser::registerValue("DBCS", 64, &counts.rows); + ConfigParser::registerValue("DOMAINS", 512, &counts.cols); + ConfigParser::registerValue("RANKS", 1, &counts.ranks); + ConfigParser::registerValue("BANKS", 1, &counts.banks); + ConfigParser::registerValue("CHANNELS", 1, &counts.channels); std::string addressScheme; - parser.registerValue("AddressMappingScheme", "RK:BK:CH:R:C", - &addressScheme); - - parser.parse(conf); + ConfigParser::registerValue("AddressMappingScheme", + "RK:BK:CH:R:C", &addressScheme); setScheme(addressScheme, counts); } void setLogLevel(const NVM::Simulation::Config& conf) { - ConfigParser parser; std::string logLevel; - parser.registerValue("LogLevel", "STAT", &logLevel); - parser.parse(conf); + ConfigParser::registerValue("LogLevel", "STAT", &logLevel); if (logLevel == "DEBUG") { log().setGlobalLevel(LogLevel::DEBUG); @@ -77,6 +72,7 @@ int main(int argc, char* argv[]) { ncycle_t simulateCycles = getMaxCycles((argc > 3) ? argv[3] : nullptr); NVM::Simulation::Config conf = readConfig(argv[1]); + ConfigParser::setConfig(conf); for (int i = 4; i < argc; i++) { conf.override(argv[i]); @@ -88,10 +84,8 @@ int main(int argc, char* argv[]) { // Build RTSystem std::unique_ptr memory; - ConfigParser parser; std::string memType; - parser.registerValue("MemType", "Simple", &memType); - parser.parse(conf); + ConfigParser::registerValue("MemType", "Simple", &memType); if (memType == "Simple") { memory = makeSimpleSystem(conf);