TypeFieldEnumAST.py revision 6657
17927SN/A# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 27927SN/A# Copyright (c) 2009 The Hewlett-Packard Development Company 37927SN/A# All rights reserved. 49988Snilay@cs.wisc.edu# 58835SAli.Saidi@ARM.com# Redistribution and use in source and binary forms, with or without 69988Snilay@cs.wisc.edu# modification, are permitted provided that the following conditions are 77927SN/A# met: redistributions of source code must retain the above copyright 87927SN/A# notice, this list of conditions and the following disclaimer; 97927SN/A# redistributions in binary form must reproduce the above copyright 107927SN/A# notice, this list of conditions and the following disclaimer in the 117927SN/A# documentation and/or other materials provided with the distribution; 127927SN/A# neither the name of the copyright holders nor the names of its 1310315Snilay@cs.wisc.edu# contributors may be used to endorse or promote products derived from 147927SN/A# this software without specific prior written permission. 157927SN/A# 169885Sstever@gmail.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 179885Sstever@gmail.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 187927SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 199988Snilay@cs.wisc.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 207927SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 217927SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 227927SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2310736Snilay@cs.wisc.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2410315Snilay@cs.wisc.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 257927SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2610315Snilay@cs.wisc.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 277927SN/A 289474Snilay@cs.wisc.edufrom slicc.ast.TypeFieldAST import TypeFieldAST 298673SN/Afrom slicc.symbols import Event, State 3010736Snilay@cs.wisc.edu 318673SN/Aclass TypeFieldEnumAST(TypeFieldAST): 3210736Snilay@cs.wisc.edu def __init__(self, slicc, field_id, pairs_ast): 337927SN/A super(TypeFieldEnumAST, self).__init__(slicc, pairs_ast) 347927SN/A 357927SN/A self.field_id = field_id 367927SN/A self.pairs_ast = pairs_ast 377927SN/A 387927SN/A def __repr__(self): 397927SN/A return "[TypeFieldEnum: %r]" % self.field_id 407927SN/A 417927SN/A def generate(self, type): 428983Snate@binkert.org # Add enumeration 437927SN/A if not type.enumAdd(self.field_id, self.pairs_ast.pairs): 447927SN/A error("Duplicate enumeration: %s:%s" % (type, self.field_id)) 457927SN/A 467927SN/A # Fill machine info 479988Snilay@cs.wisc.edu machine = self.symtab.state_machine 487927SN/A 497927SN/A if str(type) == "State": 507927SN/A if not machine: 517927SN/A error("State declaration not part of a machine.") 527927SN/A s = State(self.symtab, self.field_id, self.location, self.pairs) 537927SN/A machine.addState(s) 547927SN/A 557927SN/A if str(type) == "Event": 567927SN/A if not machine: 577927SN/A error("Event declaration not part of a machine.") 589988Snilay@cs.wisc.edu e = Event(self.symtab, self.field_id, self.location, self.pairs) 597927SN/A machine.addEvent(e) 607927SN/A