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

Change subject: mem-ruby: Use shared and per-protocol SLICC files
......................................................................

mem-ruby: Use shared and per-protocol SLICC files

This changes extends SLICC to understand two different kinds of slicc
files: files that are protocol-specific and files that are shared or
included between different protocols.

Each declaration in SLICC can now be shared or not. If it is shared,
then we can take a different action in the code generation (e.g., wrap
in a namespace).

*Developer facing change*
Removes the RubySlicc_interfaces.slicc file from the SLICC includes of
every protocol.

Changes required: If you have a custom protocol, you will need to remove
the line `include "RubySlicc_interfaces.slicc" from your .slicc file.

Change-Id: Ia6c2dafe2b8fe86749a13d17daa885bddd166855
Signed-off-by: Jason Lowe-Power <ja...@lowepower.com>
---
M src/learning_gem5/part3/MSI.slicc
M src/mem/ruby/protocol/GPU_VIPER.slicc
M src/mem/ruby/protocol/Garnet_standalone.slicc
M src/mem/ruby/protocol/MESI_Three_Level.slicc
M src/mem/ruby/protocol/MESI_Three_Level_HTM.slicc
M src/mem/ruby/protocol/MESI_Two_Level.slicc
M src/mem/ruby/protocol/MI_example.slicc
M src/mem/ruby/protocol/MOESI_AMD_Base.slicc
M src/mem/ruby/protocol/MOESI_CMP_directory.slicc
M src/mem/ruby/protocol/MOESI_CMP_token.slicc
M src/mem/ruby/protocol/MOESI_hammer.slicc
M src/mem/ruby/protocol/RubySlicc_interfaces.slicc
M src/mem/ruby/protocol/SConscript
M src/mem/ruby/protocol/chi/CHI.slicc
M src/mem/slicc/ast/DeclAST.py
M src/mem/slicc/ast/DeclListAST.py
M src/mem/slicc/ast/EnumDeclAST.py
M src/mem/slicc/ast/StateDeclAST.py
M src/mem/slicc/ast/TypeDeclAST.py
M src/mem/slicc/main.py
M src/mem/slicc/parser.py
M src/mem/slicc/symbols/SymbolTable.py
M src/mem/slicc/symbols/Type.py
23 files changed, 104 insertions(+), 45 deletions(-)



diff --git a/src/learning_gem5/part3/MSI.slicc b/src/learning_gem5/part3/MSI.slicc
index c6fdc50..4c02fcb 100644
--- a/src/learning_gem5/part3/MSI.slicc
+++ b/src/learning_gem5/part3/MSI.slicc
@@ -1,5 +1,4 @@
 protocol "MSI";
-include "RubySlicc_interfaces.slicc";
 include "MSI-msg.sm";
 include "MSI-cache.sm";
 include "MSI-dir.sm";
diff --git a/src/mem/ruby/protocol/GPU_VIPER.slicc b/src/mem/ruby/protocol/GPU_VIPER.slicc
index 196058b..2a89d02 100644
--- a/src/mem/ruby/protocol/GPU_VIPER.slicc
+++ b/src/mem/ruby/protocol/GPU_VIPER.slicc
@@ -1,5 +1,4 @@
 protocol "GPU_VIPER";
-include "RubySlicc_interfaces.slicc";
 include "MOESI_AMD_Base-msg.sm";
 include "MOESI_AMD_Base-dir.sm";
 include "MOESI_AMD_Base-dma.sm";
diff --git a/src/mem/ruby/protocol/Garnet_standalone.slicc b/src/mem/ruby/protocol/Garnet_standalone.slicc
index e467f34..8c856af 100644
--- a/src/mem/ruby/protocol/Garnet_standalone.slicc
+++ b/src/mem/ruby/protocol/Garnet_standalone.slicc
@@ -1,5 +1,4 @@
 protocol "Garnet_standalone";
-include "RubySlicc_interfaces.slicc";
 include "Garnet_standalone-msg.sm";
 include "Garnet_standalone-cache.sm";
 include "Garnet_standalone-dir.sm";
diff --git a/src/mem/ruby/protocol/MESI_Three_Level.slicc b/src/mem/ruby/protocol/MESI_Three_Level.slicc
index a24b11c..d37b937 100644
--- a/src/mem/ruby/protocol/MESI_Three_Level.slicc
+++ b/src/mem/ruby/protocol/MESI_Three_Level.slicc
@@ -1,5 +1,4 @@
 protocol "MESI_Three_Level";
-include "RubySlicc_interfaces.slicc";
 include "MESI_Two_Level-msg.sm";
 include "MESI_Three_Level-msg.sm";
 include "MESI_Three_Level-L0cache.sm";
diff --git a/src/mem/ruby/protocol/MESI_Three_Level_HTM.slicc b/src/mem/ruby/protocol/MESI_Three_Level_HTM.slicc
index 4ec31b5..88afc2f 100644
--- a/src/mem/ruby/protocol/MESI_Three_Level_HTM.slicc
+++ b/src/mem/ruby/protocol/MESI_Three_Level_HTM.slicc
@@ -1,5 +1,4 @@
 protocol "MESI_Three_Level_HTM";
-include "RubySlicc_interfaces.slicc";
 include "MESI_Two_Level-msg.sm";
 include "MESI_Three_Level-msg.sm";
 include "MESI_Three_Level_HTM-L0cache.sm";
diff --git a/src/mem/ruby/protocol/MESI_Two_Level.slicc b/src/mem/ruby/protocol/MESI_Two_Level.slicc
index b5bf104..e0f6dda 100644
--- a/src/mem/ruby/protocol/MESI_Two_Level.slicc
+++ b/src/mem/ruby/protocol/MESI_Two_Level.slicc
@@ -1,5 +1,4 @@
 protocol "MESI_Two_Level";
-include "RubySlicc_interfaces.slicc";
 include "MESI_Two_Level-msg.sm";
 include "MESI_Two_Level-L1cache.sm";
 include "MESI_Two_Level-L2cache.sm";
diff --git a/src/mem/ruby/protocol/MI_example.slicc b/src/mem/ruby/protocol/MI_example.slicc
index 7061478..b3c1585 100644
--- a/src/mem/ruby/protocol/MI_example.slicc
+++ b/src/mem/ruby/protocol/MI_example.slicc
@@ -1,5 +1,4 @@
 protocol "MI_example";
-include "RubySlicc_interfaces.slicc";
 include "MI_example-msg.sm";
 include "MI_example-cache.sm";
 include "MI_example-dir.sm";
diff --git a/src/mem/ruby/protocol/MOESI_AMD_Base.slicc b/src/mem/ruby/protocol/MOESI_AMD_Base.slicc
index b381452..50aae8c 100644
--- a/src/mem/ruby/protocol/MOESI_AMD_Base.slicc
+++ b/src/mem/ruby/protocol/MOESI_AMD_Base.slicc
@@ -1,5 +1,4 @@
 protocol "MOESI_AMD_Base";
-include "RubySlicc_interfaces.slicc";
 include "MOESI_AMD_Base-msg.sm";
 include "MOESI_AMD_Base-CorePair.sm";
 include "MOESI_AMD_Base-L3cache.sm";
diff --git a/src/mem/ruby/protocol/MOESI_CMP_directory.slicc b/src/mem/ruby/protocol/MOESI_CMP_directory.slicc
index 215a801..7370cb8 100644
--- a/src/mem/ruby/protocol/MOESI_CMP_directory.slicc
+++ b/src/mem/ruby/protocol/MOESI_CMP_directory.slicc
@@ -1,5 +1,4 @@
 protocol "MOESI_CMP_directory";
-include "RubySlicc_interfaces.slicc";
 include "MOESI_CMP_directory-msg.sm";
 include "MOESI_CMP_directory-L1cache.sm";
 include "MOESI_CMP_directory-L2cache.sm";
diff --git a/src/mem/ruby/protocol/MOESI_CMP_token.slicc b/src/mem/ruby/protocol/MOESI_CMP_token.slicc
index 5bc3a57..4f3e022 100644
--- a/src/mem/ruby/protocol/MOESI_CMP_token.slicc
+++ b/src/mem/ruby/protocol/MOESI_CMP_token.slicc
@@ -1,5 +1,4 @@
 protocol "MOESI_CMP_token";
-include "RubySlicc_interfaces.slicc";
 include "MOESI_CMP_token-msg.sm";
 include "MOESI_CMP_token-L1cache.sm";
 include "MOESI_CMP_token-L2cache.sm";
diff --git a/src/mem/ruby/protocol/MOESI_hammer.slicc b/src/mem/ruby/protocol/MOESI_hammer.slicc
index ab8eb73..fd863e1 100644
--- a/src/mem/ruby/protocol/MOESI_hammer.slicc
+++ b/src/mem/ruby/protocol/MOESI_hammer.slicc
@@ -1,5 +1,4 @@
 protocol "MOESI_hammer";
-include "RubySlicc_interfaces.slicc";
 include "MOESI_hammer-msg.sm";
 include "MOESI_hammer-cache.sm";
 include "MOESI_hammer-dir.sm";
diff --git a/src/mem/ruby/protocol/RubySlicc_interfaces.slicc b/src/mem/ruby/protocol/RubySlicc_interfaces.slicc
index f5a2b63..dfeb642 100644
--- a/src/mem/ruby/protocol/RubySlicc_interfaces.slicc
+++ b/src/mem/ruby/protocol/RubySlicc_interfaces.slicc
@@ -1,3 +1,5 @@
+// All of the sm files that are shared between all protocols
+
 include "RubySlicc_Exports.sm";
 include "RubySlicc_Types.sm";
 include "RubySlicc_Util.sm";
diff --git a/src/mem/ruby/protocol/SConscript b/src/mem/ruby/protocol/SConscript
index 238ce2f..62e3e10 100644
--- a/src/mem/ruby/protocol/SConscript
+++ b/src/mem/ruby/protocol/SConscript
@@ -66,7 +66,12 @@
     assert len(source) == 1
     filepath = source[0].srcnode().abspath

-    slicc = SLICC(filepath, protocol_base.abspath, verbose=False)
+    slicc = SLICC(
+        filepath,
+ [os.path.join(protocol_base.abspath, 'RubySlicc_interfaces.slicc')],
+        protocol_base.abspath,
+        verbose=False
+    )
     slicc.process()
     slicc.writeCodeFiles(output_dir.abspath, slicc_includes)
     if env['CONF']['SLICC_HTML']:
@@ -78,8 +83,12 @@
 def slicc_action(target, source, env):
     assert len(source) == 1
     filepath = source[0].srcnode().abspath
-
-    slicc = SLICC(filepath, protocol_base.abspath, verbose=True)
+    slicc = SLICC(
+        filepath,
+ [os.path.join(protocol_base.abspath, 'RubySlicc_interfaces.slicc')],
+        protocol_base.abspath,
+        verbose=True
+    )
     slicc.process()
     slicc.writeCodeFiles(output_dir.abspath, slicc_includes)
     if env['CONF']['SLICC_HTML']:
diff --git a/src/mem/ruby/protocol/chi/CHI.slicc b/src/mem/ruby/protocol/chi/CHI.slicc
index 27724bb..87d517c 100644
--- a/src/mem/ruby/protocol/chi/CHI.slicc
+++ b/src/mem/ruby/protocol/chi/CHI.slicc
@@ -1,6 +1,5 @@
 protocol "CHI";

-include "RubySlicc_interfaces.slicc";
 include "CHI-msg.sm";
 include "CHI-cache.sm";
 include "CHI-mem.sm";
diff --git a/src/mem/slicc/ast/DeclAST.py b/src/mem/slicc/ast/DeclAST.py
index ce3f252..7ea5c9a 100644
--- a/src/mem/slicc/ast/DeclAST.py
+++ b/src/mem/slicc/ast/DeclAST.py
@@ -30,6 +30,12 @@
 class DeclAST(AST):
     def __init__(self, slicc, pairs = None):
         super().__init__(slicc, pairs)
+        # If true, then this declaration is shared between protocols
+        self.shared = False
+
+    def setShared(self, shared: bool):
+        """Used to mark this declaration as shared between protocols"""
+        self.shared = shared

     def files(self, parent=None):
         return set()
diff --git a/src/mem/slicc/ast/DeclListAST.py b/src/mem/slicc/ast/DeclListAST.py
index 4e1538c..e25cd50 100644
--- a/src/mem/slicc/ast/DeclListAST.py
+++ b/src/mem/slicc/ast/DeclListAST.py
@@ -48,3 +48,12 @@
         for decl in self.decls:
             decl.findMachines()
             decl.generate()
+
+    def setShared(self):
+        """Mark all types in this DeclList as shared"""
+        for decl in self.decls:
+            decl.setShared(True)
+
+    def __iadd__(self, other):
+        self.decls += other.decls
+        return self
diff --git a/src/mem/slicc/ast/EnumDeclAST.py b/src/mem/slicc/ast/EnumDeclAST.py
index 9694dd9..5a3fd7a 100644
--- a/src/mem/slicc/ast/EnumDeclAST.py
+++ b/src/mem/slicc/ast/EnumDeclAST.py
@@ -53,7 +53,7 @@
         ident = str(self.type_ast)

         # Make the new type
-        t = Type(self.symtab, ident, self.location, self.pairs,
+ t = Type(self.symtab, ident, self.location, self.pairs, self.shared,
                  self.state_machine)
         self.symtab.newSymbol(t)

diff --git a/src/mem/slicc/ast/StateDeclAST.py b/src/mem/slicc/ast/StateDeclAST.py
index 300080e..4100296 100644
--- a/src/mem/slicc/ast/StateDeclAST.py
+++ b/src/mem/slicc/ast/StateDeclAST.py
@@ -52,7 +52,7 @@
         ident = str(self.type_ast)

         # Make the new type
-        t = Type(self.symtab, ident, self.location, self.pairs,
+ t = Type(self.symtab, ident, self.location, self.pairs, self.shared,
                  self.state_machine)
         self.symtab.newSymbol(t)

diff --git a/src/mem/slicc/ast/TypeDeclAST.py b/src/mem/slicc/ast/TypeDeclAST.py
index f4c4c8e..9748178 100644
--- a/src/mem/slicc/ast/TypeDeclAST.py
+++ b/src/mem/slicc/ast/TypeDeclAST.py
@@ -54,7 +54,7 @@

         # Make the new type
         new_type = Type(self.symtab, ident, self.location, self.pairs,
-                        self.state_machine)
+                        self.shared, self.state_machine)

         if machine:
             machine.addType(new_type)
diff --git a/src/mem/slicc/main.py b/src/mem/slicc/main.py
index c3afd2e..0b82a98 100644
--- a/src/mem/slicc/main.py
+++ b/src/mem/slicc/main.py
@@ -30,7 +30,7 @@

 from slicc.parser import SLICC

-usage="%prog [options] <slicc file> ... "
+usage="%prog [options] <slicc files> ... "
 version="%prog v0.4"
 brief_copyright='''
 Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
@@ -73,15 +73,11 @@
                       help="don't print messages")
     opts,files = parser.parse_args(args=args)

-    if len(files) != 1:
-        parser.print_help()
-        sys.exit(2)
-
-    slicc_file = files[0]
-    if not slicc_file.endswith('.slicc'):
- print("Must specify a .slicc file with a list of state machine files")
-        parser.print_help()
-        sys.exit(2)
+    for slicc_file in files:
+        if not slicc_file.endswith('.slicc'):
+            print("Must specify a .slicc file")
+            parser.print_help()
+            sys.exit(2)

     output = nprint if opts.quiet else eprint

@@ -90,23 +86,31 @@

     protocol_base = os.path.join(os.path.dirname(__file__),
                                  '..', 'ruby', 'protocol')
- slicc = SLICC(slicc_file, protocol_base, verbose=True, debug=opts.debug,
-                  traceback=opts.tb)
+
+    for slicc_file in files:
+        output(f"Working on {slicc_file}")
+        slicc = SLICC(
+            slicc_file,
+            [os.path.join(protocol_base, 'RubySlicc_interfaces.slicc')],
+            protocol_base,
+            verbose=True, debug=opts.debug,
+            traceback=opts.tb
+        )


-    if opts.print_files:
-        for i in sorted(slicc.files()):
-            print('    %s' % i)
-    else:
-        output("Processing AST...")
-        slicc.process()
+        if opts.print_files:
+            for i in sorted(slicc.files()):
+                print('    %s' % i)
+        else:
+            output("Processing AST...")
+            slicc.process()

-        if opts.html_path:
-            output("Writing HTML files...")
-            slicc.writeHTMLFiles(opts.html_path)
+            if opts.html_path:
+                output("Writing HTML files...")
+                slicc.writeHTMLFiles(opts.html_path)

-        output("Writing C++ files...")
-        slicc.writeCodeFiles(opts.code_path, [])
+            output("Writing C++ files...")
+            slicc.writeCodeFiles(opts.code_path, [])


     output("SLICC is Done.")
diff --git a/src/mem/slicc/parser.py b/src/mem/slicc/parser.py
index cc45f95..e2b0a64 100644
--- a/src/mem/slicc/parser.py
+++ b/src/mem/slicc/parser.py
@@ -49,15 +49,30 @@
 from slicc.symbols import SymbolTable

 class SLICC(Grammar):
- def __init__(self, filename, base_dir, verbose=False, traceback=False, **kwargs):
+    def __init__(self, protocol, includes, base_dir, verbose=False,
+                 traceback=False, **kwargs):
+        """Entrypoint for SLICC parsing
+        protocol: The protocol `.slicc` file to parse
+ includes: list of `.slicc` files that are shared between all protocols
+        """
         self.protocol = None
         self.traceback = traceback
         self.verbose = verbose
         self.symtab = SymbolTable(self)
         self.base_dir = base_dir

+        if not includes:
+            # raise error
+            pass
+
         try:
-            self.decl_list = self.parse_file(filename, **kwargs)
+            self.decl_list = self.parse_file(includes[0], **kwargs)
+            for include in includes[1:]:
+                self.decl_list += self.parse_file(include, **kwargs)
+            # set all of the types parsed so far as shared
+            self.decl_list.setShared()
+
+            self.decl_list += self.parse_file(protocol, **kwargs)
         except ParseError as e:
             if not self.traceback:
                 sys.exit(str(e))
diff --git a/src/mem/slicc/symbols/SymbolTable.py b/src/mem/slicc/symbols/SymbolTable.py
index f9f7a10..7f0b415 100644
--- a/src/mem/slicc/symbols/SymbolTable.py
+++ b/src/mem/slicc/symbols/SymbolTable.py
@@ -53,7 +53,7 @@
         pairs["primitive"] = "yes"
         pairs["external"] = "yes"
         location = Location("init", 0, no_warning=not slicc.verbose)
-        void = Type(self, "void", location, pairs)
+        void = Type(self, "void", location, pairs, False)
         self.newSymbol(void)

     def __repr__(self):
diff --git a/src/mem/slicc/symbols/Type.py b/src/mem/slicc/symbols/Type.py
index a87e6b5..a9c5303 100644
--- a/src/mem/slicc/symbols/Type.py
+++ b/src/mem/slicc/symbols/Type.py
@@ -59,10 +59,11 @@
         self.primary = False

 class Type(Symbol):
-    def __init__(self, table, ident, location, pairs, machine=None):
+ def __init__(self, table, ident, location, pairs, shared, machine=None):
         super().__init__(table, ident, location, pairs)
         self.c_ident = ident
         self.abstract_ident = ""
+        self.shared = shared
         if machine:
             if self.isExternal or self.isPrimitive:
                 if "external_name" in self:

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/58431
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: Ia6c2dafe2b8fe86749a13d17daa885bddd166855
Gerrit-Change-Number: 58431
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