Browse Source

Reporting changes and fixes

Updated reporting settings and added a redirector to catch cout to
redirect to the log output
Eyck Jentzsch 8 months 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
164 164
         return str+std::string(width-str.size(), ' ');
165 165
     }
166 166
 }
167
+
168
+class stream_redirection: public std::stringbuf {
169
+public:
170
+    stream_redirection(std::ostream& os, logging::log_level level);
171
+    ~stream_redirection();
172
+    void reset();
173
+protected:
174
+    std::streamsize xsputn(const char_type* s, std::streamsize n) override;
175
+    std::ostream& os;
176
+    logging::log_level level;
177
+    std::streambuf* old_buf;
178
+};
179
+
167 180
 }
168 181
 
169 182
 #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 {
237 237
     }
238 238
     return sc_core::SC_ZERO_TIME;
239 239
 }
240
+
241
+#ifdef ASM
242
+#include <stdint.h>
243
+static inline unsigned ilog2(uint32_t x) {
244
+  uint32_t y;
245
+  asm ( "\tbsr %1, %0\n"
246
+      : "=r"(y)
247
+      : "r" (x)
248
+  );
249
+  return y;
250
+}
251
+#else
252
+#include <limits.h>
253
+inline unsigned ilog2 (uint32_t val) {
254
+    if (val == 0) return std::numeric_limits<uint32_t>::max();
255
+    if (val == 1) return 0;
256
+    auto ret = 0U;
257
+    while (val > 1) {
258
+        val >>= 1;
259
+        ++ret;
260
+    }
261
+    return ret;
262
+}
263
+#endif
264
+
240 265
 }
241 266
 
242 267
 #endif /* _SYSC_UTILITIES_H_ */

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

@@ -36,7 +36,7 @@ template <typename T> struct tlm_managed_extension {
36 36
 
37 37
     using type = T;
38 38
 
39
-    template <typename... Args> static type *alloacte(Args &&... args) {
39
+    template <typename... Args> static type *allocate(Args &&... args) {
40 40
         auto *ret = new (pool::allocate()) type(std::forward<Args>(args)...);
41 41
         ret->is_pooled = true;
42 42
         return ret;
@@ -79,14 +79,12 @@ template <typename T> struct tlm_managed_extension {
79 79
     };
80 80
 
81 81
 protected:
82
-    tlm_managed_extension()
83
-    : is_pooled(false) {}
84
-    tlm_managed_extension(const tlm_managed_extension &)
85
-    : is_pooled(false) {}
82
+    tlm_managed_extension() = default;
83
+    tlm_managed_extension(const tlm_managed_extension &) = default;
86 84
     tlm_managed_extension &operator=(const tlm_managed_extension &other) { return *this; }
87 85
 
88 86
 private:
89
-    bool is_pooled;
87
+    bool is_pooled{false};
90 88
 };
91 89
 }
92 90
 #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) {
116 116
     if (actions & SC_ABORT) abort();
117 117
     if (actions & SC_THROW) throw rep;
118 118
 }
119
+}
119 120
 
120
-class log_stream_buf: public std::stringbuf {
121
-public:
122
-    log_stream_buf(std::ostream& os, logging::log_level level):os(os), level(level){
123
-        old_buf=os.rdbuf(this); //save and redirect
124
-    }
125
-    ~log_stream_buf(){
126
-        os.rdbuf(old_buf); // restore
127
-    }
128
-    void reset(){
129
-        os.rdbuf(old_buf); // restore
130
-        old_buf=nullptr;
131
-    }
132
-protected:
133
-    std::streamsize xsputn(const char_type* s, std::streamsize n) override {
134
-        auto sz = std::stringbuf::xsputn(s, n);
135
-        if (s[n-1]=='\n'){
136
-            if(logging::INFO <= Log<Output2FILE<STDIO>>::reporting_level() && Output2FILE<STDIO>::stream()){
137
-                auto timestr = time2string(sc_core::sc_time_stamp());
138
-                std::istringstream buf(str());
139
-                std::string line;
140
-                while(getline(buf, line)) {
141
-                    Log<Output2FILE<STDIO>>().get(logging::INFO, "") << "[" << std::setw(20) << timestr << "] "<<line;
142
-                }
121
+scc::stream_redirection::stream_redirection(std::ostream& os, logging::log_level level):os(os), level(level){
122
+    old_buf=os.rdbuf(this); //save and redirect
123
+}
124
+
125
+scc::stream_redirection::~stream_redirection(){
126
+    os.rdbuf(old_buf); // restore
127
+}
128
+
129
+void scc::stream_redirection::reset(){
130
+    os.rdbuf(old_buf); // restore
131
+    old_buf=nullptr;
132
+}
133
+
134
+std::streamsize scc::stream_redirection::xsputn(const char_type* s, std::streamsize n) {
135
+    auto sz = std::stringbuf::xsputn(s, n);
136
+    if (s[n-1]=='\n'){
137
+        if(logging::INFO <= Log<Output2FILE<STDIO>>::reporting_level() && Output2FILE<STDIO>::stream()){
138
+            auto timestr = time2string(sc_core::sc_time_stamp());
139
+            std::istringstream buf(str());
140
+            std::string line;
141
+            while(getline(buf, line)) {
142
+                Log<Output2FILE<STDIO>>().get(logging::INFO, "") << "[" << std::setw(20) << timestr << "] "<<line;
143 143
             }
144
-            str(std::string(""));
145
-            //setp(pbase(), epptr());
146 144
         }
147
-        return sz;
145
+        str(std::string(""));
148 146
     }
149
-    std::ostream& os;
150
-    logging::log_level level;
151
-    std::streambuf* old_buf;
152
-};
153
-log_stream_buf cout_redirect(std::cout, logging::INFO);
154
-log_stream_buf cerr_redirect(std::cerr, logging::ERROR);
147
+    return sz;
155 148
 }
156 149
 
157 150
 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) {
162 155
                                           SC_MEDIUM, // Logging::INFO
163 156
                                           SC_HIGH,   // logging::DEBUG
164 157
                                           SC_FULL,   // logging::TRACE
165
-                                          SC_DEBUG}; // logging::TRACE+1
158
+                                          SC_DEBUG}; // logging::DBGTRACE
166 159
     LOGGER(DEFAULT)::reporting_level() = level;
167 160
     LOGGER(SystemC)::reporting_level() = level;
168 161
     LOGGER(SystemC)::print_time() = print_time;
169 162
     LOGGER(SystemC)::abort_on_fatal() = false;
163
+    sc_report_handler::set_actions(SC_ERROR, SC_DEFAULT_ERROR_ACTIONS | SC_DISPLAY);
164
+    sc_report_handler::set_actions(SC_FATAL, SC_DEFAULT_FATAL_ACTIONS);
170 165
     sc_report_handler::set_verbosity_level(verbosity[level]);
171 166
     sc_report_handler::set_handler(report_handler);
172 167
     LOGGER(STDIO)::reporting_level() = level;
173 168
     LOGGER(STDIO)::print_time() = print_time;
174 169
     LOGGER(STDIO)::abort_on_fatal() = false;
175 170
 }
171
+