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 <tiago.muck@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/31259
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
@@ -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.ast.AST import AST
|
||||
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 @@ class FormalParamAST(AST):
|
||||
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)
|
||||
|
||||
@@ -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 @@ class SLICC(Grammar):
|
||||
'INCR', 'DECR',
|
||||
'DOUBLE_COLON', 'SEMI',
|
||||
'ASSIGN', 'DOT',
|
||||
'IDENT', 'LIT_BOOL', 'FLOATNUMBER', 'NUMBER', 'STRING' ]
|
||||
'IDENT', 'LIT_BOOL', 'FLOATNUMBER', 'NUMBER', 'STRING',
|
||||
'AMP', 'CONST' ]
|
||||
tokens += reserved.values()
|
||||
|
||||
t_EQ = r'=='
|
||||
@@ -149,6 +162,8 @@ class SLICC(Grammar):
|
||||
t_PLUS = r'\+'
|
||||
t_DASH = r'-'
|
||||
t_STAR = r'\*'
|
||||
t_AMP = r'&'
|
||||
t_CONST = r'const'
|
||||
t_SLASH = r'/'
|
||||
t_MOD = r'%'
|
||||
t_DOUBLE_COLON = r'::'
|
||||
@@ -433,11 +448,19 @@ class SLICC(Grammar):
|
||||
|
||||
def p_param__pointer(self, p):
|
||||
"param : type STAR ident"
|
||||
p[0] = ast.FormalParamAST(self, p[1], p[3], None, True)
|
||||
p[0] = ast.FormalParamAST(self, p[1], p[3], None, "PTR")
|
||||
|
||||
def p_param__ref(self, p):
|
||||
"param : type AMP ident"
|
||||
p[0] = ast.FormalParamAST(self, p[1], p[3], None, "REF")
|
||||
|
||||
def p_param__const_ref(self, p):
|
||||
"param : CONST type AMP ident"
|
||||
p[0] = ast.FormalParamAST(self, p[1], p[3], None, "CONST_REF")
|
||||
|
||||
def p_param__pointer_default(self, p):
|
||||
"param : type STAR ident ASSIGN STRING"
|
||||
p[0] = ast.FormalParamAST(self, p[1], p[3], p[5], True)
|
||||
p[0] = ast.FormalParamAST(self, p[1], p[3], p[5], "PTR")
|
||||
|
||||
def p_param__default_number(self, p):
|
||||
"param : type ident ASSIGN NUMBER"
|
||||
|
||||
Reference in New Issue
Block a user