18086SBrad.Beckmann@amd.com# Copyright (c) 2011 Advanced Micro Devices, Inc.
26657SN/A# All rights reserved.
36657SN/A#
46657SN/A# Redistribution and use in source and binary forms, with or without
56657SN/A# modification, are permitted provided that the following conditions are
66657SN/A# met: redistributions of source code must retain the above copyright
76657SN/A# notice, this list of conditions and the following disclaimer;
86657SN/A# redistributions in binary form must reproduce the above copyright
96657SN/A# notice, this list of conditions and the following disclaimer in the
106657SN/A# documentation and/or other materials provided with the distribution;
116657SN/A# neither the name of the copyright holders nor the names of its
126657SN/A# contributors may be used to endorse or promote products derived from
136657SN/A# this software without specific prior written permission.
146657SN/A#
156657SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
166657SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
176657SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
186657SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
196657SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
206657SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
216657SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
226657SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
236657SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
246657SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
256657SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
266657SN/A
276657SN/Afrom slicc.ast.TypeFieldAST import TypeFieldAST
286657SN/Afrom slicc.symbols import Event, State
296657SN/A
308086SBrad.Beckmann@amd.comclass TypeFieldStateAST(TypeFieldAST):
318086SBrad.Beckmann@amd.com    def __init__(self, slicc, field_id, perm_ast, pairs_ast):
328086SBrad.Beckmann@amd.com        super(TypeFieldStateAST, self).__init__(slicc, pairs_ast)
336657SN/A
346657SN/A        self.field_id = field_id
358086SBrad.Beckmann@amd.com        self.perm_ast = perm_ast
368086SBrad.Beckmann@amd.com        if not (perm_ast.type_ast.ident == "AccessPermission"):
378086SBrad.Beckmann@amd.com            self.error("AccessPermission enum value must be specified")
386657SN/A        self.pairs_ast = pairs_ast
396657SN/A
406657SN/A    def __repr__(self):
418086SBrad.Beckmann@amd.com        return "[TypeFieldState: %r]" % self.field_id
426657SN/A
436657SN/A    def generate(self, type):
448086SBrad.Beckmann@amd.com        if not str(type) == "State":
458086SBrad.Beckmann@amd.com            self.error("State Declaration must be of type State.")
4611320Ssteve.reinhardt@amd.com
476657SN/A        # Add enumeration
489298Snilay@cs.wisc.edu        if not type.addEnum(self.field_id, self.pairs_ast.pairs):
496690SN/A            self.error("Duplicate enumeration: %s:%s" % (type, self.field_id))
506657SN/A
516657SN/A        # Fill machine info
526657SN/A        machine = self.symtab.state_machine
536657SN/A
548086SBrad.Beckmann@amd.com        if not machine:
558086SBrad.Beckmann@amd.com            self.error("State declaration not part of a machine.")
568086SBrad.Beckmann@amd.com        s = State(self.symtab, self.field_id, self.location, self.pairs)
578086SBrad.Beckmann@amd.com        machine.addState(s)
586657SN/A
598086SBrad.Beckmann@amd.com        type.statePermPairAdd(s, self.perm_ast.value)
608086SBrad.Beckmann@amd.com
618086SBrad.Beckmann@amd.com
62