From 18401758aaf3c387e22de50da5ec74f29512fe78 Mon Sep 17 00:00:00 2001 From: Jason Lowe-Power Date: Wed, 23 Oct 2024 15:53:54 -0700 Subject: [PATCH] mem-ruby: Rename SLICC SimObjs with compatibility Rename all SLICC generated SimObjects to have the protocol in their name. This will allow for two different protocols to have the same machine names (e.g., L1Cache). For compatiblity, we check to see if the current or main protocol that is built matches the SimObject's protocol and export the backwards-compatible name. Signed-off-by: Jason Lowe-Power --- src/mem/slicc/ast/MachineAST.py | 5 +- src/mem/slicc/symbols/StateMachine.py | 66 +++++++++++++++++++++------ 2 files changed, 55 insertions(+), 16 deletions(-) diff --git a/src/mem/slicc/ast/MachineAST.py b/src/mem/slicc/ast/MachineAST.py index 764a516839..d9d4c0781c 100644 --- a/src/mem/slicc/ast/MachineAST.py +++ b/src/mem/slicc/ast/MachineAST.py @@ -46,10 +46,13 @@ class MachineAST(DeclAST): def files(self, parent=None): file_prefix = f"{self.slicc.protocol}/{self.ident}" + # Can't have multiple python simobject files with the same name + # So, we have to prepend the protocol name to the .py file + py_prefix = f"{self.slicc.protocol}/{self.slicc.protocol}_{self.ident}" s = { f"{file_prefix}_Controller.cc", f"{file_prefix}_Controller.hh", - f"{file_prefix}_Controller.py", + f"{py_prefix}_Controller.py", f"{file_prefix}_Transitions.cc", f"{file_prefix}_Wakeup.cc", } diff --git a/src/mem/slicc/symbols/StateMachine.py b/src/mem/slicc/symbols/StateMachine.py index b216b9f099..2f32a8320b 100644 --- a/src/mem/slicc/symbols/StateMachine.py +++ b/src/mem/slicc/symbols/StateMachine.py @@ -266,7 +266,7 @@ class StateMachine(Symbol): ident = self.ident protocol = self.symtab.slicc.protocol - py_ident = f"{ident}_Controller" + py_ident = f"{protocol}_{ident}_Controller" c_ident = f"{self.ident}_Controller" gen_filename = f"{protocol}/{py_ident}" @@ -304,6 +304,29 @@ class $py_ident(RubyController): ) code.dedent() + + # Needed for backwards compatibility. If you have exactly 1 protocol + # (i.e., buildEnv["PROTOCOL"] is not MULTIPLE), then for the one + # type of machine that matches this (sole) protocol, you can create an + # alias to the new name. This is only needed if using script that + # reference Ruby.py. When that is deprecated, this code can be removed + code( + """ + +from m5.defines import buildEnv +from m5.util import warn + +if buildEnv["PROTOCOL"] == "${protocol}": + class ${c_ident}(${py_ident}): + def __init__(self, *args, **kwargs): + warn( + "${c_ident} is deprecated. Use %s_${c_ident} instead", + buildEnv['PROTOCOL'] + ) + super().__init__(*args, **kwargs) +""" + ) + code.write(path, f"{gen_filename}.py") def printControllerHH(self, path): @@ -311,8 +334,11 @@ class $py_ident(RubyController): code = self.symtab.codeFormatter() ident = self.ident c_ident = f"{self.ident}_Controller" - header_string = self.symtab.slicc.protocol + '_' + self.ident - gen_filename = f"{self.symtab.slicc.protocol}/{c_ident}" + + protocol = self.symtab.slicc.protocol + header_string = protocol + "_" + self.ident + gen_filename = f"{protocol}/{c_ident}" + py_ident = f"{protocol}_{ident}_Controller" code( """ @@ -329,7 +355,7 @@ class $py_ident(RubyController): #include "mem/ruby/protocol/TransitionResult.hh" #include "mem/ruby/protocol/${protocol}/Types.hh" #include "mem/ruby/slicc_interface/AbstractController.hh" -#include "params/$c_ident.hh" +#include "params/$py_ident.hh" """ ) @@ -338,13 +364,17 @@ class $py_ident(RubyController): for var in self.objects: if var.type.ident not in seen_types and not var.type.isPrimitive: if var.type.shared or var.type.isExternal: - code(''' + code( + """ #include "mem/ruby/protocol/${{var.type.c_ident}}.hh" -''') +""" + ) else: - code(''' + 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 @@ -364,7 +394,7 @@ extern std::stringstream ${ident}_transitionComment; class $c_ident : public AbstractController { public: - typedef ${c_ident}Params Params; + typedef ${py_ident}Params Params; $c_ident(const Params &p); void init(); @@ -627,13 +657,17 @@ void unset_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr); for var in self.objects: if var.type.ident not in seen_types and not var.type.isPrimitive: if var.type.shared or var.type.isExternal: - code(''' + code( + """ #include "mem/ruby/protocol/${{var.type.c_ident}}.hh" -''') +""" + ) else: - code(''' + code( + """ #include "mem/ruby/protocol/${{protocol}}/${{var.type.c_ident}}.hh" -''') +""" + ) seen_types.add(var.type.ident) num_in_ports = len(self.in_ports) @@ -1473,9 +1507,11 @@ $c_ident::functionalReadBuffers(PacketPtr& pkt, WriteMask &mask) ) if outputRequest_types: - code(''' + code( + """ #include "mem/ruby/protocol/${protocol}/${ident}_RequestType.hh" -''') +""" + ) code( """