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 <tiago.m...@arm.com>
---
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',
'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 @@
t_PLUS = r'\+'
t_DASH = r'-'
t_STAR = r'\*'
+ t_AMP = r'&'
+ t_CONST = r'const'
t_SLASH = r'/'
t_DOUBLE_COLON = r'::'
t_SEMI = r';'
@@ -432,11 +447,19 @@
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"
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/31259
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Ic6a18169a661b3e36710b2a9f8a0e6bc5fce40f8
Gerrit-Change-Number: 31259
Gerrit-PatchSet: 1
Gerrit-Owner: Tiago Mück <tiago.m...@arm.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s