MachineAST.py revision 11282
12810SN/A# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 29614Srene.dejong@arm.com# Copyright (c) 2009 The Hewlett-Packard Development Company 38856Sandreas.hansson@arm.com# All rights reserved. 48856Sandreas.hansson@arm.com# 58856Sandreas.hansson@arm.com# Redistribution and use in source and binary forms, with or without 68856Sandreas.hansson@arm.com# modification, are permitted provided that the following conditions are 78856Sandreas.hansson@arm.com# met: redistributions of source code must retain the above copyright 88856Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer; 98856Sandreas.hansson@arm.com# redistributions in binary form must reproduce the above copyright 108856Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer in the 118856Sandreas.hansson@arm.com# documentation and/or other materials provided with the distribution; 128856Sandreas.hansson@arm.com# neither the name of the copyright holders nor the names of its 138856Sandreas.hansson@arm.com# contributors may be used to endorse or promote products derived from 142810SN/A# this software without specific prior written permission. 152810SN/A# 162810SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172810SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182810SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192810SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202810SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212810SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222810SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232810SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242810SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252810SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262810SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272810SN/A 282810SN/Afrom slicc.ast.DeclAST import DeclAST 292810SN/Afrom slicc.symbols import StateMachine, Type 302810SN/A 312810SN/Aclass MachineAST(DeclAST): 322810SN/A def __init__(self, slicc, ident, pairs_ast, config_parameters, decls): 332810SN/A super(MachineAST, self).__init__(slicc, pairs_ast) 342810SN/A 352810SN/A self.ident = ident 362810SN/A self.pairs_ast = pairs_ast 372810SN/A self.config_parameters = config_parameters 382810SN/A self.decls = decls 392810SN/A 402810SN/A def __repr__(self): 412810SN/A return "[Machine: %r]" % self.ident 422810SN/A 432810SN/A def files(self, parent=None): 442810SN/A s = set(('%s_Controller.cc' % self.ident, 452810SN/A '%s_Controller.hh' % self.ident, 462810SN/A '%s_Controller.py' % self.ident, 472810SN/A '%s_Transitions.cc' % self.ident, 4811486Snikos.nikoleris@arm.com '%s_Wakeup.cc' % self.ident)) 4911486Snikos.nikoleris@arm.com 508232Snate@binkert.org s |= self.decls.files(self.ident) 519152Satgutier@umich.edu return s 5211486Snikos.nikoleris@arm.com 5311486Snikos.nikoleris@arm.com def generate(self): 549795Sandreas.hansson@arm.com # Make a new frame 559795Sandreas.hansson@arm.com self.symtab.pushFrame() 5610263Satgutier@umich.edu 578786Sgblack@eecs.umich.edu # Create a new machine 582810SN/A machine = StateMachine(self.symtab, self.ident, self.location, 592810SN/A self.pairs, self.config_parameters) 602810SN/A 618856Sandreas.hansson@arm.com self.symtab.newCurrentMachine(machine) 628856Sandreas.hansson@arm.com 638856Sandreas.hansson@arm.com # Generate code for all the internal decls 648922Swilliam.wang@arm.com self.decls.generate() 658914Sandreas.hansson@arm.com 668856Sandreas.hansson@arm.com # Build the transition table 678856Sandreas.hansson@arm.com machine.buildTable() 684475SN/A 6911053Sandreas.hansson@arm.com # Pop the frame 705034SN/A self.symtab.popFrame() 7110360Sandreas.hansson@arm.com 7211377Sandreas.hansson@arm.com def findMachines(self): 7311377Sandreas.hansson@arm.com mtype = self.ident 7411053Sandreas.hansson@arm.com machine_type = self.symtab.find("MachineType", Type) 7510693SMarco.Balboni@ARM.com pairs = self.pairs_ast.pairs 7610693SMarco.Balboni@ARM.com 7710693SMarco.Balboni@ARM.com pairs["Primary"] = True 789263Smrinmoy.ghosh@arm.com if not machine_type.addEnum(mtype, pairs): 795034SN/A self.error("Duplicate machine name: %s:%s" % (machine_type, mtype)) 8011331Sandreas.hansson@arm.com 8110884Sandreas.hansson@arm.com # Generate code for all the internal decls 824626SN/A self.decls.findMachines() 8310360Sandreas.hansson@arm.com