# Node ID aebe70c731a7c040ee405d0e758db79951505ddc # Parent 33bce7fb8443d36d438843873de352d935184d8d diff --git a/src/mem/slicc/ast/GetPointerAST.py b/src/mem/slicc/ast/GetPointerAST.py new file mode 100644 --- /dev/null +++ b/src/mem/slicc/ast/GetPointerAST.py @@ -0,0 +1,45 @@ +# +# Copyright (c) 2015 Advanced Micro Devices, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer; +# redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution; +# neither the name of the copyright holders nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +from slicc.ast.ExprAST import ExprAST + +class GetPointerAST(ExprAST): + def __init__(self, slicc, expr_ast): + super(GetPointerAST, self).__init__(slicc) + + self.expr_ast = expr_ast + + def __repr__(self): + return "[GetPointerAST: %r]" % self.expr_ast + + def generate(self, code): + actual_type, ecode = self.expr_ast.inline(True) + + code('&($ecode)') + + return actual_type diff --git a/src/mem/slicc/ast/__init__.py b/src/mem/slicc/ast/__init__.py --- a/src/mem/slicc/ast/__init__.py +++ b/src/mem/slicc/ast/__init__.py @@ -40,6 +40,7 @@ from slicc.ast.FormalParamAST import * from slicc.ast.FuncCallExprAST import * from slicc.ast.FuncDeclAST import * +from slicc.ast.GetPointerAST import * from slicc.ast.IfStatementAST import * from slicc.ast.InPortDeclAST import * from slicc.ast.IsValidPtrExprAST import * diff --git a/src/mem/slicc/parser.py b/src/mem/slicc/parser.py --- a/src/mem/slicc/parser.py +++ b/src/mem/slicc/parser.py @@ -115,6 +115,7 @@ 'check_allocate' : 'CHECK_ALLOCATE', 'check_stop_slots' : 'CHECK_STOP_SLOTS', 'static_cast' : 'STATIC_CAST', + 'getPointer' : 'GET_POINTER', 'if' : 'IF', 'is_valid' : 'IS_VALID', 'is_invalid' : 'IS_INVALID', @@ -621,6 +622,10 @@ "aexpr : STATIC_CAST '(' type ',' expr ')'" p[0] = ast.StaticCastAST(self, p[3], "ref", p[5]) + def p_statement__getPointer(self, p): + "aexpr : GET_POINTER '(' expr ')'" + p[0] = ast.GetPointerAST(self, p[3]) + def p_expr__static_cast_ptr(self, p): "aexpr : STATIC_CAST '(' type ',' STRING ',' expr ')'" p[0] = ast.StaticCastAST(self, p[3], p[5], p[7])