From afdbe98b177eacba5a13d6cc701de241747d1014 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tiago=20M=C3=BCck?= Date: Wed, 29 Apr 2020 18:04:21 -0500 Subject: [PATCH] mem-ruby: support for template types in structs MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Templated types can now be used within structures defined in SLICC. Usage is similar to the TBETable: the templated type must have all possible methods in it's SLICC definition. Eg.: structure(Map, desc="Template map definition") { MachineID lookup(Addr); MachineID lookup(int); } structure(SomeType, desc="Some other struct definition") { MachineID addrMap, template=""; MachineID intMap, template=""; } Change-Id: I02a621cea5e4a89302762334651c6534c6574e9d Signed-off-by: Tiago Mück Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/31264 Reviewed-by: Matthew Poremba Reviewed-by: Bradford Beckmann Maintainer: Bradford Beckmann Tested-by: kokoro --- src/mem/slicc/symbols/Type.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/mem/slicc/symbols/Type.py b/src/mem/slicc/symbols/Type.py index fa5e79a74..ee319cbd7 100644 --- a/src/mem/slicc/symbols/Type.py +++ b/src/mem/slicc/symbols/Type.py @@ -1,3 +1,15 @@ +# Copyright (c) 2020 ARM Limited +# All rights reserved. +# +# The license below extends only to copyright in the software and shall +# not be construed as granting a license to any other intellectual +# property including but not limited to intellectual property relating +# to a hardware implementation of the functionality of the software +# licensed hereunder. You may use the software subject to the license +# terms below provided that you ensure that this notice is replicated +# unmodified and in its entirety in all distributions of the software, +# modified or unmodified, in source code or in binary form. +# # Copyright (c) 1999-2008 Mark D. Hill and David A. Wood # Copyright (c) 2009 The Hewlett-Packard Development Company # All rights reserved. @@ -37,6 +49,9 @@ class DataMember(Var): super(DataMember, self).__init__(symtab, ident, location, type, code, pairs, machine) self.init_code = init_code + self.real_c_type = self.type.c_ident + if "template" in pairs: + self.real_c_type += pairs["template"] class Enumeration(PairContainer): def __init__(self, ident, pairs): @@ -235,8 +250,9 @@ $klass ${{self.c_ident}}$parent code('m_$ident = ${{dm["default"]}}; // default for this field') elif "default" in dm.type: # Look for the type default - tid = dm.type.c_ident - code('m_$ident = ${{dm.type["default"]}}; // default value of $tid') + tid = dm.real_c_type + code('m_$ident = ${{dm.type["default"]}};') + code(' // default value of $tid') else: code('// m_$ident has no default') code.dedent() @@ -268,7 +284,7 @@ $klass ${{self.c_ident}}$parent # ******** Full init constructor ******** if not self.isGlobal: - params = [ 'const %s& local_%s' % (dm.type.c_ident, dm.ident) \ + params = [ 'const %s& local_%s' % (dm.real_c_type, dm.ident) \ for dm in self.data_members.values() ] params = ', '.join(params) @@ -318,7 +334,7 @@ clone() const /** \\brief Const accessor method for ${{dm.ident}} field. * \\return ${{dm.ident}} field */ -const ${{dm.type.c_ident}}& +const ${{dm.real_c_type}}& get${{dm.ident}}() const { return m_${{dm.ident}}; @@ -332,7 +348,7 @@ get${{dm.ident}}() const /** \\brief Non-const accessor method for ${{dm.ident}} field. * \\return ${{dm.ident}} field */ -${{dm.type.c_ident}}& +${{dm.real_c_type}}& get${{dm.ident}}() { return m_${{dm.ident}}; @@ -345,7 +361,7 @@ get${{dm.ident}}() code(''' /** \\brief Mutator method for ${{dm.ident}} field */ void -set${{dm.ident}}(const ${{dm.type.c_ident}}& local_${{dm.ident}}) +set${{dm.ident}}(const ${{dm.real_c_type}}& local_${{dm.ident}}) { m_${{dm.ident}} = local_${{dm.ident}}; } @@ -375,7 +391,7 @@ set${{dm.ident}}(const ${{dm.type.c_ident}}& local_${{dm.ident}}) if "desc" in dm: code('/** ${{dm["desc"]}} */') - code('$const${{dm.type.c_ident}} m_${{dm.ident}}$init;') + code('$const${{dm.real_c_type}} m_${{dm.ident}}$init;') # Prototypes for methods defined for the Type for item in self.methods: -- 2.30.2