Browse Source

Reporting changes and fixes

Updated reporting settings and added a redirector to catch cout to
redirect to the log output
pull/2/head
Eyck Jentzsch 1 year ago
parent
commit
cd46d3a73c
4 changed files with 71 additions and 39 deletions
  1. +13
    -0
      incl/scc/report.h
  2. +25
    -0
      incl/scc/utilities.h
  3. +4
    -6
      incl/tlm/tlm_extensions.h
  4. +29
    -33
      src/report.cpp

+ 13
- 0
incl/scc/report.h View File

@@ -164,6 +164,19 @@ inline std::string padded(std::string str, size_t width, bool show_ellipsis=true
return str+std::string(width-str.size(), ' ');
}
}

class stream_redirection: public std::stringbuf {
public:
stream_redirection(std::ostream& os, logging::log_level level);
~stream_redirection();
void reset();
protected:
std::streamsize xsputn(const char_type* s, std::streamsize n) override;
std::ostream& os;
logging::log_level level;
std::streambuf* old_buf;
};

}

#endif /* _SYSC_REPORT_H_ */

+ 25
- 0
incl/scc/utilities.h View File

@@ -237,6 +237,31 @@ inline sc_core::sc_time parse_from_string(std::string value) noexcept {
}
return sc_core::SC_ZERO_TIME;
}

#ifdef ASM
#include <stdint.h>
static inline unsigned ilog2(uint32_t x) {
uint32_t y;
asm ( "\tbsr %1, %0\n"
: "=r"(y)
: "r" (x)
);
return y;
}
#else
#include <limits.h>
inline unsigned ilog2 (uint32_t val) {
if (val == 0) return std::numeric_limits<uint32_t>::max();
if (val == 1) return 0;
auto ret = 0U;
while (val > 1) {
val >>= 1;
++ret;
}
return ret;
}
#endif

}

#endif /* _SYSC_UTILITIES_H_ */

+ 4
- 6
incl/tlm/tlm_extensions.h View File

@@ -36,7 +36,7 @@ template <typename T> struct tlm_managed_extension {

using type = T;

template <typename... Args> static type *alloacte(Args &&... args) {
template <typename... Args> static type *allocate(Args &&... args) {
auto *ret = new (pool::allocate()) type(std::forward<Args>(args)...);
ret->is_pooled = true;
return ret;
@@ -79,14 +79,12 @@ template <typename T> struct tlm_managed_extension {
};

protected:
tlm_managed_extension()
: is_pooled(false) {}
tlm_managed_extension(const tlm_managed_extension &)
: is_pooled(false) {}
tlm_managed_extension() = default;
tlm_managed_extension(const tlm_managed_extension &) = default;
tlm_managed_extension &operator=(const tlm_managed_extension &other) { return *this; }

private:
bool is_pooled;
bool is_pooled{false};
};
}
#endif /* SC_COMPONENTS_INCL_TLM_TLM_EXTENSIONS_H_ */

+ 29
- 33
src/report.cpp View File

@@ -116,42 +116,35 @@ void report_handler(const sc_report &rep, const sc_actions &actions) {
if (actions & SC_ABORT) abort();
if (actions & SC_THROW) throw rep;
}
}

class log_stream_buf: public std::stringbuf {
public:
log_stream_buf(std::ostream& os, logging::log_level level):os(os), level(level){
old_buf=os.rdbuf(this); //save and redirect
}
~log_stream_buf(){
os.rdbuf(old_buf); // restore
}
void reset(){
os.rdbuf(old_buf); // restore
old_buf=nullptr;
}
protected:
std::streamsize xsputn(const char_type* s, std::streamsize n) override {
auto sz = std::stringbuf::xsputn(s, n);
if (s[n-1]=='\n'){
if(logging::INFO <= Log<Output2FILE<STDIO>>::reporting_level() && Output2FILE<STDIO>::stream()){
auto timestr = time2string(sc_core::sc_time_stamp());
std::istringstream buf(str());
std::string line;
while(getline(buf, line)) {
Log<Output2FILE<STDIO>>().get(logging::INFO, "") << "[" << std::setw(20) << timestr << "] "<<line;
}
scc::stream_redirection::stream_redirection(std::ostream& os, logging::log_level level):os(os), level(level){
old_buf=os.rdbuf(this); //save and redirect
}

scc::stream_redirection::~stream_redirection(){
os.rdbuf(old_buf); // restore
}

void scc::stream_redirection::reset(){
os.rdbuf(old_buf); // restore
old_buf=nullptr;
}

std::streamsize scc::stream_redirection::xsputn(const char_type* s, std::streamsize n) {
auto sz = std::stringbuf::xsputn(s, n);
if (s[n-1]=='\n'){
if(logging::INFO <= Log<Output2FILE<STDIO>>::reporting_level() && Output2FILE<STDIO>::stream()){
auto timestr = time2string(sc_core::sc_time_stamp());
std::istringstream buf(str());
std::string line;
while(getline(buf, line)) {
Log<Output2FILE<STDIO>>().get(logging::INFO, "") << "[" << std::setw(20) << timestr << "] "<<line;
}
str(std::string(""));
//setp(pbase(), epptr());
}
return sz;
str(std::string(""));
}
std::ostream& os;
logging::log_level level;
std::streambuf* old_buf;
};
log_stream_buf cout_redirect(std::cout, logging::INFO);
log_stream_buf cerr_redirect(std::cerr, logging::ERROR);
return sz;
}

void scc::init_logging(logging::log_level level, bool print_time) {
@@ -162,14 +155,17 @@ void scc::init_logging(logging::log_level level, bool print_time) {
SC_MEDIUM, // Logging::INFO
SC_HIGH, // logging::DEBUG
SC_FULL, // logging::TRACE
SC_DEBUG}; // logging::TRACE+1
SC_DEBUG}; // logging::DBGTRACE
LOGGER(DEFAULT)::reporting_level() = level;
LOGGER(SystemC)::reporting_level() = level;
LOGGER(SystemC)::print_time() = print_time;
LOGGER(SystemC)::abort_on_fatal() = false;
sc_report_handler::set_actions(SC_ERROR, SC_DEFAULT_ERROR_ACTIONS | SC_DISPLAY);
sc_report_handler::set_actions(SC_FATAL, SC_DEFAULT_FATAL_ACTIONS);
sc_report_handler::set_verbosity_level(verbosity[level]);
sc_report_handler::set_handler(report_handler);
LOGGER(STDIO)::reporting_level() = level;
LOGGER(STDIO)::print_time() = print_time;
LOGGER(STDIO)::abort_on_fatal() = false;
}


Loading…
Cancel
Save