systemc: Add a nonstandard sc_status pretty printer operator.
authorGabe Black <gabeblack@google.com>
Wed, 8 Aug 2018 08:30:47 +0000 (01:30 -0700)
committerGabe Black <gabeblack@google.com>
Thu, 20 Sep 2018 01:42:09 +0000 (01:42 +0000)
This operator exists in the Accellera implementation, and is necessary
to make the test output match.

Change-Id: I266629d6c936d4846e88e35af36555fb392b181c
Reviewed-on: https://gem5-review.googlesource.com/12074
Reviewed-by: Gabe Black <gabeblack@google.com>
Maintainer: Gabe Black <gabeblack@google.com>

src/systemc/core/sc_main.cc
src/systemc/ext/core/sc_main.hh

index 446b7377d0a39a0a547d62fb6d3511ab8cfd95d6..641e0d0669cb2a96583cf5fa4fca48337f5021b6 100644 (file)
@@ -244,4 +244,64 @@ sc_get_status()
     return ::sc_gem5::kernel ? ::sc_gem5::kernel->status() : SC_ELABORATION;
 }
 
+std::ostream &
+operator << (std::ostream &os, sc_status s)
+{
+    switch (s) {
+      case SC_ELABORATION:
+        os << "SC_ELABORATION";
+        break;
+      case SC_BEFORE_END_OF_ELABORATION:
+        os << "SC_BEFORE_END_OF_ELABORATION";
+        break;
+      case SC_END_OF_ELABORATION:
+        os << "SC_END_OF_ELABORATION";
+        break;
+      case SC_START_OF_SIMULATION:
+        os << "SC_START_OF_SIMULATION";
+        break;
+      case SC_RUNNING:
+        os << "SC_RUNNING";
+        break;
+      case SC_PAUSED:
+        os << "SC_PAUSED";
+        break;
+      case SC_STOPPED:
+        os << "SC_STOPPED";
+        break;
+      case SC_END_OF_SIMULATION:
+        os << "SC_END_OF_SIMULATION";
+        break;
+
+        // Nonstandard
+      case SC_END_OF_INITIALIZATION:
+        os << "SC_END_OF_INITIALIZATION";
+        break;
+      case SC_END_OF_UPDATE:
+        os << "SC_END_OF_UPDATE";
+        break;
+      case SC_BEFORE_TIMESTEP:
+        os << "SC_BEFORE_TIMESTEP";
+        break;
+
+      default:
+        if (s & SC_STATUS_ANY) {
+            const char *prefix = "(";
+            for (sc_status m = (sc_status)0x1;
+                    m < SC_STATUS_ANY; m = (sc_status)(m << 1)) {
+                if (m & s) {
+                    os << prefix;
+                    prefix = "|";
+                    os << m;
+                }
+            }
+            os << ")";
+        } else {
+            ccprintf(os, "%#x", s);
+        }
+    }
+
+    return os;
+}
+
 } // namespace sc_core
index b6f5ea13e29ce8f69bef2fdd2390a0c56ea64fc1..10a68ca1530aefc142cca1f21bfb406edab9f076 100644 (file)
@@ -30,6 +30,8 @@
 #ifndef __SYSTEMC_EXT_CORE_SC_MAIN_HH__
 #define __SYSTEMC_EXT_CORE_SC_MAIN_HH__
 
+#include <iostream>
+
 #include "../dt/int/sc_nbdefs.hh"
 #include "sc_time.hh"
 
@@ -97,6 +99,8 @@ namespace sc_core
     };
 
     sc_status sc_get_status();
+
+    std::ostream &operator << (std::ostream &os, sc_status s);
 } // namespace sc_core
 
 #endif  //__SYSTEMC_EXT_CORE_SC_MAIN_HH__