+# 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.
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
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)
+# 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.
'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'=='
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'::'
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"