Jason Lowe-Power has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/58435 )

Change subject: mem-ruby: Move getNumControllers out of machines
......................................................................

mem-ruby: Move getNumControllers out of machines

Move the getNumControllers function out of the protocol-specific
machine definitions (which are now in their own namespaces) to a
Base<Machine>Machine class that the protocol-specific machines inherit
from. This design was the simplest way to keep backwards compatibility.

The one caveat is that this design means that while you can compile
multiple protocols into one binary, you cannot use the same machine type
from different protocols in one simulation. This is the current
assumption, so it shouldn't change anything for users.

Change-Id: If9eeb78c24eb5076956b9f44fa04c7e6eb0f0dd4
Signed-off-by: Jason Lowe-Power <ja...@lowepower.com>
---
M src/mem/slicc/symbols/StateMachine.py
M src/mem/slicc/symbols/Type.py
2 files changed, 44 insertions(+), 23 deletions(-)



diff --git a/src/mem/slicc/symbols/StateMachine.py b/src/mem/slicc/symbols/StateMachine.py
index 3ef6b5b..2a0d6a4 100644
--- a/src/mem/slicc/symbols/StateMachine.py
+++ b/src/mem/slicc/symbols/StateMachine.py
@@ -342,12 +342,11 @@

 extern std::stringstream ${ident}_transitionComment;

-class $c_ident : public AbstractController
+class $c_ident : public AbstractController, Base${ident}Machine
 {
   public:
     typedef ${py_ident}Params Params;
     $c_ident(const Params &p);
-    static int getNumControllers();
     void init();

     MessageBuffer *getMandatoryQueue() const;
@@ -432,7 +431,6 @@

 static std::vector<statistics::Vector *> eventVec;
 static std::vector<std::vector<statistics::Vector *> > transVec;
-static int m_num_controllers;

 // Internal functions
 ''')
@@ -596,7 +594,6 @@
 namespace ${protocol}
 {

-int $c_ident::m_num_controllers = 0;
 std::vector<statistics::Vector *>  $c_ident::eventVec;
 std::vector<std::vector<statistics::Vector *> >  $c_ident::transVec;

@@ -1030,12 +1027,6 @@
     return m_counters[state][event];
 }

-int
-$c_ident::getNumControllers()
-{
-    return m_num_controllers;
-}
-
 MessageBuffer*
 $c_ident::getMandatoryQueue() const
 {
diff --git a/src/mem/slicc/symbols/Type.py b/src/mem/slicc/symbols/Type.py
index 282f55a..2973046 100644
--- a/src/mem/slicc/symbols/Type.py
+++ b/src/mem/slicc/symbols/Type.py
@@ -583,6 +583,20 @@
 MachineID get${{enum.ident}}MachineID(NodeID RubyNode);
 ''')

+                # Machine types are expected to be overridden by protocol-
+                # specific classes.
+                if self.isMachineType:
+                    code('''
+
+class Base${{enum.ident}}Machine {
+  protected:
+    static int m_num_controllers;
+  public:
+    static int getNumControllers() { return m_num_controllers; }
+};
+
+''')
+
         if self.isStateDecl:
             code('''

@@ -699,10 +713,6 @@
 ''')

         if self.isMachineType:
-            for enum in self.enums.values():
-                if enum.primary:
-                    code('#include "mem/ruby/protocol/${{protocol}}/'
-                            '${{enum.ident}}_Controller.hh"')
             code('#include "mem/ruby/common/MachineID.hh"')

         code('''
@@ -858,13 +868,9 @@
             code.indent()
             code('  case ${{self.c_ident}}_NUM:')
             for enum in reversed(list(self.enums.values())):
-                # Check if there is a defined machine with this type
-                if enum.primary:
-                    code('''
-    base += ${{protocol}}::${{enum.ident}}_Controller::getNumControllers();
+                code('''
+    base += Base${{enum.ident}}Machine::getNumControllers();
 ''')
-                else:
-                    code('    base += 0;')
                 code('    [[fallthrough]];')
                 code('  case ${{self.c_ident}}_${{enum.ident}}:')
             code('    break;')
@@ -890,9 +896,8 @@
             # For each field
             for enum in self.enums.values():
                 code('case ${{self.c_ident}}_${{enum.ident}}:')
-                if enum.primary:
-                    code('''
-    return ${{protocol}}::${{enum.ident}}_Controller::getNumControllers();
+                code('''
+    return Base${{enum.ident}}Machine::getNumControllers();
 ''')

             # total num
@@ -916,6 +921,11 @@
       return mach;
 }
 ''')
+                if self.isMachineType:
+                    code('''
+
+int Base${{enum.ident}}Machine::m_num_controllers = 0;
+''')

         # For protocol-specific types, close the protocol namespace
         if not self.shared:

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

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: If9eeb78c24eb5076956b9f44fa04c7e6eb0f0dd4
Gerrit-Change-Number: 58435
Gerrit-PatchSet: 1
Gerrit-Owner: Jason Lowe-Power <power...@gmail.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to