OutPortDeclAST.py revision 6872
17405SAli.Saidi@ARM.com# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 27405SAli.Saidi@ARM.com# Copyright (c) 2009 The Hewlett-Packard Development Company 37405SAli.Saidi@ARM.com# All rights reserved. 47405SAli.Saidi@ARM.com# 57405SAli.Saidi@ARM.com# Redistribution and use in source and binary forms, with or without 67405SAli.Saidi@ARM.com# modification, are permitted provided that the following conditions are 77405SAli.Saidi@ARM.com# met: redistributions of source code must retain the above copyright 87405SAli.Saidi@ARM.com# notice, this list of conditions and the following disclaimer; 97405SAli.Saidi@ARM.com# redistributions in binary form must reproduce the above copyright 107405SAli.Saidi@ARM.com# notice, this list of conditions and the following disclaimer in the 117405SAli.Saidi@ARM.com# documentation and/or other materials provided with the distribution; 127405SAli.Saidi@ARM.com# neither the name of the copyright holders nor the names of its 137405SAli.Saidi@ARM.com# contributors may be used to endorse or promote products derived from 147405SAli.Saidi@ARM.com# this software without specific prior written permission. 157405SAli.Saidi@ARM.com# 167405SAli.Saidi@ARM.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 177405SAli.Saidi@ARM.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 187405SAli.Saidi@ARM.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 197405SAli.Saidi@ARM.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 207405SAli.Saidi@ARM.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 217405SAli.Saidi@ARM.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 227405SAli.Saidi@ARM.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 237405SAli.Saidi@ARM.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 247405SAli.Saidi@ARM.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 257405SAli.Saidi@ARM.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 267405SAli.Saidi@ARM.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 277405SAli.Saidi@ARM.com 287405SAli.Saidi@ARM.comfrom m5.util import code_formatter 297405SAli.Saidi@ARM.com 307405SAli.Saidi@ARM.comfrom slicc.ast.DeclAST import DeclAST 317405SAli.Saidi@ARM.comfrom slicc.ast.TypeAST import TypeAST 327405SAli.Saidi@ARM.comfrom slicc.symbols import Var 337405SAli.Saidi@ARM.comfrom slicc.symbols import Type 347405SAli.Saidi@ARM.com 357405SAli.Saidi@ARM.comclass OutPortDeclAST(DeclAST): 367405SAli.Saidi@ARM.com def __init__(self, slicc, ident, msg_type, var_expr, pairs): 377405SAli.Saidi@ARM.com super(OutPortDeclAST, self).__init__(slicc, pairs) 387405SAli.Saidi@ARM.com 397405SAli.Saidi@ARM.com self.ident = ident 407405SAli.Saidi@ARM.com self.msg_type = msg_type 417405SAli.Saidi@ARM.com self.var_expr = var_expr 427405SAli.Saidi@ARM.com self.queue_type = TypeAST(slicc, "OutPort") 437405SAli.Saidi@ARM.com 447405SAli.Saidi@ARM.com def __repr__(self): 457405SAli.Saidi@ARM.com return "[OutPortDecl: %r]" % self.ident 467427Sgblack@eecs.umich.edu 477427Sgblack@eecs.umich.edu def generate(self): 487427Sgblack@eecs.umich.edu code = code_formatter(newlines=False) 497427Sgblack@eecs.umich.edu 507427Sgblack@eecs.umich.edu queue_type = self.var_expr.generate(code) 517427Sgblack@eecs.umich.edu if not queue_type.isOutPort: 527427Sgblack@eecs.umich.edu self.error("The outport queue's type must have the 'outport' " + 537427Sgblack@eecs.umich.edu "attribute. Type '%s' does not have this attribute.", 547427Sgblack@eecs.umich.edu (queue_type)) 557427Sgblack@eecs.umich.edu 567427Sgblack@eecs.umich.edu if not self.symtab.find(self.msg_type.ident, Type): 577427Sgblack@eecs.umich.edu self.error("The message type '%s' does not exist.", 587604SGene.Wu@arm.com self.msg_type.ident) 597427Sgblack@eecs.umich.edu 607427Sgblack@eecs.umich.edu var = Var(self.symtab, self.ident, self.location, self.queue_type.type, 617427Sgblack@eecs.umich.edu str(code), self.pairs) 627427Sgblack@eecs.umich.edu self.symtab.newSymbol(var) 637427Sgblack@eecs.umich.edu