17839Snilay@cs.wisc.edu#
210966Sdavid.hashe@amd.com# Copyright (c) 2013 Advanced Micro Devices, Inc.
37839Snilay@cs.wisc.edu# Copyright (c) 2011 Mark D. Hill and David A. Wood
47839Snilay@cs.wisc.edu# All rights reserved.
57839Snilay@cs.wisc.edu#
67839Snilay@cs.wisc.edu# Redistribution and use in source and binary forms, with or without
77839Snilay@cs.wisc.edu# modification, are permitted provided that the following conditions are
87839Snilay@cs.wisc.edu# met: redistributions of source code must retain the above copyright
97839Snilay@cs.wisc.edu# notice, this list of conditions and the following disclaimer;
107839Snilay@cs.wisc.edu# redistributions in binary form must reproduce the above copyright
117839Snilay@cs.wisc.edu# notice, this list of conditions and the following disclaimer in the
127839Snilay@cs.wisc.edu# documentation and/or other materials provided with the distribution;
137839Snilay@cs.wisc.edu# neither the name of the copyright holders nor the names of its
147839Snilay@cs.wisc.edu# contributors may be used to endorse or promote products derived from
157839Snilay@cs.wisc.edu# this software without specific prior written permission.
167839Snilay@cs.wisc.edu#
177839Snilay@cs.wisc.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
187839Snilay@cs.wisc.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
197839Snilay@cs.wisc.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
207839Snilay@cs.wisc.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
217839Snilay@cs.wisc.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
227839Snilay@cs.wisc.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
237839Snilay@cs.wisc.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
247839Snilay@cs.wisc.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
257839Snilay@cs.wisc.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
267839Snilay@cs.wisc.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
277839Snilay@cs.wisc.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
287839Snilay@cs.wisc.edu#
297839Snilay@cs.wisc.edu
307839Snilay@cs.wisc.edufrom slicc.ast.StatementAST import StatementAST
317839Snilay@cs.wisc.edufrom slicc.symbols import Var
327839Snilay@cs.wisc.edu
337839Snilay@cs.wisc.educlass LocalVariableAST(StatementAST):
348085SBrad.Beckmann@amd.com    def __init__(self, slicc, type_ast, ident, pointer = False):
357839Snilay@cs.wisc.edu        super(LocalVariableAST, self).__init__(slicc)
367839Snilay@cs.wisc.edu        self.type_ast = type_ast
377839Snilay@cs.wisc.edu        self.ident    = ident
388085SBrad.Beckmann@amd.com        self.pointer = pointer
397839Snilay@cs.wisc.edu
407839Snilay@cs.wisc.edu    def __repr__(self):
417839Snilay@cs.wisc.edu        return "[LocalVariableAST: %r %r]" % (self.type_ast, self.ident)
427839Snilay@cs.wisc.edu
437839Snilay@cs.wisc.edu    @property
447839Snilay@cs.wisc.edu    def name(self):
457839Snilay@cs.wisc.edu        return self.var_name
467839Snilay@cs.wisc.edu
4710966Sdavid.hashe@amd.com    def inline(self, get_type=False):
4810966Sdavid.hashe@amd.com        code = self.slicc.codeFormatter(fix_newlines=False)
4910966Sdavid.hashe@amd.com        return_type = self.generate(code)
5010966Sdavid.hashe@amd.com        if get_type:
5110966Sdavid.hashe@amd.com            return return_type, code
5210966Sdavid.hashe@amd.com        else:
5310966Sdavid.hashe@amd.com            return code
5410966Sdavid.hashe@amd.com
557839Snilay@cs.wisc.edu    def generate(self, code):
567839Snilay@cs.wisc.edu        type = self.type_ast.type;
577839Snilay@cs.wisc.edu        ident = "%s" % self.ident;
587839Snilay@cs.wisc.edu
597839Snilay@cs.wisc.edu        # Add to symbol table
607839Snilay@cs.wisc.edu        v = Var(self.symtab, self.ident, self.location, type, ident,
617839Snilay@cs.wisc.edu                self.pairs)
627839Snilay@cs.wisc.edu        self.symtab.newSymbol(v)
638085SBrad.Beckmann@amd.com        if self.pointer or str(type) == "TBE" or (
648644Snilay@cs.wisc.edu           "interface" in type and (
658644Snilay@cs.wisc.edu               type["interface"] == "AbstractCacheEntry" or
668644Snilay@cs.wisc.edu               type["interface"] == "AbstractEntry")):
678085SBrad.Beckmann@amd.com            code += "%s* %s" % (type.c_ident, ident)
688085SBrad.Beckmann@amd.com        else:
698085SBrad.Beckmann@amd.com            code += "%s %s" % (type.c_ident, ident)
707839Snilay@cs.wisc.edu        return type
71