Func.py revision 9298
12SN/A# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 210905Sandreas.sandberg@arm.com# Copyright (c) 2009 The Hewlett-Packard Development Company 310905Sandreas.sandberg@arm.com# All rights reserved. 410905Sandreas.sandberg@arm.com# 510905Sandreas.sandberg@arm.com# Redistribution and use in source and binary forms, with or without 610905Sandreas.sandberg@arm.com# modification, are permitted provided that the following conditions are 710905Sandreas.sandberg@arm.com# met: redistributions of source code must retain the above copyright 810905Sandreas.sandberg@arm.com# notice, this list of conditions and the following disclaimer; 910905Sandreas.sandberg@arm.com# redistributions in binary form must reproduce the above copyright 1010905Sandreas.sandberg@arm.com# notice, this list of conditions and the following disclaimer in the 1110905Sandreas.sandberg@arm.com# documentation and/or other materials provided with the distribution; 1210905Sandreas.sandberg@arm.com# neither the name of the copyright holders nor the names of its 1310905Sandreas.sandberg@arm.com# contributors may be used to endorse or promote products derived from 141762SN/A# this software without specific prior written permission. 159983Sstever@gmail.com# 169983Sstever@gmail.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272SN/A 282SN/Afrom slicc.symbols.Symbol import Symbol 292SN/Afrom slicc.symbols.Type import Type 302SN/A 312SN/Aclass Func(Symbol): 322SN/A def __init__(self, table, ident, location, return_type, param_types, 332SN/A param_strings, body, pairs): 342SN/A super(Func, self).__init__(table, ident, location, pairs) 352SN/A self.return_type = return_type 362SN/A self.param_types = param_types 372SN/A self.param_strings = param_strings 382SN/A self.body = body 392SN/A self.isInternalMachineFunc = False 402SN/A self.c_ident = ident 412665Ssaidi@eecs.umich.edu self.class_name = "" 422760Sbinkertn@umich.edu 432760Sbinkertn@umich.edu def __repr__(self): 442665Ssaidi@eecs.umich.edu return "" 4510905Sandreas.sandberg@arm.com 462SN/A @property 472SN/A def prototype(self): 488229Snate@binkert.org if "external" in self: 492SN/A return "" 50363SN/A 512SN/A return_type = self.return_type.c_ident 528229Snate@binkert.org void_type = self.symtab.find("void", Type) 532SN/A if "return_by_ref" in self and self.return_type != void_type: 542SN/A return_type += "&" 552SN/A elif "return_by_pointer" in self and self.return_type != void_type: 562SN/A return_type += "*" 572SN/A 5810907Sandreas.sandberg@arm.com return "%s %s(%s);" % (return_type, self.c_ident, 59363SN/A ", ".join(self.param_strings)) 6056SN/A 611388SN/A def writeCodeFiles(self, path, includes): 62217SN/A return 63363SN/A 6410905Sandreas.sandberg@arm.com def generateCode(self): 6556SN/A '''This write a function of object Chip''' 6656SN/A if "external" in self: 6756SN/A return "" 681638SN/A 6956SN/A code = self.symtab.codeFormatter() 702SN/A 712356SN/A # Generate function header 722356SN/A void_type = self.symtab.find("void", Type) 732356SN/A return_type = self.return_type.c_ident 742SN/A if "return_by_ref" in self and self.return_type != void_type: 752SN/A return_type += "&" 764762Snate@binkert.org if "return_by_pointer" in self and self.return_type != void_type: 774762Snate@binkert.org return_type += "*" 784762Snate@binkert.org 794762Snate@binkert.org params = ', '.join(self.param_strings) 804762Snate@binkert.org 814762Snate@binkert.org code(''' 824762Snate@binkert.org$return_type 834762Snate@binkert.org${{self.class_name}}::${{self.c_ident}}($params) 844762Snate@binkert.org{ 854762Snate@binkert.org${{self.body}} 864762Snate@binkert.org} 874762Snate@binkert.org''') 884762Snate@binkert.org return str(code) 8910905Sandreas.sandberg@arm.com 904762Snate@binkert.org__all__ = [ "Func" ] 914762Snate@binkert.org