ActionDeclAST.py revision 7839:9e556fb25900
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.ast.DeclAST import DeclAST 292SN/Afrom slicc.symbols import Action, Type, Var 302SN/A 312SN/Aclass ActionDeclAST(DeclAST): 322SN/A def __init__(self, slicc, ident, pairs, statement_list): 332SN/A super(ActionDeclAST, self).__init__(slicc, pairs) 342SN/A self.ident = ident 352SN/A self.statement_list = statement_list 362SN/A 372SN/A def __repr__(self): 382SN/A return "[ActionDecl: %r]" % (self.ident) 392SN/A 402SN/A def generate(self): 412665Ssaidi@eecs.umich.edu resources = {} 422760Sbinkertn@umich.edu 432760Sbinkertn@umich.edu machine = self.symtab.state_machine 442665Ssaidi@eecs.umich.edu if machine is None: 4510905Sandreas.sandberg@arm.com self.error("Action declaration not part of a machine.") 462SN/A 472SN/A if self.statement_list: 488229Snate@binkert.org # Add new local vars 492SN/A self.symtab.pushFrame() 50363SN/A 512SN/A addr_type = self.symtab.find("Address", Type) 528229Snate@binkert.org 532SN/A if addr_type is None: 542SN/A self.error("Type 'Address' not declared.") 552SN/A 562SN/A var = Var(self.symtab, "address", self.location, addr_type, 572SN/A "addr", self.pairs) 5810907Sandreas.sandberg@arm.com self.symtab.newSymbol(var) 59363SN/A 6056SN/A if machine.TBEType != None: 611388SN/A var = Var(self.symtab, "tbe", self.location, machine.TBEType, 62217SN/A "(*m_tbe_ptr)", self.pairs) 63363SN/A self.symtab.newSymbol(var) 6410905Sandreas.sandberg@arm.com 6556SN/A if machine.EntryType != None: 6656SN/A var = Var(self.symtab, "cache_entry", self.location, 6756SN/A machine.EntryType, "(*m_cache_entry_ptr)", self.pairs) 681638SN/A self.symtab.newSymbol(var) 6956SN/A 702SN/A # Do not allows returns in actions 712356SN/A code = self.slicc.codeFormatter() 722356SN/A self.statement_list.generate(code, None) 732356SN/A self.pairs["c_code"] = str(code) 742SN/A 752SN/A self.statement_list.findResources(resources) 764762Snate@binkert.org 774762Snate@binkert.org self.symtab.popFrame() 784762Snate@binkert.org 794762Snate@binkert.org action = Action(self.symtab, self.ident, resources, self.location, 804762Snate@binkert.org self.pairs) 814762Snate@binkert.org machine.addAction(action) 824762Snate@binkert.org