StateMachine.py revision 7839
16657Snate@binkert.org# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
26657Snate@binkert.org# Copyright (c) 2009 The Hewlett-Packard Development Company
36657Snate@binkert.org# All rights reserved.
46657Snate@binkert.org#
56657Snate@binkert.org# Redistribution and use in source and binary forms, with or without
66657Snate@binkert.org# modification, are permitted provided that the following conditions are
76657Snate@binkert.org# met: redistributions of source code must retain the above copyright
86657Snate@binkert.org# notice, this list of conditions and the following disclaimer;
96657Snate@binkert.org# redistributions in binary form must reproduce the above copyright
106657Snate@binkert.org# notice, this list of conditions and the following disclaimer in the
116657Snate@binkert.org# documentation and/or other materials provided with the distribution;
126657Snate@binkert.org# neither the name of the copyright holders nor the names of its
136657Snate@binkert.org# contributors may be used to endorse or promote products derived from
146657Snate@binkert.org# this software without specific prior written permission.
156657Snate@binkert.org#
166657Snate@binkert.org# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176657Snate@binkert.org# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186657Snate@binkert.org# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196657Snate@binkert.org# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206657Snate@binkert.org# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216657Snate@binkert.org# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226657Snate@binkert.org# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236657Snate@binkert.org# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246657Snate@binkert.org# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256657Snate@binkert.org# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266657Snate@binkert.org# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276657Snate@binkert.org
286999Snate@binkert.orgfrom m5.util import orderdict
296657Snate@binkert.org
306657Snate@binkert.orgfrom slicc.symbols.Symbol import Symbol
316657Snate@binkert.orgfrom slicc.symbols.Var import Var
326657Snate@binkert.orgimport slicc.generate.html as html
336657Snate@binkert.org
346882SBrad.Beckmann@amd.compython_class_map = {"int": "Int",
357055Snate@binkert.org                    "std::string": "String",
366882SBrad.Beckmann@amd.com                    "bool": "Bool",
376882SBrad.Beckmann@amd.com                    "CacheMemory": "RubyCache",
386882SBrad.Beckmann@amd.com                    "Sequencer": "RubySequencer",
396882SBrad.Beckmann@amd.com                    "DirectoryMemory": "RubyDirectoryMemory",
406882SBrad.Beckmann@amd.com                    "MemoryControl": "RubyMemoryControl",
416888SBrad.Beckmann@amd.com                    "DMASequencer": "DMASequencer"
426882SBrad.Beckmann@amd.com                    }
436882SBrad.Beckmann@amd.com
446657Snate@binkert.orgclass StateMachine(Symbol):
456657Snate@binkert.org    def __init__(self, symtab, ident, location, pairs, config_parameters):
466657Snate@binkert.org        super(StateMachine, self).__init__(symtab, ident, location, pairs)
476657Snate@binkert.org        self.table = None
486657Snate@binkert.org        self.config_parameters = config_parameters
497839Snilay@cs.wisc.edu
506657Snate@binkert.org        for param in config_parameters:
516882SBrad.Beckmann@amd.com            if param.pointer:
526882SBrad.Beckmann@amd.com                var = Var(symtab, param.name, location, param.type_ast.type,
536882SBrad.Beckmann@amd.com                          "(*m_%s_ptr)" % param.name, {}, self)
546882SBrad.Beckmann@amd.com            else:
556882SBrad.Beckmann@amd.com                var = Var(symtab, param.name, location, param.type_ast.type,
566882SBrad.Beckmann@amd.com                          "m_%s" % param.name, {}, self)
576657Snate@binkert.org            self.symtab.registerSym(param.name, var)
586657Snate@binkert.org
596657Snate@binkert.org        self.states = orderdict()
606657Snate@binkert.org        self.events = orderdict()
616657Snate@binkert.org        self.actions = orderdict()
626657Snate@binkert.org        self.transitions = []
636657Snate@binkert.org        self.in_ports = []
646657Snate@binkert.org        self.functions = []
656657Snate@binkert.org        self.objects = []
667839Snilay@cs.wisc.edu        self.TBEType   = None
677839Snilay@cs.wisc.edu        self.EntryType = None
686657Snate@binkert.org
696657Snate@binkert.org        self.message_buffer_names = []
706657Snate@binkert.org
716657Snate@binkert.org    def __repr__(self):
726657Snate@binkert.org        return "[StateMachine: %s]" % self.ident
736657Snate@binkert.org
746657Snate@binkert.org    def addState(self, state):
756657Snate@binkert.org        assert self.table is None
766657Snate@binkert.org        self.states[state.ident] = state
776657Snate@binkert.org
786657Snate@binkert.org    def addEvent(self, event):
796657Snate@binkert.org        assert self.table is None
806657Snate@binkert.org        self.events[event.ident] = event
816657Snate@binkert.org
826657Snate@binkert.org    def addAction(self, action):
836657Snate@binkert.org        assert self.table is None
846657Snate@binkert.org
856657Snate@binkert.org        # Check for duplicate action
866657Snate@binkert.org        for other in self.actions.itervalues():
876657Snate@binkert.org            if action.ident == other.ident:
886779SBrad.Beckmann@amd.com                action.warning("Duplicate action definition: %s" % action.ident)
896657Snate@binkert.org                action.error("Duplicate action definition: %s" % action.ident)
906657Snate@binkert.org            if action.short == other.short:
916657Snate@binkert.org                other.warning("Duplicate action shorthand: %s" % other.ident)
926657Snate@binkert.org                other.warning("    shorthand = %s" % other.short)
936657Snate@binkert.org                action.warning("Duplicate action shorthand: %s" % action.ident)
946657Snate@binkert.org                action.error("    shorthand = %s" % action.short)
956657Snate@binkert.org
966657Snate@binkert.org        self.actions[action.ident] = action
976657Snate@binkert.org
986657Snate@binkert.org    def addTransition(self, trans):
996657Snate@binkert.org        assert self.table is None
1006657Snate@binkert.org        self.transitions.append(trans)
1016657Snate@binkert.org
1026657Snate@binkert.org    def addInPort(self, var):
1036657Snate@binkert.org        self.in_ports.append(var)
1046657Snate@binkert.org
1056657Snate@binkert.org    def addFunc(self, func):
1066657Snate@binkert.org        # register func in the symbol table
1076657Snate@binkert.org        self.symtab.registerSym(str(func), func)
1086657Snate@binkert.org        self.functions.append(func)
1096657Snate@binkert.org
1106657Snate@binkert.org    def addObject(self, obj):
1116657Snate@binkert.org        self.objects.append(obj)
1126657Snate@binkert.org
1137839Snilay@cs.wisc.edu    def addType(self, type):
1147839Snilay@cs.wisc.edu        type_ident = '%s' % type.c_ident
1157839Snilay@cs.wisc.edu
1167839Snilay@cs.wisc.edu        if type_ident == "%s_TBE" %self.ident:
1177839Snilay@cs.wisc.edu            if self.TBEType != None:
1187839Snilay@cs.wisc.edu                self.error("Multiple Transaction Buffer types in a " \
1197839Snilay@cs.wisc.edu                           "single machine.");
1207839Snilay@cs.wisc.edu            self.TBEType = type
1217839Snilay@cs.wisc.edu
1227839Snilay@cs.wisc.edu        elif "interface" in type and "AbstractCacheEntry" == type["interface"]:
1237839Snilay@cs.wisc.edu            if self.EntryType != None:
1247839Snilay@cs.wisc.edu                self.error("Multiple AbstractCacheEntry types in a " \
1257839Snilay@cs.wisc.edu                           "single machine.");
1267839Snilay@cs.wisc.edu            self.EntryType = type
1277839Snilay@cs.wisc.edu
1286657Snate@binkert.org    # Needs to be called before accessing the table
1296657Snate@binkert.org    def buildTable(self):
1306657Snate@binkert.org        assert self.table is None
1316657Snate@binkert.org
1326657Snate@binkert.org        table = {}
1336657Snate@binkert.org
1346657Snate@binkert.org        for trans in self.transitions:
1356657Snate@binkert.org            # Track which actions we touch so we know if we use them
1366657Snate@binkert.org            # all -- really this should be done for all symbols as
1376657Snate@binkert.org            # part of the symbol table, then only trigger it for
1386657Snate@binkert.org            # Actions, States, Events, etc.
1396657Snate@binkert.org
1406657Snate@binkert.org            for action in trans.actions:
1416657Snate@binkert.org                action.used = True
1426657Snate@binkert.org
1436657Snate@binkert.org            index = (trans.state, trans.event)
1446657Snate@binkert.org            if index in table:
1456657Snate@binkert.org                table[index].warning("Duplicate transition: %s" % table[index])
1466657Snate@binkert.org                trans.error("Duplicate transition: %s" % trans)
1476657Snate@binkert.org            table[index] = trans
1486657Snate@binkert.org
1496657Snate@binkert.org        # Look at all actions to make sure we used them all
1506657Snate@binkert.org        for action in self.actions.itervalues():
1516657Snate@binkert.org            if not action.used:
1526657Snate@binkert.org                error_msg = "Unused action: %s" % action.ident
1536657Snate@binkert.org                if "desc" in action:
1546657Snate@binkert.org                    error_msg += ", "  + action.desc
1556657Snate@binkert.org                action.warning(error_msg)
1566657Snate@binkert.org        self.table = table
1576657Snate@binkert.org
1586657Snate@binkert.org    def writeCodeFiles(self, path):
1596877Ssteve.reinhardt@amd.com        self.printControllerPython(path)
1606657Snate@binkert.org        self.printControllerHH(path)
1616657Snate@binkert.org        self.printControllerCC(path)
1626657Snate@binkert.org        self.printCSwitch(path)
1636657Snate@binkert.org        self.printCWakeup(path)
1646657Snate@binkert.org        self.printProfilerCC(path)
1656657Snate@binkert.org        self.printProfilerHH(path)
1667542SBrad.Beckmann@amd.com        self.printProfileDumperCC(path)
1677542SBrad.Beckmann@amd.com        self.printProfileDumperHH(path)
1686657Snate@binkert.org
1696657Snate@binkert.org        for func in self.functions:
1706657Snate@binkert.org            func.writeCodeFiles(path)
1716657Snate@binkert.org
1726877Ssteve.reinhardt@amd.com    def printControllerPython(self, path):
1736999Snate@binkert.org        code = self.symtab.codeFormatter()
1746877Ssteve.reinhardt@amd.com        ident = self.ident
1756877Ssteve.reinhardt@amd.com        py_ident = "%s_Controller" % ident
1766877Ssteve.reinhardt@amd.com        c_ident = "%s_Controller" % self.ident
1776877Ssteve.reinhardt@amd.com        code('''
1786877Ssteve.reinhardt@amd.comfrom m5.params import *
1796877Ssteve.reinhardt@amd.comfrom m5.SimObject import SimObject
1806877Ssteve.reinhardt@amd.comfrom Controller import RubyController
1816877Ssteve.reinhardt@amd.com
1826877Ssteve.reinhardt@amd.comclass $py_ident(RubyController):
1836877Ssteve.reinhardt@amd.com    type = '$py_ident'
1846877Ssteve.reinhardt@amd.com''')
1856877Ssteve.reinhardt@amd.com        code.indent()
1866877Ssteve.reinhardt@amd.com        for param in self.config_parameters:
1876877Ssteve.reinhardt@amd.com            dflt_str = ''
1886877Ssteve.reinhardt@amd.com            if param.default is not None:
1896877Ssteve.reinhardt@amd.com                dflt_str = str(param.default) + ', '
1906882SBrad.Beckmann@amd.com            if python_class_map.has_key(param.type_ast.type.c_ident):
1916882SBrad.Beckmann@amd.com                python_type = python_class_map[param.type_ast.type.c_ident]
1926882SBrad.Beckmann@amd.com                code('${{param.name}} = Param.${{python_type}}(${dflt_str}"")')
1936882SBrad.Beckmann@amd.com            else:
1946882SBrad.Beckmann@amd.com                self.error("Unknown c++ to python class conversion for c++ " \
1956882SBrad.Beckmann@amd.com                           "type: '%s'. Please update the python_class_map " \
1966882SBrad.Beckmann@amd.com                           "in StateMachine.py", param.type_ast.type.c_ident)
1976877Ssteve.reinhardt@amd.com        code.dedent()
1986877Ssteve.reinhardt@amd.com        code.write(path, '%s.py' % py_ident)
1996877Ssteve.reinhardt@amd.com
2006877Ssteve.reinhardt@amd.com
2016657Snate@binkert.org    def printControllerHH(self, path):
2026657Snate@binkert.org        '''Output the method declarations for the class declaration'''
2036999Snate@binkert.org        code = self.symtab.codeFormatter()
2046657Snate@binkert.org        ident = self.ident
2056657Snate@binkert.org        c_ident = "%s_Controller" % self.ident
2066657Snate@binkert.org
2076657Snate@binkert.org        self.message_buffer_names = []
2086657Snate@binkert.org
2096657Snate@binkert.org        code('''
2107007Snate@binkert.org/** \\file $c_ident.hh
2116657Snate@binkert.org *
2126657Snate@binkert.org * Auto generated C++ code started by $__file__:$__line__
2136657Snate@binkert.org * Created by slicc definition of Module "${{self.short}}"
2146657Snate@binkert.org */
2156657Snate@binkert.org
2167007Snate@binkert.org#ifndef __${ident}_CONTROLLER_HH__
2177007Snate@binkert.org#define __${ident}_CONTROLLER_HH__
2186657Snate@binkert.org
2197002Snate@binkert.org#include <iostream>
2207002Snate@binkert.org#include <sstream>
2217002Snate@binkert.org#include <string>
2227002Snate@binkert.org
2236877Ssteve.reinhardt@amd.com#include "params/$c_ident.hh"
2246877Ssteve.reinhardt@amd.com
2256657Snate@binkert.org#include "mem/ruby/common/Global.hh"
2266657Snate@binkert.org#include "mem/ruby/common/Consumer.hh"
2276657Snate@binkert.org#include "mem/ruby/slicc_interface/AbstractController.hh"
2286657Snate@binkert.org#include "mem/protocol/TransitionResult.hh"
2296657Snate@binkert.org#include "mem/protocol/Types.hh"
2306657Snate@binkert.org#include "mem/protocol/${ident}_Profiler.hh"
2317542SBrad.Beckmann@amd.com#include "mem/protocol/${ident}_ProfileDumper.hh"
2326657Snate@binkert.org''')
2336657Snate@binkert.org
2346657Snate@binkert.org        seen_types = set()
2356657Snate@binkert.org        for var in self.objects:
2366793SBrad.Beckmann@amd.com            if var.type.ident not in seen_types and not var.type.isPrimitive:
2376657Snate@binkert.org                code('#include "mem/protocol/${{var.type.c_ident}}.hh"')
2386657Snate@binkert.org            seen_types.add(var.type.ident)
2396657Snate@binkert.org
2406657Snate@binkert.org        # for adding information to the protocol debug trace
2416657Snate@binkert.org        code('''
2427002Snate@binkert.orgextern std::stringstream ${ident}_transitionComment;
2436657Snate@binkert.org
2447007Snate@binkert.orgclass $c_ident : public AbstractController
2457007Snate@binkert.org{
2467007Snate@binkert.org// the coherence checker needs to call isBlockExclusive() and isBlockShared()
2477007Snate@binkert.org// making the Chip a friend class is an easy way to do this for now
2487007Snate@binkert.org
2496657Snate@binkert.orgpublic:
2506877Ssteve.reinhardt@amd.com    typedef ${c_ident}Params Params;
2516877Ssteve.reinhardt@amd.com    $c_ident(const Params *p);
2526657Snate@binkert.org    static int getNumControllers();
2536877Ssteve.reinhardt@amd.com    void init();
2546657Snate@binkert.org    MessageBuffer* getMandatoryQueue() const;
2556657Snate@binkert.org    const int & getVersion() const;
2567002Snate@binkert.org    const std::string toString() const;
2577002Snate@binkert.org    const std::string getName() const;
2586657Snate@binkert.org    const MachineType getMachineType() const;
2597567SBrad.Beckmann@amd.com    void stallBuffer(MessageBuffer* buf, Address addr);
2607567SBrad.Beckmann@amd.com    void wakeUpBuffers(Address addr);
2616881SBrad.Beckmann@amd.com    void initNetworkPtr(Network* net_ptr) { m_net_ptr = net_ptr; }
2627002Snate@binkert.org    void print(std::ostream& out) const;
2637002Snate@binkert.org    void printConfig(std::ostream& out) const;
2646657Snate@binkert.org    void wakeup();
2657002Snate@binkert.org    void printStats(std::ostream& out) const;
2666902SBrad.Beckmann@amd.com    void clearStats();
2676863Sdrh5@cs.wisc.edu    void blockOnQueue(Address addr, MessageBuffer* port);
2686863Sdrh5@cs.wisc.edu    void unblock(Address addr);
2697007Snate@binkert.org
2706657Snate@binkert.orgprivate:
2716657Snate@binkert.org''')
2726657Snate@binkert.org
2736657Snate@binkert.org        code.indent()
2746657Snate@binkert.org        # added by SS
2756657Snate@binkert.org        for param in self.config_parameters:
2766882SBrad.Beckmann@amd.com            if param.pointer:
2776882SBrad.Beckmann@amd.com                code('${{param.type_ast.type}}* m_${{param.ident}}_ptr;')
2786882SBrad.Beckmann@amd.com            else:
2796882SBrad.Beckmann@amd.com                code('${{param.type_ast.type}} m_${{param.ident}};')
2806657Snate@binkert.org
2816657Snate@binkert.org        code('''
2826657Snate@binkert.orgint m_number_of_TBEs;
2836657Snate@binkert.org
2847007Snate@binkert.orgTransitionResult doTransition(${ident}_Event event,
2857839Snilay@cs.wisc.edu''')
2867839Snilay@cs.wisc.edu
2877839Snilay@cs.wisc.edu        if self.EntryType != None:
2887839Snilay@cs.wisc.edu            code('''
2897839Snilay@cs.wisc.edu                              ${{self.EntryType.c_ident}}* m_cache_entry_ptr,
2907839Snilay@cs.wisc.edu''')
2917839Snilay@cs.wisc.edu        if self.TBEType != None:
2927839Snilay@cs.wisc.edu            code('''
2937839Snilay@cs.wisc.edu                              ${{self.TBEType.c_ident}}* m_tbe_ptr,
2947839Snilay@cs.wisc.edu''')
2957839Snilay@cs.wisc.edu
2967839Snilay@cs.wisc.edu        code('''
2977007Snate@binkert.org                              const Address& addr);
2987007Snate@binkert.org
2997007Snate@binkert.orgTransitionResult doTransitionWorker(${ident}_Event event,
3007007Snate@binkert.org                                    ${ident}_State state,
3017007Snate@binkert.org                                    ${ident}_State& next_state,
3027839Snilay@cs.wisc.edu''')
3037839Snilay@cs.wisc.edu
3047839Snilay@cs.wisc.edu        if self.TBEType != None:
3057839Snilay@cs.wisc.edu            code('''
3067839Snilay@cs.wisc.edu                                    ${{self.TBEType.c_ident}}*& m_tbe_ptr,
3077839Snilay@cs.wisc.edu''')
3087839Snilay@cs.wisc.edu        if self.EntryType != None:
3097839Snilay@cs.wisc.edu            code('''
3107839Snilay@cs.wisc.edu                                    ${{self.EntryType.c_ident}}*& m_cache_entry_ptr,
3117839Snilay@cs.wisc.edu''')
3127839Snilay@cs.wisc.edu
3137839Snilay@cs.wisc.edu        code('''
3147007Snate@binkert.org                                    const Address& addr);
3157007Snate@binkert.org
3167002Snate@binkert.orgstd::string m_name;
3176657Snate@binkert.orgint m_transitions_per_cycle;
3186657Snate@binkert.orgint m_buffer_size;
3196657Snate@binkert.orgint m_recycle_latency;
3207055Snate@binkert.orgstd::map<std::string, std::string> m_cfg;
3216657Snate@binkert.orgNodeID m_version;
3226657Snate@binkert.orgNetwork* m_net_ptr;
3236657Snate@binkert.orgMachineID m_machineID;
3246863Sdrh5@cs.wisc.edubool m_is_blocking;
3257055Snate@binkert.orgstd::map<Address, MessageBuffer*> m_block_map;
3267567SBrad.Beckmann@amd.comtypedef std::vector<MessageBuffer*> MsgVecType;
3277567SBrad.Beckmann@amd.comtypedef m5::hash_map< Address, MsgVecType* > WaitingBufType;
3287567SBrad.Beckmann@amd.comWaitingBufType m_waiting_buffers;
3297567SBrad.Beckmann@amd.comint m_max_in_port_rank;
3307567SBrad.Beckmann@amd.comint m_cur_in_port_rank;
3317542SBrad.Beckmann@amd.comstatic ${ident}_ProfileDumper s_profileDumper;
3327542SBrad.Beckmann@amd.com${ident}_Profiler m_profiler;
3336657Snate@binkert.orgstatic int m_num_controllers;
3347007Snate@binkert.org
3356657Snate@binkert.org// Internal functions
3366657Snate@binkert.org''')
3376657Snate@binkert.org
3386657Snate@binkert.org        for func in self.functions:
3396657Snate@binkert.org            proto = func.prototype
3406657Snate@binkert.org            if proto:
3416657Snate@binkert.org                code('$proto')
3426657Snate@binkert.org
3437839Snilay@cs.wisc.edu        if self.EntryType != None:
3447839Snilay@cs.wisc.edu            code('''
3457839Snilay@cs.wisc.edu
3467839Snilay@cs.wisc.edu// Set and Reset for cache_entry variable
3477839Snilay@cs.wisc.eduvoid set_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, AbstractCacheEntry* m_new_cache_entry);
3487839Snilay@cs.wisc.eduvoid unset_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr);
3497839Snilay@cs.wisc.edu''')
3507839Snilay@cs.wisc.edu
3517839Snilay@cs.wisc.edu        if self.TBEType != None:
3527839Snilay@cs.wisc.edu            code('''
3537839Snilay@cs.wisc.edu
3547839Snilay@cs.wisc.edu// Set and Reset for tbe variable
3557839Snilay@cs.wisc.eduvoid set_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr, ${ident}_TBE* m_new_tbe);
3567839Snilay@cs.wisc.eduvoid unset_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr);
3577839Snilay@cs.wisc.edu''')
3587839Snilay@cs.wisc.edu
3596657Snate@binkert.org        code('''
3606657Snate@binkert.org
3616657Snate@binkert.org// Actions
3626657Snate@binkert.org''')
3637839Snilay@cs.wisc.edu        if self.TBEType != None and self.EntryType != None:
3647839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
3657839Snilay@cs.wisc.edu                code('/** \\brief ${{action.desc}} */')
3667839Snilay@cs.wisc.edu                code('void ${{action.ident}}(${{self.TBEType.c_ident}}*& m_tbe_ptr, ${{self.EntryType.c_ident}}*& m_cache_entry_ptr, const Address& addr);')
3677839Snilay@cs.wisc.edu        elif self.TBEType != None:
3687839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
3697839Snilay@cs.wisc.edu                code('/** \\brief ${{action.desc}} */')
3707839Snilay@cs.wisc.edu                code('void ${{action.ident}}(${{self.TBEType.c_ident}}*& m_tbe_ptr, const Address& addr);')
3717839Snilay@cs.wisc.edu        elif self.EntryType != None:
3727839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
3737839Snilay@cs.wisc.edu                code('/** \\brief ${{action.desc}} */')
3747839Snilay@cs.wisc.edu                code('void ${{action.ident}}(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, const Address& addr);')
3757839Snilay@cs.wisc.edu        else:
3767839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
3777839Snilay@cs.wisc.edu                code('/** \\brief ${{action.desc}} */')
3787839Snilay@cs.wisc.edu                code('void ${{action.ident}}(const Address& addr);')
3796657Snate@binkert.org
3806657Snate@binkert.org        # the controller internal variables
3816657Snate@binkert.org        code('''
3826657Snate@binkert.org
3837007Snate@binkert.org// Objects
3846657Snate@binkert.org''')
3856657Snate@binkert.org        for var in self.objects:
3866657Snate@binkert.org            th = var.get("template_hack", "")
3876657Snate@binkert.org            code('${{var.type.c_ident}}$th* m_${{var.c_ident}}_ptr;')
3886657Snate@binkert.org
3896657Snate@binkert.org            if var.type.ident == "MessageBuffer":
3906657Snate@binkert.org                self.message_buffer_names.append("m_%s_ptr" % var.c_ident)
3916657Snate@binkert.org
3926657Snate@binkert.org        code.dedent()
3936657Snate@binkert.org        code('};')
3947007Snate@binkert.org        code('#endif // __${ident}_CONTROLLER_H__')
3956657Snate@binkert.org        code.write(path, '%s.hh' % c_ident)
3966657Snate@binkert.org
3976657Snate@binkert.org    def printControllerCC(self, path):
3986657Snate@binkert.org        '''Output the actions for performing the actions'''
3996657Snate@binkert.org
4006999Snate@binkert.org        code = self.symtab.codeFormatter()
4016657Snate@binkert.org        ident = self.ident
4026657Snate@binkert.org        c_ident = "%s_Controller" % self.ident
4036657Snate@binkert.org
4046657Snate@binkert.org        code('''
4057007Snate@binkert.org/** \\file $c_ident.cc
4066657Snate@binkert.org *
4076657Snate@binkert.org * Auto generated C++ code started by $__file__:$__line__
4086657Snate@binkert.org * Created by slicc definition of Module "${{self.short}}"
4096657Snate@binkert.org */
4106657Snate@binkert.org
4117832Snate@binkert.org#include <cassert>
4127002Snate@binkert.org#include <sstream>
4137002Snate@binkert.org#include <string>
4147002Snate@binkert.org
4157056Snate@binkert.org#include "base/cprintf.hh"
4166657Snate@binkert.org#include "mem/protocol/${ident}_Controller.hh"
4176657Snate@binkert.org#include "mem/protocol/${ident}_State.hh"
4186657Snate@binkert.org#include "mem/protocol/${ident}_Event.hh"
4196657Snate@binkert.org#include "mem/protocol/Types.hh"
4207056Snate@binkert.org#include "mem/ruby/common/Global.hh"
4217056Snate@binkert.org#include "mem/ruby/slicc_interface/RubySlicc_includes.hh"
4226657Snate@binkert.org#include "mem/ruby/system/System.hh"
4237002Snate@binkert.org
4247002Snate@binkert.orgusing namespace std;
4256657Snate@binkert.org''')
4266657Snate@binkert.org
4276657Snate@binkert.org        # include object classes
4286657Snate@binkert.org        seen_types = set()
4296657Snate@binkert.org        for var in self.objects:
4306793SBrad.Beckmann@amd.com            if var.type.ident not in seen_types and not var.type.isPrimitive:
4316657Snate@binkert.org                code('#include "mem/protocol/${{var.type.c_ident}}.hh"')
4326657Snate@binkert.org            seen_types.add(var.type.ident)
4336657Snate@binkert.org
4346657Snate@binkert.org        code('''
4356877Ssteve.reinhardt@amd.com$c_ident *
4366877Ssteve.reinhardt@amd.com${c_ident}Params::create()
4376877Ssteve.reinhardt@amd.com{
4386877Ssteve.reinhardt@amd.com    return new $c_ident(this);
4396877Ssteve.reinhardt@amd.com}
4406877Ssteve.reinhardt@amd.com
4416657Snate@binkert.orgint $c_ident::m_num_controllers = 0;
4427542SBrad.Beckmann@amd.com${ident}_ProfileDumper $c_ident::s_profileDumper;
4436657Snate@binkert.org
4447007Snate@binkert.org// for adding information to the protocol debug trace
4456657Snate@binkert.orgstringstream ${ident}_transitionComment;
4466657Snate@binkert.org#define APPEND_TRANSITION_COMMENT(str) (${ident}_transitionComment << str)
4477007Snate@binkert.org
4486657Snate@binkert.org/** \\brief constructor */
4496877Ssteve.reinhardt@amd.com$c_ident::$c_ident(const Params *p)
4506877Ssteve.reinhardt@amd.com    : AbstractController(p)
4516657Snate@binkert.org{
4526877Ssteve.reinhardt@amd.com    m_version = p->version;
4536877Ssteve.reinhardt@amd.com    m_transitions_per_cycle = p->transitions_per_cycle;
4546877Ssteve.reinhardt@amd.com    m_buffer_size = p->buffer_size;
4556877Ssteve.reinhardt@amd.com    m_recycle_latency = p->recycle_latency;
4566877Ssteve.reinhardt@amd.com    m_number_of_TBEs = p->number_of_TBEs;
4576969SBrad.Beckmann@amd.com    m_is_blocking = false;
4586657Snate@binkert.org''')
4597567SBrad.Beckmann@amd.com        #
4607567SBrad.Beckmann@amd.com        # max_port_rank is used to size vectors and thus should be one plus the
4617567SBrad.Beckmann@amd.com        # largest port rank
4627567SBrad.Beckmann@amd.com        #
4637567SBrad.Beckmann@amd.com        max_port_rank = self.in_ports[0].pairs["max_port_rank"] + 1
4647567SBrad.Beckmann@amd.com        code('    m_max_in_port_rank = $max_port_rank;')
4656657Snate@binkert.org        code.indent()
4666882SBrad.Beckmann@amd.com
4676882SBrad.Beckmann@amd.com        #
4686882SBrad.Beckmann@amd.com        # After initializing the universal machine parameters, initialize the
4696882SBrad.Beckmann@amd.com        # this machines config parameters.  Also detemine if these configuration
4706882SBrad.Beckmann@amd.com        # params include a sequencer.  This information will be used later for
4716882SBrad.Beckmann@amd.com        # contecting the sequencer back to the L1 cache controller.
4726882SBrad.Beckmann@amd.com        #
4736882SBrad.Beckmann@amd.com        contains_sequencer = False
4746877Ssteve.reinhardt@amd.com        for param in self.config_parameters:
4756888SBrad.Beckmann@amd.com            if param.name == "sequencer" or param.name == "dma_sequencer":
4766882SBrad.Beckmann@amd.com                contains_sequencer = True
4776882SBrad.Beckmann@amd.com            if param.pointer:
4786882SBrad.Beckmann@amd.com                code('m_${{param.name}}_ptr = p->${{param.name}};')
4796882SBrad.Beckmann@amd.com            else:
4806882SBrad.Beckmann@amd.com                code('m_${{param.name}} = p->${{param.name}};')
4816882SBrad.Beckmann@amd.com
4826882SBrad.Beckmann@amd.com        #
4836882SBrad.Beckmann@amd.com        # For the l1 cache controller, add the special atomic support which
4846882SBrad.Beckmann@amd.com        # includes passing the sequencer a pointer to the controller.
4856882SBrad.Beckmann@amd.com        #
4866882SBrad.Beckmann@amd.com        if self.ident == "L1Cache":
4876882SBrad.Beckmann@amd.com            if not contains_sequencer:
4886882SBrad.Beckmann@amd.com                self.error("The L1Cache controller must include the sequencer " \
4896882SBrad.Beckmann@amd.com                           "configuration parameter")
4906882SBrad.Beckmann@amd.com
4916882SBrad.Beckmann@amd.com            code('''
4926882SBrad.Beckmann@amd.comm_sequencer_ptr->setController(this);
4936882SBrad.Beckmann@amd.com''')
4946888SBrad.Beckmann@amd.com        #
4956888SBrad.Beckmann@amd.com        # For the DMA controller, pass the sequencer a pointer to the
4966888SBrad.Beckmann@amd.com        # controller.
4976888SBrad.Beckmann@amd.com        #
4986888SBrad.Beckmann@amd.com        if self.ident == "DMA":
4996888SBrad.Beckmann@amd.com            if not contains_sequencer:
5006888SBrad.Beckmann@amd.com                self.error("The DMA controller must include the sequencer " \
5016888SBrad.Beckmann@amd.com                           "configuration parameter")
5026657Snate@binkert.org
5036888SBrad.Beckmann@amd.com            code('''
5046888SBrad.Beckmann@amd.comm_dma_sequencer_ptr->setController(this);
5056888SBrad.Beckmann@amd.com''')
5066888SBrad.Beckmann@amd.com
5076657Snate@binkert.org        code('m_num_controllers++;')
5086657Snate@binkert.org        for var in self.objects:
5096657Snate@binkert.org            if var.ident.find("mandatoryQueue") >= 0:
5106657Snate@binkert.org                code('m_${{var.c_ident}}_ptr = new ${{var.type.c_ident}}();')
5116657Snate@binkert.org
5126657Snate@binkert.org        code.dedent()
5136657Snate@binkert.org        code('''
5146657Snate@binkert.org}
5156657Snate@binkert.org
5167007Snate@binkert.orgvoid
5177007Snate@binkert.org$c_ident::init()
5186657Snate@binkert.org{
5197007Snate@binkert.org    MachineType machine_type;
5207007Snate@binkert.org    int base;
5217007Snate@binkert.org
5226657Snate@binkert.org    m_machineID.type = MachineType_${ident};
5236657Snate@binkert.org    m_machineID.num = m_version;
5246657Snate@binkert.org
5257007Snate@binkert.org    // initialize objects
5267542SBrad.Beckmann@amd.com    m_profiler.setVersion(m_version);
5277542SBrad.Beckmann@amd.com    s_profileDumper.registerProfiler(&m_profiler);
5287007Snate@binkert.org
5296657Snate@binkert.org''')
5306657Snate@binkert.org
5316657Snate@binkert.org        code.indent()
5326657Snate@binkert.org        for var in self.objects:
5336657Snate@binkert.org            vtype = var.type
5346657Snate@binkert.org            vid = "m_%s_ptr" % var.c_ident
5356657Snate@binkert.org            if "network" not in var:
5366657Snate@binkert.org                # Not a network port object
5376657Snate@binkert.org                if "primitive" in vtype:
5386657Snate@binkert.org                    code('$vid = new ${{vtype.c_ident}};')
5396657Snate@binkert.org                    if "default" in var:
5406657Snate@binkert.org                        code('(*$vid) = ${{var["default"]}};')
5416657Snate@binkert.org                else:
5426657Snate@binkert.org                    # Normal Object
5436657Snate@binkert.org                    # added by SS
5446657Snate@binkert.org                    if "factory" in var:
5456657Snate@binkert.org                        code('$vid = ${{var["factory"]}};')
5466657Snate@binkert.org                    elif var.ident.find("mandatoryQueue") < 0:
5476657Snate@binkert.org                        th = var.get("template_hack", "")
5486657Snate@binkert.org                        expr = "%s  = new %s%s" % (vid, vtype.c_ident, th)
5496657Snate@binkert.org
5506657Snate@binkert.org                        args = ""
5516657Snate@binkert.org                        if "non_obj" not in vtype and not vtype.isEnumeration:
5526657Snate@binkert.org                            if expr.find("TBETable") >= 0:
5536657Snate@binkert.org                                args = "m_number_of_TBEs"
5546657Snate@binkert.org                            else:
5556657Snate@binkert.org                                args = var.get("constructor_hack", "")
5566657Snate@binkert.org
5577007Snate@binkert.org                        code('$expr($args);')
5586657Snate@binkert.org
5596657Snate@binkert.org                    code('assert($vid != NULL);')
5606657Snate@binkert.org
5616657Snate@binkert.org                    if "default" in var:
5627007Snate@binkert.org                        code('*$vid = ${{var["default"]}}; // Object default')
5636657Snate@binkert.org                    elif "default" in vtype:
5647007Snate@binkert.org                        comment = "Type %s default" % vtype.ident
5657007Snate@binkert.org                        code('*$vid = ${{vtype["default"]}}; // $comment')
5666657Snate@binkert.org
5676657Snate@binkert.org                    # Set ordering
5686657Snate@binkert.org                    if "ordered" in var and "trigger_queue" not in var:
5696657Snate@binkert.org                        # A buffer
5706657Snate@binkert.org                        code('$vid->setOrdering(${{var["ordered"]}});')
5716657Snate@binkert.org
5726657Snate@binkert.org                    # Set randomization
5736657Snate@binkert.org                    if "random" in var:
5746657Snate@binkert.org                        # A buffer
5756657Snate@binkert.org                        code('$vid->setRandomization(${{var["random"]}});')
5766657Snate@binkert.org
5776657Snate@binkert.org                    # Set Priority
5786657Snate@binkert.org                    if vtype.isBuffer and \
5796657Snate@binkert.org                           "rank" in var and "trigger_queue" not in var:
5806657Snate@binkert.org                        code('$vid->setPriority(${{var["rank"]}});')
5817566SBrad.Beckmann@amd.com
5826657Snate@binkert.org            else:
5836657Snate@binkert.org                # Network port object
5846657Snate@binkert.org                network = var["network"]
5856657Snate@binkert.org                ordered =  var["ordered"]
5866657Snate@binkert.org                vnet = var["virtual_network"]
5876657Snate@binkert.org
5886657Snate@binkert.org                assert var.machine is not None
5896657Snate@binkert.org                code('''
5907007Snate@binkert.orgmachine_type = string_to_MachineType("${{var.machine.ident}}");
5917007Snate@binkert.orgbase = MachineType_base_number(machine_type);
5927007Snate@binkert.org$vid = m_net_ptr->get${network}NetQueue(m_version + base, $ordered, $vnet);
5936657Snate@binkert.org''')
5946657Snate@binkert.org
5956657Snate@binkert.org                code('assert($vid != NULL);')
5966657Snate@binkert.org
5976657Snate@binkert.org                # Set ordering
5986657Snate@binkert.org                if "ordered" in var:
5996657Snate@binkert.org                    # A buffer
6006657Snate@binkert.org                    code('$vid->setOrdering(${{var["ordered"]}});')
6016657Snate@binkert.org
6026657Snate@binkert.org                # Set randomization
6036657Snate@binkert.org                if "random" in var:
6046657Snate@binkert.org                    # A buffer
6056657Snate@binkert.org                    code('$vid->setRandomization(${{var["random"]}})')
6066657Snate@binkert.org
6076657Snate@binkert.org                # Set Priority
6086657Snate@binkert.org                if "rank" in var:
6096657Snate@binkert.org                    code('$vid->setPriority(${{var["rank"]}})')
6106657Snate@binkert.org
6116657Snate@binkert.org                # Set buffer size
6126657Snate@binkert.org                if vtype.isBuffer:
6136657Snate@binkert.org                    code('''
6146657Snate@binkert.orgif (m_buffer_size > 0) {
6157454Snate@binkert.org    $vid->resize(m_buffer_size);
6166657Snate@binkert.org}
6176657Snate@binkert.org''')
6186657Snate@binkert.org
6196657Snate@binkert.org                # set description (may be overriden later by port def)
6207007Snate@binkert.org                code('''
6217056Snate@binkert.org$vid->setDescription("[Version " + to_string(m_version) + ", ${ident}, name=${{var.c_ident}}]");
6227007Snate@binkert.org
6237007Snate@binkert.org''')
6246657Snate@binkert.org
6257566SBrad.Beckmann@amd.com            if vtype.isBuffer:
6267566SBrad.Beckmann@amd.com                if "recycle_latency" in var:
6277566SBrad.Beckmann@amd.com                    code('$vid->setRecycleLatency(${{var["recycle_latency"]}});')
6287566SBrad.Beckmann@amd.com                else:
6297566SBrad.Beckmann@amd.com                    code('$vid->setRecycleLatency(m_recycle_latency);')
6307566SBrad.Beckmann@amd.com
6317566SBrad.Beckmann@amd.com
6326657Snate@binkert.org        # Set the queue consumers
6337672Snate@binkert.org        code()
6346657Snate@binkert.org        for port in self.in_ports:
6356657Snate@binkert.org            code('${{port.code}}.setConsumer(this);')
6366657Snate@binkert.org
6376657Snate@binkert.org        # Set the queue descriptions
6387672Snate@binkert.org        code()
6396657Snate@binkert.org        for port in self.in_ports:
6407056Snate@binkert.org            code('${{port.code}}.setDescription("[Version " + to_string(m_version) + ", $ident, $port]");')
6416657Snate@binkert.org
6426657Snate@binkert.org        # Initialize the transition profiling
6437672Snate@binkert.org        code()
6446657Snate@binkert.org        for trans in self.transitions:
6456657Snate@binkert.org            # Figure out if we stall
6466657Snate@binkert.org            stall = False
6476657Snate@binkert.org            for action in trans.actions:
6486657Snate@binkert.org                if action.ident == "z_stall":
6496657Snate@binkert.org                    stall = True
6506657Snate@binkert.org
6516657Snate@binkert.org            # Only possible if it is not a 'z' case
6526657Snate@binkert.org            if not stall:
6536657Snate@binkert.org                state = "%s_State_%s" % (self.ident, trans.state.ident)
6546657Snate@binkert.org                event = "%s_Event_%s" % (self.ident, trans.event.ident)
6557542SBrad.Beckmann@amd.com                code('m_profiler.possibleTransition($state, $event);')
6566657Snate@binkert.org
6576657Snate@binkert.org        code.dedent()
6586657Snate@binkert.org        code('}')
6596657Snate@binkert.org
6606657Snate@binkert.org        has_mandatory_q = False
6616657Snate@binkert.org        for port in self.in_ports:
6626657Snate@binkert.org            if port.code.find("mandatoryQueue_ptr") >= 0:
6636657Snate@binkert.org                has_mandatory_q = True
6646657Snate@binkert.org
6656657Snate@binkert.org        if has_mandatory_q:
6666657Snate@binkert.org            mq_ident = "m_%s_mandatoryQueue_ptr" % self.ident
6676657Snate@binkert.org        else:
6686657Snate@binkert.org            mq_ident = "NULL"
6696657Snate@binkert.org
6706657Snate@binkert.org        code('''
6717007Snate@binkert.orgint
6727007Snate@binkert.org$c_ident::getNumControllers()
6737007Snate@binkert.org{
6746657Snate@binkert.org    return m_num_controllers;
6756657Snate@binkert.org}
6766657Snate@binkert.org
6777007Snate@binkert.orgMessageBuffer*
6787007Snate@binkert.org$c_ident::getMandatoryQueue() const
6797007Snate@binkert.org{
6806657Snate@binkert.org    return $mq_ident;
6816657Snate@binkert.org}
6826657Snate@binkert.org
6837007Snate@binkert.orgconst int &
6847007Snate@binkert.org$c_ident::getVersion() const
6857007Snate@binkert.org{
6866657Snate@binkert.org    return m_version;
6876657Snate@binkert.org}
6886657Snate@binkert.org
6897007Snate@binkert.orgconst string
6907007Snate@binkert.org$c_ident::toString() const
6917007Snate@binkert.org{
6926657Snate@binkert.org    return "$c_ident";
6936657Snate@binkert.org}
6946657Snate@binkert.org
6957007Snate@binkert.orgconst string
6967007Snate@binkert.org$c_ident::getName() const
6977007Snate@binkert.org{
6986657Snate@binkert.org    return m_name;
6996657Snate@binkert.org}
7007007Snate@binkert.org
7017007Snate@binkert.orgconst MachineType
7027007Snate@binkert.org$c_ident::getMachineType() const
7037007Snate@binkert.org{
7046657Snate@binkert.org    return MachineType_${ident};
7056657Snate@binkert.org}
7066657Snate@binkert.org
7077007Snate@binkert.orgvoid
7087567SBrad.Beckmann@amd.com$c_ident::stallBuffer(MessageBuffer* buf, Address addr)
7097567SBrad.Beckmann@amd.com{
7107567SBrad.Beckmann@amd.com    if (m_waiting_buffers.count(addr) == 0) {
7117567SBrad.Beckmann@amd.com        MsgVecType* msgVec = new MsgVecType;
7127567SBrad.Beckmann@amd.com        msgVec->resize(m_max_in_port_rank, NULL);
7137567SBrad.Beckmann@amd.com        m_waiting_buffers[addr] = msgVec;
7147567SBrad.Beckmann@amd.com    }
7157567SBrad.Beckmann@amd.com    (*(m_waiting_buffers[addr]))[m_cur_in_port_rank] = buf;
7167567SBrad.Beckmann@amd.com}
7177567SBrad.Beckmann@amd.com
7187567SBrad.Beckmann@amd.comvoid
7197567SBrad.Beckmann@amd.com$c_ident::wakeUpBuffers(Address addr)
7207567SBrad.Beckmann@amd.com{
7217567SBrad.Beckmann@amd.com    //
7227567SBrad.Beckmann@amd.com    // Wake up all possible lower rank (i.e. lower priority) buffers that could
7237567SBrad.Beckmann@amd.com    // be waiting on this message.
7247567SBrad.Beckmann@amd.com    //
7257567SBrad.Beckmann@amd.com    for (int in_port_rank = m_cur_in_port_rank - 1;
7267567SBrad.Beckmann@amd.com         in_port_rank >= 0;
7277567SBrad.Beckmann@amd.com         in_port_rank--) {
7287567SBrad.Beckmann@amd.com        if ((*(m_waiting_buffers[addr]))[in_port_rank] != NULL) {
7297567SBrad.Beckmann@amd.com            (*(m_waiting_buffers[addr]))[in_port_rank]->reanalyzeMessages(addr);
7307567SBrad.Beckmann@amd.com        }
7317567SBrad.Beckmann@amd.com    }
7327567SBrad.Beckmann@amd.com    delete m_waiting_buffers[addr];
7337567SBrad.Beckmann@amd.com    m_waiting_buffers.erase(addr);
7347567SBrad.Beckmann@amd.com}
7357567SBrad.Beckmann@amd.com
7367567SBrad.Beckmann@amd.comvoid
7377007Snate@binkert.org$c_ident::blockOnQueue(Address addr, MessageBuffer* port)
7387007Snate@binkert.org{
7396863Sdrh5@cs.wisc.edu    m_is_blocking = true;
7406863Sdrh5@cs.wisc.edu    m_block_map[addr] = port;
7416863Sdrh5@cs.wisc.edu}
7427007Snate@binkert.org
7437007Snate@binkert.orgvoid
7447007Snate@binkert.org$c_ident::unblock(Address addr)
7457007Snate@binkert.org{
7466863Sdrh5@cs.wisc.edu    m_block_map.erase(addr);
7476863Sdrh5@cs.wisc.edu    if (m_block_map.size() == 0) {
7486863Sdrh5@cs.wisc.edu       m_is_blocking = false;
7496863Sdrh5@cs.wisc.edu    }
7506863Sdrh5@cs.wisc.edu}
7516863Sdrh5@cs.wisc.edu
7527007Snate@binkert.orgvoid
7537007Snate@binkert.org$c_ident::print(ostream& out) const
7547007Snate@binkert.org{
7557007Snate@binkert.org    out << "[$c_ident " << m_version << "]";
7567007Snate@binkert.org}
7576657Snate@binkert.org
7587007Snate@binkert.orgvoid
7597007Snate@binkert.org$c_ident::printConfig(ostream& out) const
7607007Snate@binkert.org{
7616657Snate@binkert.org    out << "$c_ident config: " << m_name << endl;
7626657Snate@binkert.org    out << "  version: " << m_version << endl;
7637007Snate@binkert.org    map<string, string>::const_iterator it;
7647007Snate@binkert.org    for (it = m_cfg.begin(); it != m_cfg.end(); it++)
7657007Snate@binkert.org        out << "  " << it->first << ": " << it->second << endl;
7666657Snate@binkert.org}
7676657Snate@binkert.org
7687007Snate@binkert.orgvoid
7697007Snate@binkert.org$c_ident::printStats(ostream& out) const
7707007Snate@binkert.org{
7716902SBrad.Beckmann@amd.com''')
7726902SBrad.Beckmann@amd.com        #
7736902SBrad.Beckmann@amd.com        # Cache and Memory Controllers have specific profilers associated with
7746902SBrad.Beckmann@amd.com        # them.  Print out these stats before dumping state transition stats.
7756902SBrad.Beckmann@amd.com        #
7766902SBrad.Beckmann@amd.com        for param in self.config_parameters:
7776902SBrad.Beckmann@amd.com            if param.type_ast.type.ident == "CacheMemory" or \
7787025SBrad.Beckmann@amd.com               param.type_ast.type.ident == "DirectoryMemory" or \
7796902SBrad.Beckmann@amd.com                   param.type_ast.type.ident == "MemoryControl":
7806902SBrad.Beckmann@amd.com                assert(param.pointer)
7816902SBrad.Beckmann@amd.com                code('    m_${{param.ident}}_ptr->printStats(out);')
7826902SBrad.Beckmann@amd.com
7836902SBrad.Beckmann@amd.com        code('''
7847542SBrad.Beckmann@amd.com    if (m_version == 0) {
7857542SBrad.Beckmann@amd.com        s_profileDumper.dumpStats(out);
7867542SBrad.Beckmann@amd.com    }
7876902SBrad.Beckmann@amd.com}
7886902SBrad.Beckmann@amd.com
7896902SBrad.Beckmann@amd.comvoid $c_ident::clearStats() {
7906902SBrad.Beckmann@amd.com''')
7916902SBrad.Beckmann@amd.com        #
7926902SBrad.Beckmann@amd.com        # Cache and Memory Controllers have specific profilers associated with
7936902SBrad.Beckmann@amd.com        # them.  These stats must be cleared too.
7946902SBrad.Beckmann@amd.com        #
7956902SBrad.Beckmann@amd.com        for param in self.config_parameters:
7966902SBrad.Beckmann@amd.com            if param.type_ast.type.ident == "CacheMemory" or \
7976902SBrad.Beckmann@amd.com                   param.type_ast.type.ident == "MemoryControl":
7986902SBrad.Beckmann@amd.com                assert(param.pointer)
7996902SBrad.Beckmann@amd.com                code('    m_${{param.ident}}_ptr->clearStats();')
8006902SBrad.Beckmann@amd.com
8016902SBrad.Beckmann@amd.com        code('''
8027542SBrad.Beckmann@amd.com    m_profiler.clearStats();
8036902SBrad.Beckmann@amd.com}
8047839Snilay@cs.wisc.edu''')
8057839Snilay@cs.wisc.edu
8067839Snilay@cs.wisc.edu        if self.EntryType != None:
8077839Snilay@cs.wisc.edu            code('''
8087839Snilay@cs.wisc.edu
8097839Snilay@cs.wisc.edu// Set and Reset for cache_entry variable
8107839Snilay@cs.wisc.eduvoid
8117839Snilay@cs.wisc.edu$c_ident::set_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, AbstractCacheEntry* m_new_cache_entry)
8127839Snilay@cs.wisc.edu{
8137839Snilay@cs.wisc.edu  m_cache_entry_ptr = (${{self.EntryType.c_ident}}*)m_new_cache_entry;
8147839Snilay@cs.wisc.edu}
8157839Snilay@cs.wisc.edu
8167839Snilay@cs.wisc.eduvoid
8177839Snilay@cs.wisc.edu$c_ident::unset_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr)
8187839Snilay@cs.wisc.edu{
8197839Snilay@cs.wisc.edu  m_cache_entry_ptr = 0;
8207839Snilay@cs.wisc.edu}
8217839Snilay@cs.wisc.edu''')
8227839Snilay@cs.wisc.edu
8237839Snilay@cs.wisc.edu        if self.TBEType != None:
8247839Snilay@cs.wisc.edu            code('''
8257839Snilay@cs.wisc.edu
8267839Snilay@cs.wisc.edu// Set and Reset for tbe variable
8277839Snilay@cs.wisc.eduvoid
8287839Snilay@cs.wisc.edu$c_ident::set_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr, ${{self.TBEType.c_ident}}* m_new_tbe)
8297839Snilay@cs.wisc.edu{
8307839Snilay@cs.wisc.edu  m_tbe_ptr = m_new_tbe;
8317839Snilay@cs.wisc.edu}
8327839Snilay@cs.wisc.edu
8337839Snilay@cs.wisc.eduvoid
8347839Snilay@cs.wisc.edu$c_ident::unset_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr)
8357839Snilay@cs.wisc.edu{
8367839Snilay@cs.wisc.edu  m_tbe_ptr = NULL;
8377839Snilay@cs.wisc.edu}
8387839Snilay@cs.wisc.edu''')
8397839Snilay@cs.wisc.edu
8407839Snilay@cs.wisc.edu        code('''
8416902SBrad.Beckmann@amd.com
8426657Snate@binkert.org// Actions
8436657Snate@binkert.org''')
8447839Snilay@cs.wisc.edu        if self.TBEType != None and self.EntryType != None:
8457839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
8467839Snilay@cs.wisc.edu                if "c_code" not in action:
8477839Snilay@cs.wisc.edu                 continue
8486657Snate@binkert.org
8497839Snilay@cs.wisc.edu                code('''
8507839Snilay@cs.wisc.edu/** \\brief ${{action.desc}} */
8517839Snilay@cs.wisc.eduvoid
8527839Snilay@cs.wisc.edu$c_ident::${{action.ident}}(${{self.TBEType.c_ident}}*& m_tbe_ptr, ${{self.EntryType.c_ident}}*& m_cache_entry_ptr, const Address& addr)
8537839Snilay@cs.wisc.edu{
8547839Snilay@cs.wisc.edu    DPRINTF(RubyGenerated, "executing\\n");
8557839Snilay@cs.wisc.edu    ${{action["c_code"]}}
8567839Snilay@cs.wisc.edu}
8576657Snate@binkert.org
8587839Snilay@cs.wisc.edu''')
8597839Snilay@cs.wisc.edu        elif self.TBEType != None:
8607839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
8617839Snilay@cs.wisc.edu                if "c_code" not in action:
8627839Snilay@cs.wisc.edu                 continue
8637839Snilay@cs.wisc.edu
8647839Snilay@cs.wisc.edu                code('''
8657839Snilay@cs.wisc.edu/** \\brief ${{action.desc}} */
8667839Snilay@cs.wisc.eduvoid
8677839Snilay@cs.wisc.edu$c_ident::${{action.ident}}(${{self.TBEType.c_ident}}*& m_tbe_ptr, const Address& addr)
8687839Snilay@cs.wisc.edu{
8697839Snilay@cs.wisc.edu    DPRINTF(RubyGenerated, "executing\\n");
8707839Snilay@cs.wisc.edu    ${{action["c_code"]}}
8717839Snilay@cs.wisc.edu}
8727839Snilay@cs.wisc.edu
8737839Snilay@cs.wisc.edu''')
8747839Snilay@cs.wisc.edu        elif self.EntryType != None:
8757839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
8767839Snilay@cs.wisc.edu                if "c_code" not in action:
8777839Snilay@cs.wisc.edu                 continue
8787839Snilay@cs.wisc.edu
8797839Snilay@cs.wisc.edu                code('''
8807839Snilay@cs.wisc.edu/** \\brief ${{action.desc}} */
8817839Snilay@cs.wisc.eduvoid
8827839Snilay@cs.wisc.edu$c_ident::${{action.ident}}(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, const Address& addr)
8837839Snilay@cs.wisc.edu{
8847839Snilay@cs.wisc.edu    DPRINTF(RubyGenerated, "executing\\n");
8857839Snilay@cs.wisc.edu    ${{action["c_code"]}}
8867839Snilay@cs.wisc.edu}
8877839Snilay@cs.wisc.edu
8887839Snilay@cs.wisc.edu''')
8897839Snilay@cs.wisc.edu        else:
8907839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
8917839Snilay@cs.wisc.edu                if "c_code" not in action:
8927839Snilay@cs.wisc.edu                 continue
8937839Snilay@cs.wisc.edu
8947839Snilay@cs.wisc.edu                code('''
8956657Snate@binkert.org/** \\brief ${{action.desc}} */
8967007Snate@binkert.orgvoid
8977007Snate@binkert.org$c_ident::${{action.ident}}(const Address& addr)
8986657Snate@binkert.org{
8997780Snilay@cs.wisc.edu    DPRINTF(RubyGenerated, "executing\\n");
9006657Snate@binkert.org    ${{action["c_code"]}}
9016657Snate@binkert.org}
9026657Snate@binkert.org
9036657Snate@binkert.org''')
9046657Snate@binkert.org        code.write(path, "%s.cc" % c_ident)
9056657Snate@binkert.org
9066657Snate@binkert.org    def printCWakeup(self, path):
9076657Snate@binkert.org        '''Output the wakeup loop for the events'''
9086657Snate@binkert.org
9096999Snate@binkert.org        code = self.symtab.codeFormatter()
9106657Snate@binkert.org        ident = self.ident
9116657Snate@binkert.org
9126657Snate@binkert.org        code('''
9136657Snate@binkert.org// Auto generated C++ code started by $__file__:$__line__
9146657Snate@binkert.org// ${ident}: ${{self.short}}
9156657Snate@binkert.org
9167832Snate@binkert.org#include <cassert>
9177832Snate@binkert.org
9187007Snate@binkert.org#include "base/misc.hh"
9196657Snate@binkert.org#include "mem/ruby/common/Global.hh"
9206657Snate@binkert.org#include "mem/ruby/slicc_interface/RubySlicc_includes.hh"
9216657Snate@binkert.org#include "mem/protocol/${ident}_Controller.hh"
9226657Snate@binkert.org#include "mem/protocol/${ident}_State.hh"
9236657Snate@binkert.org#include "mem/protocol/${ident}_Event.hh"
9246657Snate@binkert.org#include "mem/protocol/Types.hh"
9256657Snate@binkert.org#include "mem/ruby/system/System.hh"
9266657Snate@binkert.org
9277055Snate@binkert.orgusing namespace std;
9287055Snate@binkert.org
9297007Snate@binkert.orgvoid
9307007Snate@binkert.org${ident}_Controller::wakeup()
9316657Snate@binkert.org{
9326657Snate@binkert.org    int counter = 0;
9336657Snate@binkert.org    while (true) {
9346657Snate@binkert.org        // Some cases will put us into an infinite loop without this limit
9356657Snate@binkert.org        assert(counter <= m_transitions_per_cycle);
9366657Snate@binkert.org        if (counter == m_transitions_per_cycle) {
9377007Snate@binkert.org            // Count how often we are fully utilized
9387007Snate@binkert.org            g_system_ptr->getProfiler()->controllerBusy(m_machineID);
9397007Snate@binkert.org
9407007Snate@binkert.org            // Wakeup in another cycle and try again
9417007Snate@binkert.org            g_eventQueue_ptr->scheduleEvent(this, 1);
9426657Snate@binkert.org            break;
9436657Snate@binkert.org        }
9446657Snate@binkert.org''')
9456657Snate@binkert.org
9466657Snate@binkert.org        code.indent()
9476657Snate@binkert.org        code.indent()
9486657Snate@binkert.org
9496657Snate@binkert.org        # InPorts
9506657Snate@binkert.org        #
9516657Snate@binkert.org        for port in self.in_ports:
9526657Snate@binkert.org            code.indent()
9536657Snate@binkert.org            code('// ${ident}InPort $port')
9547567SBrad.Beckmann@amd.com            if port.pairs.has_key("rank"):
9557567SBrad.Beckmann@amd.com                code('m_cur_in_port_rank = ${{port.pairs["rank"]}};')
9567567SBrad.Beckmann@amd.com            else:
9577567SBrad.Beckmann@amd.com                code('m_cur_in_port_rank = 0;')
9586657Snate@binkert.org            code('${{port["c_code_in_port"]}}')
9596657Snate@binkert.org            code.dedent()
9606657Snate@binkert.org
9616657Snate@binkert.org            code('')
9626657Snate@binkert.org
9636657Snate@binkert.org        code.dedent()
9646657Snate@binkert.org        code.dedent()
9656657Snate@binkert.org        code('''
9666657Snate@binkert.org        break;  // If we got this far, we have nothing left todo
9676657Snate@binkert.org    }
9687007Snate@binkert.org    // g_eventQueue_ptr->scheduleEvent(this, 1);
9696657Snate@binkert.org}
9706657Snate@binkert.org''')
9716657Snate@binkert.org
9726657Snate@binkert.org        code.write(path, "%s_Wakeup.cc" % self.ident)
9736657Snate@binkert.org
9746657Snate@binkert.org    def printCSwitch(self, path):
9756657Snate@binkert.org        '''Output switch statement for transition table'''
9766657Snate@binkert.org
9776999Snate@binkert.org        code = self.symtab.codeFormatter()
9786657Snate@binkert.org        ident = self.ident
9796657Snate@binkert.org
9806657Snate@binkert.org        code('''
9816657Snate@binkert.org// Auto generated C++ code started by $__file__:$__line__
9826657Snate@binkert.org// ${ident}: ${{self.short}}
9836657Snate@binkert.org
9847832Snate@binkert.org#include <cassert>
9857832Snate@binkert.org
9867805Snilay@cs.wisc.edu#include "base/misc.hh"
9877832Snate@binkert.org#include "base/trace.hh"
9886657Snate@binkert.org#include "mem/ruby/common/Global.hh"
9896657Snate@binkert.org#include "mem/protocol/${ident}_Controller.hh"
9906657Snate@binkert.org#include "mem/protocol/${ident}_State.hh"
9916657Snate@binkert.org#include "mem/protocol/${ident}_Event.hh"
9926657Snate@binkert.org#include "mem/protocol/Types.hh"
9936657Snate@binkert.org#include "mem/ruby/system/System.hh"
9946657Snate@binkert.org
9956657Snate@binkert.org#define HASH_FUN(state, event)  ((int(state)*${ident}_Event_NUM)+int(event))
9966657Snate@binkert.org
9976657Snate@binkert.org#define GET_TRANSITION_COMMENT() (${ident}_transitionComment.str())
9986657Snate@binkert.org#define CLEAR_TRANSITION_COMMENT() (${ident}_transitionComment.str(""))
9996657Snate@binkert.org
10007007Snate@binkert.orgTransitionResult
10017007Snate@binkert.org${ident}_Controller::doTransition(${ident}_Event event,
10027839Snilay@cs.wisc.edu''')
10037839Snilay@cs.wisc.edu        if self.EntryType != None:
10047839Snilay@cs.wisc.edu            code('''
10057839Snilay@cs.wisc.edu                                  ${{self.EntryType.c_ident}}* m_cache_entry_ptr,
10067839Snilay@cs.wisc.edu''')
10077839Snilay@cs.wisc.edu        if self.TBEType != None:
10087839Snilay@cs.wisc.edu            code('''
10097839Snilay@cs.wisc.edu                                  ${{self.TBEType.c_ident}}* m_tbe_ptr,
10107839Snilay@cs.wisc.edu''')
10117839Snilay@cs.wisc.edu        code('''
10127007Snate@binkert.org                                  const Address &addr)
10136657Snate@binkert.org{
10147839Snilay@cs.wisc.edu''')
10157839Snilay@cs.wisc.edu        if self.TBEType != None and self.EntryType != None:
10167839Snilay@cs.wisc.edu            code('${ident}_State state = ${ident}_getState(m_tbe_ptr, m_cache_entry_ptr, addr);')
10177839Snilay@cs.wisc.edu        elif self.TBEType != None:
10187839Snilay@cs.wisc.edu            code('${ident}_State state = ${ident}_getState(m_tbe_ptr, addr);')
10197839Snilay@cs.wisc.edu        elif self.EntryType != None:
10207839Snilay@cs.wisc.edu            code('${ident}_State state = ${ident}_getState(m_cache_entry_ptr, addr);')
10217839Snilay@cs.wisc.edu        else:
10227839Snilay@cs.wisc.edu            code('${ident}_State state = ${ident}_getState(addr);')
10237839Snilay@cs.wisc.edu
10247839Snilay@cs.wisc.edu        code('''
10256657Snate@binkert.org    ${ident}_State next_state = state;
10266657Snate@binkert.org
10277780Snilay@cs.wisc.edu    DPRINTF(RubyGenerated, "%s, Time: %lld, state: %s, event: %s, addr: %s\\n",
10287780Snilay@cs.wisc.edu            *this,
10297780Snilay@cs.wisc.edu            g_eventQueue_ptr->getTime(),
10307780Snilay@cs.wisc.edu            ${ident}_State_to_string(state),
10317780Snilay@cs.wisc.edu            ${ident}_Event_to_string(event),
10327780Snilay@cs.wisc.edu            addr);
10336657Snate@binkert.org
10347007Snate@binkert.org    TransitionResult result =
10357839Snilay@cs.wisc.edu''')
10367839Snilay@cs.wisc.edu        if self.TBEType != None and self.EntryType != None:
10377839Snilay@cs.wisc.edu            code('doTransitionWorker(event, state, next_state, m_tbe_ptr, m_cache_entry_ptr, addr);')
10387839Snilay@cs.wisc.edu        elif self.TBEType != None:
10397839Snilay@cs.wisc.edu            code('doTransitionWorker(event, state, next_state, m_tbe_ptr, addr);')
10407839Snilay@cs.wisc.edu        elif self.EntryType != None:
10417839Snilay@cs.wisc.edu            code('doTransitionWorker(event, state, next_state, m_cache_entry_ptr, addr);')
10427839Snilay@cs.wisc.edu        else:
10437839Snilay@cs.wisc.edu            code('doTransitionWorker(event, state, next_state, addr);')
10446657Snate@binkert.org
10457839Snilay@cs.wisc.edu        code('''
10466657Snate@binkert.org    if (result == TransitionResult_Valid) {
10477780Snilay@cs.wisc.edu        DPRINTF(RubyGenerated, "next_state: %s\\n",
10487780Snilay@cs.wisc.edu                ${ident}_State_to_string(next_state));
10497542SBrad.Beckmann@amd.com        m_profiler.countTransition(state, event);
10507832Snate@binkert.org        DPRINTFR(ProtocolTrace, "%7d %3s %10s%20s %6s>%-6s %s %s\\n",
10517832Snate@binkert.org            g_eventQueue_ptr->getTime(), m_version, "${ident}",
10527832Snate@binkert.org            ${ident}_Event_to_string(event),
10537832Snate@binkert.org            ${ident}_State_to_string(state),
10547832Snate@binkert.org            ${ident}_State_to_string(next_state),
10557832Snate@binkert.org            addr, GET_TRANSITION_COMMENT());
10566657Snate@binkert.org
10577832Snate@binkert.org        CLEAR_TRANSITION_COMMENT();
10587839Snilay@cs.wisc.edu''')
10597839Snilay@cs.wisc.edu        if self.TBEType != None and self.EntryType != None:
10607839Snilay@cs.wisc.edu            code('${ident}_setState(m_tbe_ptr, m_cache_entry_ptr, addr, next_state);')
10617839Snilay@cs.wisc.edu        elif self.TBEType != None:
10627839Snilay@cs.wisc.edu            code('${ident}_setState(m_tbe_ptr, addr, next_state);')
10637839Snilay@cs.wisc.edu        elif self.EntryType != None:
10647839Snilay@cs.wisc.edu            code('${ident}_setState(m_cache_entry_ptr, addr, next_state);')
10657839Snilay@cs.wisc.edu        else:
10667839Snilay@cs.wisc.edu            code('${ident}_setState(addr, next_state);')
10677839Snilay@cs.wisc.edu
10687839Snilay@cs.wisc.edu        code('''
10696657Snate@binkert.org    } else if (result == TransitionResult_ResourceStall) {
10707832Snate@binkert.org        DPRINTFR(ProtocolTrace, "%7s %3s %10s%20s %6s>%-6s %s %s\\n",
10717832Snate@binkert.org            g_eventQueue_ptr->getTime(), m_version, "${ident}",
10727832Snate@binkert.org            ${ident}_Event_to_string(event),
10737832Snate@binkert.org            ${ident}_State_to_string(state),
10747832Snate@binkert.org            ${ident}_State_to_string(next_state),
10757832Snate@binkert.org            addr, "Resource Stall");
10766657Snate@binkert.org    } else if (result == TransitionResult_ProtocolStall) {
10777780Snilay@cs.wisc.edu        DPRINTF(RubyGenerated, "stalling\\n");
10787832Snate@binkert.org        DPRINTFR(ProtocolTrace, "%7s %3s %10s%20s %6s>%-6s %s %s\\n",
10797832Snate@binkert.org            g_eventQueue_ptr->getTime(), m_version, "${ident}",
10807832Snate@binkert.org            ${ident}_Event_to_string(event),
10817832Snate@binkert.org            ${ident}_State_to_string(state),
10827832Snate@binkert.org            ${ident}_State_to_string(next_state),
10837832Snate@binkert.org            addr, "Protocol Stall");
10846657Snate@binkert.org    }
10856657Snate@binkert.org
10866657Snate@binkert.org    return result;
10876657Snate@binkert.org}
10886657Snate@binkert.org
10897007Snate@binkert.orgTransitionResult
10907007Snate@binkert.org${ident}_Controller::doTransitionWorker(${ident}_Event event,
10917007Snate@binkert.org                                        ${ident}_State state,
10927007Snate@binkert.org                                        ${ident}_State& next_state,
10937839Snilay@cs.wisc.edu''')
10947839Snilay@cs.wisc.edu
10957839Snilay@cs.wisc.edu        if self.TBEType != None:
10967839Snilay@cs.wisc.edu            code('''
10977839Snilay@cs.wisc.edu                                        ${{self.TBEType.c_ident}}*& m_tbe_ptr,
10987839Snilay@cs.wisc.edu''')
10997839Snilay@cs.wisc.edu        if self.EntryType != None:
11007839Snilay@cs.wisc.edu                  code('''
11017839Snilay@cs.wisc.edu                                        ${{self.EntryType.c_ident}}*& m_cache_entry_ptr,
11027839Snilay@cs.wisc.edu''')
11037839Snilay@cs.wisc.edu        code('''
11047007Snate@binkert.org                                        const Address& addr)
11056657Snate@binkert.org{
11066657Snate@binkert.org    switch(HASH_FUN(state, event)) {
11076657Snate@binkert.org''')
11086657Snate@binkert.org
11096657Snate@binkert.org        # This map will allow suppress generating duplicate code
11106657Snate@binkert.org        cases = orderdict()
11116657Snate@binkert.org
11126657Snate@binkert.org        for trans in self.transitions:
11136657Snate@binkert.org            case_string = "%s_State_%s, %s_Event_%s" % \
11146657Snate@binkert.org                (self.ident, trans.state.ident, self.ident, trans.event.ident)
11156657Snate@binkert.org
11166999Snate@binkert.org            case = self.symtab.codeFormatter()
11176657Snate@binkert.org            # Only set next_state if it changes
11186657Snate@binkert.org            if trans.state != trans.nextState:
11196657Snate@binkert.org                ns_ident = trans.nextState.ident
11206657Snate@binkert.org                case('next_state = ${ident}_State_${ns_ident};')
11216657Snate@binkert.org
11226657Snate@binkert.org            actions = trans.actions
11236657Snate@binkert.org
11246657Snate@binkert.org            # Check for resources
11256657Snate@binkert.org            case_sorter = []
11266657Snate@binkert.org            res = trans.resources
11276657Snate@binkert.org            for key,val in res.iteritems():
11286657Snate@binkert.org                if key.type.ident != "DNUCAStopTable":
11296657Snate@binkert.org                    val = '''
11307007Snate@binkert.orgif (!%s.areNSlotsAvailable(%s))
11316657Snate@binkert.org    return TransitionResult_ResourceStall;
11326657Snate@binkert.org''' % (key.code, val)
11336657Snate@binkert.org                case_sorter.append(val)
11346657Snate@binkert.org
11356657Snate@binkert.org
11366657Snate@binkert.org            # Emit the code sequences in a sorted order.  This makes the
11376657Snate@binkert.org            # output deterministic (without this the output order can vary
11386657Snate@binkert.org            # since Map's keys() on a vector of pointers is not deterministic
11396657Snate@binkert.org            for c in sorted(case_sorter):
11406657Snate@binkert.org                case("$c")
11416657Snate@binkert.org
11426657Snate@binkert.org            # Figure out if we stall
11436657Snate@binkert.org            stall = False
11446657Snate@binkert.org            for action in actions:
11456657Snate@binkert.org                if action.ident == "z_stall":
11466657Snate@binkert.org                    stall = True
11476657Snate@binkert.org                    break
11486657Snate@binkert.org
11496657Snate@binkert.org            if stall:
11506657Snate@binkert.org                case('return TransitionResult_ProtocolStall;')
11516657Snate@binkert.org            else:
11527839Snilay@cs.wisc.edu                if self.TBEType != None and self.EntryType != None:
11537839Snilay@cs.wisc.edu                    for action in actions:
11547839Snilay@cs.wisc.edu                        case('${{action.ident}}(m_tbe_ptr, m_cache_entry_ptr, addr);')
11557839Snilay@cs.wisc.edu                elif self.TBEType != None:
11567839Snilay@cs.wisc.edu                    for action in actions:
11577839Snilay@cs.wisc.edu                        case('${{action.ident}}(m_tbe_ptr, addr);')
11587839Snilay@cs.wisc.edu                elif self.EntryType != None:
11597839Snilay@cs.wisc.edu                    for action in actions:
11607839Snilay@cs.wisc.edu                        case('${{action.ident}}(m_cache_entry_ptr, addr);')
11617839Snilay@cs.wisc.edu                else:
11627839Snilay@cs.wisc.edu                    for action in actions:
11637839Snilay@cs.wisc.edu                        case('${{action.ident}}(addr);')
11646657Snate@binkert.org                case('return TransitionResult_Valid;')
11656657Snate@binkert.org
11666657Snate@binkert.org            case = str(case)
11676657Snate@binkert.org
11686657Snate@binkert.org            # Look to see if this transition code is unique.
11696657Snate@binkert.org            if case not in cases:
11706657Snate@binkert.org                cases[case] = []
11716657Snate@binkert.org
11726657Snate@binkert.org            cases[case].append(case_string)
11736657Snate@binkert.org
11746657Snate@binkert.org        # Walk through all of the unique code blocks and spit out the
11756657Snate@binkert.org        # corresponding case statement elements
11766657Snate@binkert.org        for case,transitions in cases.iteritems():
11776657Snate@binkert.org            # Iterative over all the multiple transitions that share
11786657Snate@binkert.org            # the same code
11796657Snate@binkert.org            for trans in transitions:
11806657Snate@binkert.org                code('  case HASH_FUN($trans):')
11816657Snate@binkert.org            code('    $case')
11826657Snate@binkert.org
11836657Snate@binkert.org        code('''
11846657Snate@binkert.org      default:
11857805Snilay@cs.wisc.edu        fatal("Invalid transition\\n"
11867805Snilay@cs.wisc.edu              "version: %d time: %d addr: %s event: %s state: %s\\n",
11877805Snilay@cs.wisc.edu              m_version, g_eventQueue_ptr->getTime(), addr, event, state);
11886657Snate@binkert.org    }
11896657Snate@binkert.org    return TransitionResult_Valid;
11906657Snate@binkert.org}
11916657Snate@binkert.org''')
11926657Snate@binkert.org        code.write(path, "%s_Transitions.cc" % self.ident)
11936657Snate@binkert.org
11947542SBrad.Beckmann@amd.com    def printProfileDumperHH(self, path):
11957542SBrad.Beckmann@amd.com        code = self.symtab.codeFormatter()
11967542SBrad.Beckmann@amd.com        ident = self.ident
11977542SBrad.Beckmann@amd.com
11987542SBrad.Beckmann@amd.com        code('''
11997542SBrad.Beckmann@amd.com// Auto generated C++ code started by $__file__:$__line__
12007542SBrad.Beckmann@amd.com// ${ident}: ${{self.short}}
12017542SBrad.Beckmann@amd.com
12027542SBrad.Beckmann@amd.com#ifndef __${ident}_PROFILE_DUMPER_HH__
12037542SBrad.Beckmann@amd.com#define __${ident}_PROFILE_DUMPER_HH__
12047542SBrad.Beckmann@amd.com
12057832Snate@binkert.org#include <cassert>
12067542SBrad.Beckmann@amd.com#include <iostream>
12077542SBrad.Beckmann@amd.com#include <vector>
12087542SBrad.Beckmann@amd.com
12097542SBrad.Beckmann@amd.com#include "${ident}_Profiler.hh"
12107542SBrad.Beckmann@amd.com#include "${ident}_Event.hh"
12117542SBrad.Beckmann@amd.com
12127542SBrad.Beckmann@amd.comtypedef std::vector<${ident}_Profiler *> ${ident}_profilers;
12137542SBrad.Beckmann@amd.com
12147542SBrad.Beckmann@amd.comclass ${ident}_ProfileDumper
12157542SBrad.Beckmann@amd.com{
12167542SBrad.Beckmann@amd.com  public:
12177542SBrad.Beckmann@amd.com    ${ident}_ProfileDumper();
12187542SBrad.Beckmann@amd.com    void registerProfiler(${ident}_Profiler* profiler);
12197542SBrad.Beckmann@amd.com    void dumpStats(std::ostream& out) const;
12207542SBrad.Beckmann@amd.com
12217542SBrad.Beckmann@amd.com  private:
12227542SBrad.Beckmann@amd.com    ${ident}_profilers m_profilers;
12237542SBrad.Beckmann@amd.com};
12247542SBrad.Beckmann@amd.com
12257542SBrad.Beckmann@amd.com#endif // __${ident}_PROFILE_DUMPER_HH__
12267542SBrad.Beckmann@amd.com''')
12277542SBrad.Beckmann@amd.com        code.write(path, "%s_ProfileDumper.hh" % self.ident)
12287542SBrad.Beckmann@amd.com
12297542SBrad.Beckmann@amd.com    def printProfileDumperCC(self, path):
12307542SBrad.Beckmann@amd.com        code = self.symtab.codeFormatter()
12317542SBrad.Beckmann@amd.com        ident = self.ident
12327542SBrad.Beckmann@amd.com
12337542SBrad.Beckmann@amd.com        code('''
12347542SBrad.Beckmann@amd.com// Auto generated C++ code started by $__file__:$__line__
12357542SBrad.Beckmann@amd.com// ${ident}: ${{self.short}}
12367542SBrad.Beckmann@amd.com
12377542SBrad.Beckmann@amd.com#include "mem/protocol/${ident}_ProfileDumper.hh"
12387542SBrad.Beckmann@amd.com
12397542SBrad.Beckmann@amd.com${ident}_ProfileDumper::${ident}_ProfileDumper()
12407542SBrad.Beckmann@amd.com{
12417542SBrad.Beckmann@amd.com}
12427542SBrad.Beckmann@amd.com
12437542SBrad.Beckmann@amd.comvoid
12447542SBrad.Beckmann@amd.com${ident}_ProfileDumper::registerProfiler(${ident}_Profiler* profiler)
12457542SBrad.Beckmann@amd.com{
12467542SBrad.Beckmann@amd.com    m_profilers.push_back(profiler);
12477542SBrad.Beckmann@amd.com}
12487542SBrad.Beckmann@amd.com
12497542SBrad.Beckmann@amd.comvoid
12507542SBrad.Beckmann@amd.com${ident}_ProfileDumper::dumpStats(std::ostream& out) const
12517542SBrad.Beckmann@amd.com{
12527542SBrad.Beckmann@amd.com    out << " --- ${ident} ---\\n";
12537542SBrad.Beckmann@amd.com    out << " - Event Counts -\\n";
12547542SBrad.Beckmann@amd.com    for (${ident}_Event event = ${ident}_Event_FIRST;
12557542SBrad.Beckmann@amd.com         event < ${ident}_Event_NUM;
12567542SBrad.Beckmann@amd.com         ++event) {
12577542SBrad.Beckmann@amd.com        out << (${ident}_Event) event << " [";
12587542SBrad.Beckmann@amd.com        uint64 total = 0;
12597542SBrad.Beckmann@amd.com        for (int i = 0; i < m_profilers.size(); i++) {
12607542SBrad.Beckmann@amd.com             out << m_profilers[i]->getEventCount(event) << " ";
12617542SBrad.Beckmann@amd.com             total += m_profilers[i]->getEventCount(event);
12627542SBrad.Beckmann@amd.com        }
12637542SBrad.Beckmann@amd.com        out << "] " << total << "\\n";
12647542SBrad.Beckmann@amd.com    }
12657542SBrad.Beckmann@amd.com    out << "\\n";
12667542SBrad.Beckmann@amd.com    out << " - Transitions -\\n";
12677542SBrad.Beckmann@amd.com    for (${ident}_State state = ${ident}_State_FIRST;
12687542SBrad.Beckmann@amd.com         state < ${ident}_State_NUM;
12697542SBrad.Beckmann@amd.com         ++state) {
12707542SBrad.Beckmann@amd.com        for (${ident}_Event event = ${ident}_Event_FIRST;
12717542SBrad.Beckmann@amd.com             event < ${ident}_Event_NUM;
12727542SBrad.Beckmann@amd.com             ++event) {
12737542SBrad.Beckmann@amd.com            if (m_profilers[0]->isPossible(state, event)) {
12747542SBrad.Beckmann@amd.com                out << (${ident}_State) state << "  "
12757542SBrad.Beckmann@amd.com                    << (${ident}_Event) event << " [";
12767542SBrad.Beckmann@amd.com                uint64 total = 0;
12777542SBrad.Beckmann@amd.com                for (int i = 0; i < m_profilers.size(); i++) {
12787542SBrad.Beckmann@amd.com                     out << m_profilers[i]->getTransitionCount(state, event) << " ";
12797542SBrad.Beckmann@amd.com                     total += m_profilers[i]->getTransitionCount(state, event);
12807542SBrad.Beckmann@amd.com                }
12817542SBrad.Beckmann@amd.com                out << "] " << total << "\\n";
12827542SBrad.Beckmann@amd.com            }
12837542SBrad.Beckmann@amd.com        }
12847542SBrad.Beckmann@amd.com        out << "\\n";
12857542SBrad.Beckmann@amd.com    }
12867542SBrad.Beckmann@amd.com}
12877542SBrad.Beckmann@amd.com''')
12887542SBrad.Beckmann@amd.com        code.write(path, "%s_ProfileDumper.cc" % self.ident)
12897542SBrad.Beckmann@amd.com
12906657Snate@binkert.org    def printProfilerHH(self, path):
12916999Snate@binkert.org        code = self.symtab.codeFormatter()
12926657Snate@binkert.org        ident = self.ident
12936657Snate@binkert.org
12946657Snate@binkert.org        code('''
12956657Snate@binkert.org// Auto generated C++ code started by $__file__:$__line__
12966657Snate@binkert.org// ${ident}: ${{self.short}}
12976657Snate@binkert.org
12987542SBrad.Beckmann@amd.com#ifndef __${ident}_PROFILER_HH__
12997542SBrad.Beckmann@amd.com#define __${ident}_PROFILER_HH__
13006657Snate@binkert.org
13017832Snate@binkert.org#include <cassert>
13027002Snate@binkert.org#include <iostream>
13037002Snate@binkert.org
13046657Snate@binkert.org#include "mem/ruby/common/Global.hh"
13056657Snate@binkert.org#include "mem/protocol/${ident}_State.hh"
13066657Snate@binkert.org#include "mem/protocol/${ident}_Event.hh"
13076657Snate@binkert.org
13087007Snate@binkert.orgclass ${ident}_Profiler
13097007Snate@binkert.org{
13106657Snate@binkert.org  public:
13116657Snate@binkert.org    ${ident}_Profiler();
13126657Snate@binkert.org    void setVersion(int version);
13136657Snate@binkert.org    void countTransition(${ident}_State state, ${ident}_Event event);
13146657Snate@binkert.org    void possibleTransition(${ident}_State state, ${ident}_Event event);
13157542SBrad.Beckmann@amd.com    uint64 getEventCount(${ident}_Event event);
13167542SBrad.Beckmann@amd.com    bool isPossible(${ident}_State state, ${ident}_Event event);
13177542SBrad.Beckmann@amd.com    uint64 getTransitionCount(${ident}_State state, ${ident}_Event event);
13186657Snate@binkert.org    void clearStats();
13196657Snate@binkert.org
13206657Snate@binkert.org  private:
13216657Snate@binkert.org    int m_counters[${ident}_State_NUM][${ident}_Event_NUM];
13226657Snate@binkert.org    int m_event_counters[${ident}_Event_NUM];
13236657Snate@binkert.org    bool m_possible[${ident}_State_NUM][${ident}_Event_NUM];
13246657Snate@binkert.org    int m_version;
13256657Snate@binkert.org};
13266657Snate@binkert.org
13277007Snate@binkert.org#endif // __${ident}_PROFILER_HH__
13286657Snate@binkert.org''')
13296657Snate@binkert.org        code.write(path, "%s_Profiler.hh" % self.ident)
13306657Snate@binkert.org
13316657Snate@binkert.org    def printProfilerCC(self, path):
13326999Snate@binkert.org        code = self.symtab.codeFormatter()
13336657Snate@binkert.org        ident = self.ident
13346657Snate@binkert.org
13356657Snate@binkert.org        code('''
13366657Snate@binkert.org// Auto generated C++ code started by $__file__:$__line__
13376657Snate@binkert.org// ${ident}: ${{self.short}}
13386657Snate@binkert.org
13397832Snate@binkert.org#include <cassert>
13407832Snate@binkert.org
13416657Snate@binkert.org#include "mem/protocol/${ident}_Profiler.hh"
13426657Snate@binkert.org
13436657Snate@binkert.org${ident}_Profiler::${ident}_Profiler()
13446657Snate@binkert.org{
13456657Snate@binkert.org    for (int state = 0; state < ${ident}_State_NUM; state++) {
13466657Snate@binkert.org        for (int event = 0; event < ${ident}_Event_NUM; event++) {
13476657Snate@binkert.org            m_possible[state][event] = false;
13486657Snate@binkert.org            m_counters[state][event] = 0;
13496657Snate@binkert.org        }
13506657Snate@binkert.org    }
13516657Snate@binkert.org    for (int event = 0; event < ${ident}_Event_NUM; event++) {
13526657Snate@binkert.org        m_event_counters[event] = 0;
13536657Snate@binkert.org    }
13546657Snate@binkert.org}
13557007Snate@binkert.org
13567007Snate@binkert.orgvoid
13577007Snate@binkert.org${ident}_Profiler::setVersion(int version)
13586657Snate@binkert.org{
13596657Snate@binkert.org    m_version = version;
13606657Snate@binkert.org}
13617007Snate@binkert.org
13627007Snate@binkert.orgvoid
13637007Snate@binkert.org${ident}_Profiler::clearStats()
13646657Snate@binkert.org{
13656657Snate@binkert.org    for (int state = 0; state < ${ident}_State_NUM; state++) {
13666657Snate@binkert.org        for (int event = 0; event < ${ident}_Event_NUM; event++) {
13676657Snate@binkert.org            m_counters[state][event] = 0;
13686657Snate@binkert.org        }
13696657Snate@binkert.org    }
13706657Snate@binkert.org
13716657Snate@binkert.org    for (int event = 0; event < ${ident}_Event_NUM; event++) {
13726657Snate@binkert.org        m_event_counters[event] = 0;
13736657Snate@binkert.org    }
13746657Snate@binkert.org}
13757007Snate@binkert.orgvoid
13767007Snate@binkert.org${ident}_Profiler::countTransition(${ident}_State state, ${ident}_Event event)
13776657Snate@binkert.org{
13786657Snate@binkert.org    assert(m_possible[state][event]);
13796657Snate@binkert.org    m_counters[state][event]++;
13806657Snate@binkert.org    m_event_counters[event]++;
13816657Snate@binkert.org}
13827007Snate@binkert.orgvoid
13837007Snate@binkert.org${ident}_Profiler::possibleTransition(${ident}_State state,
13847007Snate@binkert.org                                      ${ident}_Event event)
13856657Snate@binkert.org{
13866657Snate@binkert.org    m_possible[state][event] = true;
13876657Snate@binkert.org}
13887007Snate@binkert.org
13897542SBrad.Beckmann@amd.comuint64
13907542SBrad.Beckmann@amd.com${ident}_Profiler::getEventCount(${ident}_Event event)
13916657Snate@binkert.org{
13927542SBrad.Beckmann@amd.com    return m_event_counters[event];
13937542SBrad.Beckmann@amd.com}
13947002Snate@binkert.org
13957542SBrad.Beckmann@amd.combool
13967542SBrad.Beckmann@amd.com${ident}_Profiler::isPossible(${ident}_State state, ${ident}_Event event)
13977542SBrad.Beckmann@amd.com{
13987542SBrad.Beckmann@amd.com    return m_possible[state][event];
13996657Snate@binkert.org}
14007542SBrad.Beckmann@amd.com
14017542SBrad.Beckmann@amd.comuint64
14027542SBrad.Beckmann@amd.com${ident}_Profiler::getTransitionCount(${ident}_State state,
14037542SBrad.Beckmann@amd.com                                      ${ident}_Event event)
14047542SBrad.Beckmann@amd.com{
14057542SBrad.Beckmann@amd.com    return m_counters[state][event];
14067542SBrad.Beckmann@amd.com}
14077542SBrad.Beckmann@amd.com
14086657Snate@binkert.org''')
14096657Snate@binkert.org        code.write(path, "%s_Profiler.cc" % self.ident)
14106657Snate@binkert.org
14116657Snate@binkert.org    # **************************
14126657Snate@binkert.org    # ******* HTML Files *******
14136657Snate@binkert.org    # **************************
14147007Snate@binkert.org    def frameRef(self, click_href, click_target, over_href, over_num, text):
14156999Snate@binkert.org        code = self.symtab.codeFormatter(fix_newlines=False)
14167007Snate@binkert.org        code("""<A href=\"$click_href\" target=\"$click_target\" onmouseover=\"
14177007Snate@binkert.org    if (parent.frames[$over_num].location != parent.location + '$over_href') {
14187007Snate@binkert.org        parent.frames[$over_num].location='$over_href'
14197007Snate@binkert.org    }\">
14207007Snate@binkert.org    ${{html.formatShorthand(text)}}
14217007Snate@binkert.org    </A>""")
14226657Snate@binkert.org        return str(code)
14236657Snate@binkert.org
14246657Snate@binkert.org    def writeHTMLFiles(self, path):
14256657Snate@binkert.org        # Create table with no row hilighted
14266657Snate@binkert.org        self.printHTMLTransitions(path, None)
14276657Snate@binkert.org
14286657Snate@binkert.org        # Generate transition tables
14296657Snate@binkert.org        for state in self.states.itervalues():
14306657Snate@binkert.org            self.printHTMLTransitions(path, state)
14316657Snate@binkert.org
14326657Snate@binkert.org        # Generate action descriptions
14336657Snate@binkert.org        for action in self.actions.itervalues():
14346657Snate@binkert.org            name = "%s_action_%s.html" % (self.ident, action.ident)
14356657Snate@binkert.org            code = html.createSymbol(action, "Action")
14366657Snate@binkert.org            code.write(path, name)
14376657Snate@binkert.org
14386657Snate@binkert.org        # Generate state descriptions
14396657Snate@binkert.org        for state in self.states.itervalues():
14406657Snate@binkert.org            name = "%s_State_%s.html" % (self.ident, state.ident)
14416657Snate@binkert.org            code = html.createSymbol(state, "State")
14426657Snate@binkert.org            code.write(path, name)
14436657Snate@binkert.org
14446657Snate@binkert.org        # Generate event descriptions
14456657Snate@binkert.org        for event in self.events.itervalues():
14466657Snate@binkert.org            name = "%s_Event_%s.html" % (self.ident, event.ident)
14476657Snate@binkert.org            code = html.createSymbol(event, "Event")
14486657Snate@binkert.org            code.write(path, name)
14496657Snate@binkert.org
14506657Snate@binkert.org    def printHTMLTransitions(self, path, active_state):
14516999Snate@binkert.org        code = self.symtab.codeFormatter()
14526657Snate@binkert.org
14536657Snate@binkert.org        code('''
14547007Snate@binkert.org<HTML>
14557007Snate@binkert.org<BODY link="blue" vlink="blue">
14566657Snate@binkert.org
14576657Snate@binkert.org<H1 align="center">${{html.formatShorthand(self.short)}}:
14586657Snate@binkert.org''')
14596657Snate@binkert.org        code.indent()
14606657Snate@binkert.org        for i,machine in enumerate(self.symtab.getAllType(StateMachine)):
14616657Snate@binkert.org            mid = machine.ident
14626657Snate@binkert.org            if i != 0:
14636657Snate@binkert.org                extra = " - "
14646657Snate@binkert.org            else:
14656657Snate@binkert.org                extra = ""
14666657Snate@binkert.org            if machine == self:
14676657Snate@binkert.org                code('$extra$mid')
14686657Snate@binkert.org            else:
14696657Snate@binkert.org                code('$extra<A target="Table" href="${mid}_table.html">$mid</A>')
14706657Snate@binkert.org        code.dedent()
14716657Snate@binkert.org
14726657Snate@binkert.org        code("""
14736657Snate@binkert.org</H1>
14746657Snate@binkert.org
14756657Snate@binkert.org<TABLE border=1>
14766657Snate@binkert.org<TR>
14776657Snate@binkert.org  <TH> </TH>
14786657Snate@binkert.org""")
14796657Snate@binkert.org
14806657Snate@binkert.org        for event in self.events.itervalues():
14816657Snate@binkert.org            href = "%s_Event_%s.html" % (self.ident, event.ident)
14826657Snate@binkert.org            ref = self.frameRef(href, "Status", href, "1", event.short)
14836657Snate@binkert.org            code('<TH bgcolor=white>$ref</TH>')
14846657Snate@binkert.org
14856657Snate@binkert.org        code('</TR>')
14866657Snate@binkert.org        # -- Body of table
14876657Snate@binkert.org        for state in self.states.itervalues():
14886657Snate@binkert.org            # -- Each row
14896657Snate@binkert.org            if state == active_state:
14906657Snate@binkert.org                color = "yellow"
14916657Snate@binkert.org            else:
14926657Snate@binkert.org                color = "white"
14936657Snate@binkert.org
14946657Snate@binkert.org            click = "%s_table_%s.html" % (self.ident, state.ident)
14956657Snate@binkert.org            over = "%s_State_%s.html" % (self.ident, state.ident)
14966657Snate@binkert.org            text = html.formatShorthand(state.short)
14976657Snate@binkert.org            ref = self.frameRef(click, "Table", over, "1", state.short)
14986657Snate@binkert.org            code('''
14996657Snate@binkert.org<TR>
15006657Snate@binkert.org  <TH bgcolor=$color>$ref</TH>
15016657Snate@binkert.org''')
15026657Snate@binkert.org
15036657Snate@binkert.org            # -- One column for each event
15046657Snate@binkert.org            for event in self.events.itervalues():
15056657Snate@binkert.org                trans = self.table.get((state,event), None)
15066657Snate@binkert.org                if trans is None:
15076657Snate@binkert.org                    # This is the no transition case
15086657Snate@binkert.org                    if state == active_state:
15096657Snate@binkert.org                        color = "#C0C000"
15106657Snate@binkert.org                    else:
15116657Snate@binkert.org                        color = "lightgrey"
15126657Snate@binkert.org
15136657Snate@binkert.org                    code('<TD bgcolor=$color>&nbsp;</TD>')
15146657Snate@binkert.org                    continue
15156657Snate@binkert.org
15166657Snate@binkert.org                next = trans.nextState
15176657Snate@binkert.org                stall_action = False
15186657Snate@binkert.org
15196657Snate@binkert.org                # -- Get the actions
15206657Snate@binkert.org                for action in trans.actions:
15216657Snate@binkert.org                    if action.ident == "z_stall" or \
15226657Snate@binkert.org                       action.ident == "zz_recycleMandatoryQueue":
15236657Snate@binkert.org                        stall_action = True
15246657Snate@binkert.org
15256657Snate@binkert.org                # -- Print out "actions/next-state"
15266657Snate@binkert.org                if stall_action:
15276657Snate@binkert.org                    if state == active_state:
15286657Snate@binkert.org                        color = "#C0C000"
15296657Snate@binkert.org                    else:
15306657Snate@binkert.org                        color = "lightgrey"
15316657Snate@binkert.org
15326657Snate@binkert.org                elif active_state and next.ident == active_state.ident:
15336657Snate@binkert.org                    color = "aqua"
15346657Snate@binkert.org                elif state == active_state:
15356657Snate@binkert.org                    color = "yellow"
15366657Snate@binkert.org                else:
15376657Snate@binkert.org                    color = "white"
15386657Snate@binkert.org
15396657Snate@binkert.org                code('<TD bgcolor=$color>')
15406657Snate@binkert.org                for action in trans.actions:
15416657Snate@binkert.org                    href = "%s_action_%s.html" % (self.ident, action.ident)
15426657Snate@binkert.org                    ref = self.frameRef(href, "Status", href, "1",
15436657Snate@binkert.org                                        action.short)
15447007Snate@binkert.org                    code('  $ref')
15456657Snate@binkert.org                if next != state:
15466657Snate@binkert.org                    if trans.actions:
15476657Snate@binkert.org                        code('/')
15486657Snate@binkert.org                    click = "%s_table_%s.html" % (self.ident, next.ident)
15496657Snate@binkert.org                    over = "%s_State_%s.html" % (self.ident, next.ident)
15506657Snate@binkert.org                    ref = self.frameRef(click, "Table", over, "1", next.short)
15516657Snate@binkert.org                    code("$ref")
15527007Snate@binkert.org                code("</TD>")
15536657Snate@binkert.org
15546657Snate@binkert.org            # -- Each row
15556657Snate@binkert.org            if state == active_state:
15566657Snate@binkert.org                color = "yellow"
15576657Snate@binkert.org            else:
15586657Snate@binkert.org                color = "white"
15596657Snate@binkert.org
15606657Snate@binkert.org            click = "%s_table_%s.html" % (self.ident, state.ident)
15616657Snate@binkert.org            over = "%s_State_%s.html" % (self.ident, state.ident)
15626657Snate@binkert.org            ref = self.frameRef(click, "Table", over, "1", state.short)
15636657Snate@binkert.org            code('''
15646657Snate@binkert.org  <TH bgcolor=$color>$ref</TH>
15656657Snate@binkert.org</TR>
15666657Snate@binkert.org''')
15676657Snate@binkert.org        code('''
15687007Snate@binkert.org<!- Column footer->
15696657Snate@binkert.org<TR>
15706657Snate@binkert.org  <TH> </TH>
15716657Snate@binkert.org''')
15726657Snate@binkert.org
15736657Snate@binkert.org        for event in self.events.itervalues():
15746657Snate@binkert.org            href = "%s_Event_%s.html" % (self.ident, event.ident)
15756657Snate@binkert.org            ref = self.frameRef(href, "Status", href, "1", event.short)
15766657Snate@binkert.org            code('<TH bgcolor=white>$ref</TH>')
15776657Snate@binkert.org        code('''
15786657Snate@binkert.org</TR>
15796657Snate@binkert.org</TABLE>
15806657Snate@binkert.org</BODY></HTML>
15816657Snate@binkert.org''')
15826657Snate@binkert.org
15836657Snate@binkert.org
15846657Snate@binkert.org        if active_state:
15856657Snate@binkert.org            name = "%s_table_%s.html" % (self.ident, active_state.ident)
15866657Snate@binkert.org        else:
15876657Snate@binkert.org            name = "%s_table.html" % self.ident
15886657Snate@binkert.org        code.write(path, name)
15896657Snate@binkert.org
15906657Snate@binkert.org__all__ = [ "StateMachine" ]
1591