From 0c25abdb00bbf5d6690a795ec2b4b57666e4fa7f Mon Sep 17 00:00:00 2001 From: mariusmonton Date: Tue, 22 Jan 2019 12:33:32 +0100 Subject: [PATCH] Fixed bug --- inc/Log.h | 1 + src/CPU.cpp | 4 ++-- src/Execute.cpp | 2 +- src/Log.cpp | 15 ++++++++++----- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/inc/Log.h b/inc/Log.h index c5907e3..6808646 100644 --- a/inc/Log.h +++ b/inc/Log.h @@ -71,6 +71,7 @@ private: static Log* instance; Log(const char* filename); std::ofstream m_stream; + std::ofstream m_sink; }; #endif diff --git a/src/CPU.cpp b/src/CPU.cpp index a3af919..49c61c3 100644 --- a/src/CPU.cpp +++ b/src/CPU.cpp @@ -38,7 +38,7 @@ bool CPU::cpu_process_IRQ() { /* updated MEPC register */ old_pc = register_bank->getPC(); register_bank->setCSR(CSR_MEPC, old_pc); - // log->SC_log(Log::INFO) << "Old PC Value 0x" << hex << old_pc << endl; + log->SC_log(Log::INFO) << "Old PC Value 0x" << hex << old_pc << endl; /* update MCAUSE register */ register_bank->setCSR(CSR_MCAUSE, 0x8000000); @@ -46,7 +46,7 @@ bool CPU::cpu_process_IRQ() { /* set new PC address */ new_pc = register_bank->getCSR(CSR_MTVEC); new_pc = new_pc & 0xFFFFFFFC; // last two bits always to 0 - // log->SC_log(Log::DEBUG) << "NEW PC Value 0x" << hex << new_pc << endl; + log->SC_log(Log::DEBUG) << "NEW PC Value 0x" << hex << new_pc << endl; register_bank->setPC(new_pc); ret_value = true; diff --git a/src/Execute.cpp b/src/Execute.cpp index 51f373e..21a2958 100644 --- a/src/Execute.cpp +++ b/src/Execute.cpp @@ -2152,7 +2152,7 @@ void Execute::RaiseException(uint32_t cause, uint32_t inst) { regs->setPC( new_pc); - log->SC_log(Log::INFO) << "Exception! new PC " << hex << new_pc << endl; + log->SC_log(Log::INFO) << "Exception! new PC 0x" << hex << new_pc << endl; regs->dump(); cout << "Simulation time " << sc_time_stamp() << endl; diff --git a/src/Log.cpp b/src/Log.cpp index 511c41c..4b8a6ee 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -2,8 +2,7 @@ Log* Log::getInstance() { - if (instance == 0) - { + if (instance == 0) { instance = new Log("Log.txt"); } @@ -16,18 +15,24 @@ Log::Log(const char* filename) { } void Log::SC_log(std::string msg, enum LogLevel level) { - if (level >= currentLogLevel) { + + if (level <= currentLogLevel) { m_stream << "time " << sc_core::sc_time_stamp() << ": " << msg << std::endl; + } else { + m_stream << "patata" << std::endl; } } std::ofstream& Log::SC_log(enum LogLevel level) { - if (level >= currentLogLevel) { + if (level <= currentLogLevel) { m_stream << "time " << sc_core::sc_time_stamp() << ": "; + return m_stream; + } else { + return m_sink; } - return m_stream; + } void Log::setLogLevel(enum LogLevel newLevel) {