LocalVariableAST.py revision 8644
17839Snilay@cs.wisc.edu# 27839Snilay@cs.wisc.edu# Copyright (c) 2011 Mark D. Hill and David A. Wood 37839Snilay@cs.wisc.edu# All rights reserved. 47839Snilay@cs.wisc.edu# 57839Snilay@cs.wisc.edu# Redistribution and use in source and binary forms, with or without 67839Snilay@cs.wisc.edu# modification, are permitted provided that the following conditions are 77839Snilay@cs.wisc.edu# met: redistributions of source code must retain the above copyright 87839Snilay@cs.wisc.edu# notice, this list of conditions and the following disclaimer; 97839Snilay@cs.wisc.edu# redistributions in binary form must reproduce the above copyright 107839Snilay@cs.wisc.edu# notice, this list of conditions and the following disclaimer in the 117839Snilay@cs.wisc.edu# documentation and/or other materials provided with the distribution; 127839Snilay@cs.wisc.edu# neither the name of the copyright holders nor the names of its 137839Snilay@cs.wisc.edu# contributors may be used to endorse or promote products derived from 147839Snilay@cs.wisc.edu# this software without specific prior written permission. 157839Snilay@cs.wisc.edu# 167839Snilay@cs.wisc.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 177839Snilay@cs.wisc.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 187839Snilay@cs.wisc.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 197839Snilay@cs.wisc.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 207839Snilay@cs.wisc.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 217839Snilay@cs.wisc.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 227839Snilay@cs.wisc.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 237839Snilay@cs.wisc.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 247839Snilay@cs.wisc.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 257839Snilay@cs.wisc.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 267839Snilay@cs.wisc.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 277839Snilay@cs.wisc.edu# 287839Snilay@cs.wisc.edu 297839Snilay@cs.wisc.edufrom slicc.ast.StatementAST import StatementAST 307839Snilay@cs.wisc.edufrom slicc.symbols import Var 317839Snilay@cs.wisc.edu 327839Snilay@cs.wisc.educlass LocalVariableAST(StatementAST): 338085SBrad.Beckmann@amd.com def __init__(self, slicc, type_ast, ident, pointer = False): 347839Snilay@cs.wisc.edu super(LocalVariableAST, self).__init__(slicc) 357839Snilay@cs.wisc.edu self.type_ast = type_ast 367839Snilay@cs.wisc.edu self.ident = ident 378085SBrad.Beckmann@amd.com self.pointer = pointer 387839Snilay@cs.wisc.edu 397839Snilay@cs.wisc.edu def __repr__(self): 407839Snilay@cs.wisc.edu return "[LocalVariableAST: %r %r]" % (self.type_ast, self.ident) 417839Snilay@cs.wisc.edu 427839Snilay@cs.wisc.edu @property 437839Snilay@cs.wisc.edu def name(self): 447839Snilay@cs.wisc.edu return self.var_name 457839Snilay@cs.wisc.edu 467839Snilay@cs.wisc.edu def generate(self, code): 477839Snilay@cs.wisc.edu type = self.type_ast.type; 487839Snilay@cs.wisc.edu ident = "%s" % self.ident; 497839Snilay@cs.wisc.edu 507839Snilay@cs.wisc.edu # Add to symbol table 517839Snilay@cs.wisc.edu v = Var(self.symtab, self.ident, self.location, type, ident, 527839Snilay@cs.wisc.edu self.pairs) 537839Snilay@cs.wisc.edu self.symtab.newSymbol(v) 548085SBrad.Beckmann@amd.com if self.pointer or str(type) == "TBE" or ( 558644Snilay@cs.wisc.edu "interface" in type and ( 568644Snilay@cs.wisc.edu type["interface"] == "AbstractCacheEntry" or 578644Snilay@cs.wisc.edu type["interface"] == "AbstractEntry")): 588085SBrad.Beckmann@amd.com code += "%s* %s" % (type.c_ident, ident) 598085SBrad.Beckmann@amd.com else: 608085SBrad.Beckmann@amd.com code += "%s %s" % (type.c_ident, ident) 617839Snilay@cs.wisc.edu return type 62