From e31eae3f9e73a9566f7405528e823991acc7f208 Mon Sep 17 00:00:00 2001 From: mariusmonton Date: Tue, 12 Feb 2019 14:08:40 +0100 Subject: [PATCH] added command line arguments --- src/Log.cpp | 1 + src/Simulator.cpp | 61 ++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/src/Log.cpp b/src/Log.cpp index f7d8887..9a4b257 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -34,6 +34,7 @@ std::ofstream& Log::SC_log(enum LogLevel level) { } void Log::setLogLevel(enum LogLevel newLevel) { + std::cout << "LogLevel set to " << newLevel << std::endl; currentLogLevel = newLevel; } diff --git a/src/Simulator.cpp b/src/Simulator.cpp index d598a52..27544f1 100644 --- a/src/Simulator.cpp +++ b/src/Simulator.cpp @@ -13,6 +13,7 @@ #include "tlm_utils/simple_target_socket.h" #include +#include #include "CPU.h" #include "Memory.h" @@ -28,7 +29,7 @@ string filename; /** * @class Simulator - * This class instiates all necessary modules, connects its ports and starts + * This class instantiates all necessary modules, connects its ports and starts * the simulation. * * @brief Top simulation entity @@ -40,14 +41,13 @@ SC_MODULE(Simulator) BusCtrl* Bus; Trace *trace; Timer *timer; - Log *log; +// Log *log; uint32_t start_PC; SC_CTOR(Simulator) { - log = Log::getInstance(); - log->setLogLevel(Log::INFO); +// log = Log::getInstance(); MainMemory = new Memory("Main_Memory", filename); start_PC = MainMemory->getPCfromHEX(); @@ -88,20 +88,63 @@ void intHandler(int dummy) { exit(-1); } +void process_arguments(int argc, char* argv[]) { + + int c; + int debug_level; + Log *log; + + log = Log::getInstance(); + log->setLogLevel(Log::ERROR); + while ((c = getopt (argc, argv, "D:f:?")) != -1) { + switch (c) { + case 'D': + debug_level = atoi(optarg); + + switch (debug_level) { + case 3: + log->setLogLevel(Log::INFO); + break; + case 2: + log->setLogLevel(Log::WARNING); + break; + case 1: + log->setLogLevel(Log::DEBUG); + break; + case 0: + log->setLogLevel(Log::ERROR); + break; + default: + log->setLogLevel(Log::INFO); + break; + } + break; + case 'f' : + filename = std::string(optarg); + break; + case '?' : + std::cout << "Call ./RISCV_TLM -D (0..4) filename.hex" << std::endl; + break; + } + } + if (filename.empty()) { + filename = std::string(argv[optind]); + } + +} + int sc_main(int argc, char* argv[]) { + /* Capture Ctrl+C and finish the simulation */ signal(SIGINT, intHandler); /* SystemC time resolution set to 1 ns*/ sc_set_time_resolution(1, SC_NS); - if (argv[1] == nullptr) { - cerr << "Filename needed for hex memory" << endl; - return -1; - } - filename = argv[1]; + /* Parse and process program arguments. -f is mandatory */ + process_arguments(argc, argv); top = new Simulator("top"); sc_start();