Transition.py revision 11325:67cc559d513a
12SN/A# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
21762SN/A# Copyright (c) 2009 The Hewlett-Packard Development Company
35502Snate@binkert.org# All rights reserved.
49983Sstever@gmail.com#
52SN/A# Redistribution and use in source and binary forms, with or without
62SN/A# modification, are permitted provided that the following conditions are
72SN/A# met: redistributions of source code must retain the above copyright
82SN/A# notice, this list of conditions and the following disclaimer;
92SN/A# redistributions in binary form must reproduce the above copyright
102SN/A# notice, this list of conditions and the following disclaimer in the
112SN/A# documentation and/or other materials provided with the distribution;
122SN/A# neither the name of the copyright holders nor the names of its
132SN/A# contributors may be used to endorse or promote products derived from
142SN/A# this software without specific prior written permission.
152SN/A#
162SN/A# 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.symbols.Symbol import Symbol
292665Ssaidi@eecs.umich.edufrom slicc.symbols.State import WildcardState
302665Ssaidi@eecs.umich.edu
312665Ssaidi@eecs.umich.educlass Transition(Symbol):
322665Ssaidi@eecs.umich.edu    def __init__(self, table, machine, state, event, nextState, actions,
332SN/A                 request_types, location):
342SN/A        ident = "%s|%s" % (state, event)
355501Snate@binkert.org        super(Transition, self).__init__(table, ident, location)
362SN/A
372SN/A        self.state = machine.states[state]
382SN/A        self.event = machine.events[event]
392SN/A        if nextState == '*':
405502Snate@binkert.org            # check to make sure there is a getNextState function declared
415501Snate@binkert.org            found = False
425501Snate@binkert.org            for func in machine.functions:
431717SN/A                if func.c_ident == 'getNextState_Addr':
448232Snate@binkert.org                    found = True
455501Snate@binkert.org                    break
469356Snilay@cs.wisc.edu            if not found:
472SN/A                fatal("Machine uses a wildcard transition without getNextState defined")
482SN/A            self.nextState = WildcardState(machine.symtab,
492SN/A                                           '*', location)
509983Sstever@gmail.com        else:
519983Sstever@gmail.com            self.nextState = machine.states[nextState]
522SN/A        self.actions = [ machine.actions[a] for a in actions ]
539983Sstever@gmail.com        self.request_types = [ machine.request_types[s] for s in request_types ]
542SN/A        self.resources = {}
559983Sstever@gmail.com
562SN/A        for action in self.actions:
572SN/A            for var,value in action.resources.iteritems():
589983Sstever@gmail.com                num = int(value)
599983Sstever@gmail.com                if var in self.resources:
609983Sstever@gmail.com                    num += int(value)
619983Sstever@gmail.com                self.resources[var] = str(num)
629983Sstever@gmail.com
639983Sstever@gmail.com    def __repr__(self):
649983Sstever@gmail.com      return "[Transition: (%r, %r) -> %r, %r]" % \
659983Sstever@gmail.com             (self.state, self.event, self.nextState, self.actions)
669983Sstever@gmail.com
679983Sstever@gmail.com    def getActionShorthands(self):
689983Sstever@gmail.com        assert self.actions
699983Sstever@gmail.com
709983Sstever@gmail.com        return ''.join(a.short for a in self.actions)
719983Sstever@gmail.com
729983Sstever@gmail.com__all__ = [ "Transition" ]
739983Sstever@gmail.com