LocalVariableAST.py revision 7839:9e556fb25900
19793Sakash.bagdia@arm.com#
28706Sandreas.hansson@arm.com# Copyright (c) 2011 Mark D. Hill and David A. Wood
38706Sandreas.hansson@arm.com# All rights reserved.
48706Sandreas.hansson@arm.com#
58706Sandreas.hansson@arm.com# Redistribution and use in source and binary forms, with or without
68706Sandreas.hansson@arm.com# modification, are permitted provided that the following conditions are
78706Sandreas.hansson@arm.com# met: redistributions of source code must retain the above copyright
88706Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer;
98706Sandreas.hansson@arm.com# redistributions in binary form must reproduce the above copyright
108706Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer in the
118706Sandreas.hansson@arm.com# documentation and/or other materials provided with the distribution;
128706Sandreas.hansson@arm.com# neither the name of the copyright holders nor the names of its
135369Ssaidi@eecs.umich.edu# contributors may be used to endorse or promote products derived from
143005Sstever@eecs.umich.edu# this software without specific prior written permission.
153005Sstever@eecs.umich.edu#
163005Sstever@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
173005Sstever@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
183005Sstever@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
193005Sstever@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
203005Sstever@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
213005Sstever@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
223005Sstever@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
233005Sstever@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
243005Sstever@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
253005Sstever@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
263005Sstever@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
273005Sstever@eecs.umich.edu#
283005Sstever@eecs.umich.edu
293005Sstever@eecs.umich.edufrom slicc.ast.StatementAST import StatementAST
303005Sstever@eecs.umich.edufrom slicc.symbols import Var
313005Sstever@eecs.umich.edu
323005Sstever@eecs.umich.educlass LocalVariableAST(StatementAST):
333005Sstever@eecs.umich.edu    def __init__(self, slicc, type_ast, ident):
343005Sstever@eecs.umich.edu        super(LocalVariableAST, self).__init__(slicc)
353005Sstever@eecs.umich.edu        self.type_ast = type_ast
363005Sstever@eecs.umich.edu        self.ident    = ident
373005Sstever@eecs.umich.edu
383005Sstever@eecs.umich.edu    def __repr__(self):
393005Sstever@eecs.umich.edu        return "[LocalVariableAST: %r %r]" % (self.type_ast, self.ident)
403005Sstever@eecs.umich.edu
412710SN/A    @property
422710SN/A    def name(self):
433005Sstever@eecs.umich.edu        return self.var_name
442889SN/A
4512564Sgabeblack@google.com    def generate(self, code):
4612564Sgabeblack@google.com        type = self.type_ast.type;
476654Snate@binkert.org        ident = "%s" % self.ident;
486654Snate@binkert.org
499907Snilay@cs.wisc.edu        # Add to symbol table
506654Snate@binkert.org        v = Var(self.symtab, self.ident, self.location, type, ident,
512667SN/A                self.pairs)
526654Snate@binkert.org        self.symtab.newSymbol(v)
536654Snate@binkert.org        code += "%s* %s" % (type.c_ident, ident)
5412395Sswapnilster@gmail.com        return type
555457Ssaidi@eecs.umich.edu