diff --git a/src/mem/ruby/structures/MN_TBETable.hh b/src/mem/ruby/structures/MN_TBETable.hh index 04c666ac52..b907d5658f 100644 --- a/src/mem/ruby/structures/MN_TBETable.hh +++ b/src/mem/ruby/structures/MN_TBETable.hh @@ -41,7 +41,7 @@ #include #include -#include "mem/ruby/protocol/MiscNode_TBE.hh" +#include "mem/ruby/protocol/CHI/MiscNode_TBE.hh" #include "mem/ruby/structures/TBETable.hh" namespace gem5 diff --git a/src/mem/slicc/ast/EnumDeclAST.py b/src/mem/slicc/ast/EnumDeclAST.py index e9d84a8186..c52089330a 100644 --- a/src/mem/slicc/ast/EnumDeclAST.py +++ b/src/mem/slicc/ast/EnumDeclAST.py @@ -50,6 +50,8 @@ class EnumDeclAST(DeclAST): ident = f"{parent}_{self.type_ast.ident}" else: ident = self.type_ast.ident + if not self.shared: + ident = f"{self.slicc.protocol}/{ident}" s = {f"{ident}.hh", f"{ident}.cc"} return s diff --git a/src/mem/slicc/ast/MachineAST.py b/src/mem/slicc/ast/MachineAST.py index a6cb8a93ee..764a516839 100644 --- a/src/mem/slicc/ast/MachineAST.py +++ b/src/mem/slicc/ast/MachineAST.py @@ -45,12 +45,13 @@ class MachineAST(DeclAST): return f"[Machine: {self.ident!r}]" def files(self, parent=None): + file_prefix = f"{self.slicc.protocol}/{self.ident}" s = { - f"{self.ident}_Controller.cc", - f"{self.ident}_Controller.hh", - f"{self.ident}_Controller.py", - f"{self.ident}_Transitions.cc", - f"{self.ident}_Wakeup.cc", + f"{file_prefix}_Controller.cc", + f"{file_prefix}_Controller.hh", + f"{file_prefix}_Controller.py", + f"{file_prefix}_Transitions.cc", + f"{file_prefix}_Wakeup.cc", } s |= self.decls.files(self.ident) diff --git a/src/mem/slicc/ast/StateDeclAST.py b/src/mem/slicc/ast/StateDeclAST.py index be3eb592e2..e20e746ebb 100644 --- a/src/mem/slicc/ast/StateDeclAST.py +++ b/src/mem/slicc/ast/StateDeclAST.py @@ -49,6 +49,8 @@ class StateDeclAST(DeclAST): ident = f"{parent}_{self.type_ast.ident}" else: ident = self.type_ast.ident + if not self.shared: + ident = f"{self.slicc.protocol}/{ident}" s = {f"{ident}.hh", f"{ident}.cc"} return s diff --git a/src/mem/slicc/ast/TypeDeclAST.py b/src/mem/slicc/ast/TypeDeclAST.py index 3bc5f20ba9..e3e513983c 100644 --- a/src/mem/slicc/ast/TypeDeclAST.py +++ b/src/mem/slicc/ast/TypeDeclAST.py @@ -47,6 +47,8 @@ class TypeDeclAST(DeclAST): ident = f"{parent}_{self.type_ast.ident}" else: ident = self.type_ast.ident + if not self.shared: + ident = f"{self.slicc.protocol}/{ident}" return {f"{ident}.hh", f"{ident}.cc"} def generate(self): diff --git a/src/mem/slicc/parser.py b/src/mem/slicc/parser.py index 07bf646ed1..f3a9ed2f11 100644 --- a/src/mem/slicc/parser.py +++ b/src/mem/slicc/parser.py @@ -109,7 +109,7 @@ class SLICC(Grammar): self.symtab.writeHTMLFiles(html_path) def files(self): - f = {"Types.hh"} + f = {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 a0be1a227c..b216b9f099 100644 --- a/src/mem/slicc/symbols/StateMachine.py +++ b/src/mem/slicc/symbols/StateMachine.py @@ -265,8 +265,10 @@ class StateMachine(Symbol): code = self.symtab.codeFormatter() ident = self.ident + protocol = self.symtab.slicc.protocol py_ident = f"{ident}_Controller" c_ident = f"{self.ident}_Controller" + gen_filename = f"{protocol}/{py_ident}" code( """ @@ -276,8 +278,8 @@ from m5.objects.Controller import RubyController 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() @@ -302,20 +304,22 @@ class $py_ident(RubyController): ) code.dedent() - code.write(path, f"{py_ident}.py") + code.write(path, f"{gen_filename}.py") def printControllerHH(self, path): """Output the method declarations for the class declaration""" 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}" 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 #include @@ -323,7 +327,7 @@ class $py_ident(RubyController): #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" @@ -333,7 +337,14 @@ class $py_ident(RubyController): 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 @@ -537,11 +548,11 @@ void unset_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr); } // namespace ruby } // namespace gem5 -#endif // __${ident}_CONTROLLER_H__ +#endif // __${header_string}_CONTROLLER_H__ """ ) - code.write(path, f"{c_ident}.hh") + code.write(path, f"{gen_filename}.hh") def printControllerCC(self, path, includes): """Output the actions for performing the actions""" @@ -549,6 +560,7 @@ void unset_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr); code = self.symtab.codeFormatter() ident = self.ident c_ident = f"{self.ident}_Controller" + 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 @@ -599,10 +611,10 @@ void unset_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr); 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" """ @@ -614,7 +626,14 @@ void unset_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr); 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) @@ -1413,13 +1432,14 @@ $c_ident::functionalReadBuffers(PacketPtr& pkt, WriteMask &mask) """ ) - code.write(path, f"{c_ident}.cc") + code.write(path, f"{gen_filename}_Controller.cc") 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: @@ -1445,19 +1465,21 @@ $c_ident::functionalReadBuffers(PacketPtr& pkt, WriteMask &mask) 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" """ @@ -1568,13 +1590,14 @@ ${ident}_Controller::wakeup() """ ) - code.write(path, f"{self.ident}_Wakeup.cc") + code.write(path, f"{gen_filename}_Wakeup.cc") 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( """ @@ -1586,10 +1609,10 @@ ${ident}_Controller::wakeup() #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)) @@ -1884,7 +1907,7 @@ if (!checkResourceAvailable({}_RequestType_{}, addr)) {{ } // namespace gem5 """ ) - code.write(path, f"{self.ident}_Transitions.cc") + code.write(path, f"{gen_filename}_Transitions.cc") # ************************** # ******* HTML Files ******* diff --git a/src/mem/slicc/symbols/SymbolTable.py b/src/mem/slicc/symbols/SymbolTable.py index e1c5addb64..23c11e1a80 100644 --- a/src/mem/slicc/symbols/SymbolTable.py +++ b/src/mem/slicc/symbols/SymbolTable.py @@ -135,6 +135,7 @@ class SymbolTable: def writeCodeFiles(self, path, includes): makeDir(path) + makeDir(os.path.join(path, self.slicc.protocol)) code = self.codeFormatter() @@ -143,9 +144,12 @@ class SymbolTable: 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 52ed858ebe..6566334c04 100644 --- a/src/mem/slicc/symbols/Type.py +++ b/src/mem/slicc/symbols/Type.py @@ -76,7 +76,15 @@ class Type(Symbol): self.c_ident = self["external_name"] else: # Append with machine name - self.c_ident = f"{machine}_{ident}" + 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") @@ -230,8 +238,8 @@ class Type(Symbol): 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 @@ -242,7 +250,7 @@ class Type(Symbol): 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: @@ -560,11 +568,11 @@ operator<<(::std::ostream& out, const ${{self.c_ident}}& obj) } // namespace ruby } // namespace gem5 -#endif // __${{self.c_ident}}_HH__ +#endif // __${{self.header_string}}_HH__ """ ) - code.write(path, f"{self.c_ident}.hh") + code.write(path, f"{self.gen_filename}.hh") def printTypeCC(self, path): code = self.symtab.codeFormatter() @@ -574,7 +582,7 @@ operator<<(::std::ostream& out, const ${{self.c_ident}}& obj) #include #include -#include "mem/ruby/protocol/${{self.c_ident}}.hh" +#include "mem/ruby/protocol/${{self.gen_filename}}.hh" #include "mem/ruby/system/RubySystem.hh" namespace gem5 @@ -640,14 +648,14 @@ out << "${{dm.ident}} = " << printAddress(m_${{dm.ident}}, block_size_bits) << " """ ) - code.write(path, f"{self.c_ident}.cc") + code.write(path, f"{self.gen_filename}.cc") 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 #include @@ -793,11 +801,11 @@ struct hash # Trailer code( """ -#endif // __${{self.c_ident}}_HH__ +#endif // __${{self.header_string}}_HH__ """ ) - code.write(path, f"{self.c_ident}.hh") + code.write(path, f"{self.gen_filename}.hh") def printEnumCC(self, path): code = self.symtab.codeFormatter() @@ -808,7 +816,7 @@ struct hash #include #include "base/logging.hh" -#include "mem/ruby/protocol/${{self.c_ident}}.hh" +#include "mem/ruby/protocol/${{self.gen_filename}}.hh" """ ) @@ -873,8 +881,8 @@ AccessPermission ${{self.c_ident}}_to_permission(const ${{self.c_ident}}& obj) for enum in self.enums.values(): if enum.primary: code( - '#include "mem/ruby/protocol/${{enum.ident}}' - '_Controller.hh"' + "#include \"mem/ruby/protocol/${{protocol}}/" + "${{enum.ident}}_Controller.hh\"" ) code('#include "mem/ruby/common/MachineID.hh"') @@ -1124,7 +1132,7 @@ get${{enum.ident}}MachineID(NodeID RubyNode) ) # Write the file - code.write(path, f"{self.c_ident}.cc") + code.write(path, f"{self.gen_filename}.cc") __all__ = ["Type"]