[gem5-dev] Change in gem5/gem5[develop]: mem-ruby: allow qualifiers in SLICC functions
Tiago Mück has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/31259 ) Change subject: mem-ruby: allow qualifiers in SLICC functions .. mem-ruby: allow qualifiers in SLICC functions All parameters in functions defined within SLICC are const& by default (except for the implicit types, e.g. TBE). This allow us to specify if we want to pass parameters as & or const&. Default behavior is maintained. A use case is to allow refactoring of common code in actions that enqueue messages. Messages can be passed as a non-const ref. to to functions with common initialization. E.g.: void initRequestMsg(RequestMsg & out_msg) { // Common msg init code } action(sendRequest1, ...) { enqueue(...) { initRequestMsg(out_msg); // Request1 specific code } } action(sendRequest2, ...) { enqueue(...) { initRequestMsg(out_msg); // Request2 specific code } } Change-Id: Ic6a18169a661b3e36710b2a9f8a0e6bc5fce40f8 Signed-off-by: Tiago Mück Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/31259 Reviewed-by: Jason Lowe-Power Maintainer: Jason Lowe-Power Tested-by: kokoro --- M src/mem/slicc/ast/FormalParamAST.py M src/mem/slicc/parser.py 2 files changed, 59 insertions(+), 9 deletions(-) Approvals: Jason Lowe-Power: Looks good to me, approved; Looks good to me, approved kokoro: Regressions pass diff --git a/src/mem/slicc/ast/FormalParamAST.py b/src/mem/slicc/ast/FormalParamAST.py index 778b5c1..57f5c94 100644 --- a/src/mem/slicc/ast/FormalParamAST.py +++ b/src/mem/slicc/ast/FormalParamAST.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. @@ -29,12 +41,12 @@ from slicc.symbols import Var class FormalParamAST(AST): -def __init__(self, slicc, type_ast, ident, default = None, pointer = False): +def __init__(self, slicc, type_ast, ident, default = None, qualifier=""): super(FormalParamAST, self).__init__(slicc) self.type_ast = type_ast self.ident = ident self.default = default -self.pointer = pointer +self.qualifier = qualifier def __repr__(self): return "[FormalParamAST: %s]" % self.ident @@ -52,11 +64,26 @@ self.pairs) self.symtab.newSymbol(v) -if self.pointer or str(type) == "TBE" or ( -# Check whether type is entry by checking the interface since -# in protocol files, entries use AbstractCacheEntry as interfaces. +# Qualifier is always a pointer for TBE table and Cache entries. +# It's expected to be left unspecified or specified as ptr. +qualifier = self.qualifier +if str(type) == "TBE" or ( "interface" in type and ( type["interface"] == "AbstractCacheEntry")): +if qualifier not in ["", "PTR"] : +self.warning("Parameter \'%s\' is always pointer. " + "%s qualifier ignored" % (self.ident, qualifier)) +qualifier = "PTR" + +# default +if qualifier == "": +qualifier = "CONST_REF" + +if qualifier == "PTR": return type, "%s* %s" % (type.c_ident, param) -else: +elif qualifier == "REF": +return type, "%s& %s" % (type.c_ident, param) +elif qualifier == "CONST_REF": return type, "const %s& %s" % (type.c_ident, param) +else: +self.error("Invalid qualifier for param \'%s\'" % self.ident) diff --git a/src/mem/slicc/parser.py b/src/mem/slicc/parser.py index 13dde9a..51a68d0 100644 --- a/src/mem/slicc/parser.py +++ b/src/mem/slicc/parser.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
[gem5-dev] Change in gem5/gem5[develop]: mem-ruby: allow qualifiers in SLICC functions
Tiago Mück has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/31259 ) Change subject: mem-ruby: allow qualifiers in SLICC functions .. mem-ruby: allow qualifiers in SLICC functions All parameters in functions defined within SLICC are const& by default (except for the implicit types, e.g. TBE). This allow us to specify if we want to pass parameters as & or const&. Default behavior is maintained. A use case is to allow refactoring of common code in actions that enqueue messages. Messages can be passed as a non-const ref. to to functions with common initialization. E.g.: void initRequestMsg(RequestMsg & out_msg) { // Common msg init code } action(sendRequest1, ...) { enqueue(...) { initRequestMsg(out_msg); // Request1 specific code } } action(sendRequest2, ...) { enqueue(...) { initRequestMsg(out_msg); // Request2 specific code } } Change-Id: Ic6a18169a661b3e36710b2a9f8a0e6bc5fce40f8 Signed-off-by: Tiago Mück --- M src/mem/slicc/ast/FormalParamAST.py M src/mem/slicc/parser.py 2 files changed, 59 insertions(+), 9 deletions(-) diff --git a/src/mem/slicc/ast/FormalParamAST.py b/src/mem/slicc/ast/FormalParamAST.py index 778b5c1..57f5c94 100644 --- a/src/mem/slicc/ast/FormalParamAST.py +++ b/src/mem/slicc/ast/FormalParamAST.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. @@ -29,12 +41,12 @@ from slicc.symbols import Var class FormalParamAST(AST): -def __init__(self, slicc, type_ast, ident, default = None, pointer = False): +def __init__(self, slicc, type_ast, ident, default = None, qualifier=""): super(FormalParamAST, self).__init__(slicc) self.type_ast = type_ast self.ident = ident self.default = default -self.pointer = pointer +self.qualifier = qualifier def __repr__(self): return "[FormalParamAST: %s]" % self.ident @@ -52,11 +64,26 @@ self.pairs) self.symtab.newSymbol(v) -if self.pointer or str(type) == "TBE" or ( -# Check whether type is entry by checking the interface since -# in protocol files, entries use AbstractCacheEntry as interfaces. +# Qualifier is always a pointer for TBE table and Cache entries. +# It's expected to be left unspecified or specified as ptr. +qualifier = self.qualifier +if str(type) == "TBE" or ( "interface" in type and ( type["interface"] == "AbstractCacheEntry")): +if qualifier not in ["", "PTR"] : +self.warning("Parameter \'%s\' is always pointer. " + "%s qualifier ignored" % (self.ident, qualifier)) +qualifier = "PTR" + +# default +if qualifier == "": +qualifier = "CONST_REF" + +if qualifier == "PTR": return type, "%s* %s" % (type.c_ident, param) -else: +elif qualifier == "REF": +return type, "%s& %s" % (type.c_ident, param) +elif qualifier == "CONST_REF": return type, "const %s& %s" % (type.c_ident, param) +else: +self.error("Invalid qualifier for param \'%s\'" % self.ident) diff --git a/src/mem/slicc/parser.py b/src/mem/slicc/parser.py index 643eec6..721ca58 100644 --- a/src/mem/slicc/parser.py +++ b/src/mem/slicc/parser.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) 2009 The Hewlett-Packard Development Company # Copyright (c) 2017 Google Inc. # All rights reserved. @@ -132,7 +144,8 @@ 'INCR', 'DECR',