mem-ruby: Add static_cast by value in SLICC
At the moment it is possible to static_cast by pointer/reference only: static_cast(type, "pointer", val) -> static_cast<type*>(val); static_cast(type, "reference", val) -> static_cast<type&>(val); With this patch it will also be possible to do something like static_cast(type, "value", val) -> static_cast<type>(val); Which is important when wishing to convert integer types into custom onces and viceversa. This patch is also deferring static_cast type check to C++ At the moment it is difficult to use the static_cast utility in slicc as it tries to handle type checking in the language itself. This would force us to explicitly define compatible types (like an Addr and an int as an example). Rather than pushing the burden on us, we should always allow a developer to use a static_cast in slicc and let the C++ compiler complain if the generated code is not compatible Change-Id: I0586b9224b1e41751a07d15e2d48a435061c2582 Signed-off-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
This commit is contained in:
@@ -1,3 +1,15 @@
|
||||
# Copyright (c) 2023 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 Advanced Micro Devices, Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
@@ -42,22 +54,9 @@ class StaticCastAST(ExprAST):
|
||||
actual_type, ecode = self.expr_ast.inline(True)
|
||||
if self.type_modifier == "pointer":
|
||||
code("static_cast<${{self.type_ast.type.c_ident}} *>($ecode)")
|
||||
elif self.type_modifier == "value":
|
||||
code("static_cast<${{self.type_ast.type.c_ident}} >($ecode)")
|
||||
else:
|
||||
code("static_cast<${{self.type_ast.type.c_ident}} &>($ecode)")
|
||||
|
||||
if not "interface" in self.type_ast.type:
|
||||
self.expr_ast.error(
|
||||
"static cast only premitted for those types "
|
||||
"that implement inherit an interface"
|
||||
)
|
||||
|
||||
# The interface type should match
|
||||
if str(actual_type) != str(self.type_ast.type["interface"]):
|
||||
self.expr_ast.error(
|
||||
"static cast miss-match, type is '%s',"
|
||||
"but inherited type is '%s'",
|
||||
actual_type,
|
||||
self.type_ast.type["interface"],
|
||||
)
|
||||
|
||||
return self.type_ast.type
|
||||
|
||||
Reference in New Issue
Block a user