StateMachine.py revision 10968
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
338189SLisa.Hsu@amd.comimport re
346657Snate@binkert.org
359499Snilay@cs.wisc.edupython_class_map = {
369499Snilay@cs.wisc.edu                    "int": "Int",
379364Snilay@cs.wisc.edu                    "uint32_t" : "UInt32",
387055Snate@binkert.org                    "std::string": "String",
396882SBrad.Beckmann@amd.com                    "bool": "Bool",
406882SBrad.Beckmann@amd.com                    "CacheMemory": "RubyCache",
418191SLisa.Hsu@amd.com                    "WireBuffer": "RubyWireBuffer",
426882SBrad.Beckmann@amd.com                    "Sequencer": "RubySequencer",
436882SBrad.Beckmann@amd.com                    "DirectoryMemory": "RubyDirectoryMemory",
449102SNuwan.Jayasena@amd.com                    "MemoryControl": "MemoryControl",
459366Snilay@cs.wisc.edu                    "DMASequencer": "DMASequencer",
469499Snilay@cs.wisc.edu                    "Prefetcher":"Prefetcher",
479499Snilay@cs.wisc.edu                    "Cycles":"Cycles",
489499Snilay@cs.wisc.edu                   }
496882SBrad.Beckmann@amd.com
506657Snate@binkert.orgclass StateMachine(Symbol):
516657Snate@binkert.org    def __init__(self, symtab, ident, location, pairs, config_parameters):
526657Snate@binkert.org        super(StateMachine, self).__init__(symtab, ident, location, pairs)
536657Snate@binkert.org        self.table = None
5410311Snilay@cs.wisc.edu
5510311Snilay@cs.wisc.edu        # Data members in the State Machine that have been declared before
5610311Snilay@cs.wisc.edu        # the opening brace '{'  of the machine.  Note that these along with
5710311Snilay@cs.wisc.edu        # the members in self.objects form the entire set of data members.
586657Snate@binkert.org        self.config_parameters = config_parameters
5910311Snilay@cs.wisc.edu
609366Snilay@cs.wisc.edu        self.prefetchers = []
617839Snilay@cs.wisc.edu
626657Snate@binkert.org        for param in config_parameters:
636882SBrad.Beckmann@amd.com            if param.pointer:
6410308Snilay@cs.wisc.edu                var = Var(symtab, param.ident, location, param.type_ast.type,
6510308Snilay@cs.wisc.edu                          "(*m_%s_ptr)" % param.ident, {}, self)
666882SBrad.Beckmann@amd.com            else:
6710308Snilay@cs.wisc.edu                var = Var(symtab, param.ident, location, param.type_ast.type,
6810308Snilay@cs.wisc.edu                          "m_%s" % param.ident, {}, self)
6910308Snilay@cs.wisc.edu
7010308Snilay@cs.wisc.edu            self.symtab.registerSym(param.ident, var)
7110308Snilay@cs.wisc.edu
729366Snilay@cs.wisc.edu            if str(param.type_ast.type) == "Prefetcher":
739366Snilay@cs.wisc.edu                self.prefetchers.append(var)
746657Snate@binkert.org
756657Snate@binkert.org        self.states = orderdict()
766657Snate@binkert.org        self.events = orderdict()
776657Snate@binkert.org        self.actions = orderdict()
789104Shestness@cs.utexas.edu        self.request_types = orderdict()
796657Snate@binkert.org        self.transitions = []
806657Snate@binkert.org        self.in_ports = []
816657Snate@binkert.org        self.functions = []
8210311Snilay@cs.wisc.edu
8310311Snilay@cs.wisc.edu        # Data members in the State Machine that have been declared inside
8410311Snilay@cs.wisc.edu        # the {} machine.  Note that these along with the config params
8510311Snilay@cs.wisc.edu        # form the entire set of data members of the machine.
866657Snate@binkert.org        self.objects = []
877839Snilay@cs.wisc.edu        self.TBEType   = None
887839Snilay@cs.wisc.edu        self.EntryType = None
896657Snate@binkert.org
906657Snate@binkert.org    def __repr__(self):
916657Snate@binkert.org        return "[StateMachine: %s]" % self.ident
926657Snate@binkert.org
936657Snate@binkert.org    def addState(self, state):
946657Snate@binkert.org        assert self.table is None
956657Snate@binkert.org        self.states[state.ident] = state
966657Snate@binkert.org
976657Snate@binkert.org    def addEvent(self, event):
986657Snate@binkert.org        assert self.table is None
996657Snate@binkert.org        self.events[event.ident] = event
1006657Snate@binkert.org
1016657Snate@binkert.org    def addAction(self, action):
1026657Snate@binkert.org        assert self.table is None
1036657Snate@binkert.org
1046657Snate@binkert.org        # Check for duplicate action
1056657Snate@binkert.org        for other in self.actions.itervalues():
1066657Snate@binkert.org            if action.ident == other.ident:
1076779SBrad.Beckmann@amd.com                action.warning("Duplicate action definition: %s" % action.ident)
1086657Snate@binkert.org                action.error("Duplicate action definition: %s" % action.ident)
1096657Snate@binkert.org            if action.short == other.short:
1106657Snate@binkert.org                other.warning("Duplicate action shorthand: %s" % other.ident)
1116657Snate@binkert.org                other.warning("    shorthand = %s" % other.short)
1126657Snate@binkert.org                action.warning("Duplicate action shorthand: %s" % action.ident)
1136657Snate@binkert.org                action.error("    shorthand = %s" % action.short)
1146657Snate@binkert.org
1156657Snate@binkert.org        self.actions[action.ident] = action
1166657Snate@binkert.org
1179104Shestness@cs.utexas.edu    def addRequestType(self, request_type):
1189104Shestness@cs.utexas.edu        assert self.table is None
1199104Shestness@cs.utexas.edu        self.request_types[request_type.ident] = request_type
1209104Shestness@cs.utexas.edu
1216657Snate@binkert.org    def addTransition(self, trans):
1226657Snate@binkert.org        assert self.table is None
1236657Snate@binkert.org        self.transitions.append(trans)
1246657Snate@binkert.org
1256657Snate@binkert.org    def addInPort(self, var):
1266657Snate@binkert.org        self.in_ports.append(var)
1276657Snate@binkert.org
1286657Snate@binkert.org    def addFunc(self, func):
1296657Snate@binkert.org        # register func in the symbol table
1306657Snate@binkert.org        self.symtab.registerSym(str(func), func)
1316657Snate@binkert.org        self.functions.append(func)
1326657Snate@binkert.org
1336657Snate@binkert.org    def addObject(self, obj):
13410307Snilay@cs.wisc.edu        self.symtab.registerSym(str(obj), obj)
1356657Snate@binkert.org        self.objects.append(obj)
1366657Snate@binkert.org
1377839Snilay@cs.wisc.edu    def addType(self, type):
1387839Snilay@cs.wisc.edu        type_ident = '%s' % type.c_ident
1397839Snilay@cs.wisc.edu
1407839Snilay@cs.wisc.edu        if type_ident == "%s_TBE" %self.ident:
1417839Snilay@cs.wisc.edu            if self.TBEType != None:
1427839Snilay@cs.wisc.edu                self.error("Multiple Transaction Buffer types in a " \
1437839Snilay@cs.wisc.edu                           "single machine.");
1447839Snilay@cs.wisc.edu            self.TBEType = type
1457839Snilay@cs.wisc.edu
1467839Snilay@cs.wisc.edu        elif "interface" in type and "AbstractCacheEntry" == type["interface"]:
14710968Sdavid.hashe@amd.com            if "main" in type and "false" == type["main"].lower():
14810968Sdavid.hashe@amd.com                pass # this isn't the EntryType
14910968Sdavid.hashe@amd.com            else:
15010968Sdavid.hashe@amd.com                if self.EntryType != None:
15110968Sdavid.hashe@amd.com                    self.error("Multiple AbstractCacheEntry types in a " \
15210968Sdavid.hashe@amd.com                               "single machine.");
15310968Sdavid.hashe@amd.com                self.EntryType = type
1547839Snilay@cs.wisc.edu
1556657Snate@binkert.org    # Needs to be called before accessing the table
1566657Snate@binkert.org    def buildTable(self):
1576657Snate@binkert.org        assert self.table is None
1586657Snate@binkert.org
1596657Snate@binkert.org        table = {}
1606657Snate@binkert.org
1616657Snate@binkert.org        for trans in self.transitions:
1626657Snate@binkert.org            # Track which actions we touch so we know if we use them
1636657Snate@binkert.org            # all -- really this should be done for all symbols as
1646657Snate@binkert.org            # part of the symbol table, then only trigger it for
1656657Snate@binkert.org            # Actions, States, Events, etc.
1666657Snate@binkert.org
1676657Snate@binkert.org            for action in trans.actions:
1686657Snate@binkert.org                action.used = True
1696657Snate@binkert.org
1706657Snate@binkert.org            index = (trans.state, trans.event)
1716657Snate@binkert.org            if index in table:
1726657Snate@binkert.org                table[index].warning("Duplicate transition: %s" % table[index])
1736657Snate@binkert.org                trans.error("Duplicate transition: %s" % trans)
1746657Snate@binkert.org            table[index] = trans
1756657Snate@binkert.org
1766657Snate@binkert.org        # Look at all actions to make sure we used them all
1776657Snate@binkert.org        for action in self.actions.itervalues():
1786657Snate@binkert.org            if not action.used:
1796657Snate@binkert.org                error_msg = "Unused action: %s" % action.ident
1806657Snate@binkert.org                if "desc" in action:
1816657Snate@binkert.org                    error_msg += ", "  + action.desc
1826657Snate@binkert.org                action.warning(error_msg)
1836657Snate@binkert.org        self.table = table
1846657Snate@binkert.org
18510963Sdavid.hashe@amd.com    # determine the port->msg buffer mappings
18610963Sdavid.hashe@amd.com    def getBufferMaps(self, ident):
18710963Sdavid.hashe@amd.com        msg_bufs = []
18810963Sdavid.hashe@amd.com        port_to_buf_map = {}
18910963Sdavid.hashe@amd.com        in_msg_bufs = {}
19010963Sdavid.hashe@amd.com        for port in self.in_ports:
19110963Sdavid.hashe@amd.com            buf_name = "m_%s_ptr" % port.buffer_expr.name
19210963Sdavid.hashe@amd.com            msg_bufs.append(buf_name)
19310963Sdavid.hashe@amd.com            port_to_buf_map[port] = msg_bufs.index(buf_name)
19410963Sdavid.hashe@amd.com            if buf_name not in in_msg_bufs:
19510963Sdavid.hashe@amd.com                in_msg_bufs[buf_name] = [port]
19610963Sdavid.hashe@amd.com            else:
19710963Sdavid.hashe@amd.com                in_msg_bufs[buf_name].append(port)
19810963Sdavid.hashe@amd.com        return port_to_buf_map, in_msg_bufs, msg_bufs
19910963Sdavid.hashe@amd.com
2009219Spower.jg@gmail.com    def writeCodeFiles(self, path, includes):
2016877Ssteve.reinhardt@amd.com        self.printControllerPython(path)
2026657Snate@binkert.org        self.printControllerHH(path)
2039219Spower.jg@gmail.com        self.printControllerCC(path, includes)
2046657Snate@binkert.org        self.printCSwitch(path)
2059219Spower.jg@gmail.com        self.printCWakeup(path, includes)
2066657Snate@binkert.org
2076877Ssteve.reinhardt@amd.com    def printControllerPython(self, path):
2086999Snate@binkert.org        code = self.symtab.codeFormatter()
2096877Ssteve.reinhardt@amd.com        ident = self.ident
21010308Snilay@cs.wisc.edu
2116877Ssteve.reinhardt@amd.com        py_ident = "%s_Controller" % ident
2126877Ssteve.reinhardt@amd.com        c_ident = "%s_Controller" % self.ident
21310308Snilay@cs.wisc.edu
2146877Ssteve.reinhardt@amd.com        code('''
2156877Ssteve.reinhardt@amd.comfrom m5.params import *
2166877Ssteve.reinhardt@amd.comfrom m5.SimObject import SimObject
2176877Ssteve.reinhardt@amd.comfrom Controller import RubyController
2186877Ssteve.reinhardt@amd.com
2196877Ssteve.reinhardt@amd.comclass $py_ident(RubyController):
2206877Ssteve.reinhardt@amd.com    type = '$py_ident'
2219338SAndreas.Sandberg@arm.com    cxx_header = 'mem/protocol/${c_ident}.hh'
2226877Ssteve.reinhardt@amd.com''')
2236877Ssteve.reinhardt@amd.com        code.indent()
2246877Ssteve.reinhardt@amd.com        for param in self.config_parameters:
2256877Ssteve.reinhardt@amd.com            dflt_str = ''
22610308Snilay@cs.wisc.edu
22710308Snilay@cs.wisc.edu            if param.rvalue is not None:
22810308Snilay@cs.wisc.edu                dflt_str = str(param.rvalue.inline()) + ', '
22910308Snilay@cs.wisc.edu
23010311Snilay@cs.wisc.edu            if param.type_ast.type.c_ident == "MessageBuffer":
23110311Snilay@cs.wisc.edu                if param["network"] == "To":
23210311Snilay@cs.wisc.edu                    code('${{param.ident}} = MasterPort(${dflt_str}"")')
23310311Snilay@cs.wisc.edu                else:
23410311Snilay@cs.wisc.edu                    code('${{param.ident}} = SlavePort(${dflt_str}"")')
23510311Snilay@cs.wisc.edu
23610311Snilay@cs.wisc.edu            elif python_class_map.has_key(param.type_ast.type.c_ident):
2376882SBrad.Beckmann@amd.com                python_type = python_class_map[param.type_ast.type.c_ident]
23810308Snilay@cs.wisc.edu                code('${{param.ident}} = Param.${{python_type}}(${dflt_str}"")')
23910308Snilay@cs.wisc.edu
2406882SBrad.Beckmann@amd.com            else:
2416882SBrad.Beckmann@amd.com                self.error("Unknown c++ to python class conversion for c++ " \
2426882SBrad.Beckmann@amd.com                           "type: '%s'. Please update the python_class_map " \
2436882SBrad.Beckmann@amd.com                           "in StateMachine.py", param.type_ast.type.c_ident)
2446877Ssteve.reinhardt@amd.com        code.dedent()
2456877Ssteve.reinhardt@amd.com        code.write(path, '%s.py' % py_ident)
24610917Sbrandon.potter@amd.com
2476877Ssteve.reinhardt@amd.com
2486657Snate@binkert.org    def printControllerHH(self, path):
2496657Snate@binkert.org        '''Output the method declarations for the class declaration'''
2506999Snate@binkert.org        code = self.symtab.codeFormatter()
2516657Snate@binkert.org        ident = self.ident
2526657Snate@binkert.org        c_ident = "%s_Controller" % self.ident
2536657Snate@binkert.org
2546657Snate@binkert.org        code('''
2557007Snate@binkert.org/** \\file $c_ident.hh
2566657Snate@binkert.org *
2576657Snate@binkert.org * Auto generated C++ code started by $__file__:$__line__
2586657Snate@binkert.org * Created by slicc definition of Module "${{self.short}}"
2596657Snate@binkert.org */
2606657Snate@binkert.org
2617007Snate@binkert.org#ifndef __${ident}_CONTROLLER_HH__
2627007Snate@binkert.org#define __${ident}_CONTROLLER_HH__
2636657Snate@binkert.org
2647002Snate@binkert.org#include <iostream>
2657002Snate@binkert.org#include <sstream>
2667002Snate@binkert.org#include <string>
2677002Snate@binkert.org
2686657Snate@binkert.org#include "mem/protocol/TransitionResult.hh"
2696657Snate@binkert.org#include "mem/protocol/Types.hh"
2708229Snate@binkert.org#include "mem/ruby/common/Consumer.hh"
2718229Snate@binkert.org#include "mem/ruby/slicc_interface/AbstractController.hh"
2728229Snate@binkert.org#include "params/$c_ident.hh"
2736657Snate@binkert.org''')
2746657Snate@binkert.org
2756657Snate@binkert.org        seen_types = set()
2766657Snate@binkert.org        for var in self.objects:
2776793SBrad.Beckmann@amd.com            if var.type.ident not in seen_types and not var.type.isPrimitive:
2786657Snate@binkert.org                code('#include "mem/protocol/${{var.type.c_ident}}.hh"')
27910311Snilay@cs.wisc.edu                seen_types.add(var.type.ident)
2806657Snate@binkert.org
2816657Snate@binkert.org        # for adding information to the protocol debug trace
2826657Snate@binkert.org        code('''
2837002Snate@binkert.orgextern std::stringstream ${ident}_transitionComment;
2846657Snate@binkert.org
2857007Snate@binkert.orgclass $c_ident : public AbstractController
2867007Snate@binkert.org{
2879271Snilay@cs.wisc.edu  public:
2886877Ssteve.reinhardt@amd.com    typedef ${c_ident}Params Params;
2896877Ssteve.reinhardt@amd.com    $c_ident(const Params *p);
2906657Snate@binkert.org    static int getNumControllers();
2916877Ssteve.reinhardt@amd.com    void init();
29210311Snilay@cs.wisc.edu
2936657Snate@binkert.org    MessageBuffer* getMandatoryQueue() const;
29410311Snilay@cs.wisc.edu    void setNetQueue(const std::string& name, MessageBuffer *b);
2959745Snilay@cs.wisc.edu
2967002Snate@binkert.org    void print(std::ostream& out) const;
2976657Snate@binkert.org    void wakeup();
29810012Snilay@cs.wisc.edu    void resetStats();
2999745Snilay@cs.wisc.edu    void regStats();
3009745Snilay@cs.wisc.edu    void collateStats();
3019745Snilay@cs.wisc.edu
3028683Snilay@cs.wisc.edu    void recordCacheTrace(int cntrl, CacheRecorder* tr);
3038683Snilay@cs.wisc.edu    Sequencer* getSequencer() const;
3047007Snate@binkert.org
30510524Snilay@cs.wisc.edu    int functionalWriteBuffers(PacketPtr&);
3069302Snilay@cs.wisc.edu
3079745Snilay@cs.wisc.edu    void countTransition(${ident}_State state, ${ident}_Event event);
3089745Snilay@cs.wisc.edu    void possibleTransition(${ident}_State state, ${ident}_Event event);
3099745Snilay@cs.wisc.edu    uint64 getEventCount(${ident}_Event event);
3109745Snilay@cs.wisc.edu    bool isPossible(${ident}_State state, ${ident}_Event event);
3119745Snilay@cs.wisc.edu    uint64 getTransitionCount(${ident}_State state, ${ident}_Event event);
3129745Snilay@cs.wisc.edu
3136657Snate@binkert.orgprivate:
3146657Snate@binkert.org''')
3156657Snate@binkert.org
3166657Snate@binkert.org        code.indent()
3176657Snate@binkert.org        # added by SS
3186657Snate@binkert.org        for param in self.config_parameters:
3196882SBrad.Beckmann@amd.com            if param.pointer:
3206882SBrad.Beckmann@amd.com                code('${{param.type_ast.type}}* m_${{param.ident}}_ptr;')
3216882SBrad.Beckmann@amd.com            else:
3226882SBrad.Beckmann@amd.com                code('${{param.type_ast.type}} m_${{param.ident}};')
3236657Snate@binkert.org
3246657Snate@binkert.org        code('''
3257007Snate@binkert.orgTransitionResult doTransition(${ident}_Event event,
3267839Snilay@cs.wisc.edu''')
3277839Snilay@cs.wisc.edu
3287839Snilay@cs.wisc.edu        if self.EntryType != None:
3297839Snilay@cs.wisc.edu            code('''
3307839Snilay@cs.wisc.edu                              ${{self.EntryType.c_ident}}* m_cache_entry_ptr,
3317839Snilay@cs.wisc.edu''')
3327839Snilay@cs.wisc.edu        if self.TBEType != None:
3337839Snilay@cs.wisc.edu            code('''
3347839Snilay@cs.wisc.edu                              ${{self.TBEType.c_ident}}* m_tbe_ptr,
3357839Snilay@cs.wisc.edu''')
3367839Snilay@cs.wisc.edu
3377839Snilay@cs.wisc.edu        code('''
33810010Snilay@cs.wisc.edu                              const Address addr);
3397007Snate@binkert.org
3407007Snate@binkert.orgTransitionResult doTransitionWorker(${ident}_Event event,
3417007Snate@binkert.org                                    ${ident}_State state,
3427007Snate@binkert.org                                    ${ident}_State& next_state,
3437839Snilay@cs.wisc.edu''')
3447839Snilay@cs.wisc.edu
3457839Snilay@cs.wisc.edu        if self.TBEType != None:
3467839Snilay@cs.wisc.edu            code('''
3477839Snilay@cs.wisc.edu                                    ${{self.TBEType.c_ident}}*& m_tbe_ptr,
3487839Snilay@cs.wisc.edu''')
3497839Snilay@cs.wisc.edu        if self.EntryType != None:
3507839Snilay@cs.wisc.edu            code('''
3517839Snilay@cs.wisc.edu                                    ${{self.EntryType.c_ident}}*& m_cache_entry_ptr,
3527839Snilay@cs.wisc.edu''')
3537839Snilay@cs.wisc.edu
3547839Snilay@cs.wisc.edu        code('''
3557007Snate@binkert.org                                    const Address& addr);
3567007Snate@binkert.org
3579745Snilay@cs.wisc.eduint m_counters[${ident}_State_NUM][${ident}_Event_NUM];
3589745Snilay@cs.wisc.eduint m_event_counters[${ident}_Event_NUM];
3599745Snilay@cs.wisc.edubool m_possible[${ident}_State_NUM][${ident}_Event_NUM];
3609745Snilay@cs.wisc.edu
3619745Snilay@cs.wisc.edustatic std::vector<Stats::Vector *> eventVec;
3629745Snilay@cs.wisc.edustatic std::vector<std::vector<Stats::Vector *> > transVec;
3636657Snate@binkert.orgstatic int m_num_controllers;
3647007Snate@binkert.org
3656657Snate@binkert.org// Internal functions
3666657Snate@binkert.org''')
3676657Snate@binkert.org
3686657Snate@binkert.org        for func in self.functions:
3696657Snate@binkert.org            proto = func.prototype
3706657Snate@binkert.org            if proto:
3716657Snate@binkert.org                code('$proto')
3726657Snate@binkert.org
3737839Snilay@cs.wisc.edu        if self.EntryType != None:
3747839Snilay@cs.wisc.edu            code('''
3757839Snilay@cs.wisc.edu
3767839Snilay@cs.wisc.edu// Set and Reset for cache_entry variable
3777839Snilay@cs.wisc.eduvoid set_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, AbstractCacheEntry* m_new_cache_entry);
3787839Snilay@cs.wisc.eduvoid unset_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr);
3797839Snilay@cs.wisc.edu''')
3807839Snilay@cs.wisc.edu
3817839Snilay@cs.wisc.edu        if self.TBEType != None:
3827839Snilay@cs.wisc.edu            code('''
3837839Snilay@cs.wisc.edu
3847839Snilay@cs.wisc.edu// Set and Reset for tbe variable
3857839Snilay@cs.wisc.eduvoid set_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr, ${ident}_TBE* m_new_tbe);
3867839Snilay@cs.wisc.eduvoid unset_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr);
3877839Snilay@cs.wisc.edu''')
3887839Snilay@cs.wisc.edu
38910121Snilay@cs.wisc.edu        # Prototype the actions that the controller can take
3906657Snate@binkert.org        code('''
3916657Snate@binkert.org
3926657Snate@binkert.org// Actions
3936657Snate@binkert.org''')
3947839Snilay@cs.wisc.edu        if self.TBEType != None and self.EntryType != None:
3957839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
3967839Snilay@cs.wisc.edu                code('/** \\brief ${{action.desc}} */')
39710121Snilay@cs.wisc.edu                code('void ${{action.ident}}(${{self.TBEType.c_ident}}*& '
39810121Snilay@cs.wisc.edu                     'm_tbe_ptr, ${{self.EntryType.c_ident}}*& '
39910121Snilay@cs.wisc.edu                     'm_cache_entry_ptr, const Address& addr);')
4007839Snilay@cs.wisc.edu        elif self.TBEType != None:
4017839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
4027839Snilay@cs.wisc.edu                code('/** \\brief ${{action.desc}} */')
40310121Snilay@cs.wisc.edu                code('void ${{action.ident}}(${{self.TBEType.c_ident}}*& '
40410121Snilay@cs.wisc.edu                     'm_tbe_ptr, const Address& addr);')
4057839Snilay@cs.wisc.edu        elif self.EntryType != None:
4067839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
4077839Snilay@cs.wisc.edu                code('/** \\brief ${{action.desc}} */')
40810121Snilay@cs.wisc.edu                code('void ${{action.ident}}(${{self.EntryType.c_ident}}*& '
40910121Snilay@cs.wisc.edu                     'm_cache_entry_ptr, const Address& addr);')
4107839Snilay@cs.wisc.edu        else:
4117839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
4127839Snilay@cs.wisc.edu                code('/** \\brief ${{action.desc}} */')
4137839Snilay@cs.wisc.edu                code('void ${{action.ident}}(const Address& addr);')
4146657Snate@binkert.org
4156657Snate@binkert.org        # the controller internal variables
4166657Snate@binkert.org        code('''
4176657Snate@binkert.org
4187007Snate@binkert.org// Objects
4196657Snate@binkert.org''')
4206657Snate@binkert.org        for var in self.objects:
4219273Snilay@cs.wisc.edu            th = var.get("template", "")
42210305Snilay@cs.wisc.edu            code('${{var.type.c_ident}}$th* m_${{var.ident}}_ptr;')
4236657Snate@binkert.org
4246657Snate@binkert.org        code.dedent()
4256657Snate@binkert.org        code('};')
4267007Snate@binkert.org        code('#endif // __${ident}_CONTROLLER_H__')
4276657Snate@binkert.org        code.write(path, '%s.hh' % c_ident)
4286657Snate@binkert.org
4299219Spower.jg@gmail.com    def printControllerCC(self, path, includes):
4306657Snate@binkert.org        '''Output the actions for performing the actions'''
4316657Snate@binkert.org
4326999Snate@binkert.org        code = self.symtab.codeFormatter()
4336657Snate@binkert.org        ident = self.ident
4346657Snate@binkert.org        c_ident = "%s_Controller" % self.ident
4356657Snate@binkert.org
4366657Snate@binkert.org        code('''
4377007Snate@binkert.org/** \\file $c_ident.cc
4386657Snate@binkert.org *
4396657Snate@binkert.org * Auto generated C++ code started by $__file__:$__line__
4406657Snate@binkert.org * Created by slicc definition of Module "${{self.short}}"
4416657Snate@binkert.org */
4426657Snate@binkert.org
4438946Sandreas.hansson@arm.com#include <sys/types.h>
44410963Sdavid.hashe@amd.com#include <typeinfo>
4458946Sandreas.hansson@arm.com#include <unistd.h>
4468946Sandreas.hansson@arm.com
4477832Snate@binkert.org#include <cassert>
4487002Snate@binkert.org#include <sstream>
4497002Snate@binkert.org#include <string>
4507002Snate@binkert.org
4518641Snate@binkert.org#include "base/compiler.hh"
4527056Snate@binkert.org#include "base/cprintf.hh"
4538232Snate@binkert.org#include "debug/RubyGenerated.hh"
4548232Snate@binkert.org#include "debug/RubySlicc.hh"
4556657Snate@binkert.org#include "mem/protocol/${ident}_Controller.hh"
4568229Snate@binkert.org#include "mem/protocol/${ident}_Event.hh"
4576657Snate@binkert.org#include "mem/protocol/${ident}_State.hh"
4586657Snate@binkert.org#include "mem/protocol/Types.hh"
4596657Snate@binkert.org#include "mem/ruby/system/System.hh"
4609219Spower.jg@gmail.com''')
4619219Spower.jg@gmail.com        for include_path in includes:
4629219Spower.jg@gmail.com            code('#include "${{include_path}}"')
4639219Spower.jg@gmail.com
4649219Spower.jg@gmail.com        code('''
4657002Snate@binkert.org
4667002Snate@binkert.orgusing namespace std;
4676657Snate@binkert.org''')
4686657Snate@binkert.org
4696657Snate@binkert.org        # include object classes
4706657Snate@binkert.org        seen_types = set()
4716657Snate@binkert.org        for var in self.objects:
4726793SBrad.Beckmann@amd.com            if var.type.ident not in seen_types and not var.type.isPrimitive:
4736657Snate@binkert.org                code('#include "mem/protocol/${{var.type.c_ident}}.hh"')
4746657Snate@binkert.org            seen_types.add(var.type.ident)
4756657Snate@binkert.org
47610121Snilay@cs.wisc.edu        num_in_ports = len(self.in_ports)
47710121Snilay@cs.wisc.edu
4786657Snate@binkert.org        code('''
4796877Ssteve.reinhardt@amd.com$c_ident *
4806877Ssteve.reinhardt@amd.com${c_ident}Params::create()
4816877Ssteve.reinhardt@amd.com{
4826877Ssteve.reinhardt@amd.com    return new $c_ident(this);
4836877Ssteve.reinhardt@amd.com}
4846877Ssteve.reinhardt@amd.com
4856657Snate@binkert.orgint $c_ident::m_num_controllers = 0;
4869745Snilay@cs.wisc.edustd::vector<Stats::Vector *>  $c_ident::eventVec;
4879745Snilay@cs.wisc.edustd::vector<std::vector<Stats::Vector *> >  $c_ident::transVec;
4886657Snate@binkert.org
4897007Snate@binkert.org// for adding information to the protocol debug trace
4906657Snate@binkert.orgstringstream ${ident}_transitionComment;
4919801Snilay@cs.wisc.edu
4929801Snilay@cs.wisc.edu#ifndef NDEBUG
4936657Snate@binkert.org#define APPEND_TRANSITION_COMMENT(str) (${ident}_transitionComment << str)
4949801Snilay@cs.wisc.edu#else
4959801Snilay@cs.wisc.edu#define APPEND_TRANSITION_COMMENT(str) do {} while (0)
4969801Snilay@cs.wisc.edu#endif
4977007Snate@binkert.org
4986657Snate@binkert.org/** \\brief constructor */
4996877Ssteve.reinhardt@amd.com$c_ident::$c_ident(const Params *p)
5006877Ssteve.reinhardt@amd.com    : AbstractController(p)
5016657Snate@binkert.org{
50210078Snilay@cs.wisc.edu    m_machineID.type = MachineType_${ident};
50310078Snilay@cs.wisc.edu    m_machineID.num = m_version;
50410121Snilay@cs.wisc.edu    m_num_controllers++;
50510121Snilay@cs.wisc.edu
50610121Snilay@cs.wisc.edu    m_in_ports = $num_in_ports;
5076657Snate@binkert.org''')
5086657Snate@binkert.org        code.indent()
5096882SBrad.Beckmann@amd.com
5106882SBrad.Beckmann@amd.com        #
5116882SBrad.Beckmann@amd.com        # After initializing the universal machine parameters, initialize the
51210121Snilay@cs.wisc.edu        # this machines config parameters.  Also if these configuration params
51310121Snilay@cs.wisc.edu        # include a sequencer, connect the it to the controller.
5146882SBrad.Beckmann@amd.com        #
5156877Ssteve.reinhardt@amd.com        for param in self.config_parameters:
51610311Snilay@cs.wisc.edu
51710311Snilay@cs.wisc.edu            # Do not initialize messgage buffers since they are initialized
51810311Snilay@cs.wisc.edu            # when the port based connections are made.
51910311Snilay@cs.wisc.edu            if param.type_ast.type.c_ident == "MessageBuffer":
52010311Snilay@cs.wisc.edu                continue
52110311Snilay@cs.wisc.edu
5226882SBrad.Beckmann@amd.com            if param.pointer:
52310308Snilay@cs.wisc.edu                code('m_${{param.ident}}_ptr = p->${{param.ident}};')
5246882SBrad.Beckmann@amd.com            else:
52510308Snilay@cs.wisc.edu                code('m_${{param.ident}} = p->${{param.ident}};')
52610311Snilay@cs.wisc.edu
52710308Snilay@cs.wisc.edu            if re.compile("sequencer").search(param.ident):
52810308Snilay@cs.wisc.edu                code('m_${{param.ident}}_ptr->setController(this);')
52910917Sbrandon.potter@amd.com
5306657Snate@binkert.org        for var in self.objects:
5316657Snate@binkert.org            if var.ident.find("mandatoryQueue") >= 0:
5329508Snilay@cs.wisc.edu                code('''
53310305Snilay@cs.wisc.edum_${{var.ident}}_ptr = new ${{var.type.c_ident}}();
53410305Snilay@cs.wisc.edum_${{var.ident}}_ptr->setReceiver(this);
5359508Snilay@cs.wisc.edu''')
5366657Snate@binkert.org
5379595Snilay@cs.wisc.edu        code('''
5389745Snilay@cs.wisc.edu
5399745Snilay@cs.wisc.edufor (int state = 0; state < ${ident}_State_NUM; state++) {
5409745Snilay@cs.wisc.edu    for (int event = 0; event < ${ident}_Event_NUM; event++) {
5419745Snilay@cs.wisc.edu        m_possible[state][event] = false;
5429745Snilay@cs.wisc.edu        m_counters[state][event] = 0;
5439745Snilay@cs.wisc.edu    }
5449745Snilay@cs.wisc.edu}
5459745Snilay@cs.wisc.edufor (int event = 0; event < ${ident}_Event_NUM; event++) {
5469745Snilay@cs.wisc.edu    m_event_counters[event] = 0;
5479745Snilay@cs.wisc.edu}
5489595Snilay@cs.wisc.edu''')
5496657Snate@binkert.org        code.dedent()
5506657Snate@binkert.org        code('''
5516657Snate@binkert.org}
5526657Snate@binkert.org
5537007Snate@binkert.orgvoid
55410311Snilay@cs.wisc.edu$c_ident::setNetQueue(const std::string& name, MessageBuffer *b)
55510311Snilay@cs.wisc.edu{
55610311Snilay@cs.wisc.edu    MachineType machine_type = string_to_MachineType("${{self.ident}}");
55710311Snilay@cs.wisc.edu    int base M5_VAR_USED = MachineType_base_number(machine_type);
55810311Snilay@cs.wisc.edu
55910311Snilay@cs.wisc.edu''')
56010311Snilay@cs.wisc.edu        code.indent()
56110311Snilay@cs.wisc.edu
56210311Snilay@cs.wisc.edu        # set for maintaining the vnet, direction pairs already seen for this
56310311Snilay@cs.wisc.edu        # machine.  This map helps in implementing the check for avoiding
56410311Snilay@cs.wisc.edu        # multiple message buffers being mapped to the same vnet.
56510311Snilay@cs.wisc.edu        vnet_dir_set = set()
56610311Snilay@cs.wisc.edu
56710311Snilay@cs.wisc.edu        for var in self.config_parameters:
56810311Snilay@cs.wisc.edu            if "network" in var:
56910311Snilay@cs.wisc.edu                vtype = var.type_ast.type
57010311Snilay@cs.wisc.edu                vid = "m_%s_ptr" % var.ident
57110311Snilay@cs.wisc.edu
57210311Snilay@cs.wisc.edu                code('''
57310311Snilay@cs.wisc.eduif ("${{var.ident}}" == name) {
57410311Snilay@cs.wisc.edu    $vid = b;
57510311Snilay@cs.wisc.edu    assert($vid != NULL);
57610311Snilay@cs.wisc.edu''')
57710311Snilay@cs.wisc.edu                code.indent()
57810311Snilay@cs.wisc.edu                # Network port object
57910311Snilay@cs.wisc.edu                network = var["network"]
58010311Snilay@cs.wisc.edu                ordered =  var["ordered"]
58110311Snilay@cs.wisc.edu
58210311Snilay@cs.wisc.edu                if "virtual_network" in var:
58310311Snilay@cs.wisc.edu                    vnet = var["virtual_network"]
58410311Snilay@cs.wisc.edu                    vnet_type = var["vnet_type"]
58510311Snilay@cs.wisc.edu
58610311Snilay@cs.wisc.edu                    assert (vnet, network) not in vnet_dir_set
58710311Snilay@cs.wisc.edu                    vnet_dir_set.add((vnet,network))
58810311Snilay@cs.wisc.edu
58910311Snilay@cs.wisc.edu                    code('''
59010311Snilay@cs.wisc.edum_net_ptr->set${network}NetQueue(m_version + base, $ordered, $vnet,
59110311Snilay@cs.wisc.edu                                 "$vnet_type", b);
59210311Snilay@cs.wisc.edu''')
59310311Snilay@cs.wisc.edu                # Set the end
59410311Snilay@cs.wisc.edu                if network == "To":
59510311Snilay@cs.wisc.edu                    code('$vid->setSender(this);')
59610311Snilay@cs.wisc.edu                else:
59710311Snilay@cs.wisc.edu                    code('$vid->setReceiver(this);')
59810311Snilay@cs.wisc.edu
59910311Snilay@cs.wisc.edu                # Set ordering
60010311Snilay@cs.wisc.edu                code('$vid->setOrdering(${{var["ordered"]}});')
60110311Snilay@cs.wisc.edu
60210311Snilay@cs.wisc.edu                # Set randomization
60310311Snilay@cs.wisc.edu                if "random" in var:
60410311Snilay@cs.wisc.edu                    # A buffer
60510311Snilay@cs.wisc.edu                    code('$vid->setRandomization(${{var["random"]}});')
60610311Snilay@cs.wisc.edu
60710311Snilay@cs.wisc.edu                # Set Priority
60810311Snilay@cs.wisc.edu                if "rank" in var:
60910311Snilay@cs.wisc.edu                    code('$vid->setPriority(${{var["rank"]}})')
61010311Snilay@cs.wisc.edu
61110311Snilay@cs.wisc.edu                # Set buffer size
61210311Snilay@cs.wisc.edu                code('$vid->resize(m_buffer_size);')
61310311Snilay@cs.wisc.edu
61410311Snilay@cs.wisc.edu                if "recycle_latency" in var:
61510311Snilay@cs.wisc.edu                    code('$vid->setRecycleLatency( ' \
61610311Snilay@cs.wisc.edu                         'Cycles(${{var["recycle_latency"]}}));')
61710311Snilay@cs.wisc.edu                else:
61810311Snilay@cs.wisc.edu                    code('$vid->setRecycleLatency(m_recycle_latency);')
61910311Snilay@cs.wisc.edu
62010311Snilay@cs.wisc.edu                # set description (may be overriden later by port def)
62110311Snilay@cs.wisc.edu                code('''
62210311Snilay@cs.wisc.edu$vid->setDescription("[Version " + to_string(m_version) + ", ${ident}, name=${{var.ident}}]");
62310311Snilay@cs.wisc.edu''')
62410311Snilay@cs.wisc.edu                code.dedent()
62510311Snilay@cs.wisc.edu                code('}\n')
62610311Snilay@cs.wisc.edu
62710311Snilay@cs.wisc.edu        code.dedent()
62810311Snilay@cs.wisc.edu        code('''
62910311Snilay@cs.wisc.edu}
63010311Snilay@cs.wisc.edu
63110311Snilay@cs.wisc.eduvoid
6327007Snate@binkert.org$c_ident::init()
6336657Snate@binkert.org{
6347007Snate@binkert.org    // initialize objects
6357007Snate@binkert.org
6366657Snate@binkert.org''')
6376657Snate@binkert.org
6386657Snate@binkert.org        code.indent()
63910311Snilay@cs.wisc.edu
6406657Snate@binkert.org        for var in self.objects:
6416657Snate@binkert.org            vtype = var.type
64210305Snilay@cs.wisc.edu            vid = "m_%s_ptr" % var.ident
6436657Snate@binkert.org            if "network" not in var:
6446657Snate@binkert.org                # Not a network port object
6456657Snate@binkert.org                if "primitive" in vtype:
6466657Snate@binkert.org                    code('$vid = new ${{vtype.c_ident}};')
6476657Snate@binkert.org                    if "default" in var:
6486657Snate@binkert.org                        code('(*$vid) = ${{var["default"]}};')
6496657Snate@binkert.org                else:
6506657Snate@binkert.org                    # Normal Object
6519595Snilay@cs.wisc.edu                    if var.ident.find("mandatoryQueue") < 0:
6529273Snilay@cs.wisc.edu                        th = var.get("template", "")
6536657Snate@binkert.org                        expr = "%s  = new %s%s" % (vid, vtype.c_ident, th)
6546657Snate@binkert.org                        args = ""
6556657Snate@binkert.org                        if "non_obj" not in vtype and not vtype.isEnumeration:
6569364Snilay@cs.wisc.edu                            args = var.get("constructor", "")
6577007Snate@binkert.org                        code('$expr($args);')
6586657Snate@binkert.org
6596657Snate@binkert.org                    code('assert($vid != NULL);')
6606657Snate@binkert.org
6616657Snate@binkert.org                    if "default" in var:
6627007Snate@binkert.org                        code('*$vid = ${{var["default"]}}; // Object default')
6636657Snate@binkert.org                    elif "default" in vtype:
6647007Snate@binkert.org                        comment = "Type %s default" % vtype.ident
6657007Snate@binkert.org                        code('*$vid = ${{vtype["default"]}}; // $comment')
6666657Snate@binkert.org
6676657Snate@binkert.org                    # Set ordering
6689508Snilay@cs.wisc.edu                    if "ordered" in var:
6696657Snate@binkert.org                        # A buffer
6706657Snate@binkert.org                        code('$vid->setOrdering(${{var["ordered"]}});')
6716657Snate@binkert.org
6726657Snate@binkert.org                    # Set randomization
6736657Snate@binkert.org                    if "random" in var:
6746657Snate@binkert.org                        # A buffer
6756657Snate@binkert.org                        code('$vid->setRandomization(${{var["random"]}});')
6766657Snate@binkert.org
6776657Snate@binkert.org                    # Set Priority
6789508Snilay@cs.wisc.edu                    if vtype.isBuffer and "rank" in var:
6796657Snate@binkert.org                        code('$vid->setPriority(${{var["rank"]}});')
6807566SBrad.Beckmann@amd.com
6819508Snilay@cs.wisc.edu                    # Set sender and receiver for trigger queue
6829508Snilay@cs.wisc.edu                    if var.ident.find("triggerQueue") >= 0:
6839508Snilay@cs.wisc.edu                        code('$vid->setSender(this);')
6849508Snilay@cs.wisc.edu                        code('$vid->setReceiver(this);')
6859508Snilay@cs.wisc.edu                    elif vtype.c_ident == "TimerTable":
6869508Snilay@cs.wisc.edu                        code('$vid->setClockObj(this);')
6879604Snilay@cs.wisc.edu                    elif var.ident.find("optionalQueue") >= 0:
6889604Snilay@cs.wisc.edu                        code('$vid->setSender(this);')
6899604Snilay@cs.wisc.edu                        code('$vid->setReceiver(this);')
6909508Snilay@cs.wisc.edu
6917566SBrad.Beckmann@amd.com            if vtype.isBuffer:
6927566SBrad.Beckmann@amd.com                if "recycle_latency" in var:
6939499Snilay@cs.wisc.edu                    code('$vid->setRecycleLatency( ' \
6949499Snilay@cs.wisc.edu                         'Cycles(${{var["recycle_latency"]}}));')
6957566SBrad.Beckmann@amd.com                else:
6967566SBrad.Beckmann@amd.com                    code('$vid->setRecycleLatency(m_recycle_latency);')
6977566SBrad.Beckmann@amd.com
6989366Snilay@cs.wisc.edu        # Set the prefetchers
6999366Snilay@cs.wisc.edu        code()
7009366Snilay@cs.wisc.edu        for prefetcher in self.prefetchers:
7019366Snilay@cs.wisc.edu            code('${{prefetcher.code}}.setController(this);')
7027566SBrad.Beckmann@amd.com
7037672Snate@binkert.org        code()
7046657Snate@binkert.org        for port in self.in_ports:
7059465Snilay@cs.wisc.edu            # Set the queue consumers
7066657Snate@binkert.org            code('${{port.code}}.setConsumer(this);')
7079465Snilay@cs.wisc.edu            # Set the queue descriptions
7087056Snate@binkert.org            code('${{port.code}}.setDescription("[Version " + to_string(m_version) + ", $ident, $port]");')
7096657Snate@binkert.org
7106657Snate@binkert.org        # Initialize the transition profiling
7117672Snate@binkert.org        code()
7126657Snate@binkert.org        for trans in self.transitions:
7136657Snate@binkert.org            # Figure out if we stall
7146657Snate@binkert.org            stall = False
7156657Snate@binkert.org            for action in trans.actions:
7166657Snate@binkert.org                if action.ident == "z_stall":
7176657Snate@binkert.org                    stall = True
7186657Snate@binkert.org
7196657Snate@binkert.org            # Only possible if it is not a 'z' case
7206657Snate@binkert.org            if not stall:
7216657Snate@binkert.org                state = "%s_State_%s" % (self.ident, trans.state.ident)
7226657Snate@binkert.org                event = "%s_Event_%s" % (self.ident, trans.event.ident)
7239745Snilay@cs.wisc.edu                code('possibleTransition($state, $event);')
7246657Snate@binkert.org
7256657Snate@binkert.org        code.dedent()
7269496Snilay@cs.wisc.edu        code('''
7279496Snilay@cs.wisc.edu    AbstractController::init();
72810012Snilay@cs.wisc.edu    resetStats();
7299496Snilay@cs.wisc.edu}
7309496Snilay@cs.wisc.edu''')
7316657Snate@binkert.org
73210121Snilay@cs.wisc.edu        mq_ident = "NULL"
7336657Snate@binkert.org        for port in self.in_ports:
7346657Snate@binkert.org            if port.code.find("mandatoryQueue_ptr") >= 0:
73510305Snilay@cs.wisc.edu                mq_ident = "m_mandatoryQueue_ptr"
7366657Snate@binkert.org
7378683Snilay@cs.wisc.edu        seq_ident = "NULL"
7388683Snilay@cs.wisc.edu        for param in self.config_parameters:
73910308Snilay@cs.wisc.edu            if param.ident == "sequencer":
7408683Snilay@cs.wisc.edu                assert(param.pointer)
74110308Snilay@cs.wisc.edu                seq_ident = "m_%s_ptr" % param.ident
7428683Snilay@cs.wisc.edu
7436657Snate@binkert.org        code('''
7449745Snilay@cs.wisc.edu
7459745Snilay@cs.wisc.eduvoid
7469745Snilay@cs.wisc.edu$c_ident::regStats()
7479745Snilay@cs.wisc.edu{
74810012Snilay@cs.wisc.edu    AbstractController::regStats();
74910012Snilay@cs.wisc.edu
7509745Snilay@cs.wisc.edu    if (m_version == 0) {
7519745Snilay@cs.wisc.edu        for (${ident}_Event event = ${ident}_Event_FIRST;
7529745Snilay@cs.wisc.edu             event < ${ident}_Event_NUM; ++event) {
7539745Snilay@cs.wisc.edu            Stats::Vector *t = new Stats::Vector();
7549745Snilay@cs.wisc.edu            t->init(m_num_controllers);
75510919Sbrandon.potter@amd.com            t->name(params()->ruby_system->name() + ".${c_ident}." +
75610012Snilay@cs.wisc.edu                ${ident}_Event_to_string(event));
7579745Snilay@cs.wisc.edu            t->flags(Stats::pdf | Stats::total | Stats::oneline |
7589745Snilay@cs.wisc.edu                     Stats::nozero);
7599745Snilay@cs.wisc.edu
7609745Snilay@cs.wisc.edu            eventVec.push_back(t);
7619745Snilay@cs.wisc.edu        }
7629745Snilay@cs.wisc.edu
7639745Snilay@cs.wisc.edu        for (${ident}_State state = ${ident}_State_FIRST;
7649745Snilay@cs.wisc.edu             state < ${ident}_State_NUM; ++state) {
7659745Snilay@cs.wisc.edu
7669745Snilay@cs.wisc.edu            transVec.push_back(std::vector<Stats::Vector *>());
7679745Snilay@cs.wisc.edu
7689745Snilay@cs.wisc.edu            for (${ident}_Event event = ${ident}_Event_FIRST;
7699745Snilay@cs.wisc.edu                 event < ${ident}_Event_NUM; ++event) {
7709745Snilay@cs.wisc.edu
7719745Snilay@cs.wisc.edu                Stats::Vector *t = new Stats::Vector();
7729745Snilay@cs.wisc.edu                t->init(m_num_controllers);
77310919Sbrandon.potter@amd.com                t->name(params()->ruby_system->name() + ".${c_ident}." +
77410012Snilay@cs.wisc.edu                        ${ident}_State_to_string(state) +
7759745Snilay@cs.wisc.edu                        "." + ${ident}_Event_to_string(event));
7769745Snilay@cs.wisc.edu
7779745Snilay@cs.wisc.edu                t->flags(Stats::pdf | Stats::total | Stats::oneline |
7789745Snilay@cs.wisc.edu                         Stats::nozero);
7799745Snilay@cs.wisc.edu                transVec[state].push_back(t);
7809745Snilay@cs.wisc.edu            }
7819745Snilay@cs.wisc.edu        }
7829745Snilay@cs.wisc.edu    }
7839745Snilay@cs.wisc.edu}
7849745Snilay@cs.wisc.edu
7859745Snilay@cs.wisc.eduvoid
7869745Snilay@cs.wisc.edu$c_ident::collateStats()
7879745Snilay@cs.wisc.edu{
7889745Snilay@cs.wisc.edu    for (${ident}_Event event = ${ident}_Event_FIRST;
7899745Snilay@cs.wisc.edu         event < ${ident}_Event_NUM; ++event) {
7909745Snilay@cs.wisc.edu        for (unsigned int i = 0; i < m_num_controllers; ++i) {
79110920Sbrandon.potter@amd.com            RubySystem *rs = params()->ruby_system;
7929745Snilay@cs.wisc.edu            std::map<uint32_t, AbstractController *>::iterator it =
79310920Sbrandon.potter@amd.com                     rs->m_abstract_controls[MachineType_${ident}].find(i);
79410920Sbrandon.potter@amd.com            assert(it != rs->m_abstract_controls[MachineType_${ident}].end());
7959745Snilay@cs.wisc.edu            (*eventVec[event])[i] =
7969745Snilay@cs.wisc.edu                (($c_ident *)(*it).second)->getEventCount(event);
7979745Snilay@cs.wisc.edu        }
7989745Snilay@cs.wisc.edu    }
7999745Snilay@cs.wisc.edu
8009745Snilay@cs.wisc.edu    for (${ident}_State state = ${ident}_State_FIRST;
8019745Snilay@cs.wisc.edu         state < ${ident}_State_NUM; ++state) {
8029745Snilay@cs.wisc.edu
8039745Snilay@cs.wisc.edu        for (${ident}_Event event = ${ident}_Event_FIRST;
8049745Snilay@cs.wisc.edu             event < ${ident}_Event_NUM; ++event) {
8059745Snilay@cs.wisc.edu
8069745Snilay@cs.wisc.edu            for (unsigned int i = 0; i < m_num_controllers; ++i) {
80710920Sbrandon.potter@amd.com                RubySystem *rs = params()->ruby_system;
8089745Snilay@cs.wisc.edu                std::map<uint32_t, AbstractController *>::iterator it =
80910920Sbrandon.potter@amd.com                         rs->m_abstract_controls[MachineType_${ident}].find(i);
81010920Sbrandon.potter@amd.com                assert(it != rs->m_abstract_controls[MachineType_${ident}].end());
8119745Snilay@cs.wisc.edu                (*transVec[state][event])[i] =
8129745Snilay@cs.wisc.edu                    (($c_ident *)(*it).second)->getTransitionCount(state, event);
8139745Snilay@cs.wisc.edu            }
8149745Snilay@cs.wisc.edu        }
8159745Snilay@cs.wisc.edu    }
8169745Snilay@cs.wisc.edu}
8179745Snilay@cs.wisc.edu
8189745Snilay@cs.wisc.eduvoid
8199745Snilay@cs.wisc.edu$c_ident::countTransition(${ident}_State state, ${ident}_Event event)
8209745Snilay@cs.wisc.edu{
8219745Snilay@cs.wisc.edu    assert(m_possible[state][event]);
8229745Snilay@cs.wisc.edu    m_counters[state][event]++;
8239745Snilay@cs.wisc.edu    m_event_counters[event]++;
8249745Snilay@cs.wisc.edu}
8259745Snilay@cs.wisc.eduvoid
8269745Snilay@cs.wisc.edu$c_ident::possibleTransition(${ident}_State state,
8279745Snilay@cs.wisc.edu                             ${ident}_Event event)
8289745Snilay@cs.wisc.edu{
8299745Snilay@cs.wisc.edu    m_possible[state][event] = true;
8309745Snilay@cs.wisc.edu}
8319745Snilay@cs.wisc.edu
8329745Snilay@cs.wisc.eduuint64
8339745Snilay@cs.wisc.edu$c_ident::getEventCount(${ident}_Event event)
8349745Snilay@cs.wisc.edu{
8359745Snilay@cs.wisc.edu    return m_event_counters[event];
8369745Snilay@cs.wisc.edu}
8379745Snilay@cs.wisc.edu
8389745Snilay@cs.wisc.edubool
8399745Snilay@cs.wisc.edu$c_ident::isPossible(${ident}_State state, ${ident}_Event event)
8409745Snilay@cs.wisc.edu{
8419745Snilay@cs.wisc.edu    return m_possible[state][event];
8429745Snilay@cs.wisc.edu}
8439745Snilay@cs.wisc.edu
8449745Snilay@cs.wisc.eduuint64
8459745Snilay@cs.wisc.edu$c_ident::getTransitionCount(${ident}_State state,
8469745Snilay@cs.wisc.edu                             ${ident}_Event event)
8479745Snilay@cs.wisc.edu{
8489745Snilay@cs.wisc.edu    return m_counters[state][event];
8499745Snilay@cs.wisc.edu}
8509745Snilay@cs.wisc.edu
8517007Snate@binkert.orgint
8527007Snate@binkert.org$c_ident::getNumControllers()
8537007Snate@binkert.org{
8546657Snate@binkert.org    return m_num_controllers;
8556657Snate@binkert.org}
8566657Snate@binkert.org
8577007Snate@binkert.orgMessageBuffer*
8587007Snate@binkert.org$c_ident::getMandatoryQueue() const
8597007Snate@binkert.org{
8606657Snate@binkert.org    return $mq_ident;
8616657Snate@binkert.org}
8626657Snate@binkert.org
8638683Snilay@cs.wisc.eduSequencer*
8648683Snilay@cs.wisc.edu$c_ident::getSequencer() const
8658683Snilay@cs.wisc.edu{
8668683Snilay@cs.wisc.edu    return $seq_ident;
8678683Snilay@cs.wisc.edu}
8688683Snilay@cs.wisc.edu
8697007Snate@binkert.orgvoid
8707007Snate@binkert.org$c_ident::print(ostream& out) const
8717007Snate@binkert.org{
8727007Snate@binkert.org    out << "[$c_ident " << m_version << "]";
8737007Snate@binkert.org}
8746657Snate@binkert.org
87510012Snilay@cs.wisc.eduvoid $c_ident::resetStats()
8769745Snilay@cs.wisc.edu{
8779745Snilay@cs.wisc.edu    for (int state = 0; state < ${ident}_State_NUM; state++) {
8789745Snilay@cs.wisc.edu        for (int event = 0; event < ${ident}_Event_NUM; event++) {
8799745Snilay@cs.wisc.edu            m_counters[state][event] = 0;
8809745Snilay@cs.wisc.edu        }
8819745Snilay@cs.wisc.edu    }
8826902SBrad.Beckmann@amd.com
8839745Snilay@cs.wisc.edu    for (int event = 0; event < ${ident}_Event_NUM; event++) {
8849745Snilay@cs.wisc.edu        m_event_counters[event] = 0;
8859745Snilay@cs.wisc.edu    }
8869745Snilay@cs.wisc.edu
88710012Snilay@cs.wisc.edu    AbstractController::resetStats();
8886902SBrad.Beckmann@amd.com}
8897839Snilay@cs.wisc.edu''')
8907839Snilay@cs.wisc.edu
8917839Snilay@cs.wisc.edu        if self.EntryType != None:
8927839Snilay@cs.wisc.edu            code('''
8937839Snilay@cs.wisc.edu
8947839Snilay@cs.wisc.edu// Set and Reset for cache_entry variable
8957839Snilay@cs.wisc.eduvoid
8967839Snilay@cs.wisc.edu$c_ident::set_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, AbstractCacheEntry* m_new_cache_entry)
8977839Snilay@cs.wisc.edu{
8987839Snilay@cs.wisc.edu  m_cache_entry_ptr = (${{self.EntryType.c_ident}}*)m_new_cache_entry;
8997839Snilay@cs.wisc.edu}
9007839Snilay@cs.wisc.edu
9017839Snilay@cs.wisc.eduvoid
9027839Snilay@cs.wisc.edu$c_ident::unset_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr)
9037839Snilay@cs.wisc.edu{
9047839Snilay@cs.wisc.edu  m_cache_entry_ptr = 0;
9057839Snilay@cs.wisc.edu}
9067839Snilay@cs.wisc.edu''')
9077839Snilay@cs.wisc.edu
9087839Snilay@cs.wisc.edu        if self.TBEType != None:
9097839Snilay@cs.wisc.edu            code('''
9107839Snilay@cs.wisc.edu
9117839Snilay@cs.wisc.edu// Set and Reset for tbe variable
9127839Snilay@cs.wisc.eduvoid
9137839Snilay@cs.wisc.edu$c_ident::set_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr, ${{self.TBEType.c_ident}}* m_new_tbe)
9147839Snilay@cs.wisc.edu{
9157839Snilay@cs.wisc.edu  m_tbe_ptr = m_new_tbe;
9167839Snilay@cs.wisc.edu}
9177839Snilay@cs.wisc.edu
9187839Snilay@cs.wisc.eduvoid
9197839Snilay@cs.wisc.edu$c_ident::unset_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr)
9207839Snilay@cs.wisc.edu{
9217839Snilay@cs.wisc.edu  m_tbe_ptr = NULL;
9227839Snilay@cs.wisc.edu}
9237839Snilay@cs.wisc.edu''')
9247839Snilay@cs.wisc.edu
9257839Snilay@cs.wisc.edu        code('''
9266902SBrad.Beckmann@amd.com
9278683Snilay@cs.wisc.eduvoid
9288683Snilay@cs.wisc.edu$c_ident::recordCacheTrace(int cntrl, CacheRecorder* tr)
9298683Snilay@cs.wisc.edu{
9308683Snilay@cs.wisc.edu''')
9318683Snilay@cs.wisc.edu        #
9328683Snilay@cs.wisc.edu        # Record cache contents for all associated caches.
9338683Snilay@cs.wisc.edu        #
9348683Snilay@cs.wisc.edu        code.indent()
9358683Snilay@cs.wisc.edu        for param in self.config_parameters:
9368683Snilay@cs.wisc.edu            if param.type_ast.type.ident == "CacheMemory":
9378683Snilay@cs.wisc.edu                assert(param.pointer)
9388683Snilay@cs.wisc.edu                code('m_${{param.ident}}_ptr->recordCacheContents(cntrl, tr);')
9398683Snilay@cs.wisc.edu
9408683Snilay@cs.wisc.edu        code.dedent()
9418683Snilay@cs.wisc.edu        code('''
9428683Snilay@cs.wisc.edu}
9438683Snilay@cs.wisc.edu
9446657Snate@binkert.org// Actions
9456657Snate@binkert.org''')
9467839Snilay@cs.wisc.edu        if self.TBEType != None and self.EntryType != None:
9477839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
9487839Snilay@cs.wisc.edu                if "c_code" not in action:
9497839Snilay@cs.wisc.edu                 continue
9506657Snate@binkert.org
9517839Snilay@cs.wisc.edu                code('''
9527839Snilay@cs.wisc.edu/** \\brief ${{action.desc}} */
9537839Snilay@cs.wisc.eduvoid
9547839Snilay@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)
9557839Snilay@cs.wisc.edu{
9568055Sksewell@umich.edu    DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n");
95710963Sdavid.hashe@amd.com    try {
95810963Sdavid.hashe@amd.com       ${{action["c_code"]}}
95910963Sdavid.hashe@amd.com    } catch (const RejectException & e) {
96010963Sdavid.hashe@amd.com       fatal("Error in action ${{ident}}:${{action.ident}}: "
96110963Sdavid.hashe@amd.com             "executed a peek statement with the wrong message "
96210963Sdavid.hashe@amd.com             "type specified. ");
96310963Sdavid.hashe@amd.com    }
9647839Snilay@cs.wisc.edu}
9656657Snate@binkert.org
9667839Snilay@cs.wisc.edu''')
9677839Snilay@cs.wisc.edu        elif self.TBEType != None:
9687839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
9697839Snilay@cs.wisc.edu                if "c_code" not in action:
9707839Snilay@cs.wisc.edu                 continue
9717839Snilay@cs.wisc.edu
9727839Snilay@cs.wisc.edu                code('''
9737839Snilay@cs.wisc.edu/** \\brief ${{action.desc}} */
9747839Snilay@cs.wisc.eduvoid
9757839Snilay@cs.wisc.edu$c_ident::${{action.ident}}(${{self.TBEType.c_ident}}*& m_tbe_ptr, const Address& addr)
9767839Snilay@cs.wisc.edu{
9778055Sksewell@umich.edu    DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n");
9787839Snilay@cs.wisc.edu    ${{action["c_code"]}}
9797839Snilay@cs.wisc.edu}
9807839Snilay@cs.wisc.edu
9817839Snilay@cs.wisc.edu''')
9827839Snilay@cs.wisc.edu        elif self.EntryType != None:
9837839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
9847839Snilay@cs.wisc.edu                if "c_code" not in action:
9857839Snilay@cs.wisc.edu                 continue
9867839Snilay@cs.wisc.edu
9877839Snilay@cs.wisc.edu                code('''
9887839Snilay@cs.wisc.edu/** \\brief ${{action.desc}} */
9897839Snilay@cs.wisc.eduvoid
9907839Snilay@cs.wisc.edu$c_ident::${{action.ident}}(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, const Address& addr)
9917839Snilay@cs.wisc.edu{
9928055Sksewell@umich.edu    DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n");
9937839Snilay@cs.wisc.edu    ${{action["c_code"]}}
9947839Snilay@cs.wisc.edu}
9957839Snilay@cs.wisc.edu
9967839Snilay@cs.wisc.edu''')
9977839Snilay@cs.wisc.edu        else:
9987839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
9997839Snilay@cs.wisc.edu                if "c_code" not in action:
10007839Snilay@cs.wisc.edu                 continue
10017839Snilay@cs.wisc.edu
10027839Snilay@cs.wisc.edu                code('''
10036657Snate@binkert.org/** \\brief ${{action.desc}} */
10047007Snate@binkert.orgvoid
10057007Snate@binkert.org$c_ident::${{action.ident}}(const Address& addr)
10066657Snate@binkert.org{
10078055Sksewell@umich.edu    DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n");
10086657Snate@binkert.org    ${{action["c_code"]}}
10096657Snate@binkert.org}
10106657Snate@binkert.org
10116657Snate@binkert.org''')
10128478Snilay@cs.wisc.edu        for func in self.functions:
10138478Snilay@cs.wisc.edu            code(func.generateCode())
10148478Snilay@cs.wisc.edu
10159302Snilay@cs.wisc.edu        # Function for functional writes to messages buffered in the controller
10169302Snilay@cs.wisc.edu        code('''
101710524Snilay@cs.wisc.eduint
10189302Snilay@cs.wisc.edu$c_ident::functionalWriteBuffers(PacketPtr& pkt)
10199302Snilay@cs.wisc.edu{
102010524Snilay@cs.wisc.edu    int num_functional_writes = 0;
10219302Snilay@cs.wisc.edu''')
10229302Snilay@cs.wisc.edu        for var in self.objects:
10239302Snilay@cs.wisc.edu            vtype = var.type
10249302Snilay@cs.wisc.edu            if vtype.isBuffer:
102510305Snilay@cs.wisc.edu                vid = "m_%s_ptr" % var.ident
10269302Snilay@cs.wisc.edu                code('num_functional_writes += $vid->functionalWrite(pkt);')
102710311Snilay@cs.wisc.edu
102810311Snilay@cs.wisc.edu        for var in self.config_parameters:
102910311Snilay@cs.wisc.edu            vtype = var.type_ast.type
103010311Snilay@cs.wisc.edu            if vtype.isBuffer:
103110311Snilay@cs.wisc.edu                vid = "m_%s_ptr" % var.ident
103210311Snilay@cs.wisc.edu                code('num_functional_writes += $vid->functionalWrite(pkt);')
103310311Snilay@cs.wisc.edu
10349302Snilay@cs.wisc.edu        code('''
10359302Snilay@cs.wisc.edu    return num_functional_writes;
10369302Snilay@cs.wisc.edu}
10379302Snilay@cs.wisc.edu''')
10389302Snilay@cs.wisc.edu
10396657Snate@binkert.org        code.write(path, "%s.cc" % c_ident)
10406657Snate@binkert.org
10419219Spower.jg@gmail.com    def printCWakeup(self, path, includes):
10426657Snate@binkert.org        '''Output the wakeup loop for the events'''
10436657Snate@binkert.org
10446999Snate@binkert.org        code = self.symtab.codeFormatter()
10456657Snate@binkert.org        ident = self.ident
10466657Snate@binkert.org
10479104Shestness@cs.utexas.edu        outputRequest_types = True
10489104Shestness@cs.utexas.edu        if len(self.request_types) == 0:
10499104Shestness@cs.utexas.edu            outputRequest_types = False
10509104Shestness@cs.utexas.edu
10516657Snate@binkert.org        code('''
10526657Snate@binkert.org// Auto generated C++ code started by $__file__:$__line__
10536657Snate@binkert.org// ${ident}: ${{self.short}}
10546657Snate@binkert.org
10558946Sandreas.hansson@arm.com#include <sys/types.h>
105610963Sdavid.hashe@amd.com#include <typeinfo>
10578946Sandreas.hansson@arm.com#include <unistd.h>
10588946Sandreas.hansson@arm.com
10597832Snate@binkert.org#include <cassert>
10607832Snate@binkert.org
10617007Snate@binkert.org#include "base/misc.hh"
10628232Snate@binkert.org#include "debug/RubySlicc.hh"
10638229Snate@binkert.org#include "mem/protocol/${ident}_Controller.hh"
10648229Snate@binkert.org#include "mem/protocol/${ident}_Event.hh"
10658229Snate@binkert.org#include "mem/protocol/${ident}_State.hh"
10669104Shestness@cs.utexas.edu''')
10679104Shestness@cs.utexas.edu
10689104Shestness@cs.utexas.edu        if outputRequest_types:
10699104Shestness@cs.utexas.edu            code('''#include "mem/protocol/${ident}_RequestType.hh"''')
10709104Shestness@cs.utexas.edu
10719104Shestness@cs.utexas.edu        code('''
10728229Snate@binkert.org#include "mem/protocol/Types.hh"
10736657Snate@binkert.org#include "mem/ruby/system/System.hh"
10749219Spower.jg@gmail.com''')
10759219Spower.jg@gmail.com
10769219Spower.jg@gmail.com
10779219Spower.jg@gmail.com        for include_path in includes:
10789219Spower.jg@gmail.com            code('#include "${{include_path}}"')
10799219Spower.jg@gmail.com
108010963Sdavid.hashe@amd.com        port_to_buf_map, in_msg_bufs, msg_bufs = self.getBufferMaps(ident)
108110963Sdavid.hashe@amd.com
10829219Spower.jg@gmail.com        code('''
10836657Snate@binkert.org
10847055Snate@binkert.orgusing namespace std;
10857055Snate@binkert.org
10867007Snate@binkert.orgvoid
10877007Snate@binkert.org${ident}_Controller::wakeup()
10886657Snate@binkert.org{
10896657Snate@binkert.org    int counter = 0;
10906657Snate@binkert.org    while (true) {
109110963Sdavid.hashe@amd.com        unsigned char rejected[${{len(msg_bufs)}}];
109210963Sdavid.hashe@amd.com        memset(rejected, 0, sizeof(unsigned char)*${{len(msg_bufs)}});
10936657Snate@binkert.org        // Some cases will put us into an infinite loop without this limit
10946657Snate@binkert.org        assert(counter <= m_transitions_per_cycle);
10956657Snate@binkert.org        if (counter == m_transitions_per_cycle) {
10967007Snate@binkert.org            // Count how often we are fully utilized
10979496Snilay@cs.wisc.edu            m_fully_busy_cycles++;
10987007Snate@binkert.org
10997007Snate@binkert.org            // Wakeup in another cycle and try again
11009499Snilay@cs.wisc.edu            scheduleEvent(Cycles(1));
11016657Snate@binkert.org            break;
11026657Snate@binkert.org        }
11036657Snate@binkert.org''')
11046657Snate@binkert.org
11056657Snate@binkert.org        code.indent()
11066657Snate@binkert.org        code.indent()
11076657Snate@binkert.org
11086657Snate@binkert.org        # InPorts
11096657Snate@binkert.org        #
11106657Snate@binkert.org        for port in self.in_ports:
11116657Snate@binkert.org            code.indent()
11126657Snate@binkert.org            code('// ${ident}InPort $port')
11137567SBrad.Beckmann@amd.com            if port.pairs.has_key("rank"):
11149996Snilay@cs.wisc.edu                code('m_cur_in_port = ${{port.pairs["rank"]}};')
11157567SBrad.Beckmann@amd.com            else:
11169996Snilay@cs.wisc.edu                code('m_cur_in_port = 0;')
111710963Sdavid.hashe@amd.com            if port in port_to_buf_map:
111810963Sdavid.hashe@amd.com                code('try {')
111910963Sdavid.hashe@amd.com                code.indent()
11206657Snate@binkert.org            code('${{port["c_code_in_port"]}}')
112110963Sdavid.hashe@amd.com
112210963Sdavid.hashe@amd.com            if port in port_to_buf_map:
112310963Sdavid.hashe@amd.com                code.dedent()
112410963Sdavid.hashe@amd.com                code('''
112510963Sdavid.hashe@amd.com            } catch (const RejectException & e) {
112610963Sdavid.hashe@amd.com                rejected[${{port_to_buf_map[port]}}]++;
112710963Sdavid.hashe@amd.com            }
112810963Sdavid.hashe@amd.com''')
11296657Snate@binkert.org            code.dedent()
11306657Snate@binkert.org            code('')
11316657Snate@binkert.org
11326657Snate@binkert.org        code.dedent()
11336657Snate@binkert.org        code.dedent()
11346657Snate@binkert.org        code('''
113510963Sdavid.hashe@amd.com        // If we got this far, we have nothing left todo or something went
113610963Sdavid.hashe@amd.com        // wrong''')
113710963Sdavid.hashe@amd.com        for buf_name, ports in in_msg_bufs.items():
113810963Sdavid.hashe@amd.com            if len(ports) > 1:
113910963Sdavid.hashe@amd.com                # only produce checks when a buffer is shared by multiple ports
114010963Sdavid.hashe@amd.com                code('''
114110963Sdavid.hashe@amd.com        if (${{buf_name}}->isReady() && rejected[${{port_to_buf_map[ports[0]]}}] == ${{len(ports)}})
114210963Sdavid.hashe@amd.com        {
114310963Sdavid.hashe@amd.com            // no port claimed the message on the top of this buffer
114410963Sdavid.hashe@amd.com            panic("Runtime Error at Ruby Time: %d. "
114510963Sdavid.hashe@amd.com                  "All ports rejected a message. "
114610963Sdavid.hashe@amd.com                  "You are probably sending a message type to this controller "
114710963Sdavid.hashe@amd.com                  "over a virtual network that do not define an in_port for "
114810963Sdavid.hashe@amd.com                  "the incoming message type.\\n",
114910963Sdavid.hashe@amd.com                  Cycles(1));
115010963Sdavid.hashe@amd.com        }
115110963Sdavid.hashe@amd.com''')
115210963Sdavid.hashe@amd.com        code('''
115310963Sdavid.hashe@amd.com        break;
11546657Snate@binkert.org    }
11556657Snate@binkert.org}
11566657Snate@binkert.org''')
11576657Snate@binkert.org
11586657Snate@binkert.org        code.write(path, "%s_Wakeup.cc" % self.ident)
11596657Snate@binkert.org
11606657Snate@binkert.org    def printCSwitch(self, path):
11616657Snate@binkert.org        '''Output switch statement for transition table'''
11626657Snate@binkert.org
11636999Snate@binkert.org        code = self.symtab.codeFormatter()
11646657Snate@binkert.org        ident = self.ident
11656657Snate@binkert.org
11666657Snate@binkert.org        code('''
11676657Snate@binkert.org// Auto generated C++ code started by $__file__:$__line__
11686657Snate@binkert.org// ${ident}: ${{self.short}}
11696657Snate@binkert.org
11707832Snate@binkert.org#include <cassert>
11717832Snate@binkert.org
11727805Snilay@cs.wisc.edu#include "base/misc.hh"
11737832Snate@binkert.org#include "base/trace.hh"
11748232Snate@binkert.org#include "debug/ProtocolTrace.hh"
11758232Snate@binkert.org#include "debug/RubyGenerated.hh"
11768229Snate@binkert.org#include "mem/protocol/${ident}_Controller.hh"
11778229Snate@binkert.org#include "mem/protocol/${ident}_Event.hh"
11788229Snate@binkert.org#include "mem/protocol/${ident}_State.hh"
11798229Snate@binkert.org#include "mem/protocol/Types.hh"
11806657Snate@binkert.org#include "mem/ruby/system/System.hh"
11816657Snate@binkert.org
11826657Snate@binkert.org#define HASH_FUN(state, event)  ((int(state)*${ident}_Event_NUM)+int(event))
11836657Snate@binkert.org
11846657Snate@binkert.org#define GET_TRANSITION_COMMENT() (${ident}_transitionComment.str())
11856657Snate@binkert.org#define CLEAR_TRANSITION_COMMENT() (${ident}_transitionComment.str(""))
11866657Snate@binkert.org
11877007Snate@binkert.orgTransitionResult
11887007Snate@binkert.org${ident}_Controller::doTransition(${ident}_Event event,
11897839Snilay@cs.wisc.edu''')
11907839Snilay@cs.wisc.edu        if self.EntryType != None:
11917839Snilay@cs.wisc.edu            code('''
11927839Snilay@cs.wisc.edu                                  ${{self.EntryType.c_ident}}* m_cache_entry_ptr,
11937839Snilay@cs.wisc.edu''')
11947839Snilay@cs.wisc.edu        if self.TBEType != None:
11957839Snilay@cs.wisc.edu            code('''
11967839Snilay@cs.wisc.edu                                  ${{self.TBEType.c_ident}}* m_tbe_ptr,
11977839Snilay@cs.wisc.edu''')
11987839Snilay@cs.wisc.edu        code('''
119910010Snilay@cs.wisc.edu                                  const Address addr)
12006657Snate@binkert.org{
12017839Snilay@cs.wisc.edu''')
120210305Snilay@cs.wisc.edu        code.indent()
120310305Snilay@cs.wisc.edu
12047839Snilay@cs.wisc.edu        if self.TBEType != None and self.EntryType != None:
12058337Snilay@cs.wisc.edu            code('${ident}_State state = getState(m_tbe_ptr, m_cache_entry_ptr, addr);')
12067839Snilay@cs.wisc.edu        elif self.TBEType != None:
12078337Snilay@cs.wisc.edu            code('${ident}_State state = getState(m_tbe_ptr, addr);')
12087839Snilay@cs.wisc.edu        elif self.EntryType != None:
12098337Snilay@cs.wisc.edu            code('${ident}_State state = getState(m_cache_entry_ptr, addr);')
12107839Snilay@cs.wisc.edu        else:
12118337Snilay@cs.wisc.edu            code('${ident}_State state = getState(addr);')
12127839Snilay@cs.wisc.edu
12137839Snilay@cs.wisc.edu        code('''
121410305Snilay@cs.wisc.edu${ident}_State next_state = state;
12156657Snate@binkert.org
121610305Snilay@cs.wisc.eduDPRINTF(RubyGenerated, "%s, Time: %lld, state: %s, event: %s, addr: %s\\n",
121710305Snilay@cs.wisc.edu        *this, curCycle(), ${ident}_State_to_string(state),
121810305Snilay@cs.wisc.edu        ${ident}_Event_to_string(event), addr);
12196657Snate@binkert.org
122010305Snilay@cs.wisc.eduTransitionResult result =
12217839Snilay@cs.wisc.edu''')
12227839Snilay@cs.wisc.edu        if self.TBEType != None and self.EntryType != None:
12237839Snilay@cs.wisc.edu            code('doTransitionWorker(event, state, next_state, m_tbe_ptr, m_cache_entry_ptr, addr);')
12247839Snilay@cs.wisc.edu        elif self.TBEType != None:
12257839Snilay@cs.wisc.edu            code('doTransitionWorker(event, state, next_state, m_tbe_ptr, addr);')
12267839Snilay@cs.wisc.edu        elif self.EntryType != None:
12277839Snilay@cs.wisc.edu            code('doTransitionWorker(event, state, next_state, m_cache_entry_ptr, addr);')
12287839Snilay@cs.wisc.edu        else:
12297839Snilay@cs.wisc.edu            code('doTransitionWorker(event, state, next_state, addr);')
12306657Snate@binkert.org
123110963Sdavid.hashe@amd.com        port_to_buf_map, in_msg_bufs, msg_bufs = self.getBufferMaps(ident)
123210963Sdavid.hashe@amd.com
12337839Snilay@cs.wisc.edu        code('''
12346657Snate@binkert.org
123510305Snilay@cs.wisc.eduif (result == TransitionResult_Valid) {
123610305Snilay@cs.wisc.edu    DPRINTF(RubyGenerated, "next_state: %s\\n",
123710305Snilay@cs.wisc.edu            ${ident}_State_to_string(next_state));
123810305Snilay@cs.wisc.edu    countTransition(state, event);
123910305Snilay@cs.wisc.edu
124010305Snilay@cs.wisc.edu    DPRINTFR(ProtocolTrace, "%15d %3s %10s%20s %6s>%-6s %s %s\\n",
124110305Snilay@cs.wisc.edu             curTick(), m_version, "${ident}",
124210305Snilay@cs.wisc.edu             ${ident}_Event_to_string(event),
124310305Snilay@cs.wisc.edu             ${ident}_State_to_string(state),
124410305Snilay@cs.wisc.edu             ${ident}_State_to_string(next_state),
124510305Snilay@cs.wisc.edu             addr, GET_TRANSITION_COMMENT());
124610305Snilay@cs.wisc.edu
124710305Snilay@cs.wisc.edu    CLEAR_TRANSITION_COMMENT();
12487839Snilay@cs.wisc.edu''')
12497839Snilay@cs.wisc.edu        if self.TBEType != None and self.EntryType != None:
12508337Snilay@cs.wisc.edu            code('setState(m_tbe_ptr, m_cache_entry_ptr, addr, next_state);')
12518341Snilay@cs.wisc.edu            code('setAccessPermission(m_cache_entry_ptr, addr, next_state);')
12527839Snilay@cs.wisc.edu        elif self.TBEType != None:
12538337Snilay@cs.wisc.edu            code('setState(m_tbe_ptr, addr, next_state);')
12548341Snilay@cs.wisc.edu            code('setAccessPermission(addr, next_state);')
12557839Snilay@cs.wisc.edu        elif self.EntryType != None:
12568337Snilay@cs.wisc.edu            code('setState(m_cache_entry_ptr, addr, next_state);')
12578341Snilay@cs.wisc.edu            code('setAccessPermission(m_cache_entry_ptr, addr, next_state);')
12587839Snilay@cs.wisc.edu        else:
12598337Snilay@cs.wisc.edu            code('setState(addr, next_state);')
12608341Snilay@cs.wisc.edu            code('setAccessPermission(addr, next_state);')
12617839Snilay@cs.wisc.edu
12627839Snilay@cs.wisc.edu        code('''
126310305Snilay@cs.wisc.edu} else if (result == TransitionResult_ResourceStall) {
126410305Snilay@cs.wisc.edu    DPRINTFR(ProtocolTrace, "%15s %3s %10s%20s %6s>%-6s %s %s\\n",
126510305Snilay@cs.wisc.edu             curTick(), m_version, "${ident}",
126610305Snilay@cs.wisc.edu             ${ident}_Event_to_string(event),
126710305Snilay@cs.wisc.edu             ${ident}_State_to_string(state),
126810305Snilay@cs.wisc.edu             ${ident}_State_to_string(next_state),
126910305Snilay@cs.wisc.edu             addr, "Resource Stall");
127010305Snilay@cs.wisc.edu} else if (result == TransitionResult_ProtocolStall) {
127110305Snilay@cs.wisc.edu    DPRINTF(RubyGenerated, "stalling\\n");
127210305Snilay@cs.wisc.edu    DPRINTFR(ProtocolTrace, "%15s %3s %10s%20s %6s>%-6s %s %s\\n",
127310305Snilay@cs.wisc.edu             curTick(), m_version, "${ident}",
127410305Snilay@cs.wisc.edu             ${ident}_Event_to_string(event),
127510305Snilay@cs.wisc.edu             ${ident}_State_to_string(state),
127610305Snilay@cs.wisc.edu             ${ident}_State_to_string(next_state),
127710305Snilay@cs.wisc.edu             addr, "Protocol Stall");
127810305Snilay@cs.wisc.edu}
12796657Snate@binkert.org
128010305Snilay@cs.wisc.edureturn result;
128110305Snilay@cs.wisc.edu''')
128210305Snilay@cs.wisc.edu        code.dedent()
128310305Snilay@cs.wisc.edu        code('''
12846657Snate@binkert.org}
12856657Snate@binkert.org
12867007Snate@binkert.orgTransitionResult
12877007Snate@binkert.org${ident}_Controller::doTransitionWorker(${ident}_Event event,
12887007Snate@binkert.org                                        ${ident}_State state,
12897007Snate@binkert.org                                        ${ident}_State& next_state,
12907839Snilay@cs.wisc.edu''')
12917839Snilay@cs.wisc.edu
12927839Snilay@cs.wisc.edu        if self.TBEType != None:
12937839Snilay@cs.wisc.edu            code('''
12947839Snilay@cs.wisc.edu                                        ${{self.TBEType.c_ident}}*& m_tbe_ptr,
12957839Snilay@cs.wisc.edu''')
12967839Snilay@cs.wisc.edu        if self.EntryType != None:
12977839Snilay@cs.wisc.edu                  code('''
12987839Snilay@cs.wisc.edu                                        ${{self.EntryType.c_ident}}*& m_cache_entry_ptr,
12997839Snilay@cs.wisc.edu''')
13007839Snilay@cs.wisc.edu        code('''
13017007Snate@binkert.org                                        const Address& addr)
13026657Snate@binkert.org{
13036657Snate@binkert.org    switch(HASH_FUN(state, event)) {
13046657Snate@binkert.org''')
13056657Snate@binkert.org
13066657Snate@binkert.org        # This map will allow suppress generating duplicate code
13076657Snate@binkert.org        cases = orderdict()
13086657Snate@binkert.org
13096657Snate@binkert.org        for trans in self.transitions:
13106657Snate@binkert.org            case_string = "%s_State_%s, %s_Event_%s" % \
13116657Snate@binkert.org                (self.ident, trans.state.ident, self.ident, trans.event.ident)
13126657Snate@binkert.org
13136999Snate@binkert.org            case = self.symtab.codeFormatter()
13146657Snate@binkert.org            # Only set next_state if it changes
13156657Snate@binkert.org            if trans.state != trans.nextState:
131610964Sdavid.hashe@amd.com                if trans.nextState.isWildcard():
131710964Sdavid.hashe@amd.com                    # When * is encountered as an end state of a transition,
131810964Sdavid.hashe@amd.com                    # the next state is determined by calling the
131910964Sdavid.hashe@amd.com                    # machine-specific getNextState function. The next state
132010964Sdavid.hashe@amd.com                    # is determined before any actions of the transition
132110964Sdavid.hashe@amd.com                    # execute, and therefore the next state calculation cannot
132210964Sdavid.hashe@amd.com                    # depend on any of the transitionactions.
132310964Sdavid.hashe@amd.com                    case('next_state = getNextState(addr);')
132410964Sdavid.hashe@amd.com                else:
132510964Sdavid.hashe@amd.com                    ns_ident = trans.nextState.ident
132610964Sdavid.hashe@amd.com                    case('next_state = ${ident}_State_${ns_ident};')
13276657Snate@binkert.org
13286657Snate@binkert.org            actions = trans.actions
13299104Shestness@cs.utexas.edu            request_types = trans.request_types
13306657Snate@binkert.org
13316657Snate@binkert.org            # Check for resources
13326657Snate@binkert.org            case_sorter = []
13336657Snate@binkert.org            res = trans.resources
13346657Snate@binkert.org            for key,val in res.iteritems():
133510228Snilay@cs.wisc.edu                val = '''
13367007Snate@binkert.orgif (!%s.areNSlotsAvailable(%s))
13376657Snate@binkert.org    return TransitionResult_ResourceStall;
13386657Snate@binkert.org''' % (key.code, val)
13396657Snate@binkert.org                case_sorter.append(val)
13406657Snate@binkert.org
13419105SBrad.Beckmann@amd.com            # Check all of the request_types for resource constraints
13429105SBrad.Beckmann@amd.com            for request_type in request_types:
13439105SBrad.Beckmann@amd.com                val = '''
13449105SBrad.Beckmann@amd.comif (!checkResourceAvailable(%s_RequestType_%s, addr)) {
13459105SBrad.Beckmann@amd.com    return TransitionResult_ResourceStall;
13469105SBrad.Beckmann@amd.com}
13479105SBrad.Beckmann@amd.com''' % (self.ident, request_type.ident)
13489105SBrad.Beckmann@amd.com                case_sorter.append(val)
13496657Snate@binkert.org
13506657Snate@binkert.org            # Emit the code sequences in a sorted order.  This makes the
13516657Snate@binkert.org            # output deterministic (without this the output order can vary
13526657Snate@binkert.org            # since Map's keys() on a vector of pointers is not deterministic
13536657Snate@binkert.org            for c in sorted(case_sorter):
13546657Snate@binkert.org                case("$c")
13556657Snate@binkert.org
13569104Shestness@cs.utexas.edu            # Record access types for this transition
13579104Shestness@cs.utexas.edu            for request_type in request_types:
13589104Shestness@cs.utexas.edu                case('recordRequestType(${ident}_RequestType_${{request_type.ident}}, addr);')
13599104Shestness@cs.utexas.edu
13606657Snate@binkert.org            # Figure out if we stall
13616657Snate@binkert.org            stall = False
13626657Snate@binkert.org            for action in actions:
13636657Snate@binkert.org                if action.ident == "z_stall":
13646657Snate@binkert.org                    stall = True
13656657Snate@binkert.org                    break
13666657Snate@binkert.org
13676657Snate@binkert.org            if stall:
13686657Snate@binkert.org                case('return TransitionResult_ProtocolStall;')
13696657Snate@binkert.org            else:
13707839Snilay@cs.wisc.edu                if self.TBEType != None and self.EntryType != None:
13717839Snilay@cs.wisc.edu                    for action in actions:
13727839Snilay@cs.wisc.edu                        case('${{action.ident}}(m_tbe_ptr, m_cache_entry_ptr, addr);')
13737839Snilay@cs.wisc.edu                elif self.TBEType != None:
13747839Snilay@cs.wisc.edu                    for action in actions:
13757839Snilay@cs.wisc.edu                        case('${{action.ident}}(m_tbe_ptr, addr);')
13767839Snilay@cs.wisc.edu                elif self.EntryType != None:
13777839Snilay@cs.wisc.edu                    for action in actions:
13787839Snilay@cs.wisc.edu                        case('${{action.ident}}(m_cache_entry_ptr, addr);')
13797839Snilay@cs.wisc.edu                else:
13807839Snilay@cs.wisc.edu                    for action in actions:
13817839Snilay@cs.wisc.edu                        case('${{action.ident}}(addr);')
13826657Snate@binkert.org                case('return TransitionResult_Valid;')
13836657Snate@binkert.org
13846657Snate@binkert.org            case = str(case)
13856657Snate@binkert.org
13866657Snate@binkert.org            # Look to see if this transition code is unique.
13876657Snate@binkert.org            if case not in cases:
13886657Snate@binkert.org                cases[case] = []
13896657Snate@binkert.org
13906657Snate@binkert.org            cases[case].append(case_string)
13916657Snate@binkert.org
13926657Snate@binkert.org        # Walk through all of the unique code blocks and spit out the
13936657Snate@binkert.org        # corresponding case statement elements
13946657Snate@binkert.org        for case,transitions in cases.iteritems():
13956657Snate@binkert.org            # Iterative over all the multiple transitions that share
13966657Snate@binkert.org            # the same code
13976657Snate@binkert.org            for trans in transitions:
13986657Snate@binkert.org                code('  case HASH_FUN($trans):')
139910305Snilay@cs.wisc.edu            code('    $case\n')
14006657Snate@binkert.org
14016657Snate@binkert.org        code('''
14026657Snate@binkert.org      default:
140310962SBrad.Beckmann@amd.com        panic("Invalid transition\\n"
14048159SBrad.Beckmann@amd.com              "%s time: %d addr: %s event: %s state: %s\\n",
14059465Snilay@cs.wisc.edu              name(), curCycle(), addr, event, state);
14066657Snate@binkert.org    }
140710305Snilay@cs.wisc.edu
14086657Snate@binkert.org    return TransitionResult_Valid;
14096657Snate@binkert.org}
14106657Snate@binkert.org''')
14116657Snate@binkert.org        code.write(path, "%s_Transitions.cc" % self.ident)
14126657Snate@binkert.org
14136657Snate@binkert.org
14146657Snate@binkert.org    # **************************
14156657Snate@binkert.org    # ******* HTML Files *******
14166657Snate@binkert.org    # **************************
14177007Snate@binkert.org    def frameRef(self, click_href, click_target, over_href, over_num, text):
14186999Snate@binkert.org        code = self.symtab.codeFormatter(fix_newlines=False)
14197007Snate@binkert.org        code("""<A href=\"$click_href\" target=\"$click_target\" onmouseover=\"
14207007Snate@binkert.org    if (parent.frames[$over_num].location != parent.location + '$over_href') {
14217007Snate@binkert.org        parent.frames[$over_num].location='$over_href'
14227007Snate@binkert.org    }\">
14237007Snate@binkert.org    ${{html.formatShorthand(text)}}
14247007Snate@binkert.org    </A>""")
14256657Snate@binkert.org        return str(code)
14266657Snate@binkert.org
14276657Snate@binkert.org    def writeHTMLFiles(self, path):
14286657Snate@binkert.org        # Create table with no row hilighted
14296657Snate@binkert.org        self.printHTMLTransitions(path, None)
14306657Snate@binkert.org
14316657Snate@binkert.org        # Generate transition tables
14326657Snate@binkert.org        for state in self.states.itervalues():
14336657Snate@binkert.org            self.printHTMLTransitions(path, state)
14346657Snate@binkert.org
14356657Snate@binkert.org        # Generate action descriptions
14366657Snate@binkert.org        for action in self.actions.itervalues():
14376657Snate@binkert.org            name = "%s_action_%s.html" % (self.ident, action.ident)
14386657Snate@binkert.org            code = html.createSymbol(action, "Action")
14396657Snate@binkert.org            code.write(path, name)
14406657Snate@binkert.org
14416657Snate@binkert.org        # Generate state descriptions
14426657Snate@binkert.org        for state in self.states.itervalues():
14436657Snate@binkert.org            name = "%s_State_%s.html" % (self.ident, state.ident)
14446657Snate@binkert.org            code = html.createSymbol(state, "State")
14456657Snate@binkert.org            code.write(path, name)
14466657Snate@binkert.org
14476657Snate@binkert.org        # Generate event descriptions
14486657Snate@binkert.org        for event in self.events.itervalues():
14496657Snate@binkert.org            name = "%s_Event_%s.html" % (self.ident, event.ident)
14506657Snate@binkert.org            code = html.createSymbol(event, "Event")
14516657Snate@binkert.org            code.write(path, name)
14526657Snate@binkert.org
14536657Snate@binkert.org    def printHTMLTransitions(self, path, active_state):
14546999Snate@binkert.org        code = self.symtab.codeFormatter()
14556657Snate@binkert.org
14566657Snate@binkert.org        code('''
14577007Snate@binkert.org<HTML>
14587007Snate@binkert.org<BODY link="blue" vlink="blue">
14596657Snate@binkert.org
14606657Snate@binkert.org<H1 align="center">${{html.formatShorthand(self.short)}}:
14616657Snate@binkert.org''')
14626657Snate@binkert.org        code.indent()
14636657Snate@binkert.org        for i,machine in enumerate(self.symtab.getAllType(StateMachine)):
14646657Snate@binkert.org            mid = machine.ident
14656657Snate@binkert.org            if i != 0:
14666657Snate@binkert.org                extra = " - "
14676657Snate@binkert.org            else:
14686657Snate@binkert.org                extra = ""
14696657Snate@binkert.org            if machine == self:
14706657Snate@binkert.org                code('$extra$mid')
14716657Snate@binkert.org            else:
14726657Snate@binkert.org                code('$extra<A target="Table" href="${mid}_table.html">$mid</A>')
14736657Snate@binkert.org        code.dedent()
14746657Snate@binkert.org
14756657Snate@binkert.org        code("""
14766657Snate@binkert.org</H1>
14776657Snate@binkert.org
14786657Snate@binkert.org<TABLE border=1>
14796657Snate@binkert.org<TR>
14806657Snate@binkert.org  <TH> </TH>
14816657Snate@binkert.org""")
14826657Snate@binkert.org
14836657Snate@binkert.org        for event in self.events.itervalues():
14846657Snate@binkert.org            href = "%s_Event_%s.html" % (self.ident, event.ident)
14856657Snate@binkert.org            ref = self.frameRef(href, "Status", href, "1", event.short)
14866657Snate@binkert.org            code('<TH bgcolor=white>$ref</TH>')
14876657Snate@binkert.org
14886657Snate@binkert.org        code('</TR>')
14896657Snate@binkert.org        # -- Body of table
14906657Snate@binkert.org        for state in self.states.itervalues():
14916657Snate@binkert.org            # -- Each row
14926657Snate@binkert.org            if state == active_state:
14936657Snate@binkert.org                color = "yellow"
14946657Snate@binkert.org            else:
14956657Snate@binkert.org                color = "white"
14966657Snate@binkert.org
14976657Snate@binkert.org            click = "%s_table_%s.html" % (self.ident, state.ident)
14986657Snate@binkert.org            over = "%s_State_%s.html" % (self.ident, state.ident)
14996657Snate@binkert.org            text = html.formatShorthand(state.short)
15006657Snate@binkert.org            ref = self.frameRef(click, "Table", over, "1", state.short)
15016657Snate@binkert.org            code('''
15026657Snate@binkert.org<TR>
15036657Snate@binkert.org  <TH bgcolor=$color>$ref</TH>
15046657Snate@binkert.org''')
15056657Snate@binkert.org
15066657Snate@binkert.org            # -- One column for each event
15076657Snate@binkert.org            for event in self.events.itervalues():
15086657Snate@binkert.org                trans = self.table.get((state,event), None)
15096657Snate@binkert.org                if trans is None:
15106657Snate@binkert.org                    # This is the no transition case
15116657Snate@binkert.org                    if state == active_state:
15126657Snate@binkert.org                        color = "#C0C000"
15136657Snate@binkert.org                    else:
15146657Snate@binkert.org                        color = "lightgrey"
15156657Snate@binkert.org
15166657Snate@binkert.org                    code('<TD bgcolor=$color>&nbsp;</TD>')
15176657Snate@binkert.org                    continue
15186657Snate@binkert.org
15196657Snate@binkert.org                next = trans.nextState
15206657Snate@binkert.org                stall_action = False
15216657Snate@binkert.org
15226657Snate@binkert.org                # -- Get the actions
15236657Snate@binkert.org                for action in trans.actions:
15246657Snate@binkert.org                    if action.ident == "z_stall" or \
15256657Snate@binkert.org                       action.ident == "zz_recycleMandatoryQueue":
15266657Snate@binkert.org                        stall_action = True
15276657Snate@binkert.org
15286657Snate@binkert.org                # -- Print out "actions/next-state"
15296657Snate@binkert.org                if stall_action:
15306657Snate@binkert.org                    if state == active_state:
15316657Snate@binkert.org                        color = "#C0C000"
15326657Snate@binkert.org                    else:
15336657Snate@binkert.org                        color = "lightgrey"
15346657Snate@binkert.org
15356657Snate@binkert.org                elif active_state and next.ident == active_state.ident:
15366657Snate@binkert.org                    color = "aqua"
15376657Snate@binkert.org                elif state == active_state:
15386657Snate@binkert.org                    color = "yellow"
15396657Snate@binkert.org                else:
15406657Snate@binkert.org                    color = "white"
15416657Snate@binkert.org
15426657Snate@binkert.org                code('<TD bgcolor=$color>')
15436657Snate@binkert.org                for action in trans.actions:
15446657Snate@binkert.org                    href = "%s_action_%s.html" % (self.ident, action.ident)
15456657Snate@binkert.org                    ref = self.frameRef(href, "Status", href, "1",
15466657Snate@binkert.org                                        action.short)
15477007Snate@binkert.org                    code('  $ref')
15486657Snate@binkert.org                if next != state:
15496657Snate@binkert.org                    if trans.actions:
15506657Snate@binkert.org                        code('/')
15516657Snate@binkert.org                    click = "%s_table_%s.html" % (self.ident, next.ident)
15526657Snate@binkert.org                    over = "%s_State_%s.html" % (self.ident, next.ident)
15536657Snate@binkert.org                    ref = self.frameRef(click, "Table", over, "1", next.short)
15546657Snate@binkert.org                    code("$ref")
15557007Snate@binkert.org                code("</TD>")
15566657Snate@binkert.org
15576657Snate@binkert.org            # -- Each row
15586657Snate@binkert.org            if state == active_state:
15596657Snate@binkert.org                color = "yellow"
15606657Snate@binkert.org            else:
15616657Snate@binkert.org                color = "white"
15626657Snate@binkert.org
15636657Snate@binkert.org            click = "%s_table_%s.html" % (self.ident, state.ident)
15646657Snate@binkert.org            over = "%s_State_%s.html" % (self.ident, state.ident)
15656657Snate@binkert.org            ref = self.frameRef(click, "Table", over, "1", state.short)
15666657Snate@binkert.org            code('''
15676657Snate@binkert.org  <TH bgcolor=$color>$ref</TH>
15686657Snate@binkert.org</TR>
15696657Snate@binkert.org''')
15706657Snate@binkert.org        code('''
157110917Sbrandon.potter@amd.com<!- Column footer->
15726657Snate@binkert.org<TR>
15736657Snate@binkert.org  <TH> </TH>
15746657Snate@binkert.org''')
15756657Snate@binkert.org
15766657Snate@binkert.org        for event in self.events.itervalues():
15776657Snate@binkert.org            href = "%s_Event_%s.html" % (self.ident, event.ident)
15786657Snate@binkert.org            ref = self.frameRef(href, "Status", href, "1", event.short)
15796657Snate@binkert.org            code('<TH bgcolor=white>$ref</TH>')
15806657Snate@binkert.org        code('''
15816657Snate@binkert.org</TR>
15826657Snate@binkert.org</TABLE>
15836657Snate@binkert.org</BODY></HTML>
15846657Snate@binkert.org''')
15856657Snate@binkert.org
15866657Snate@binkert.org
15876657Snate@binkert.org        if active_state:
15886657Snate@binkert.org            name = "%s_table_%s.html" % (self.ident, active_state.ident)
15896657Snate@binkert.org        else:
15906657Snate@binkert.org            name = "%s_table.html" % self.ident
15916657Snate@binkert.org        code.write(path, name)
15926657Snate@binkert.org
15936657Snate@binkert.org__all__ = [ "StateMachine" ]
1594