Gabe Black has submitted this change and it was merged. ( https://gem5-review.googlesource.com/c/public/gem5/+/12620 )

Change subject: systemc: Implement the sc_*_resolved classes.
......................................................................

systemc: Implement the sc_*_resolved classes.

Change-Id: Ib595da10e0f900ee4cc1847d41d29251dacb55d7
Reviewed-on: https://gem5-review.googlesource.com/c/12620
Reviewed-by: Gabe Black <[email protected]>
Maintainer: Gabe Black <[email protected]>
---
M src/systemc/channel/sc_in_resolved.cc
M src/systemc/channel/sc_inout_resolved.cc
M src/systemc/channel/sc_out_resolved.cc
M src/systemc/channel/sc_signal_resolved.cc
M src/systemc/ext/channel/sc_in_resolved.hh
M src/systemc/ext/channel/sc_inout_resolved.hh
M src/systemc/ext/channel/sc_out_resolved.hh
M src/systemc/ext/channel/sc_signal_resolved.hh
8 files changed, 98 insertions(+), 53 deletions(-)

Approvals:
  Gabe Black: Looks good to me, approved; Looks good to me, approved



diff --git a/src/systemc/channel/sc_in_resolved.cc b/src/systemc/channel/sc_in_resolved.cc
index b57f4cd..40190c8 100644
--- a/src/systemc/channel/sc_in_resolved.cc
+++ b/src/systemc/channel/sc_in_resolved.cc
@@ -29,6 +29,7 @@

 #include "base/logging.hh"
 #include "systemc/ext/channel/sc_in_resolved.hh"
+#include "systemc/ext/channel/sc_signal_resolved.hh"

 namespace sc_core
 {
@@ -41,8 +42,15 @@

 sc_in_resolved::~sc_in_resolved() {}

-void sc_in_resolved::end_of_elaboration() {}
-
-const char *sc_in_resolved::kind() const { return "sc_in_resolved"; }
+void
+sc_in_resolved::end_of_elaboration()
+{
+    sc_in<sc_dt::sc_logic>::end_of_elaboration();
+    if (!dynamic_cast<sc_signal_resolved *>(get_interface())) {
+        std::string msg = csprintf("%s (%s)", name(), kind());
+ SC_REPORT_ERROR("(E117) resolved port not bound to resolved signal",
+                msg.c_str());
+    }
+}

 } // namespace sc_core
diff --git a/src/systemc/channel/sc_inout_resolved.cc b/src/systemc/channel/sc_inout_resolved.cc
index 71cece8..8355a88 100644
--- a/src/systemc/channel/sc_inout_resolved.cc
+++ b/src/systemc/channel/sc_inout_resolved.cc
@@ -29,6 +29,8 @@

 #include "base/logging.hh"
 #include "systemc/ext/channel/sc_inout_resolved.hh"
+#include "systemc/ext/channel/sc_signal_resolved.hh"
+#include "systemc/ext/utils/sc_report_handler.hh"

 namespace sc_core
 {
@@ -41,45 +43,52 @@

 sc_inout_resolved::~sc_inout_resolved() {}

-void sc_inout_resolved::end_of_elaboration() {}
+void
+sc_inout_resolved::end_of_elaboration()
+{
+    sc_inout<sc_dt::sc_logic>::end_of_elaboration();
+    if (!dynamic_cast<sc_signal_resolved *>(get_interface())) {
+        std::string msg = csprintf("%s (%s)", name(), kind());
+ SC_REPORT_ERROR("(E117) resolved port not bound to resolved signal",
+                msg.c_str());
+    }
+}

 sc_inout_resolved &
-sc_inout_resolved::operator = (const sc_dt::sc_logic &)
+sc_inout_resolved::operator = (const sc_dt::sc_logic &l)
 {
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+    (*this)->write(l);
     return *this;
 }

 sc_inout_resolved &
-sc_inout_resolved::operator = (const sc_signal_in_if<sc_dt::sc_logic> &)
+sc_inout_resolved::operator = (const sc_signal_in_if<sc_dt::sc_logic> &i)
 {
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+    (*this)->write(i.read());
     return *this;
 }

 sc_inout_resolved &
 sc_inout_resolved::operator = (
-        const sc_port<sc_signal_in_if<sc_dt::sc_logic>, 1> &)
+        const sc_port<sc_signal_in_if<sc_dt::sc_logic>, 1> &p)
 {
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+    (*this)->write(p->read());
     return *this;
 }

 sc_inout_resolved &
 sc_inout_resolved::operator = (
-        const sc_port<sc_signal_inout_if<sc_dt::sc_logic>, 1> &)
+        const sc_port<sc_signal_inout_if<sc_dt::sc_logic>, 1> &p)
 {
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+    (*this)->write(p->read());
     return *this;
 }

 sc_inout_resolved &
-sc_inout_resolved::operator = (const sc_inout_resolved &)
+sc_inout_resolved::operator = (const sc_inout_resolved &p)
 {
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+    (*this)->write(p->read());
     return *this;
 }

-const char *sc_inout_resolved::kind() const { return "sc_inout_resolved"; }
-
 } // namespace sc_core
diff --git a/src/systemc/channel/sc_out_resolved.cc b/src/systemc/channel/sc_out_resolved.cc
index a3947f6..af61f31 100644
--- a/src/systemc/channel/sc_out_resolved.cc
+++ b/src/systemc/channel/sc_out_resolved.cc
@@ -33,50 +33,45 @@
 namespace sc_core
 {

-sc_out_resolved::sc_out_resolved() : sc_out<sc_dt::sc_logic>() {}
-
-sc_out_resolved::sc_out_resolved(const char *name) :
-        sc_out<sc_dt::sc_logic>(name) {}
-
+sc_out_resolved::sc_out_resolved() : sc_inout_resolved() {}
+sc_out_resolved::sc_out_resolved(const char *name) : sc_inout_resolved(name) {}
 sc_out_resolved::~sc_out_resolved() {}

 sc_out_resolved &
-sc_out_resolved::operator = (const sc_dt::sc_logic &)
+sc_out_resolved::operator = (const sc_dt::sc_logic &l)
 {
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+    (*this)->write(l);
     return *this;
 }

 sc_out_resolved &
-sc_out_resolved::operator = (const sc_signal_in_if<sc_dt::sc_logic> &)
+sc_out_resolved::operator = (const sc_signal_in_if<sc_dt::sc_logic> &i)
 {
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+    (*this)->write(i.read());
     return *this;
 }

 sc_out_resolved &
 sc_out_resolved::operator = (
-        const sc_port<sc_signal_in_if<sc_dt::sc_logic>, 1> &)
+        const sc_port<sc_signal_in_if<sc_dt::sc_logic>, 1> &p)
 {
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+    (*this)->write(p->read());
     return *this;
 }

 sc_out_resolved &
 sc_out_resolved::operator = (
-        const sc_port<sc_signal_inout_if<sc_dt::sc_logic>, 1> &)
+        const sc_port<sc_signal_inout_if<sc_dt::sc_logic>, 1> &p)
 {
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+    (*this)->write(p->read());
     return *this;
 }

 sc_out_resolved &
-sc_out_resolved::operator = (const sc_out_resolved &)
+sc_out_resolved::operator = (const sc_out_resolved &p)
 {
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+    (*this)->write(p->read());
     return *this;
 }

-const char *sc_out_resolved::kind() const { return "sc_out_resolved"; }
-
 } // namespace sc_core
diff --git a/src/systemc/channel/sc_signal_resolved.cc b/src/systemc/channel/sc_signal_resolved.cc
index 9043184..1190824 100644
--- a/src/systemc/channel/sc_signal_resolved.cc
+++ b/src/systemc/channel/sc_signal_resolved.cc
@@ -28,6 +28,8 @@
  */

 #include "base/logging.hh"
+#include "systemc/core/process.hh"
+#include "systemc/core/scheduler.hh"
 #include "systemc/ext/channel/sc_signal_resolved.hh"
 #include "systemc/ext/core/sc_module.hh" // for sc_gen_unique_name

@@ -44,39 +46,58 @@
 {}

 sc_signal_resolved::~sc_signal_resolved() {}
+void sc_signal_resolved::register_port(sc_port_base &, const char *) {}

 void
-sc_signal_resolved::register_port(sc_port_base &, const char *)
+sc_signal_resolved::write(const sc_dt::sc_logic &l)
 {
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
-}
+    ::sc_gem5::Process *p = ::sc_gem5::scheduler.current();

-void
-sc_signal_resolved::write(const sc_dt::sc_logic &)
-{
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+    auto it = inputs.find(p);
+    if (it == inputs.end()) {
+        inputs.emplace(p, l);
+        request_update();
+    } else if (it->second != l) {
+        it->second = l;
+        request_update();
+    }
 }

 sc_signal_resolved &
-sc_signal_resolved::operator = (const sc_dt::sc_logic &)
+sc_signal_resolved::operator = (const sc_dt::sc_logic &l)
 {
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+    write(l);
     return *this;
 }

 sc_signal_resolved &
-sc_signal_resolved::operator = (const sc_signal_resolved &)
+sc_signal_resolved::operator = (const sc_signal_resolved &r)
 {
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+    write(r.read());
     return *this;
 }

-const char *sc_signal_resolved::kind() const { return "sc_signal_resolved"; }
-
 void
 sc_signal_resolved::update()
 {
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+    using sc_dt::Log_0;
+    using sc_dt::Log_1;
+    using sc_dt::Log_Z;
+    using sc_dt::Log_X;
+    static sc_dt::sc_logic_value_t merge_table[4][4] = {
+        { Log_0, Log_X, Log_0, Log_X },
+        { Log_X, Log_1, Log_1, Log_X },
+        { Log_0, Log_1, Log_Z, Log_X },
+        { Log_X, Log_X, Log_X, Log_X }
+    };
+
+ // Resolve the inputs, and give the result to the underlying signal class.
+    m_new_val = Log_Z;
+    for (auto &input: inputs)
+        m_new_val = merge_table[m_new_val.value()][input.second.value()];
+
+    // Ask the signal to update it's value.
+    sc_signal<sc_dt::sc_logic, SC_MANY_WRITERS>::update();
 }

 } // namespace sc_core
diff --git a/src/systemc/ext/channel/sc_in_resolved.hh b/src/systemc/ext/channel/sc_in_resolved.hh
index 1c49b8c..6aba8ee 100644
--- a/src/systemc/ext/channel/sc_in_resolved.hh
+++ b/src/systemc/ext/channel/sc_in_resolved.hh
@@ -51,7 +51,7 @@

     virtual void end_of_elaboration();

-    virtual const char *kind() const;
+    virtual const char *kind() const { return "sc_in_resolved"; }

   private:
     // Disabled
diff --git a/src/systemc/ext/channel/sc_inout_resolved.hh b/src/systemc/ext/channel/sc_inout_resolved.hh
index 32348db..7466bc3 100644
--- a/src/systemc/ext/channel/sc_inout_resolved.hh
+++ b/src/systemc/ext/channel/sc_inout_resolved.hh
@@ -62,7 +62,7 @@
             const sc_port<sc_signal_inout_if<sc_dt::sc_logic>, 1> &);
     sc_inout_resolved &operator = (const sc_inout_resolved &);

-    virtual const char *kind() const;
+    virtual const char *kind() const { return "sc_inout_resolved"; }

   private:
     // Disabled
diff --git a/src/systemc/ext/channel/sc_out_resolved.hh b/src/systemc/ext/channel/sc_out_resolved.hh
index 0a8f298..25f9234 100644
--- a/src/systemc/ext/channel/sc_out_resolved.hh
+++ b/src/systemc/ext/channel/sc_out_resolved.hh
@@ -30,6 +30,7 @@
 #ifndef __SYSTEMC_EXT_CHANNEL_SC_OUT_RESOLVED_HH__
 #define __SYSTEMC_EXT_CHANNEL_SC_OUT_RESOLVED_HH__

+#include "sc_inout_resolved.hh"
 #include "sc_out.hh"
 #include "sc_signal_in_if.hh"
 #include "sc_signal_inout_if.hh"
@@ -45,7 +46,7 @@
 namespace sc_core
 {

-class sc_out_resolved : public sc_out<sc_dt::sc_logic>
+class sc_out_resolved : public sc_inout_resolved
 {
   public:
     sc_out_resolved();
@@ -60,11 +61,11 @@
             const sc_port<sc_signal_inout_if<sc_dt::sc_logic>, 1> &);
     sc_out_resolved &operator = (const sc_out_resolved &);

-    virtual const char *kind() const;
+    virtual const char *kind() const { return "sc_out_resolved"; }

   private:
     // Disabled
-    sc_out_resolved(const sc_out_resolved &) : sc_out<sc_dt::sc_logic>() {}
+    sc_out_resolved(const sc_out_resolved &) : sc_inout_resolved() {}
 };

 } // namespace sc_core
diff --git a/src/systemc/ext/channel/sc_signal_resolved.hh b/src/systemc/ext/channel/sc_signal_resolved.hh
index f04fa36..6daacc0 100644
--- a/src/systemc/ext/channel/sc_signal_resolved.hh
+++ b/src/systemc/ext/channel/sc_signal_resolved.hh
@@ -30,6 +30,8 @@
 #ifndef __SYSTEMC_EXT_CHANNEL_SC_SIGNAL_RESOLVED_HH__
 #define __SYSTEMC_EXT_CHANNEL_SC_SIGNAL_RESOLVED_HH__

+#include <map>
+
 #include "sc_signal.hh"
 #include "sc_signal_inout_if.hh"

@@ -40,6 +42,13 @@

 };

+namespace sc_gem5
+{
+
+class Process;
+
+} // namespace sc_gem5
+
 namespace sc_core
 {

@@ -58,7 +67,7 @@
     sc_signal_resolved &operator = (const sc_dt::sc_logic &);
     sc_signal_resolved &operator = (const sc_signal_resolved &);

-    virtual const char *kind() const;
+    virtual const char *kind() const { return "sc_signal_resolved"; }

   protected:
     virtual void update();
@@ -68,6 +77,8 @@
     sc_signal_resolved(const sc_signal_resolved &) :
             sc_interface(), sc_signal<sc_dt::sc_logic, SC_MANY_WRITERS>()
     {}
+
+    std::map<::sc_gem5::Process *, sc_dt::sc_logic> inputs;
 };

 } // namespace sc_core

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/12620
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: Ib595da10e0f900ee4cc1847d41d29251dacb55d7
Gerrit-Change-Number: 12620
Gerrit-PatchSet: 7
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Giacomo Travaglini <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Matthias Jung <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to