Jason Lowe-Power has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/58433 )
Change subject: mem-ruby: Move protocol files to subdir
......................................................................
mem-ruby: Move protocol files to subdir
Move all generated protocol-specific files to a subdirectory with the
protocol's name.
This change also updates SLICC to have separate variables for the
filename, c identifier and python identifier instead of just using
variations of the c identifier.
Change-Id: I62f69a4606b030ee23cb2d96493f3257a6923748
Signed-off-by: Jason Lowe-Power <ja...@lowepower.com>
---
M src/mem/slicc/ast/EnumDeclAST.py
M src/mem/slicc/ast/MachineAST.py
M src/mem/slicc/ast/StateDeclAST.py
M src/mem/slicc/ast/TypeDeclAST.py
M src/mem/slicc/parser.py
M src/mem/slicc/symbols/StateMachine.py
M src/mem/slicc/symbols/SymbolTable.py
M src/mem/slicc/symbols/Type.py
8 files changed, 109 insertions(+), 51 deletions(-)
diff --git a/src/mem/slicc/ast/EnumDeclAST.py
b/src/mem/slicc/ast/EnumDeclAST.py
index 5a3fd7a..3e71dc0 100644
--- a/src/mem/slicc/ast/EnumDeclAST.py
+++ b/src/mem/slicc/ast/EnumDeclAST.py
@@ -46,6 +46,8 @@
ident = "%s_%s" % (parent, self.type_ast.ident)
else:
ident = self.type_ast.ident
+ if not self.shared:
+ ident = f"{self.slicc.protocol}/{ident}"
s = set(("%s.hh" % ident, "%s.cc" % ident))
return s
diff --git a/src/mem/slicc/ast/MachineAST.py
b/src/mem/slicc/ast/MachineAST.py
index 7434d6b..4114f01 100644
--- a/src/mem/slicc/ast/MachineAST.py
+++ b/src/mem/slicc/ast/MachineAST.py
@@ -41,11 +41,13 @@
return "[Machine: %r]" % self.ident
def files(self, parent=None):
- s = set(('%s_Controller.cc' % self.ident,
- '%s_Controller.hh' % self.ident,
- '%s_Controller.py' % self.ident,
- '%s_Transitions.cc' % self.ident,
- '%s_Wakeup.cc' % self.ident))
+ import os
+ file_prefix = os.path.join(self.slicc.protocol, self.ident)
+ s = set(('%s_Controller.cc' % file_prefix,
+ '%s_Controller.hh' % file_prefix,
+ '%s_Controller.py' % file_prefix,
+ '%s_Transitions.cc' % file_prefix,
+ '%s_Wakeup.cc' % file_prefix))
s |= self.decls.files(self.ident)
return s
diff --git a/src/mem/slicc/ast/StateDeclAST.py
b/src/mem/slicc/ast/StateDeclAST.py
index 4100296..1fffaa1 100644
--- a/src/mem/slicc/ast/StateDeclAST.py
+++ b/src/mem/slicc/ast/StateDeclAST.py
@@ -45,6 +45,8 @@
ident = "%s_%s" % (parent, self.type_ast.ident)
else:
ident = self.type_ast.ident
+ if not self.shared:
+ ident = f"{self.slicc.protocol}/{ident}"
s = set(("%s.hh" % ident, "%s.cc" % ident))
return s
diff --git a/src/mem/slicc/ast/TypeDeclAST.py
b/src/mem/slicc/ast/TypeDeclAST.py
index 9748178..000d66e 100644
--- a/src/mem/slicc/ast/TypeDeclAST.py
+++ b/src/mem/slicc/ast/TypeDeclAST.py
@@ -46,6 +46,8 @@
ident = "%s_%s" % (parent, self.type_ast.ident)
else:
ident = self.type_ast.ident
+ if not self.shared:
+ ident = f"{self.slicc.protocol}/{ident}"
return set(("%s.hh" % ident, "%s.cc" % ident))
def generate(self):
diff --git a/src/mem/slicc/parser.py b/src/mem/slicc/parser.py
index e2b0a64..78a16bf 100644
--- a/src/mem/slicc/parser.py
+++ b/src/mem/slicc/parser.py
@@ -97,7 +97,7 @@
self.symtab.writeHTMLFiles(html_path)
def files(self):
- f = set(['Types.hh'])
+ f = set([os.path.join(self.protocol, 'Types.hh')])
f |= self.decl_list.files()
diff --git a/src/mem/slicc/symbols/StateMachine.py
b/src/mem/slicc/symbols/StateMachine.py
index e220731..2540b0d 100644
--- a/src/mem/slicc/symbols/StateMachine.py
+++ b/src/mem/slicc/symbols/StateMachine.py
@@ -235,8 +235,10 @@
code = self.symtab.codeFormatter()
ident = self.ident
+ protocol = self.symtab.slicc.protocol
py_ident = "%s_Controller" % ident
c_ident = "%s_Controller" % self.ident
+ gen_filename = f"{protocol}/{py_ident}"
code('''
from m5.params import *
@@ -245,8 +247,8 @@
class $py_ident(RubyController):
type = '$py_ident'
- cxx_header = 'mem/ruby/protocol/${c_ident}.hh'
- cxx_class = 'gem5::ruby::$protocol::$py_ident'
+ cxx_header = 'mem/ruby/protocol/${protocol}/${c_ident}.hh'
+ cxx_class = 'gem5::ruby::$protocol::$c_ident'
''')
code.indent()
for param in self.config_parameters:
@@ -265,7 +267,7 @@
"in StateMachine.py",
param.type_ast.type.c_ident)
code.dedent()
- code.write(path, '%s.py' % py_ident)
+ code.write(path, '%s.py' % gen_filename)
def printControllerHH(self, path):
@@ -273,12 +275,14 @@
code = self.symtab.codeFormatter()
ident = self.ident
c_ident = "%s_Controller" % self.ident
+ header_string = self.symtab.slicc.protocol + '_' + self.ident
+ gen_filename = f"{self.symtab.slicc.protocol}/{c_ident}"
code('''
// Created by slicc definition of Module "${{self.short}}"
-#ifndef __${ident}_CONTROLLER_HH__
-#define __${ident}_CONTROLLER_HH__
+#ifndef __${header_string}_CONTROLLER_HH__
+#define __${header_string}_CONTROLLER_HH__
#include <iostream>
#include <sstream>
@@ -286,7 +290,7 @@
#include "mem/ruby/common/Consumer.hh"
#include "mem/ruby/protocol/TransitionResult.hh"
-#include "mem/ruby/protocol/Types.hh"
+#include "mem/ruby/protocol/${protocol}/Types.hh"
#include "mem/ruby/slicc_interface/AbstractController.hh"
#include "params/$c_ident.hh"
@@ -295,7 +299,14 @@
seen_types = set()
for var in self.objects:
if var.type.ident not in seen_types and not
var.type.isPrimitive:
-
code('#include "mem/ruby/protocol/${{var.type.c_ident}}.hh"')
+ if var.type.shared or var.type.isExternal:
+ code('''
+#include "mem/ruby/protocol/${{var.type.c_ident}}.hh"
+''')
+ else:
+ code('''
+#include "mem/ruby/protocol/${{protocol}}/${{var.type.c_ident}}.hh"
+''')
seen_types.add(var.type.ident)
# for adding information to the protocol debug trace
@@ -470,10 +481,10 @@
} // namespace ruby
} // namespace gem5
-#endif // __${ident}_CONTROLLER_H__
+#endif // __${header_string}_CONTROLLER_H__
''')
- code.write(path, '%s.hh' % c_ident)
+ code.write(path, '%s.hh' % gen_filename)
def printControllerCC(self, path, includes):
'''Output the actions for performing the actions'''
@@ -481,6 +492,7 @@
code = self.symtab.codeFormatter()
ident = self.ident
c_ident = "%s_Controller" % self.ident
+ gen_filename = f"{self.symtab.slicc.protocol}/{self.ident}"
# Unfortunately, clang compilers will throw a "call to function ...
# that is neither visible in the template definition nor found by
@@ -528,10 +540,10 @@
code('#include "debug/${{f}}.hh"')
code('''
#include "mem/ruby/network/Network.hh"
-#include "mem/ruby/protocol/${ident}_Controller.hh"
-#include "mem/ruby/protocol/${ident}_Event.hh"
-#include "mem/ruby/protocol/${ident}_State.hh"
-#include "mem/ruby/protocol/Types.hh"
+#include "mem/ruby/protocol/${gen_filename}_Controller.hh"
+#include "mem/ruby/protocol/${gen_filename}_Event.hh"
+#include "mem/ruby/protocol/${gen_filename}_State.hh"
+#include "mem/ruby/protocol/${protocol}/Types.hh"
#include "mem/ruby/system/RubySystem.hh"
''')
@@ -542,7 +554,14 @@
seen_types = set()
for var in self.objects:
if var.type.ident not in seen_types and not
var.type.isPrimitive:
-
code('#include "mem/ruby/protocol/${{var.type.c_ident}}.hh"')
+ if var.type.shared or var.type.isExternal:
+ code('''
+#include "mem/ruby/protocol/${{var.type.c_ident}}.hh"
+''')
+ else:
+ code('''
+#include "mem/ruby/protocol/${{protocol}}/${{var.type.c_ident}}.hh"
+''')
seen_types.add(var.type.ident)
num_in_ports = len(self.in_ports)
@@ -1233,13 +1252,14 @@
} // namespace gem5
''')
- code.write(path, "%s.cc" % c_ident)
+ code.write(path, "%s_Controller.cc" % gen_filename)
def printCWakeup(self, path, includes):
'''Output the wakeup loop for the events'''
code = self.symtab.codeFormatter()
ident = self.ident
+ gen_filename = f"{self.symtab.slicc.protocol}/{self.ident}"
outputRequest_types = True
if len(self.request_types) == 0:
@@ -1262,17 +1282,19 @@
for f in sorted(self.debug_flags):
code('#include "debug/${{f}}.hh"')
code('''
-#include "mem/ruby/protocol/${ident}_Controller.hh"
-#include "mem/ruby/protocol/${ident}_Event.hh"
-#include "mem/ruby/protocol/${ident}_State.hh"
+#include "mem/ruby/protocol/${gen_filename}_Controller.hh"
+#include "mem/ruby/protocol/${gen_filename}_Event.hh"
+#include "mem/ruby/protocol/${gen_filename}_State.hh"
''')
if outputRequest_types:
-
code('''#include "mem/ruby/protocol/${ident}_RequestType.hh"''')
+ code('''
+#include "mem/ruby/protocol/${protocol}/${ident}_RequestType.hh"
+''')
code('''
-#include "mem/ruby/protocol/Types.hh"
+#include "mem/ruby/protocol/${protocol}/Types.hh"
#include "mem/ruby/system/RubySystem.hh"
''')
@@ -1373,13 +1395,14 @@
} // namespace gem5
''')
- code.write(path, "%s_Wakeup.cc" % self.ident)
+ code.write(path, "%s_Wakeup.cc" % gen_filename)
def printCSwitch(self, path):
'''Output switch statement for transition table'''
code = self.symtab.codeFormatter()
ident = self.ident
+ gen_filename = f"{self.symtab.slicc.protocol}/{self.ident}"
code('''
// ${ident}: ${{self.short}}
@@ -1390,10 +1413,10 @@
#include "base/trace.hh"
#include "debug/ProtocolTrace.hh"
#include "debug/RubyGenerated.hh"
-#include "mem/ruby/protocol/${ident}_Controller.hh"
-#include "mem/ruby/protocol/${ident}_Event.hh"
-#include "mem/ruby/protocol/${ident}_State.hh"
-#include "mem/ruby/protocol/Types.hh"
+#include "mem/ruby/protocol/${gen_filename}_Controller.hh"
+#include "mem/ruby/protocol/${gen_filename}_Event.hh"
+#include "mem/ruby/protocol/${gen_filename}_State.hh"
+#include "mem/ruby/protocol/${protocol}/Types.hh"
#include "mem/ruby/system/RubySystem.hh"
#define HASH_FUN(state, event)
((int(state)*${ident}_Event_NUM)+int(event))
@@ -1642,7 +1665,7 @@
} // namespace ruby
} // namespace gem5
''')
- code.write(path, "%s_Transitions.cc" % self.ident)
+ code.write(path, "%s_Transitions.cc" % gen_filename)
# **************************
diff --git a/src/mem/slicc/symbols/SymbolTable.py
b/src/mem/slicc/symbols/SymbolTable.py
index 7f0b415..d51ba18 100644
--- a/src/mem/slicc/symbols/SymbolTable.py
+++ b/src/mem/slicc/symbols/SymbolTable.py
@@ -133,6 +133,7 @@
def writeCodeFiles(self, path, includes):
makeDir(path)
+ makeDir(os.path.join(path, self.slicc.protocol))
code = self.codeFormatter()
@@ -141,9 +142,12 @@
for symbol in self.sym_vec:
if isinstance(symbol, Type) and not symbol.isPrimitive:
- code('#include "mem/ruby/protocol/${{symbol.c_ident}}.hh"')
+ ident = symbol.c_ident
+ if not symbol.shared and not symbol.isExternal:
+ ident = f"{self.slicc.protocol}/{ident}"
+ code('#include "mem/ruby/protocol/${{ident}}.hh"')
- code.write(path, "Types.hh")
+ code.write(path, f"{self.slicc.protocol}/Types.hh")
for symbol in self.sym_vec:
symbol.writeCodeFiles(path, includes)
diff --git a/src/mem/slicc/symbols/Type.py b/src/mem/slicc/symbols/Type.py
index bb8ff0c..282f55a 100644
--- a/src/mem/slicc/symbols/Type.py
+++ b/src/mem/slicc/symbols/Type.py
@@ -71,6 +71,14 @@
else:
# Append with machine name
self.c_ident = "%s_%s" % (machine, ident)
+ if shared or not table.slicc.protocol or self.isExternal:
+ self.protocol_specific = ""
+ self.gen_filename = self.c_ident
+ self.header_string = self.c_ident
+ else:
+ self.protocol_specific = table.slicc.protocol
+ self.gen_filename = self.protocol_specific + '/' + self.c_ident
+ self.header_string = self.protocol_specific + '_' +
self.c_ident
self.pairs.setdefault("desc", "No description avaliable")
@@ -204,8 +212,8 @@
def printTypeHH(self, path):
code = self.symtab.codeFormatter()
code('''
-#ifndef __${{self.c_ident}}_HH__
-#define __${{self.c_ident}}_HH__
+#ifndef __${{self.header_string}}_HH__
+#define __${{self.header_string}}_HH__
#include <iostream>
@@ -215,7 +223,7 @@
for dm in self.data_members.values():
if not dm.type.isPrimitive:
- code('#include "mem/ruby/protocol/$0.hh"', dm.type.c_ident)
+
code('#include "mem/ruby/protocol/$0.hh"',dm.type.gen_filename)
parent = ""
if "interface" in self:
@@ -416,10 +424,10 @@
} // namespace ruby
} // namespace gem5
-#endif // __${{self.c_ident}}_HH__
+#endif // __${{self.header_string}}_HH__
''')
- code.write(path, "%s.hh" % self.c_ident)
+ code.write(path, "%s.hh" % self.gen_filename)
def printTypeCC(self, path):
code = self.symtab.codeFormatter()
@@ -428,7 +436,7 @@
#include <iostream>
#include <memory>
-#include "mem/ruby/protocol/${{self.c_ident}}.hh"
+#include "mem/ruby/protocol/${{self.gen_filename}}.hh"
#include "mem/ruby/system/RubySystem.hh"
namespace gem5
@@ -486,13 +494,13 @@
} // namespace gem5
''')
- code.write(path, "%s.cc" % self.c_ident)
+ code.write(path, "%s.cc" % self.gen_filename)
def printEnumHH(self, path):
code = self.symtab.codeFormatter()
code('''
-#ifndef __${{self.c_ident}}_HH__
-#define __${{self.c_ident}}_HH__
+#ifndef __${{self.header_string}}_HH__
+#define __${{self.header_string}}_HH__
#include <iostream>
#include <string>
@@ -621,10 +629,10 @@
# Trailer
code('''
-#endif // __${{self.c_ident}}_HH__
+#endif // __${{self.header_string}}_HH__
''')
- code.write(path, "%s.hh" % self.c_ident)
+ code.write(path, "%s.hh" % self.gen_filename)
def printEnumCC(self, path):
code = self.symtab.codeFormatter()
@@ -634,7 +642,7 @@
#include <string>
#include "base/logging.hh"
-#include "mem/ruby/protocol/${{self.c_ident}}.hh"
+#include "mem/ruby/protocol/${{self.gen_filename}}.hh"
''')
@@ -693,8 +701,8 @@
if self.isMachineType:
for enum in self.enums.values():
if enum.primary:
- code('#include "mem/ruby/protocol/${{enum.ident}}'
- '_Controller.hh"')
+ code('#include "mem/ruby/protocol/${{protocol}}/'
+ '${{enum.ident}}_Controller.hh"')
code('#include "mem/ruby/common/MachineID.hh"')
code('''
@@ -886,8 +894,6 @@
code('''
return ${{protocol}}::${{enum.ident}}_Controller::getNumControllers();
''')
- else:
- code('return 0;')
# total num
code('''
@@ -924,6 +930,6 @@
''')
# Write the file
- code.write(path, "%s.cc" % self.c_ident)
+ code.write(path, "%s.cc" % self.gen_filename)
__all__ = [ "Type" ]
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/58433
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: I62f69a4606b030ee23cb2d96493f3257a6923748
Gerrit-Change-Number: 58433
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