PeekStatementAST.py revision 11111
110259SAndrew.Bardsley@arm.com# Copyright (c) 2013 Advanced Micro Devices, Inc. 213610Sgiacomo.gabrielli@arm.com# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 310259SAndrew.Bardsley@arm.com# Copyright (c) 2009 The Hewlett-Packard Development Company 410259SAndrew.Bardsley@arm.com# All rights reserved. 510259SAndrew.Bardsley@arm.com# 610259SAndrew.Bardsley@arm.com# Redistribution and use in source and binary forms, with or without 710259SAndrew.Bardsley@arm.com# modification, are permitted provided that the following conditions are 810259SAndrew.Bardsley@arm.com# met: redistributions of source code must retain the above copyright 910259SAndrew.Bardsley@arm.com# notice, this list of conditions and the following disclaimer; 1010259SAndrew.Bardsley@arm.com# redistributions in binary form must reproduce the above copyright 1110259SAndrew.Bardsley@arm.com# notice, this list of conditions and the following disclaimer in the 1210259SAndrew.Bardsley@arm.com# documentation and/or other materials provided with the distribution; 1310259SAndrew.Bardsley@arm.com# neither the name of the copyright holders nor the names of its 1410259SAndrew.Bardsley@arm.com# contributors may be used to endorse or promote products derived from 1510259SAndrew.Bardsley@arm.com# this software without specific prior written permission. 1610259SAndrew.Bardsley@arm.com# 1710259SAndrew.Bardsley@arm.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1810259SAndrew.Bardsley@arm.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1910259SAndrew.Bardsley@arm.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2010259SAndrew.Bardsley@arm.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2110259SAndrew.Bardsley@arm.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2210259SAndrew.Bardsley@arm.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2310259SAndrew.Bardsley@arm.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2410259SAndrew.Bardsley@arm.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2510259SAndrew.Bardsley@arm.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2610259SAndrew.Bardsley@arm.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2710259SAndrew.Bardsley@arm.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2810259SAndrew.Bardsley@arm.com 2910259SAndrew.Bardsley@arm.comfrom slicc.ast.StatementAST import StatementAST 3010259SAndrew.Bardsley@arm.comfrom slicc.symbols import Var 3110259SAndrew.Bardsley@arm.com 3210259SAndrew.Bardsley@arm.comclass PeekStatementAST(StatementAST): 3310259SAndrew.Bardsley@arm.com def __init__(self, slicc, queue_name, type_ast, pairs, statements, method): 3410259SAndrew.Bardsley@arm.com super(PeekStatementAST, self).__init__(slicc, pairs) 3510259SAndrew.Bardsley@arm.com 3610259SAndrew.Bardsley@arm.com self.queue_name = queue_name 3710259SAndrew.Bardsley@arm.com self.type_ast = type_ast 3810259SAndrew.Bardsley@arm.com self.statements = statements 3910259SAndrew.Bardsley@arm.com self.method = method 4010259SAndrew.Bardsley@arm.com 4110259SAndrew.Bardsley@arm.com def __repr__(self): 4210259SAndrew.Bardsley@arm.com return "[PeekStatementAST: %r queue_name: %r type: %r %r]" % \ 4310259SAndrew.Bardsley@arm.com (self.method, self.queue_name, self.type_ast, self.statements) 4410259SAndrew.Bardsley@arm.com 4510259SAndrew.Bardsley@arm.com def generate(self, code, return_type): 4610259SAndrew.Bardsley@arm.com self.symtab.pushFrame() 4710259SAndrew.Bardsley@arm.com 4810259SAndrew.Bardsley@arm.com msg_type = self.type_ast.type 4910259SAndrew.Bardsley@arm.com 5010259SAndrew.Bardsley@arm.com # Add new local var to symbol table 5110259SAndrew.Bardsley@arm.com var = Var(self.symtab, "in_msg", self.location, msg_type, "(*in_msg_ptr)", 5210259SAndrew.Bardsley@arm.com self.pairs) 5310259SAndrew.Bardsley@arm.com self.symtab.newSymbol(var) 5410259SAndrew.Bardsley@arm.com 5510259SAndrew.Bardsley@arm.com # Check the queue type 5610319SAndreas.Sandberg@ARM.com self.queue_name.assertType("InPort") 5710259SAndrew.Bardsley@arm.com 5810259SAndrew.Bardsley@arm.com # Declare the new "in_msg_ptr" variable 5910259SAndrew.Bardsley@arm.com mtid = msg_type.c_ident 6010259SAndrew.Bardsley@arm.com qcode = self.queue_name.var.code 6111608Snikos.nikoleris@arm.com code(''' 6210259SAndrew.Bardsley@arm.com{ 6310259SAndrew.Bardsley@arm.com // Declare message 6410259SAndrew.Bardsley@arm.com const $mtid* in_msg_ptr M5_VAR_USED; 6510259SAndrew.Bardsley@arm.com in_msg_ptr = dynamic_cast<const $mtid *>(($qcode).${{self.method}}()); 6610259SAndrew.Bardsley@arm.com if (in_msg_ptr == NULL) { 6710259SAndrew.Bardsley@arm.com // If the cast fails, this is the wrong inport (wrong message type). 6810259SAndrew.Bardsley@arm.com // Throw an exception, and the caller will decide to either try a 6910259SAndrew.Bardsley@arm.com // different inport or punt. 7010259SAndrew.Bardsley@arm.com throw RejectException(); 7110259SAndrew.Bardsley@arm.com } 7210259SAndrew.Bardsley@arm.com''') 7310259SAndrew.Bardsley@arm.com 7410319SAndreas.Sandberg@ARM.com if self.pairs.has_key("block_on"): 7510259SAndrew.Bardsley@arm.com address_field = self.pairs['block_on'] 7610259SAndrew.Bardsley@arm.com code(''' 7710259SAndrew.Bardsley@arm.com if (m_is_blocking && 7810259SAndrew.Bardsley@arm.com (m_block_map.count(in_msg_ptr->m_$address_field) == 1) && 7910259SAndrew.Bardsley@arm.com (m_block_map[in_msg_ptr->m_$address_field] != &$qcode)) { 8010259SAndrew.Bardsley@arm.com $qcode.delayHead(clockEdge(), cyclesToTicks(Cycles(1))); 8110259SAndrew.Bardsley@arm.com continue; 8210259SAndrew.Bardsley@arm.com } 8310259SAndrew.Bardsley@arm.com ''') 8410259SAndrew.Bardsley@arm.com 8510259SAndrew.Bardsley@arm.com if self.pairs.has_key("wake_up"): 8610259SAndrew.Bardsley@arm.com address_field = self.pairs['wake_up'] 8710259SAndrew.Bardsley@arm.com code(''' 8810259SAndrew.Bardsley@arm.com if (m_waiting_buffers.count(in_msg_ptr->m_$address_field) > 0) { 8910259SAndrew.Bardsley@arm.com wakeUpBuffers(in_msg_ptr->m_$address_field); 9010259SAndrew.Bardsley@arm.com } 9110259SAndrew.Bardsley@arm.com ''') 9210259SAndrew.Bardsley@arm.com 9310259SAndrew.Bardsley@arm.com # The other statements 9410259SAndrew.Bardsley@arm.com self.statements.generate(code, return_type) 9510259SAndrew.Bardsley@arm.com self.symtab.popFrame() 9610259SAndrew.Bardsley@arm.com code("}") 9710259SAndrew.Bardsley@arm.com 9810259SAndrew.Bardsley@arm.com def findResources(self, resources): 9910259SAndrew.Bardsley@arm.com self.statements.findResources(resources) 10010259SAndrew.Bardsley@arm.com