StateDeclAST.py revision 8086
15222Sksewell@umich.edu# Copyright (c) 2011 Advanced Micro Devices, Inc. 25268Sksewell@umich.edu# All rights reserved. 35254Sksewell@umich.edu# 45222Sksewell@umich.edu# Redistribution and use in source and binary forms, with or without 55254Sksewell@umich.edu# modification, are permitted provided that the following conditions are 65254Sksewell@umich.edu# met: redistributions of source code must retain the above copyright 75254Sksewell@umich.edu# notice, this list of conditions and the following disclaimer; 85254Sksewell@umich.edu# redistributions in binary form must reproduce the above copyright 95254Sksewell@umich.edu# notice, this list of conditions and the following disclaimer in the 105254Sksewell@umich.edu# documentation and/or other materials provided with the distribution; 115254Sksewell@umich.edu# neither the name of the copyright holders nor the names of its 125254Sksewell@umich.edu# contributors may be used to endorse or promote products derived from 135254Sksewell@umich.edu# this software without specific prior written permission. 145254Sksewell@umich.edu# 155222Sksewell@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 165254Sksewell@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 175254Sksewell@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 185254Sksewell@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 195254Sksewell@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 205254Sksewell@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 215254Sksewell@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 225254Sksewell@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 235254Sksewell@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 245254Sksewell@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 255254Sksewell@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 265254Sksewell@umich.edu 275222Sksewell@umich.edufrom slicc.ast.DeclAST import DeclAST 285254Sksewell@umich.edufrom slicc.symbols import Func, Type 295254Sksewell@umich.edu 305254Sksewell@umich.educlass StateDeclAST(DeclAST): 315222Sksewell@umich.edu def __init__(self, slicc, type_ast, pairs, states): 325222Sksewell@umich.edu super(StateDeclAST, self).__init__(slicc, pairs) 335222Sksewell@umich.edu 345222Sksewell@umich.edu self.type_ast = type_ast 355222Sksewell@umich.edu self.states = states 365222Sksewell@umich.edu 375222Sksewell@umich.edu def __repr__(self): 385222Sksewell@umich.edu return "[StateDecl: %s]" % (self.type_ast) 395222Sksewell@umich.edu 405222Sksewell@umich.edu def files(self, parent=None): 415222Sksewell@umich.edu if "external" in self: 4211793Sbrandon.potter@amd.com return set() 4311793Sbrandon.potter@amd.com 449329Sdam.sunwoo@arm.com if parent: 458229Snate@binkert.org ident = "%s_%s" % (parent, self.type_ast.ident) 465222Sksewell@umich.edu else: 478229Snate@binkert.org ident = self.type_ast.ident 485222Sksewell@umich.edu s = set(("%s.hh" % ident, "%s.cc" % ident)) 498229Snate@binkert.org return s 505222Sksewell@umich.edu 518775Sgblack@eecs.umich.edu def generate(self): 525222Sksewell@umich.edu ident = str(self.type_ast) 538229Snate@binkert.org 545222Sksewell@umich.edu # Make the new type 555222Sksewell@umich.edu t = Type(self.symtab, ident, self.location, self.pairs, 565222Sksewell@umich.edu self.state_machine) 575222Sksewell@umich.edu self.symtab.newSymbol(t) 585222Sksewell@umich.edu 595222Sksewell@umich.edu # Add all of the states of the type to it 605222Sksewell@umich.edu for state in self.states: 615222Sksewell@umich.edu state.generate(t) 625222Sksewell@umich.edu 635222Sksewell@umich.edu # Add the implicit State_to_string method - FIXME, this is a bit dirty 645222Sksewell@umich.edu func_id = "%s_to_string" % t.c_ident 655222Sksewell@umich.edu 665222Sksewell@umich.edu pairs = { "external" : "yes" } 675222Sksewell@umich.edu func = Func(self.symtab, func_id, self.location, 685222Sksewell@umich.edu self.symtab.find("std::string", Type), [ t ], [], "", 695222Sksewell@umich.edu pairs, None) 705222Sksewell@umich.edu self.symtab.newSymbol(func) 715222Sksewell@umich.edu 725222Sksewell@umich.edu # Add the State_to_permission method 735222Sksewell@umich.edu func_id = "%s_to_permission" % t.c_ident 745222Sksewell@umich.edu 755222Sksewell@umich.edu pairs = { "external" : "yes" } 765222Sksewell@umich.edu func = Func(self.symtab, func_id, self.location, 778741Sgblack@eecs.umich.edu self.symtab.find("AccessPermission", Type), [ t ], [], "", 785222Sksewell@umich.edu pairs, None) 795222Sksewell@umich.edu self.symtab.newSymbol(func) 805222Sksewell@umich.edu