StateMachine.py revision 11116
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
310972Sdavid.hashe@amd.com# Copyright (c) 2013 Advanced Micro Devices, Inc.
46657Snate@binkert.org# All rights reserved.
56657Snate@binkert.org#
66657Snate@binkert.org# Redistribution and use in source and binary forms, with or without
76657Snate@binkert.org# modification, are permitted provided that the following conditions are
86657Snate@binkert.org# met: redistributions of source code must retain the above copyright
96657Snate@binkert.org# notice, this list of conditions and the following disclaimer;
106657Snate@binkert.org# redistributions in binary form must reproduce the above copyright
116657Snate@binkert.org# notice, this list of conditions and the following disclaimer in the
126657Snate@binkert.org# documentation and/or other materials provided with the distribution;
136657Snate@binkert.org# neither the name of the copyright holders nor the names of its
146657Snate@binkert.org# contributors may be used to endorse or promote products derived from
156657Snate@binkert.org# this software without specific prior written permission.
166657Snate@binkert.org#
176657Snate@binkert.org# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
186657Snate@binkert.org# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
196657Snate@binkert.org# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
206657Snate@binkert.org# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
216657Snate@binkert.org# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
226657Snate@binkert.org# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
236657Snate@binkert.org# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
246657Snate@binkert.org# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
256657Snate@binkert.org# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
266657Snate@binkert.org# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
276657Snate@binkert.org# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
286657Snate@binkert.org
296999Snate@binkert.orgfrom m5.util import orderdict
306657Snate@binkert.org
316657Snate@binkert.orgfrom slicc.symbols.Symbol import Symbol
326657Snate@binkert.orgfrom slicc.symbols.Var import Var
336657Snate@binkert.orgimport slicc.generate.html as html
348189SLisa.Hsu@amd.comimport re
356657Snate@binkert.org
369499Snilay@cs.wisc.edupython_class_map = {
379499Snilay@cs.wisc.edu                    "int": "Int",
389364Snilay@cs.wisc.edu                    "uint32_t" : "UInt32",
397055Snate@binkert.org                    "std::string": "String",
406882SBrad.Beckmann@amd.com                    "bool": "Bool",
416882SBrad.Beckmann@amd.com                    "CacheMemory": "RubyCache",
428191SLisa.Hsu@amd.com                    "WireBuffer": "RubyWireBuffer",
436882SBrad.Beckmann@amd.com                    "Sequencer": "RubySequencer",
446882SBrad.Beckmann@amd.com                    "DirectoryMemory": "RubyDirectoryMemory",
459102SNuwan.Jayasena@amd.com                    "MemoryControl": "MemoryControl",
4611084Snilay@cs.wisc.edu                    "MessageBuffer": "MessageBuffer",
479366Snilay@cs.wisc.edu                    "DMASequencer": "DMASequencer",
489499Snilay@cs.wisc.edu                    "Prefetcher":"Prefetcher",
499499Snilay@cs.wisc.edu                    "Cycles":"Cycles",
509499Snilay@cs.wisc.edu                   }
516882SBrad.Beckmann@amd.com
526657Snate@binkert.orgclass StateMachine(Symbol):
536657Snate@binkert.org    def __init__(self, symtab, ident, location, pairs, config_parameters):
546657Snate@binkert.org        super(StateMachine, self).__init__(symtab, ident, location, pairs)
556657Snate@binkert.org        self.table = None
5610311Snilay@cs.wisc.edu
5710311Snilay@cs.wisc.edu        # Data members in the State Machine that have been declared before
5810311Snilay@cs.wisc.edu        # the opening brace '{'  of the machine.  Note that these along with
5910311Snilay@cs.wisc.edu        # the members in self.objects form the entire set of data members.
606657Snate@binkert.org        self.config_parameters = config_parameters
6110311Snilay@cs.wisc.edu
629366Snilay@cs.wisc.edu        self.prefetchers = []
637839Snilay@cs.wisc.edu
646657Snate@binkert.org        for param in config_parameters:
656882SBrad.Beckmann@amd.com            if param.pointer:
6610308Snilay@cs.wisc.edu                var = Var(symtab, param.ident, location, param.type_ast.type,
6710308Snilay@cs.wisc.edu                          "(*m_%s_ptr)" % param.ident, {}, self)
686882SBrad.Beckmann@amd.com            else:
6910308Snilay@cs.wisc.edu                var = Var(symtab, param.ident, location, param.type_ast.type,
7010308Snilay@cs.wisc.edu                          "m_%s" % param.ident, {}, self)
7110308Snilay@cs.wisc.edu
7210308Snilay@cs.wisc.edu            self.symtab.registerSym(param.ident, var)
7310308Snilay@cs.wisc.edu
749366Snilay@cs.wisc.edu            if str(param.type_ast.type) == "Prefetcher":
759366Snilay@cs.wisc.edu                self.prefetchers.append(var)
766657Snate@binkert.org
776657Snate@binkert.org        self.states = orderdict()
786657Snate@binkert.org        self.events = orderdict()
796657Snate@binkert.org        self.actions = orderdict()
809104Shestness@cs.utexas.edu        self.request_types = orderdict()
816657Snate@binkert.org        self.transitions = []
826657Snate@binkert.org        self.in_ports = []
836657Snate@binkert.org        self.functions = []
8410311Snilay@cs.wisc.edu
8510311Snilay@cs.wisc.edu        # Data members in the State Machine that have been declared inside
8610311Snilay@cs.wisc.edu        # the {} machine.  Note that these along with the config params
8710311Snilay@cs.wisc.edu        # form the entire set of data members of the machine.
886657Snate@binkert.org        self.objects = []
897839Snilay@cs.wisc.edu        self.TBEType   = None
907839Snilay@cs.wisc.edu        self.EntryType = None
9110972Sdavid.hashe@amd.com        self.debug_flags = set()
9210972Sdavid.hashe@amd.com        self.debug_flags.add('RubyGenerated')
9310972Sdavid.hashe@amd.com        self.debug_flags.add('RubySlicc')
946657Snate@binkert.org
956657Snate@binkert.org    def __repr__(self):
966657Snate@binkert.org        return "[StateMachine: %s]" % self.ident
976657Snate@binkert.org
986657Snate@binkert.org    def addState(self, state):
996657Snate@binkert.org        assert self.table is None
1006657Snate@binkert.org        self.states[state.ident] = state
1016657Snate@binkert.org
1026657Snate@binkert.org    def addEvent(self, event):
1036657Snate@binkert.org        assert self.table is None
1046657Snate@binkert.org        self.events[event.ident] = event
1056657Snate@binkert.org
1066657Snate@binkert.org    def addAction(self, action):
1076657Snate@binkert.org        assert self.table is None
1086657Snate@binkert.org
1096657Snate@binkert.org        # Check for duplicate action
1106657Snate@binkert.org        for other in self.actions.itervalues():
1116657Snate@binkert.org            if action.ident == other.ident:
1126779SBrad.Beckmann@amd.com                action.warning("Duplicate action definition: %s" % action.ident)
1136657Snate@binkert.org                action.error("Duplicate action definition: %s" % action.ident)
1146657Snate@binkert.org            if action.short == other.short:
1156657Snate@binkert.org                other.warning("Duplicate action shorthand: %s" % other.ident)
1166657Snate@binkert.org                other.warning("    shorthand = %s" % other.short)
1176657Snate@binkert.org                action.warning("Duplicate action shorthand: %s" % action.ident)
1186657Snate@binkert.org                action.error("    shorthand = %s" % action.short)
1196657Snate@binkert.org
1206657Snate@binkert.org        self.actions[action.ident] = action
1216657Snate@binkert.org
12210972Sdavid.hashe@amd.com    def addDebugFlag(self, flag):
12310972Sdavid.hashe@amd.com        self.debug_flags.add(flag)
12410972Sdavid.hashe@amd.com
1259104Shestness@cs.utexas.edu    def addRequestType(self, request_type):
1269104Shestness@cs.utexas.edu        assert self.table is None
1279104Shestness@cs.utexas.edu        self.request_types[request_type.ident] = request_type
1289104Shestness@cs.utexas.edu
1296657Snate@binkert.org    def addTransition(self, trans):
1306657Snate@binkert.org        assert self.table is None
1316657Snate@binkert.org        self.transitions.append(trans)
1326657Snate@binkert.org
1336657Snate@binkert.org    def addInPort(self, var):
1346657Snate@binkert.org        self.in_ports.append(var)
1356657Snate@binkert.org
1366657Snate@binkert.org    def addFunc(self, func):
1376657Snate@binkert.org        # register func in the symbol table
1386657Snate@binkert.org        self.symtab.registerSym(str(func), func)
1396657Snate@binkert.org        self.functions.append(func)
1406657Snate@binkert.org
1416657Snate@binkert.org    def addObject(self, obj):
14210307Snilay@cs.wisc.edu        self.symtab.registerSym(str(obj), obj)
1436657Snate@binkert.org        self.objects.append(obj)
1446657Snate@binkert.org
1457839Snilay@cs.wisc.edu    def addType(self, type):
1467839Snilay@cs.wisc.edu        type_ident = '%s' % type.c_ident
1477839Snilay@cs.wisc.edu
1487839Snilay@cs.wisc.edu        if type_ident == "%s_TBE" %self.ident:
1497839Snilay@cs.wisc.edu            if self.TBEType != None:
1507839Snilay@cs.wisc.edu                self.error("Multiple Transaction Buffer types in a " \
1517839Snilay@cs.wisc.edu                           "single machine.");
1527839Snilay@cs.wisc.edu            self.TBEType = type
1537839Snilay@cs.wisc.edu
1547839Snilay@cs.wisc.edu        elif "interface" in type and "AbstractCacheEntry" == type["interface"]:
15510968Sdavid.hashe@amd.com            if "main" in type and "false" == type["main"].lower():
15610968Sdavid.hashe@amd.com                pass # this isn't the EntryType
15710968Sdavid.hashe@amd.com            else:
15810968Sdavid.hashe@amd.com                if self.EntryType != None:
15910968Sdavid.hashe@amd.com                    self.error("Multiple AbstractCacheEntry types in a " \
16010968Sdavid.hashe@amd.com                               "single machine.");
16110968Sdavid.hashe@amd.com                self.EntryType = type
1627839Snilay@cs.wisc.edu
1636657Snate@binkert.org    # Needs to be called before accessing the table
1646657Snate@binkert.org    def buildTable(self):
1656657Snate@binkert.org        assert self.table is None
1666657Snate@binkert.org
1676657Snate@binkert.org        table = {}
1686657Snate@binkert.org
1696657Snate@binkert.org        for trans in self.transitions:
1706657Snate@binkert.org            # Track which actions we touch so we know if we use them
1716657Snate@binkert.org            # all -- really this should be done for all symbols as
1726657Snate@binkert.org            # part of the symbol table, then only trigger it for
1736657Snate@binkert.org            # Actions, States, Events, etc.
1746657Snate@binkert.org
1756657Snate@binkert.org            for action in trans.actions:
1766657Snate@binkert.org                action.used = True
1776657Snate@binkert.org
1786657Snate@binkert.org            index = (trans.state, trans.event)
1796657Snate@binkert.org            if index in table:
1806657Snate@binkert.org                table[index].warning("Duplicate transition: %s" % table[index])
1816657Snate@binkert.org                trans.error("Duplicate transition: %s" % trans)
1826657Snate@binkert.org            table[index] = trans
1836657Snate@binkert.org
1846657Snate@binkert.org        # Look at all actions to make sure we used them all
1856657Snate@binkert.org        for action in self.actions.itervalues():
1866657Snate@binkert.org            if not action.used:
1876657Snate@binkert.org                error_msg = "Unused action: %s" % action.ident
1886657Snate@binkert.org                if "desc" in action:
1896657Snate@binkert.org                    error_msg += ", "  + action.desc
1906657Snate@binkert.org                action.warning(error_msg)
1916657Snate@binkert.org        self.table = table
1926657Snate@binkert.org
19310963Sdavid.hashe@amd.com    # determine the port->msg buffer mappings
19410963Sdavid.hashe@amd.com    def getBufferMaps(self, ident):
19510963Sdavid.hashe@amd.com        msg_bufs = []
19610963Sdavid.hashe@amd.com        port_to_buf_map = {}
19710963Sdavid.hashe@amd.com        in_msg_bufs = {}
19810963Sdavid.hashe@amd.com        for port in self.in_ports:
19911095Snilay@cs.wisc.edu            buf_name = "m_%s_ptr" % port.pairs["buffer_expr"].name
20010963Sdavid.hashe@amd.com            msg_bufs.append(buf_name)
20110963Sdavid.hashe@amd.com            port_to_buf_map[port] = msg_bufs.index(buf_name)
20210963Sdavid.hashe@amd.com            if buf_name not in in_msg_bufs:
20310963Sdavid.hashe@amd.com                in_msg_bufs[buf_name] = [port]
20410963Sdavid.hashe@amd.com            else:
20510963Sdavid.hashe@amd.com                in_msg_bufs[buf_name].append(port)
20610963Sdavid.hashe@amd.com        return port_to_buf_map, in_msg_bufs, msg_bufs
20710963Sdavid.hashe@amd.com
2089219Spower.jg@gmail.com    def writeCodeFiles(self, path, includes):
2096877Ssteve.reinhardt@amd.com        self.printControllerPython(path)
2106657Snate@binkert.org        self.printControllerHH(path)
2119219Spower.jg@gmail.com        self.printControllerCC(path, includes)
2126657Snate@binkert.org        self.printCSwitch(path)
2139219Spower.jg@gmail.com        self.printCWakeup(path, includes)
2146657Snate@binkert.org
2156877Ssteve.reinhardt@amd.com    def printControllerPython(self, path):
2166999Snate@binkert.org        code = self.symtab.codeFormatter()
2176877Ssteve.reinhardt@amd.com        ident = self.ident
21810308Snilay@cs.wisc.edu
2196877Ssteve.reinhardt@amd.com        py_ident = "%s_Controller" % ident
2206877Ssteve.reinhardt@amd.com        c_ident = "%s_Controller" % self.ident
22110308Snilay@cs.wisc.edu
2226877Ssteve.reinhardt@amd.com        code('''
2236877Ssteve.reinhardt@amd.comfrom m5.params import *
2246877Ssteve.reinhardt@amd.comfrom m5.SimObject import SimObject
2256877Ssteve.reinhardt@amd.comfrom Controller import RubyController
2266877Ssteve.reinhardt@amd.com
2276877Ssteve.reinhardt@amd.comclass $py_ident(RubyController):
2286877Ssteve.reinhardt@amd.com    type = '$py_ident'
2299338SAndreas.Sandberg@arm.com    cxx_header = 'mem/protocol/${c_ident}.hh'
2306877Ssteve.reinhardt@amd.com''')
2316877Ssteve.reinhardt@amd.com        code.indent()
2326877Ssteve.reinhardt@amd.com        for param in self.config_parameters:
2336877Ssteve.reinhardt@amd.com            dflt_str = ''
23410308Snilay@cs.wisc.edu
23510308Snilay@cs.wisc.edu            if param.rvalue is not None:
23610308Snilay@cs.wisc.edu                dflt_str = str(param.rvalue.inline()) + ', '
23710308Snilay@cs.wisc.edu
23811084Snilay@cs.wisc.edu            if python_class_map.has_key(param.type_ast.type.c_ident):
2396882SBrad.Beckmann@amd.com                python_type = python_class_map[param.type_ast.type.c_ident]
24010308Snilay@cs.wisc.edu                code('${{param.ident}} = Param.${{python_type}}(${dflt_str}"")')
24110308Snilay@cs.wisc.edu
2426882SBrad.Beckmann@amd.com            else:
2436882SBrad.Beckmann@amd.com                self.error("Unknown c++ to python class conversion for c++ " \
2446882SBrad.Beckmann@amd.com                           "type: '%s'. Please update the python_class_map " \
2456882SBrad.Beckmann@amd.com                           "in StateMachine.py", param.type_ast.type.c_ident)
24611021Sjthestness@gmail.com
2476877Ssteve.reinhardt@amd.com        code.dedent()
2486877Ssteve.reinhardt@amd.com        code.write(path, '%s.py' % py_ident)
24910917Sbrandon.potter@amd.com
2506877Ssteve.reinhardt@amd.com
2516657Snate@binkert.org    def printControllerHH(self, path):
2526657Snate@binkert.org        '''Output the method declarations for the class declaration'''
2536999Snate@binkert.org        code = self.symtab.codeFormatter()
2546657Snate@binkert.org        ident = self.ident
2556657Snate@binkert.org        c_ident = "%s_Controller" % self.ident
2566657Snate@binkert.org
2576657Snate@binkert.org        code('''
2587007Snate@binkert.org/** \\file $c_ident.hh
2596657Snate@binkert.org *
2606657Snate@binkert.org * Auto generated C++ code started by $__file__:$__line__
2616657Snate@binkert.org * Created by slicc definition of Module "${{self.short}}"
2626657Snate@binkert.org */
2636657Snate@binkert.org
2647007Snate@binkert.org#ifndef __${ident}_CONTROLLER_HH__
2657007Snate@binkert.org#define __${ident}_CONTROLLER_HH__
2666657Snate@binkert.org
2677002Snate@binkert.org#include <iostream>
2687002Snate@binkert.org#include <sstream>
2697002Snate@binkert.org#include <string>
2707002Snate@binkert.org
2716657Snate@binkert.org#include "mem/protocol/TransitionResult.hh"
2726657Snate@binkert.org#include "mem/protocol/Types.hh"
2738229Snate@binkert.org#include "mem/ruby/common/Consumer.hh"
2748229Snate@binkert.org#include "mem/ruby/slicc_interface/AbstractController.hh"
2758229Snate@binkert.org#include "params/$c_ident.hh"
27610972Sdavid.hashe@amd.com
2776657Snate@binkert.org''')
2786657Snate@binkert.org
2796657Snate@binkert.org        seen_types = set()
2806657Snate@binkert.org        for var in self.objects:
2816793SBrad.Beckmann@amd.com            if var.type.ident not in seen_types and not var.type.isPrimitive:
2826657Snate@binkert.org                code('#include "mem/protocol/${{var.type.c_ident}}.hh"')
28310311Snilay@cs.wisc.edu                seen_types.add(var.type.ident)
2846657Snate@binkert.org
2856657Snate@binkert.org        # for adding information to the protocol debug trace
2866657Snate@binkert.org        code('''
2877002Snate@binkert.orgextern std::stringstream ${ident}_transitionComment;
2886657Snate@binkert.org
2897007Snate@binkert.orgclass $c_ident : public AbstractController
2907007Snate@binkert.org{
2919271Snilay@cs.wisc.edu  public:
2926877Ssteve.reinhardt@amd.com    typedef ${c_ident}Params Params;
2936877Ssteve.reinhardt@amd.com    $c_ident(const Params *p);
2946657Snate@binkert.org    static int getNumControllers();
2956877Ssteve.reinhardt@amd.com    void init();
29610311Snilay@cs.wisc.edu
29711084Snilay@cs.wisc.edu    MessageBuffer *getMandatoryQueue() const;
29811084Snilay@cs.wisc.edu    MessageBuffer *getMemoryQueue() const;
29911021Sjthestness@gmail.com    void initNetQueues();
3009745Snilay@cs.wisc.edu
3017002Snate@binkert.org    void print(std::ostream& out) const;
3026657Snate@binkert.org    void wakeup();
30310012Snilay@cs.wisc.edu    void resetStats();
3049745Snilay@cs.wisc.edu    void regStats();
3059745Snilay@cs.wisc.edu    void collateStats();
3069745Snilay@cs.wisc.edu
3078683Snilay@cs.wisc.edu    void recordCacheTrace(int cntrl, CacheRecorder* tr);
3088683Snilay@cs.wisc.edu    Sequencer* getSequencer() const;
3097007Snate@binkert.org
31010524Snilay@cs.wisc.edu    int functionalWriteBuffers(PacketPtr&);
3119302Snilay@cs.wisc.edu
3129745Snilay@cs.wisc.edu    void countTransition(${ident}_State state, ${ident}_Event event);
3139745Snilay@cs.wisc.edu    void possibleTransition(${ident}_State state, ${ident}_Event event);
31411061Snilay@cs.wisc.edu    uint64_t getEventCount(${ident}_Event event);
3159745Snilay@cs.wisc.edu    bool isPossible(${ident}_State state, ${ident}_Event event);
31611061Snilay@cs.wisc.edu    uint64_t getTransitionCount(${ident}_State state, ${ident}_Event event);
3179745Snilay@cs.wisc.edu
3186657Snate@binkert.orgprivate:
3196657Snate@binkert.org''')
3206657Snate@binkert.org
3216657Snate@binkert.org        code.indent()
3226657Snate@binkert.org        # added by SS
3236657Snate@binkert.org        for param in self.config_parameters:
3246882SBrad.Beckmann@amd.com            if param.pointer:
3256882SBrad.Beckmann@amd.com                code('${{param.type_ast.type}}* m_${{param.ident}}_ptr;')
3266882SBrad.Beckmann@amd.com            else:
3276882SBrad.Beckmann@amd.com                code('${{param.type_ast.type}} m_${{param.ident}};')
3286657Snate@binkert.org
3296657Snate@binkert.org        code('''
3307007Snate@binkert.orgTransitionResult doTransition(${ident}_Event event,
3317839Snilay@cs.wisc.edu''')
3327839Snilay@cs.wisc.edu
3337839Snilay@cs.wisc.edu        if self.EntryType != None:
3347839Snilay@cs.wisc.edu            code('''
3357839Snilay@cs.wisc.edu                              ${{self.EntryType.c_ident}}* m_cache_entry_ptr,
3367839Snilay@cs.wisc.edu''')
3377839Snilay@cs.wisc.edu        if self.TBEType != None:
3387839Snilay@cs.wisc.edu            code('''
3397839Snilay@cs.wisc.edu                              ${{self.TBEType.c_ident}}* m_tbe_ptr,
3407839Snilay@cs.wisc.edu''')
3417839Snilay@cs.wisc.edu
3427839Snilay@cs.wisc.edu        code('''
34311025Snilay@cs.wisc.edu                              Addr addr);
3447007Snate@binkert.org
3457007Snate@binkert.orgTransitionResult doTransitionWorker(${ident}_Event event,
3467007Snate@binkert.org                                    ${ident}_State state,
3477007Snate@binkert.org                                    ${ident}_State& next_state,
3487839Snilay@cs.wisc.edu''')
3497839Snilay@cs.wisc.edu
3507839Snilay@cs.wisc.edu        if self.TBEType != None:
3517839Snilay@cs.wisc.edu            code('''
3527839Snilay@cs.wisc.edu                                    ${{self.TBEType.c_ident}}*& m_tbe_ptr,
3537839Snilay@cs.wisc.edu''')
3547839Snilay@cs.wisc.edu        if self.EntryType != None:
3557839Snilay@cs.wisc.edu            code('''
3567839Snilay@cs.wisc.edu                                    ${{self.EntryType.c_ident}}*& m_cache_entry_ptr,
3577839Snilay@cs.wisc.edu''')
3587839Snilay@cs.wisc.edu
3597839Snilay@cs.wisc.edu        code('''
36011025Snilay@cs.wisc.edu                                    Addr addr);
3617007Snate@binkert.org
3629745Snilay@cs.wisc.eduint m_counters[${ident}_State_NUM][${ident}_Event_NUM];
3639745Snilay@cs.wisc.eduint m_event_counters[${ident}_Event_NUM];
3649745Snilay@cs.wisc.edubool m_possible[${ident}_State_NUM][${ident}_Event_NUM];
3659745Snilay@cs.wisc.edu
3669745Snilay@cs.wisc.edustatic std::vector<Stats::Vector *> eventVec;
3679745Snilay@cs.wisc.edustatic std::vector<std::vector<Stats::Vector *> > transVec;
3686657Snate@binkert.orgstatic int m_num_controllers;
3697007Snate@binkert.org
3706657Snate@binkert.org// Internal functions
3716657Snate@binkert.org''')
3726657Snate@binkert.org
3736657Snate@binkert.org        for func in self.functions:
3746657Snate@binkert.org            proto = func.prototype
3756657Snate@binkert.org            if proto:
3766657Snate@binkert.org                code('$proto')
3776657Snate@binkert.org
3787839Snilay@cs.wisc.edu        if self.EntryType != None:
3797839Snilay@cs.wisc.edu            code('''
3807839Snilay@cs.wisc.edu
3817839Snilay@cs.wisc.edu// Set and Reset for cache_entry variable
3827839Snilay@cs.wisc.eduvoid set_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, AbstractCacheEntry* m_new_cache_entry);
3837839Snilay@cs.wisc.eduvoid unset_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr);
3847839Snilay@cs.wisc.edu''')
3857839Snilay@cs.wisc.edu
3867839Snilay@cs.wisc.edu        if self.TBEType != None:
3877839Snilay@cs.wisc.edu            code('''
3887839Snilay@cs.wisc.edu
3897839Snilay@cs.wisc.edu// Set and Reset for tbe variable
3907839Snilay@cs.wisc.eduvoid set_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr, ${ident}_TBE* m_new_tbe);
3917839Snilay@cs.wisc.eduvoid unset_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr);
3927839Snilay@cs.wisc.edu''')
3937839Snilay@cs.wisc.edu
39410121Snilay@cs.wisc.edu        # Prototype the actions that the controller can take
3956657Snate@binkert.org        code('''
3966657Snate@binkert.org
3976657Snate@binkert.org// Actions
3986657Snate@binkert.org''')
3997839Snilay@cs.wisc.edu        if self.TBEType != None and self.EntryType != None:
4007839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
4017839Snilay@cs.wisc.edu                code('/** \\brief ${{action.desc}} */')
40210121Snilay@cs.wisc.edu                code('void ${{action.ident}}(${{self.TBEType.c_ident}}*& '
40310121Snilay@cs.wisc.edu                     'm_tbe_ptr, ${{self.EntryType.c_ident}}*& '
40411025Snilay@cs.wisc.edu                     'm_cache_entry_ptr, Addr addr);')
4057839Snilay@cs.wisc.edu        elif self.TBEType != 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.TBEType.c_ident}}*& '
40911025Snilay@cs.wisc.edu                     'm_tbe_ptr, Addr addr);')
4107839Snilay@cs.wisc.edu        elif self.EntryType != None:
4117839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
4127839Snilay@cs.wisc.edu                code('/** \\brief ${{action.desc}} */')
41310121Snilay@cs.wisc.edu                code('void ${{action.ident}}(${{self.EntryType.c_ident}}*& '
41411025Snilay@cs.wisc.edu                     'm_cache_entry_ptr, Addr addr);')
4157839Snilay@cs.wisc.edu        else:
4167839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
4177839Snilay@cs.wisc.edu                code('/** \\brief ${{action.desc}} */')
41811025Snilay@cs.wisc.edu                code('void ${{action.ident}}(Addr addr);')
4196657Snate@binkert.org
4206657Snate@binkert.org        # the controller internal variables
4216657Snate@binkert.org        code('''
4226657Snate@binkert.org
4237007Snate@binkert.org// Objects
4246657Snate@binkert.org''')
4256657Snate@binkert.org        for var in self.objects:
4269273Snilay@cs.wisc.edu            th = var.get("template", "")
42710305Snilay@cs.wisc.edu            code('${{var.type.c_ident}}$th* m_${{var.ident}}_ptr;')
4286657Snate@binkert.org
4296657Snate@binkert.org        code.dedent()
4306657Snate@binkert.org        code('};')
4317007Snate@binkert.org        code('#endif // __${ident}_CONTROLLER_H__')
4326657Snate@binkert.org        code.write(path, '%s.hh' % c_ident)
4336657Snate@binkert.org
4349219Spower.jg@gmail.com    def printControllerCC(self, path, includes):
4356657Snate@binkert.org        '''Output the actions for performing the actions'''
4366657Snate@binkert.org
4376999Snate@binkert.org        code = self.symtab.codeFormatter()
4386657Snate@binkert.org        ident = self.ident
4396657Snate@binkert.org        c_ident = "%s_Controller" % self.ident
4406657Snate@binkert.org
4416657Snate@binkert.org        code('''
4427007Snate@binkert.org/** \\file $c_ident.cc
4436657Snate@binkert.org *
4446657Snate@binkert.org * Auto generated C++ code started by $__file__:$__line__
4456657Snate@binkert.org * Created by slicc definition of Module "${{self.short}}"
4466657Snate@binkert.org */
4476657Snate@binkert.org
4488946Sandreas.hansson@arm.com#include <sys/types.h>
4498946Sandreas.hansson@arm.com#include <unistd.h>
4508946Sandreas.hansson@arm.com
4517832Snate@binkert.org#include <cassert>
4527002Snate@binkert.org#include <sstream>
4537002Snate@binkert.org#include <string>
45410972Sdavid.hashe@amd.com#include <typeinfo>
4557002Snate@binkert.org
4568641Snate@binkert.org#include "base/compiler.hh"
4577056Snate@binkert.org#include "base/cprintf.hh"
45810972Sdavid.hashe@amd.com
45910972Sdavid.hashe@amd.com''')
46010972Sdavid.hashe@amd.com        for f in self.debug_flags:
46110972Sdavid.hashe@amd.com            code('#include "debug/${{f}}.hh"')
46210972Sdavid.hashe@amd.com        code('''
4636657Snate@binkert.org#include "mem/protocol/${ident}_Controller.hh"
4648229Snate@binkert.org#include "mem/protocol/${ident}_Event.hh"
4656657Snate@binkert.org#include "mem/protocol/${ident}_State.hh"
4666657Snate@binkert.org#include "mem/protocol/Types.hh"
46711108Sdavid.hashe@amd.com#include "mem/ruby/system/RubySystem.hh"
46810972Sdavid.hashe@amd.com
4699219Spower.jg@gmail.com''')
4709219Spower.jg@gmail.com        for include_path in includes:
4719219Spower.jg@gmail.com            code('#include "${{include_path}}"')
4729219Spower.jg@gmail.com
4739219Spower.jg@gmail.com        code('''
4747002Snate@binkert.org
4757002Snate@binkert.orgusing namespace std;
4766657Snate@binkert.org''')
4776657Snate@binkert.org
4786657Snate@binkert.org        # include object classes
4796657Snate@binkert.org        seen_types = set()
4806657Snate@binkert.org        for var in self.objects:
4816793SBrad.Beckmann@amd.com            if var.type.ident not in seen_types and not var.type.isPrimitive:
4826657Snate@binkert.org                code('#include "mem/protocol/${{var.type.c_ident}}.hh"')
4836657Snate@binkert.org            seen_types.add(var.type.ident)
4846657Snate@binkert.org
48510121Snilay@cs.wisc.edu        num_in_ports = len(self.in_ports)
48610121Snilay@cs.wisc.edu
4876657Snate@binkert.org        code('''
4886877Ssteve.reinhardt@amd.com$c_ident *
4896877Ssteve.reinhardt@amd.com${c_ident}Params::create()
4906877Ssteve.reinhardt@amd.com{
4916877Ssteve.reinhardt@amd.com    return new $c_ident(this);
4926877Ssteve.reinhardt@amd.com}
4936877Ssteve.reinhardt@amd.com
4946657Snate@binkert.orgint $c_ident::m_num_controllers = 0;
4959745Snilay@cs.wisc.edustd::vector<Stats::Vector *>  $c_ident::eventVec;
4969745Snilay@cs.wisc.edustd::vector<std::vector<Stats::Vector *> >  $c_ident::transVec;
4976657Snate@binkert.org
4987007Snate@binkert.org// for adding information to the protocol debug trace
4996657Snate@binkert.orgstringstream ${ident}_transitionComment;
5009801Snilay@cs.wisc.edu
5019801Snilay@cs.wisc.edu#ifndef NDEBUG
5026657Snate@binkert.org#define APPEND_TRANSITION_COMMENT(str) (${ident}_transitionComment << str)
5039801Snilay@cs.wisc.edu#else
5049801Snilay@cs.wisc.edu#define APPEND_TRANSITION_COMMENT(str) do {} while (0)
5059801Snilay@cs.wisc.edu#endif
5067007Snate@binkert.org
5076657Snate@binkert.org/** \\brief constructor */
5086877Ssteve.reinhardt@amd.com$c_ident::$c_ident(const Params *p)
5096877Ssteve.reinhardt@amd.com    : AbstractController(p)
5106657Snate@binkert.org{
51110078Snilay@cs.wisc.edu    m_machineID.type = MachineType_${ident};
51210078Snilay@cs.wisc.edu    m_machineID.num = m_version;
51310121Snilay@cs.wisc.edu    m_num_controllers++;
51410121Snilay@cs.wisc.edu
51510121Snilay@cs.wisc.edu    m_in_ports = $num_in_ports;
5166657Snate@binkert.org''')
5176657Snate@binkert.org        code.indent()
5186882SBrad.Beckmann@amd.com
5196882SBrad.Beckmann@amd.com        #
5206882SBrad.Beckmann@amd.com        # After initializing the universal machine parameters, initialize the
52110121Snilay@cs.wisc.edu        # this machines config parameters.  Also if these configuration params
52210121Snilay@cs.wisc.edu        # include a sequencer, connect the it to the controller.
5236882SBrad.Beckmann@amd.com        #
5246877Ssteve.reinhardt@amd.com        for param in self.config_parameters:
5256882SBrad.Beckmann@amd.com            if param.pointer:
52610308Snilay@cs.wisc.edu                code('m_${{param.ident}}_ptr = p->${{param.ident}};')
5276882SBrad.Beckmann@amd.com            else:
52810308Snilay@cs.wisc.edu                code('m_${{param.ident}} = p->${{param.ident}};')
52910311Snilay@cs.wisc.edu
53010308Snilay@cs.wisc.edu            if re.compile("sequencer").search(param.ident):
53110308Snilay@cs.wisc.edu                code('m_${{param.ident}}_ptr->setController(this);')
53210917Sbrandon.potter@amd.com
5339595Snilay@cs.wisc.edu        code('''
5349745Snilay@cs.wisc.edu
5359745Snilay@cs.wisc.edufor (int state = 0; state < ${ident}_State_NUM; state++) {
5369745Snilay@cs.wisc.edu    for (int event = 0; event < ${ident}_Event_NUM; event++) {
5379745Snilay@cs.wisc.edu        m_possible[state][event] = false;
5389745Snilay@cs.wisc.edu        m_counters[state][event] = 0;
5399745Snilay@cs.wisc.edu    }
5409745Snilay@cs.wisc.edu}
5419745Snilay@cs.wisc.edufor (int event = 0; event < ${ident}_Event_NUM; event++) {
5429745Snilay@cs.wisc.edu    m_event_counters[event] = 0;
5439745Snilay@cs.wisc.edu}
5449595Snilay@cs.wisc.edu''')
5456657Snate@binkert.org        code.dedent()
5466657Snate@binkert.org        code('''
5476657Snate@binkert.org}
5486657Snate@binkert.org
5497007Snate@binkert.orgvoid
55011021Sjthestness@gmail.com$c_ident::initNetQueues()
55110311Snilay@cs.wisc.edu{
55210311Snilay@cs.wisc.edu    MachineType machine_type = string_to_MachineType("${{self.ident}}");
55310311Snilay@cs.wisc.edu    int base M5_VAR_USED = MachineType_base_number(machine_type);
55410311Snilay@cs.wisc.edu
55510311Snilay@cs.wisc.edu''')
55610311Snilay@cs.wisc.edu        code.indent()
55710311Snilay@cs.wisc.edu
55810311Snilay@cs.wisc.edu        # set for maintaining the vnet, direction pairs already seen for this
55910311Snilay@cs.wisc.edu        # machine.  This map helps in implementing the check for avoiding
56010311Snilay@cs.wisc.edu        # multiple message buffers being mapped to the same vnet.
56110311Snilay@cs.wisc.edu        vnet_dir_set = set()
56210311Snilay@cs.wisc.edu
56310311Snilay@cs.wisc.edu        for var in self.config_parameters:
56411084Snilay@cs.wisc.edu            vid = "m_%s_ptr" % var.ident
56510311Snilay@cs.wisc.edu            if "network" in var:
56610311Snilay@cs.wisc.edu                vtype = var.type_ast.type
56711021Sjthestness@gmail.com                code('assert($vid != NULL);')
56811021Sjthestness@gmail.com
56910311Snilay@cs.wisc.edu                # Network port object
57010311Snilay@cs.wisc.edu                network = var["network"]
57110311Snilay@cs.wisc.edu
57210311Snilay@cs.wisc.edu                if "virtual_network" in var:
57310311Snilay@cs.wisc.edu                    vnet = var["virtual_network"]
57410311Snilay@cs.wisc.edu                    vnet_type = var["vnet_type"]
57510311Snilay@cs.wisc.edu
57610311Snilay@cs.wisc.edu                    assert (vnet, network) not in vnet_dir_set
57710311Snilay@cs.wisc.edu                    vnet_dir_set.add((vnet,network))
57810311Snilay@cs.wisc.edu
57910311Snilay@cs.wisc.edu                    code('''
58011021Sjthestness@gmail.comm_net_ptr->set${network}NetQueue(m_version + base, $vid->getOrdered(), $vnet,
58111021Sjthestness@gmail.com                                 "$vnet_type", $vid);
58210311Snilay@cs.wisc.edu''')
58310311Snilay@cs.wisc.edu                # Set Priority
58410311Snilay@cs.wisc.edu                if "rank" in var:
58510311Snilay@cs.wisc.edu                    code('$vid->setPriority(${{var["rank"]}})')
58610311Snilay@cs.wisc.edu
58710311Snilay@cs.wisc.edu        code.dedent()
58810311Snilay@cs.wisc.edu        code('''
58910311Snilay@cs.wisc.edu}
59010311Snilay@cs.wisc.edu
59110311Snilay@cs.wisc.eduvoid
5927007Snate@binkert.org$c_ident::init()
5936657Snate@binkert.org{
5947007Snate@binkert.org    // initialize objects
5956657Snate@binkert.org''')
5966657Snate@binkert.org
5976657Snate@binkert.org        code.indent()
59810311Snilay@cs.wisc.edu
5996657Snate@binkert.org        for var in self.objects:
6006657Snate@binkert.org            vtype = var.type
60110305Snilay@cs.wisc.edu            vid = "m_%s_ptr" % var.ident
6026657Snate@binkert.org            if "network" not in var:
6036657Snate@binkert.org                # Not a network port object
6046657Snate@binkert.org                if "primitive" in vtype:
6056657Snate@binkert.org                    code('$vid = new ${{vtype.c_ident}};')
6066657Snate@binkert.org                    if "default" in var:
6076657Snate@binkert.org                        code('(*$vid) = ${{var["default"]}};')
6086657Snate@binkert.org                else:
6096657Snate@binkert.org                    # Normal Object
61011084Snilay@cs.wisc.edu                    th = var.get("template", "")
61111084Snilay@cs.wisc.edu                    expr = "%s  = new %s%s" % (vid, vtype.c_ident, th)
61211084Snilay@cs.wisc.edu                    args = ""
61311084Snilay@cs.wisc.edu                    if "non_obj" not in vtype and not vtype.isEnumeration:
61411084Snilay@cs.wisc.edu                        args = var.get("constructor", "")
6156657Snate@binkert.org
61611084Snilay@cs.wisc.edu                    code('$expr($args);')
6176657Snate@binkert.org                    code('assert($vid != NULL);')
6186657Snate@binkert.org
6196657Snate@binkert.org                    if "default" in var:
6207007Snate@binkert.org                        code('*$vid = ${{var["default"]}}; // Object default')
6216657Snate@binkert.org                    elif "default" in vtype:
6227007Snate@binkert.org                        comment = "Type %s default" % vtype.ident
6237007Snate@binkert.org                        code('*$vid = ${{vtype["default"]}}; // $comment')
6246657Snate@binkert.org
6259366Snilay@cs.wisc.edu        # Set the prefetchers
6269366Snilay@cs.wisc.edu        code()
6279366Snilay@cs.wisc.edu        for prefetcher in self.prefetchers:
6289366Snilay@cs.wisc.edu            code('${{prefetcher.code}}.setController(this);')
6297566SBrad.Beckmann@amd.com
6307672Snate@binkert.org        code()
6316657Snate@binkert.org        for port in self.in_ports:
6329465Snilay@cs.wisc.edu            # Set the queue consumers
6336657Snate@binkert.org            code('${{port.code}}.setConsumer(this);')
6346657Snate@binkert.org
6356657Snate@binkert.org        # Initialize the transition profiling
6367672Snate@binkert.org        code()
6376657Snate@binkert.org        for trans in self.transitions:
6386657Snate@binkert.org            # Figure out if we stall
6396657Snate@binkert.org            stall = False
6406657Snate@binkert.org            for action in trans.actions:
6416657Snate@binkert.org                if action.ident == "z_stall":
6426657Snate@binkert.org                    stall = True
6436657Snate@binkert.org
6446657Snate@binkert.org            # Only possible if it is not a 'z' case
6456657Snate@binkert.org            if not stall:
6466657Snate@binkert.org                state = "%s_State_%s" % (self.ident, trans.state.ident)
6476657Snate@binkert.org                event = "%s_Event_%s" % (self.ident, trans.event.ident)
6489745Snilay@cs.wisc.edu                code('possibleTransition($state, $event);')
6496657Snate@binkert.org
6506657Snate@binkert.org        code.dedent()
6519496Snilay@cs.wisc.edu        code('''
6529496Snilay@cs.wisc.edu    AbstractController::init();
65310012Snilay@cs.wisc.edu    resetStats();
6549496Snilay@cs.wisc.edu}
6559496Snilay@cs.wisc.edu''')
6566657Snate@binkert.org
65710121Snilay@cs.wisc.edu        mq_ident = "NULL"
6586657Snate@binkert.org        for port in self.in_ports:
6596657Snate@binkert.org            if port.code.find("mandatoryQueue_ptr") >= 0:
66010305Snilay@cs.wisc.edu                mq_ident = "m_mandatoryQueue_ptr"
6616657Snate@binkert.org
66211021Sjthestness@gmail.com        memq_ident = "NULL"
66311021Sjthestness@gmail.com        for port in self.in_ports:
66411021Sjthestness@gmail.com            if port.code.find("responseFromMemory_ptr") >= 0:
66511021Sjthestness@gmail.com                memq_ident = "m_responseFromMemory_ptr"
66611021Sjthestness@gmail.com
6678683Snilay@cs.wisc.edu        seq_ident = "NULL"
6688683Snilay@cs.wisc.edu        for param in self.config_parameters:
66910308Snilay@cs.wisc.edu            if param.ident == "sequencer":
6708683Snilay@cs.wisc.edu                assert(param.pointer)
67110308Snilay@cs.wisc.edu                seq_ident = "m_%s_ptr" % param.ident
6728683Snilay@cs.wisc.edu
6736657Snate@binkert.org        code('''
6749745Snilay@cs.wisc.edu
6759745Snilay@cs.wisc.eduvoid
6769745Snilay@cs.wisc.edu$c_ident::regStats()
6779745Snilay@cs.wisc.edu{
67810012Snilay@cs.wisc.edu    AbstractController::regStats();
67910012Snilay@cs.wisc.edu
6809745Snilay@cs.wisc.edu    if (m_version == 0) {
6819745Snilay@cs.wisc.edu        for (${ident}_Event event = ${ident}_Event_FIRST;
6829745Snilay@cs.wisc.edu             event < ${ident}_Event_NUM; ++event) {
6839745Snilay@cs.wisc.edu            Stats::Vector *t = new Stats::Vector();
6849745Snilay@cs.wisc.edu            t->init(m_num_controllers);
68510919Sbrandon.potter@amd.com            t->name(params()->ruby_system->name() + ".${c_ident}." +
68610012Snilay@cs.wisc.edu                ${ident}_Event_to_string(event));
6879745Snilay@cs.wisc.edu            t->flags(Stats::pdf | Stats::total | Stats::oneline |
6889745Snilay@cs.wisc.edu                     Stats::nozero);
6899745Snilay@cs.wisc.edu
6909745Snilay@cs.wisc.edu            eventVec.push_back(t);
6919745Snilay@cs.wisc.edu        }
6929745Snilay@cs.wisc.edu
6939745Snilay@cs.wisc.edu        for (${ident}_State state = ${ident}_State_FIRST;
6949745Snilay@cs.wisc.edu             state < ${ident}_State_NUM; ++state) {
6959745Snilay@cs.wisc.edu
6969745Snilay@cs.wisc.edu            transVec.push_back(std::vector<Stats::Vector *>());
6979745Snilay@cs.wisc.edu
6989745Snilay@cs.wisc.edu            for (${ident}_Event event = ${ident}_Event_FIRST;
6999745Snilay@cs.wisc.edu                 event < ${ident}_Event_NUM; ++event) {
7009745Snilay@cs.wisc.edu
7019745Snilay@cs.wisc.edu                Stats::Vector *t = new Stats::Vector();
7029745Snilay@cs.wisc.edu                t->init(m_num_controllers);
70310919Sbrandon.potter@amd.com                t->name(params()->ruby_system->name() + ".${c_ident}." +
70410012Snilay@cs.wisc.edu                        ${ident}_State_to_string(state) +
7059745Snilay@cs.wisc.edu                        "." + ${ident}_Event_to_string(event));
7069745Snilay@cs.wisc.edu
7079745Snilay@cs.wisc.edu                t->flags(Stats::pdf | Stats::total | Stats::oneline |
7089745Snilay@cs.wisc.edu                         Stats::nozero);
7099745Snilay@cs.wisc.edu                transVec[state].push_back(t);
7109745Snilay@cs.wisc.edu            }
7119745Snilay@cs.wisc.edu        }
7129745Snilay@cs.wisc.edu    }
7139745Snilay@cs.wisc.edu}
7149745Snilay@cs.wisc.edu
7159745Snilay@cs.wisc.eduvoid
7169745Snilay@cs.wisc.edu$c_ident::collateStats()
7179745Snilay@cs.wisc.edu{
7189745Snilay@cs.wisc.edu    for (${ident}_Event event = ${ident}_Event_FIRST;
7199745Snilay@cs.wisc.edu         event < ${ident}_Event_NUM; ++event) {
7209745Snilay@cs.wisc.edu        for (unsigned int i = 0; i < m_num_controllers; ++i) {
72110920Sbrandon.potter@amd.com            RubySystem *rs = params()->ruby_system;
7229745Snilay@cs.wisc.edu            std::map<uint32_t, AbstractController *>::iterator it =
72310920Sbrandon.potter@amd.com                     rs->m_abstract_controls[MachineType_${ident}].find(i);
72410920Sbrandon.potter@amd.com            assert(it != rs->m_abstract_controls[MachineType_${ident}].end());
7259745Snilay@cs.wisc.edu            (*eventVec[event])[i] =
7269745Snilay@cs.wisc.edu                (($c_ident *)(*it).second)->getEventCount(event);
7279745Snilay@cs.wisc.edu        }
7289745Snilay@cs.wisc.edu    }
7299745Snilay@cs.wisc.edu
7309745Snilay@cs.wisc.edu    for (${ident}_State state = ${ident}_State_FIRST;
7319745Snilay@cs.wisc.edu         state < ${ident}_State_NUM; ++state) {
7329745Snilay@cs.wisc.edu
7339745Snilay@cs.wisc.edu        for (${ident}_Event event = ${ident}_Event_FIRST;
7349745Snilay@cs.wisc.edu             event < ${ident}_Event_NUM; ++event) {
7359745Snilay@cs.wisc.edu
7369745Snilay@cs.wisc.edu            for (unsigned int i = 0; i < m_num_controllers; ++i) {
73710920Sbrandon.potter@amd.com                RubySystem *rs = params()->ruby_system;
7389745Snilay@cs.wisc.edu                std::map<uint32_t, AbstractController *>::iterator it =
73910920Sbrandon.potter@amd.com                         rs->m_abstract_controls[MachineType_${ident}].find(i);
74010920Sbrandon.potter@amd.com                assert(it != rs->m_abstract_controls[MachineType_${ident}].end());
7419745Snilay@cs.wisc.edu                (*transVec[state][event])[i] =
7429745Snilay@cs.wisc.edu                    (($c_ident *)(*it).second)->getTransitionCount(state, event);
7439745Snilay@cs.wisc.edu            }
7449745Snilay@cs.wisc.edu        }
7459745Snilay@cs.wisc.edu    }
7469745Snilay@cs.wisc.edu}
7479745Snilay@cs.wisc.edu
7489745Snilay@cs.wisc.eduvoid
7499745Snilay@cs.wisc.edu$c_ident::countTransition(${ident}_State state, ${ident}_Event event)
7509745Snilay@cs.wisc.edu{
7519745Snilay@cs.wisc.edu    assert(m_possible[state][event]);
7529745Snilay@cs.wisc.edu    m_counters[state][event]++;
7539745Snilay@cs.wisc.edu    m_event_counters[event]++;
7549745Snilay@cs.wisc.edu}
7559745Snilay@cs.wisc.eduvoid
7569745Snilay@cs.wisc.edu$c_ident::possibleTransition(${ident}_State state,
7579745Snilay@cs.wisc.edu                             ${ident}_Event event)
7589745Snilay@cs.wisc.edu{
7599745Snilay@cs.wisc.edu    m_possible[state][event] = true;
7609745Snilay@cs.wisc.edu}
7619745Snilay@cs.wisc.edu
76211061Snilay@cs.wisc.eduuint64_t
7639745Snilay@cs.wisc.edu$c_ident::getEventCount(${ident}_Event event)
7649745Snilay@cs.wisc.edu{
7659745Snilay@cs.wisc.edu    return m_event_counters[event];
7669745Snilay@cs.wisc.edu}
7679745Snilay@cs.wisc.edu
7689745Snilay@cs.wisc.edubool
7699745Snilay@cs.wisc.edu$c_ident::isPossible(${ident}_State state, ${ident}_Event event)
7709745Snilay@cs.wisc.edu{
7719745Snilay@cs.wisc.edu    return m_possible[state][event];
7729745Snilay@cs.wisc.edu}
7739745Snilay@cs.wisc.edu
77411061Snilay@cs.wisc.eduuint64_t
7759745Snilay@cs.wisc.edu$c_ident::getTransitionCount(${ident}_State state,
7769745Snilay@cs.wisc.edu                             ${ident}_Event event)
7779745Snilay@cs.wisc.edu{
7789745Snilay@cs.wisc.edu    return m_counters[state][event];
7799745Snilay@cs.wisc.edu}
7809745Snilay@cs.wisc.edu
7817007Snate@binkert.orgint
7827007Snate@binkert.org$c_ident::getNumControllers()
7837007Snate@binkert.org{
7846657Snate@binkert.org    return m_num_controllers;
7856657Snate@binkert.org}
7866657Snate@binkert.org
7877007Snate@binkert.orgMessageBuffer*
7887007Snate@binkert.org$c_ident::getMandatoryQueue() const
7897007Snate@binkert.org{
7906657Snate@binkert.org    return $mq_ident;
7916657Snate@binkert.org}
7926657Snate@binkert.org
79311021Sjthestness@gmail.comMessageBuffer*
79411021Sjthestness@gmail.com$c_ident::getMemoryQueue() const
79511021Sjthestness@gmail.com{
79611021Sjthestness@gmail.com    return $memq_ident;
79711021Sjthestness@gmail.com}
79811021Sjthestness@gmail.com
7998683Snilay@cs.wisc.eduSequencer*
8008683Snilay@cs.wisc.edu$c_ident::getSequencer() const
8018683Snilay@cs.wisc.edu{
8028683Snilay@cs.wisc.edu    return $seq_ident;
8038683Snilay@cs.wisc.edu}
8048683Snilay@cs.wisc.edu
8057007Snate@binkert.orgvoid
8067007Snate@binkert.org$c_ident::print(ostream& out) const
8077007Snate@binkert.org{
8087007Snate@binkert.org    out << "[$c_ident " << m_version << "]";
8097007Snate@binkert.org}
8106657Snate@binkert.org
81110012Snilay@cs.wisc.eduvoid $c_ident::resetStats()
8129745Snilay@cs.wisc.edu{
8139745Snilay@cs.wisc.edu    for (int state = 0; state < ${ident}_State_NUM; state++) {
8149745Snilay@cs.wisc.edu        for (int event = 0; event < ${ident}_Event_NUM; event++) {
8159745Snilay@cs.wisc.edu            m_counters[state][event] = 0;
8169745Snilay@cs.wisc.edu        }
8179745Snilay@cs.wisc.edu    }
8186902SBrad.Beckmann@amd.com
8199745Snilay@cs.wisc.edu    for (int event = 0; event < ${ident}_Event_NUM; event++) {
8209745Snilay@cs.wisc.edu        m_event_counters[event] = 0;
8219745Snilay@cs.wisc.edu    }
8229745Snilay@cs.wisc.edu
82310012Snilay@cs.wisc.edu    AbstractController::resetStats();
8246902SBrad.Beckmann@amd.com}
8257839Snilay@cs.wisc.edu''')
8267839Snilay@cs.wisc.edu
8277839Snilay@cs.wisc.edu        if self.EntryType != None:
8287839Snilay@cs.wisc.edu            code('''
8297839Snilay@cs.wisc.edu
8307839Snilay@cs.wisc.edu// Set and Reset for cache_entry variable
8317839Snilay@cs.wisc.eduvoid
8327839Snilay@cs.wisc.edu$c_ident::set_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, AbstractCacheEntry* m_new_cache_entry)
8337839Snilay@cs.wisc.edu{
8347839Snilay@cs.wisc.edu  m_cache_entry_ptr = (${{self.EntryType.c_ident}}*)m_new_cache_entry;
8357839Snilay@cs.wisc.edu}
8367839Snilay@cs.wisc.edu
8377839Snilay@cs.wisc.eduvoid
8387839Snilay@cs.wisc.edu$c_ident::unset_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr)
8397839Snilay@cs.wisc.edu{
8407839Snilay@cs.wisc.edu  m_cache_entry_ptr = 0;
8417839Snilay@cs.wisc.edu}
8427839Snilay@cs.wisc.edu''')
8437839Snilay@cs.wisc.edu
8447839Snilay@cs.wisc.edu        if self.TBEType != None:
8457839Snilay@cs.wisc.edu            code('''
8467839Snilay@cs.wisc.edu
8477839Snilay@cs.wisc.edu// Set and Reset for tbe variable
8487839Snilay@cs.wisc.eduvoid
8497839Snilay@cs.wisc.edu$c_ident::set_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr, ${{self.TBEType.c_ident}}* m_new_tbe)
8507839Snilay@cs.wisc.edu{
8517839Snilay@cs.wisc.edu  m_tbe_ptr = m_new_tbe;
8527839Snilay@cs.wisc.edu}
8537839Snilay@cs.wisc.edu
8547839Snilay@cs.wisc.eduvoid
8557839Snilay@cs.wisc.edu$c_ident::unset_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr)
8567839Snilay@cs.wisc.edu{
8577839Snilay@cs.wisc.edu  m_tbe_ptr = NULL;
8587839Snilay@cs.wisc.edu}
8597839Snilay@cs.wisc.edu''')
8607839Snilay@cs.wisc.edu
8617839Snilay@cs.wisc.edu        code('''
8626902SBrad.Beckmann@amd.com
8638683Snilay@cs.wisc.eduvoid
8648683Snilay@cs.wisc.edu$c_ident::recordCacheTrace(int cntrl, CacheRecorder* tr)
8658683Snilay@cs.wisc.edu{
8668683Snilay@cs.wisc.edu''')
8678683Snilay@cs.wisc.edu        #
8688683Snilay@cs.wisc.edu        # Record cache contents for all associated caches.
8698683Snilay@cs.wisc.edu        #
8708683Snilay@cs.wisc.edu        code.indent()
8718683Snilay@cs.wisc.edu        for param in self.config_parameters:
8728683Snilay@cs.wisc.edu            if param.type_ast.type.ident == "CacheMemory":
8738683Snilay@cs.wisc.edu                assert(param.pointer)
8748683Snilay@cs.wisc.edu                code('m_${{param.ident}}_ptr->recordCacheContents(cntrl, tr);')
8758683Snilay@cs.wisc.edu
8768683Snilay@cs.wisc.edu        code.dedent()
8778683Snilay@cs.wisc.edu        code('''
8788683Snilay@cs.wisc.edu}
8798683Snilay@cs.wisc.edu
8806657Snate@binkert.org// Actions
8816657Snate@binkert.org''')
8827839Snilay@cs.wisc.edu        if self.TBEType != None and self.EntryType != None:
8837839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
8847839Snilay@cs.wisc.edu                if "c_code" not in action:
8857839Snilay@cs.wisc.edu                 continue
8866657Snate@binkert.org
8877839Snilay@cs.wisc.edu                code('''
8887839Snilay@cs.wisc.edu/** \\brief ${{action.desc}} */
8897839Snilay@cs.wisc.eduvoid
89011025Snilay@cs.wisc.edu$c_ident::${{action.ident}}(${{self.TBEType.c_ident}}*& m_tbe_ptr, ${{self.EntryType.c_ident}}*& m_cache_entry_ptr, Addr addr)
8917839Snilay@cs.wisc.edu{
8928055Sksewell@umich.edu    DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n");
89310963Sdavid.hashe@amd.com    try {
89410963Sdavid.hashe@amd.com       ${{action["c_code"]}}
89510963Sdavid.hashe@amd.com    } catch (const RejectException & e) {
89610963Sdavid.hashe@amd.com       fatal("Error in action ${{ident}}:${{action.ident}}: "
89710963Sdavid.hashe@amd.com             "executed a peek statement with the wrong message "
89810963Sdavid.hashe@amd.com             "type specified. ");
89910963Sdavid.hashe@amd.com    }
9007839Snilay@cs.wisc.edu}
9016657Snate@binkert.org
9027839Snilay@cs.wisc.edu''')
9037839Snilay@cs.wisc.edu        elif self.TBEType != None:
9047839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
9057839Snilay@cs.wisc.edu                if "c_code" not in action:
9067839Snilay@cs.wisc.edu                 continue
9077839Snilay@cs.wisc.edu
9087839Snilay@cs.wisc.edu                code('''
9097839Snilay@cs.wisc.edu/** \\brief ${{action.desc}} */
9107839Snilay@cs.wisc.eduvoid
91111025Snilay@cs.wisc.edu$c_ident::${{action.ident}}(${{self.TBEType.c_ident}}*& m_tbe_ptr, Addr addr)
9127839Snilay@cs.wisc.edu{
9138055Sksewell@umich.edu    DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n");
9147839Snilay@cs.wisc.edu    ${{action["c_code"]}}
9157839Snilay@cs.wisc.edu}
9167839Snilay@cs.wisc.edu
9177839Snilay@cs.wisc.edu''')
9187839Snilay@cs.wisc.edu        elif self.EntryType != None:
9197839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
9207839Snilay@cs.wisc.edu                if "c_code" not in action:
9217839Snilay@cs.wisc.edu                 continue
9227839Snilay@cs.wisc.edu
9237839Snilay@cs.wisc.edu                code('''
9247839Snilay@cs.wisc.edu/** \\brief ${{action.desc}} */
9257839Snilay@cs.wisc.eduvoid
92611025Snilay@cs.wisc.edu$c_ident::${{action.ident}}(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, Addr addr)
9277839Snilay@cs.wisc.edu{
9288055Sksewell@umich.edu    DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n");
9297839Snilay@cs.wisc.edu    ${{action["c_code"]}}
9307839Snilay@cs.wisc.edu}
9317839Snilay@cs.wisc.edu
9327839Snilay@cs.wisc.edu''')
9337839Snilay@cs.wisc.edu        else:
9347839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
9357839Snilay@cs.wisc.edu                if "c_code" not in action:
9367839Snilay@cs.wisc.edu                 continue
9377839Snilay@cs.wisc.edu
9387839Snilay@cs.wisc.edu                code('''
9396657Snate@binkert.org/** \\brief ${{action.desc}} */
9407007Snate@binkert.orgvoid
94111025Snilay@cs.wisc.edu$c_ident::${{action.ident}}(Addr addr)
9426657Snate@binkert.org{
9438055Sksewell@umich.edu    DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n");
9446657Snate@binkert.org    ${{action["c_code"]}}
9456657Snate@binkert.org}
9466657Snate@binkert.org
9476657Snate@binkert.org''')
9488478Snilay@cs.wisc.edu        for func in self.functions:
9498478Snilay@cs.wisc.edu            code(func.generateCode())
9508478Snilay@cs.wisc.edu
9519302Snilay@cs.wisc.edu        # Function for functional writes to messages buffered in the controller
9529302Snilay@cs.wisc.edu        code('''
95310524Snilay@cs.wisc.eduint
9549302Snilay@cs.wisc.edu$c_ident::functionalWriteBuffers(PacketPtr& pkt)
9559302Snilay@cs.wisc.edu{
95610524Snilay@cs.wisc.edu    int num_functional_writes = 0;
9579302Snilay@cs.wisc.edu''')
9589302Snilay@cs.wisc.edu        for var in self.objects:
9599302Snilay@cs.wisc.edu            vtype = var.type
9609302Snilay@cs.wisc.edu            if vtype.isBuffer:
96110305Snilay@cs.wisc.edu                vid = "m_%s_ptr" % var.ident
9629302Snilay@cs.wisc.edu                code('num_functional_writes += $vid->functionalWrite(pkt);')
96310311Snilay@cs.wisc.edu
96410311Snilay@cs.wisc.edu        for var in self.config_parameters:
96510311Snilay@cs.wisc.edu            vtype = var.type_ast.type
96610311Snilay@cs.wisc.edu            if vtype.isBuffer:
96710311Snilay@cs.wisc.edu                vid = "m_%s_ptr" % var.ident
96810311Snilay@cs.wisc.edu                code('num_functional_writes += $vid->functionalWrite(pkt);')
96910311Snilay@cs.wisc.edu
9709302Snilay@cs.wisc.edu        code('''
9719302Snilay@cs.wisc.edu    return num_functional_writes;
9729302Snilay@cs.wisc.edu}
9739302Snilay@cs.wisc.edu''')
9749302Snilay@cs.wisc.edu
9756657Snate@binkert.org        code.write(path, "%s.cc" % c_ident)
9766657Snate@binkert.org
9779219Spower.jg@gmail.com    def printCWakeup(self, path, includes):
9786657Snate@binkert.org        '''Output the wakeup loop for the events'''
9796657Snate@binkert.org
9806999Snate@binkert.org        code = self.symtab.codeFormatter()
9816657Snate@binkert.org        ident = self.ident
9826657Snate@binkert.org
9839104Shestness@cs.utexas.edu        outputRequest_types = True
9849104Shestness@cs.utexas.edu        if len(self.request_types) == 0:
9859104Shestness@cs.utexas.edu            outputRequest_types = False
9869104Shestness@cs.utexas.edu
9876657Snate@binkert.org        code('''
9886657Snate@binkert.org// Auto generated C++ code started by $__file__:$__line__
9896657Snate@binkert.org// ${ident}: ${{self.short}}
9906657Snate@binkert.org
9918946Sandreas.hansson@arm.com#include <sys/types.h>
9928946Sandreas.hansson@arm.com#include <unistd.h>
9938946Sandreas.hansson@arm.com
9947832Snate@binkert.org#include <cassert>
99510972Sdavid.hashe@amd.com#include <typeinfo>
9967832Snate@binkert.org
9977007Snate@binkert.org#include "base/misc.hh"
99810972Sdavid.hashe@amd.com
99910972Sdavid.hashe@amd.com''')
100010972Sdavid.hashe@amd.com        for f in self.debug_flags:
100110972Sdavid.hashe@amd.com            code('#include "debug/${{f}}.hh"')
100210972Sdavid.hashe@amd.com        code('''
10038229Snate@binkert.org#include "mem/protocol/${ident}_Controller.hh"
10048229Snate@binkert.org#include "mem/protocol/${ident}_Event.hh"
10058229Snate@binkert.org#include "mem/protocol/${ident}_State.hh"
100610972Sdavid.hashe@amd.com
10079104Shestness@cs.utexas.edu''')
10089104Shestness@cs.utexas.edu
10099104Shestness@cs.utexas.edu        if outputRequest_types:
10109104Shestness@cs.utexas.edu            code('''#include "mem/protocol/${ident}_RequestType.hh"''')
10119104Shestness@cs.utexas.edu
10129104Shestness@cs.utexas.edu        code('''
10138229Snate@binkert.org#include "mem/protocol/Types.hh"
101411108Sdavid.hashe@amd.com#include "mem/ruby/system/RubySystem.hh"
101510972Sdavid.hashe@amd.com
10169219Spower.jg@gmail.com''')
10179219Spower.jg@gmail.com
10189219Spower.jg@gmail.com
10199219Spower.jg@gmail.com        for include_path in includes:
10209219Spower.jg@gmail.com            code('#include "${{include_path}}"')
10219219Spower.jg@gmail.com
102210963Sdavid.hashe@amd.com        port_to_buf_map, in_msg_bufs, msg_bufs = self.getBufferMaps(ident)
102310963Sdavid.hashe@amd.com
10249219Spower.jg@gmail.com        code('''
10256657Snate@binkert.org
10267055Snate@binkert.orgusing namespace std;
10277055Snate@binkert.org
10287007Snate@binkert.orgvoid
10297007Snate@binkert.org${ident}_Controller::wakeup()
10306657Snate@binkert.org{
10316657Snate@binkert.org    int counter = 0;
10326657Snate@binkert.org    while (true) {
103310963Sdavid.hashe@amd.com        unsigned char rejected[${{len(msg_bufs)}}];
103410963Sdavid.hashe@amd.com        memset(rejected, 0, sizeof(unsigned char)*${{len(msg_bufs)}});
10356657Snate@binkert.org        // Some cases will put us into an infinite loop without this limit
10366657Snate@binkert.org        assert(counter <= m_transitions_per_cycle);
10376657Snate@binkert.org        if (counter == m_transitions_per_cycle) {
10387007Snate@binkert.org            // Count how often we are fully utilized
10399496Snilay@cs.wisc.edu            m_fully_busy_cycles++;
10407007Snate@binkert.org
10417007Snate@binkert.org            // Wakeup in another cycle and try again
10429499Snilay@cs.wisc.edu            scheduleEvent(Cycles(1));
10436657Snate@binkert.org            break;
10446657Snate@binkert.org        }
10456657Snate@binkert.org''')
10466657Snate@binkert.org
10476657Snate@binkert.org        code.indent()
10486657Snate@binkert.org        code.indent()
10496657Snate@binkert.org
10506657Snate@binkert.org        # InPorts
10516657Snate@binkert.org        #
10526657Snate@binkert.org        for port in self.in_ports:
10536657Snate@binkert.org            code.indent()
10546657Snate@binkert.org            code('// ${ident}InPort $port')
10557567SBrad.Beckmann@amd.com            if port.pairs.has_key("rank"):
10569996Snilay@cs.wisc.edu                code('m_cur_in_port = ${{port.pairs["rank"]}};')
10577567SBrad.Beckmann@amd.com            else:
10589996Snilay@cs.wisc.edu                code('m_cur_in_port = 0;')
105910963Sdavid.hashe@amd.com            if port in port_to_buf_map:
106010963Sdavid.hashe@amd.com                code('try {')
106110963Sdavid.hashe@amd.com                code.indent()
10626657Snate@binkert.org            code('${{port["c_code_in_port"]}}')
106310963Sdavid.hashe@amd.com
106410963Sdavid.hashe@amd.com            if port in port_to_buf_map:
106510963Sdavid.hashe@amd.com                code.dedent()
106610963Sdavid.hashe@amd.com                code('''
106710963Sdavid.hashe@amd.com            } catch (const RejectException & e) {
106810963Sdavid.hashe@amd.com                rejected[${{port_to_buf_map[port]}}]++;
106910963Sdavid.hashe@amd.com            }
107010963Sdavid.hashe@amd.com''')
10716657Snate@binkert.org            code.dedent()
10726657Snate@binkert.org            code('')
10736657Snate@binkert.org
10746657Snate@binkert.org        code.dedent()
10756657Snate@binkert.org        code.dedent()
10766657Snate@binkert.org        code('''
107710963Sdavid.hashe@amd.com        // If we got this far, we have nothing left todo or something went
107810963Sdavid.hashe@amd.com        // wrong''')
107910963Sdavid.hashe@amd.com        for buf_name, ports in in_msg_bufs.items():
108010963Sdavid.hashe@amd.com            if len(ports) > 1:
108110963Sdavid.hashe@amd.com                # only produce checks when a buffer is shared by multiple ports
108210963Sdavid.hashe@amd.com                code('''
108311116Santhony.gutierrez@amd.com        if (${{buf_name}}->isReady(clockEdge()) && rejected[${{port_to_buf_map[ports[0]]}}] == ${{len(ports)}})
108410963Sdavid.hashe@amd.com        {
108510963Sdavid.hashe@amd.com            // no port claimed the message on the top of this buffer
108610963Sdavid.hashe@amd.com            panic("Runtime Error at Ruby Time: %d. "
108710963Sdavid.hashe@amd.com                  "All ports rejected a message. "
108810963Sdavid.hashe@amd.com                  "You are probably sending a message type to this controller "
108910963Sdavid.hashe@amd.com                  "over a virtual network that do not define an in_port for "
109010963Sdavid.hashe@amd.com                  "the incoming message type.\\n",
109110963Sdavid.hashe@amd.com                  Cycles(1));
109210963Sdavid.hashe@amd.com        }
109310963Sdavid.hashe@amd.com''')
109410963Sdavid.hashe@amd.com        code('''
109510963Sdavid.hashe@amd.com        break;
10966657Snate@binkert.org    }
10976657Snate@binkert.org}
10986657Snate@binkert.org''')
10996657Snate@binkert.org
11006657Snate@binkert.org        code.write(path, "%s_Wakeup.cc" % self.ident)
11016657Snate@binkert.org
11026657Snate@binkert.org    def printCSwitch(self, path):
11036657Snate@binkert.org        '''Output switch statement for transition table'''
11046657Snate@binkert.org
11056999Snate@binkert.org        code = self.symtab.codeFormatter()
11066657Snate@binkert.org        ident = self.ident
11076657Snate@binkert.org
11086657Snate@binkert.org        code('''
11096657Snate@binkert.org// Auto generated C++ code started by $__file__:$__line__
11106657Snate@binkert.org// ${ident}: ${{self.short}}
11116657Snate@binkert.org
11127832Snate@binkert.org#include <cassert>
11137832Snate@binkert.org
11147805Snilay@cs.wisc.edu#include "base/misc.hh"
11157832Snate@binkert.org#include "base/trace.hh"
11168232Snate@binkert.org#include "debug/ProtocolTrace.hh"
11178232Snate@binkert.org#include "debug/RubyGenerated.hh"
11188229Snate@binkert.org#include "mem/protocol/${ident}_Controller.hh"
11198229Snate@binkert.org#include "mem/protocol/${ident}_Event.hh"
11208229Snate@binkert.org#include "mem/protocol/${ident}_State.hh"
11218229Snate@binkert.org#include "mem/protocol/Types.hh"
112211108Sdavid.hashe@amd.com#include "mem/ruby/system/RubySystem.hh"
11236657Snate@binkert.org
11246657Snate@binkert.org#define HASH_FUN(state, event)  ((int(state)*${ident}_Event_NUM)+int(event))
11256657Snate@binkert.org
11266657Snate@binkert.org#define GET_TRANSITION_COMMENT() (${ident}_transitionComment.str())
11276657Snate@binkert.org#define CLEAR_TRANSITION_COMMENT() (${ident}_transitionComment.str(""))
11286657Snate@binkert.org
11297007Snate@binkert.orgTransitionResult
11307007Snate@binkert.org${ident}_Controller::doTransition(${ident}_Event event,
11317839Snilay@cs.wisc.edu''')
11327839Snilay@cs.wisc.edu        if self.EntryType != None:
11337839Snilay@cs.wisc.edu            code('''
11347839Snilay@cs.wisc.edu                                  ${{self.EntryType.c_ident}}* m_cache_entry_ptr,
11357839Snilay@cs.wisc.edu''')
11367839Snilay@cs.wisc.edu        if self.TBEType != None:
11377839Snilay@cs.wisc.edu            code('''
11387839Snilay@cs.wisc.edu                                  ${{self.TBEType.c_ident}}* m_tbe_ptr,
11397839Snilay@cs.wisc.edu''')
11407839Snilay@cs.wisc.edu        code('''
114111025Snilay@cs.wisc.edu                                  Addr addr)
11426657Snate@binkert.org{
11437839Snilay@cs.wisc.edu''')
114410305Snilay@cs.wisc.edu        code.indent()
114510305Snilay@cs.wisc.edu
11467839Snilay@cs.wisc.edu        if self.TBEType != None and self.EntryType != None:
11478337Snilay@cs.wisc.edu            code('${ident}_State state = getState(m_tbe_ptr, m_cache_entry_ptr, addr);')
11487839Snilay@cs.wisc.edu        elif self.TBEType != None:
11498337Snilay@cs.wisc.edu            code('${ident}_State state = getState(m_tbe_ptr, addr);')
11507839Snilay@cs.wisc.edu        elif self.EntryType != None:
11518337Snilay@cs.wisc.edu            code('${ident}_State state = getState(m_cache_entry_ptr, addr);')
11527839Snilay@cs.wisc.edu        else:
11538337Snilay@cs.wisc.edu            code('${ident}_State state = getState(addr);')
11547839Snilay@cs.wisc.edu
11557839Snilay@cs.wisc.edu        code('''
115610305Snilay@cs.wisc.edu${ident}_State next_state = state;
11576657Snate@binkert.org
115810305Snilay@cs.wisc.eduDPRINTF(RubyGenerated, "%s, Time: %lld, state: %s, event: %s, addr: %s\\n",
115910305Snilay@cs.wisc.edu        *this, curCycle(), ${ident}_State_to_string(state),
116010305Snilay@cs.wisc.edu        ${ident}_Event_to_string(event), addr);
11616657Snate@binkert.org
116210305Snilay@cs.wisc.eduTransitionResult result =
11637839Snilay@cs.wisc.edu''')
11647839Snilay@cs.wisc.edu        if self.TBEType != None and self.EntryType != None:
11657839Snilay@cs.wisc.edu            code('doTransitionWorker(event, state, next_state, m_tbe_ptr, m_cache_entry_ptr, addr);')
11667839Snilay@cs.wisc.edu        elif self.TBEType != None:
11677839Snilay@cs.wisc.edu            code('doTransitionWorker(event, state, next_state, m_tbe_ptr, addr);')
11687839Snilay@cs.wisc.edu        elif self.EntryType != None:
11697839Snilay@cs.wisc.edu            code('doTransitionWorker(event, state, next_state, m_cache_entry_ptr, addr);')
11707839Snilay@cs.wisc.edu        else:
11717839Snilay@cs.wisc.edu            code('doTransitionWorker(event, state, next_state, addr);')
11726657Snate@binkert.org
117311049Snilay@cs.wisc.edu        port_to_buf_map, in_msg_bufs, msg_bufs = self.getBufferMaps(ident)
117411049Snilay@cs.wisc.edu
11757839Snilay@cs.wisc.edu        code('''
11766657Snate@binkert.org
117710305Snilay@cs.wisc.eduif (result == TransitionResult_Valid) {
117810305Snilay@cs.wisc.edu    DPRINTF(RubyGenerated, "next_state: %s\\n",
117910305Snilay@cs.wisc.edu            ${ident}_State_to_string(next_state));
118010305Snilay@cs.wisc.edu    countTransition(state, event);
118110305Snilay@cs.wisc.edu
118211025Snilay@cs.wisc.edu    DPRINTFR(ProtocolTrace, "%15d %3s %10s%20s %6s>%-6s %#x %s\\n",
118310305Snilay@cs.wisc.edu             curTick(), m_version, "${ident}",
118410305Snilay@cs.wisc.edu             ${ident}_Event_to_string(event),
118510305Snilay@cs.wisc.edu             ${ident}_State_to_string(state),
118610305Snilay@cs.wisc.edu             ${ident}_State_to_string(next_state),
118710305Snilay@cs.wisc.edu             addr, GET_TRANSITION_COMMENT());
118810305Snilay@cs.wisc.edu
118910305Snilay@cs.wisc.edu    CLEAR_TRANSITION_COMMENT();
11907839Snilay@cs.wisc.edu''')
11917839Snilay@cs.wisc.edu        if self.TBEType != None and self.EntryType != None:
11928337Snilay@cs.wisc.edu            code('setState(m_tbe_ptr, m_cache_entry_ptr, addr, next_state);')
11938341Snilay@cs.wisc.edu            code('setAccessPermission(m_cache_entry_ptr, addr, next_state);')
11947839Snilay@cs.wisc.edu        elif self.TBEType != None:
11958337Snilay@cs.wisc.edu            code('setState(m_tbe_ptr, addr, next_state);')
11968341Snilay@cs.wisc.edu            code('setAccessPermission(addr, next_state);')
11977839Snilay@cs.wisc.edu        elif self.EntryType != None:
11988337Snilay@cs.wisc.edu            code('setState(m_cache_entry_ptr, addr, next_state);')
11998341Snilay@cs.wisc.edu            code('setAccessPermission(m_cache_entry_ptr, addr, next_state);')
12007839Snilay@cs.wisc.edu        else:
12018337Snilay@cs.wisc.edu            code('setState(addr, next_state);')
12028341Snilay@cs.wisc.edu            code('setAccessPermission(addr, next_state);')
12037839Snilay@cs.wisc.edu
12047839Snilay@cs.wisc.edu        code('''
120510305Snilay@cs.wisc.edu} else if (result == TransitionResult_ResourceStall) {
120611025Snilay@cs.wisc.edu    DPRINTFR(ProtocolTrace, "%15s %3s %10s%20s %6s>%-6s %#x %s\\n",
120710305Snilay@cs.wisc.edu             curTick(), m_version, "${ident}",
120810305Snilay@cs.wisc.edu             ${ident}_Event_to_string(event),
120910305Snilay@cs.wisc.edu             ${ident}_State_to_string(state),
121010305Snilay@cs.wisc.edu             ${ident}_State_to_string(next_state),
121110305Snilay@cs.wisc.edu             addr, "Resource Stall");
121210305Snilay@cs.wisc.edu} else if (result == TransitionResult_ProtocolStall) {
121310305Snilay@cs.wisc.edu    DPRINTF(RubyGenerated, "stalling\\n");
121411025Snilay@cs.wisc.edu    DPRINTFR(ProtocolTrace, "%15s %3s %10s%20s %6s>%-6s %#x %s\\n",
121510305Snilay@cs.wisc.edu             curTick(), m_version, "${ident}",
121610305Snilay@cs.wisc.edu             ${ident}_Event_to_string(event),
121710305Snilay@cs.wisc.edu             ${ident}_State_to_string(state),
121810305Snilay@cs.wisc.edu             ${ident}_State_to_string(next_state),
121910305Snilay@cs.wisc.edu             addr, "Protocol Stall");
122010305Snilay@cs.wisc.edu}
12216657Snate@binkert.org
122210305Snilay@cs.wisc.edureturn result;
122310305Snilay@cs.wisc.edu''')
122410305Snilay@cs.wisc.edu        code.dedent()
122510305Snilay@cs.wisc.edu        code('''
12266657Snate@binkert.org}
12276657Snate@binkert.org
12287007Snate@binkert.orgTransitionResult
12297007Snate@binkert.org${ident}_Controller::doTransitionWorker(${ident}_Event event,
12307007Snate@binkert.org                                        ${ident}_State state,
12317007Snate@binkert.org                                        ${ident}_State& next_state,
12327839Snilay@cs.wisc.edu''')
12337839Snilay@cs.wisc.edu
12347839Snilay@cs.wisc.edu        if self.TBEType != None:
12357839Snilay@cs.wisc.edu            code('''
12367839Snilay@cs.wisc.edu                                        ${{self.TBEType.c_ident}}*& m_tbe_ptr,
12377839Snilay@cs.wisc.edu''')
12387839Snilay@cs.wisc.edu        if self.EntryType != None:
12397839Snilay@cs.wisc.edu                  code('''
12407839Snilay@cs.wisc.edu                                        ${{self.EntryType.c_ident}}*& m_cache_entry_ptr,
12417839Snilay@cs.wisc.edu''')
12427839Snilay@cs.wisc.edu        code('''
124311025Snilay@cs.wisc.edu                                        Addr addr)
12446657Snate@binkert.org{
12456657Snate@binkert.org    switch(HASH_FUN(state, event)) {
12466657Snate@binkert.org''')
12476657Snate@binkert.org
12486657Snate@binkert.org        # This map will allow suppress generating duplicate code
12496657Snate@binkert.org        cases = orderdict()
12506657Snate@binkert.org
12516657Snate@binkert.org        for trans in self.transitions:
12526657Snate@binkert.org            case_string = "%s_State_%s, %s_Event_%s" % \
12536657Snate@binkert.org                (self.ident, trans.state.ident, self.ident, trans.event.ident)
12546657Snate@binkert.org
12556999Snate@binkert.org            case = self.symtab.codeFormatter()
12566657Snate@binkert.org            # Only set next_state if it changes
12576657Snate@binkert.org            if trans.state != trans.nextState:
125810964Sdavid.hashe@amd.com                if trans.nextState.isWildcard():
125910964Sdavid.hashe@amd.com                    # When * is encountered as an end state of a transition,
126010964Sdavid.hashe@amd.com                    # the next state is determined by calling the
126110964Sdavid.hashe@amd.com                    # machine-specific getNextState function. The next state
126210964Sdavid.hashe@amd.com                    # is determined before any actions of the transition
126310964Sdavid.hashe@amd.com                    # execute, and therefore the next state calculation cannot
126410964Sdavid.hashe@amd.com                    # depend on any of the transitionactions.
126510964Sdavid.hashe@amd.com                    case('next_state = getNextState(addr);')
126610964Sdavid.hashe@amd.com                else:
126710964Sdavid.hashe@amd.com                    ns_ident = trans.nextState.ident
126810964Sdavid.hashe@amd.com                    case('next_state = ${ident}_State_${ns_ident};')
12696657Snate@binkert.org
12706657Snate@binkert.org            actions = trans.actions
12719104Shestness@cs.utexas.edu            request_types = trans.request_types
12726657Snate@binkert.org
12736657Snate@binkert.org            # Check for resources
12746657Snate@binkert.org            case_sorter = []
12756657Snate@binkert.org            res = trans.resources
12766657Snate@binkert.org            for key,val in res.iteritems():
127710228Snilay@cs.wisc.edu                val = '''
127811111Snilay@cs.wisc.eduif (!%s.areNSlotsAvailable(%s, clockEdge()))
12796657Snate@binkert.org    return TransitionResult_ResourceStall;
12806657Snate@binkert.org''' % (key.code, val)
12816657Snate@binkert.org                case_sorter.append(val)
12826657Snate@binkert.org
12839105SBrad.Beckmann@amd.com            # Check all of the request_types for resource constraints
12849105SBrad.Beckmann@amd.com            for request_type in request_types:
12859105SBrad.Beckmann@amd.com                val = '''
12869105SBrad.Beckmann@amd.comif (!checkResourceAvailable(%s_RequestType_%s, addr)) {
12879105SBrad.Beckmann@amd.com    return TransitionResult_ResourceStall;
12889105SBrad.Beckmann@amd.com}
12899105SBrad.Beckmann@amd.com''' % (self.ident, request_type.ident)
12909105SBrad.Beckmann@amd.com                case_sorter.append(val)
12916657Snate@binkert.org
12926657Snate@binkert.org            # Emit the code sequences in a sorted order.  This makes the
12936657Snate@binkert.org            # output deterministic (without this the output order can vary
12946657Snate@binkert.org            # since Map's keys() on a vector of pointers is not deterministic
12956657Snate@binkert.org            for c in sorted(case_sorter):
12966657Snate@binkert.org                case("$c")
12976657Snate@binkert.org
12989104Shestness@cs.utexas.edu            # Record access types for this transition
12999104Shestness@cs.utexas.edu            for request_type in request_types:
13009104Shestness@cs.utexas.edu                case('recordRequestType(${ident}_RequestType_${{request_type.ident}}, addr);')
13019104Shestness@cs.utexas.edu
13026657Snate@binkert.org            # Figure out if we stall
13036657Snate@binkert.org            stall = False
13046657Snate@binkert.org            for action in actions:
13056657Snate@binkert.org                if action.ident == "z_stall":
13066657Snate@binkert.org                    stall = True
13076657Snate@binkert.org                    break
13086657Snate@binkert.org
13096657Snate@binkert.org            if stall:
13106657Snate@binkert.org                case('return TransitionResult_ProtocolStall;')
13116657Snate@binkert.org            else:
13127839Snilay@cs.wisc.edu                if self.TBEType != None and self.EntryType != None:
13137839Snilay@cs.wisc.edu                    for action in actions:
13147839Snilay@cs.wisc.edu                        case('${{action.ident}}(m_tbe_ptr, m_cache_entry_ptr, addr);')
13157839Snilay@cs.wisc.edu                elif self.TBEType != None:
13167839Snilay@cs.wisc.edu                    for action in actions:
13177839Snilay@cs.wisc.edu                        case('${{action.ident}}(m_tbe_ptr, addr);')
13187839Snilay@cs.wisc.edu                elif self.EntryType != None:
13197839Snilay@cs.wisc.edu                    for action in actions:
13207839Snilay@cs.wisc.edu                        case('${{action.ident}}(m_cache_entry_ptr, addr);')
13217839Snilay@cs.wisc.edu                else:
13227839Snilay@cs.wisc.edu                    for action in actions:
13237839Snilay@cs.wisc.edu                        case('${{action.ident}}(addr);')
13246657Snate@binkert.org                case('return TransitionResult_Valid;')
13256657Snate@binkert.org
13266657Snate@binkert.org            case = str(case)
13276657Snate@binkert.org
13286657Snate@binkert.org            # Look to see if this transition code is unique.
13296657Snate@binkert.org            if case not in cases:
13306657Snate@binkert.org                cases[case] = []
13316657Snate@binkert.org
13326657Snate@binkert.org            cases[case].append(case_string)
13336657Snate@binkert.org
13346657Snate@binkert.org        # Walk through all of the unique code blocks and spit out the
13356657Snate@binkert.org        # corresponding case statement elements
13366657Snate@binkert.org        for case,transitions in cases.iteritems():
13376657Snate@binkert.org            # Iterative over all the multiple transitions that share
13386657Snate@binkert.org            # the same code
13396657Snate@binkert.org            for trans in transitions:
13406657Snate@binkert.org                code('  case HASH_FUN($trans):')
134110305Snilay@cs.wisc.edu            code('    $case\n')
13426657Snate@binkert.org
13436657Snate@binkert.org        code('''
13446657Snate@binkert.org      default:
134510962SBrad.Beckmann@amd.com        panic("Invalid transition\\n"
13468159SBrad.Beckmann@amd.com              "%s time: %d addr: %s event: %s state: %s\\n",
13479465Snilay@cs.wisc.edu              name(), curCycle(), addr, event, state);
13486657Snate@binkert.org    }
134910305Snilay@cs.wisc.edu
13506657Snate@binkert.org    return TransitionResult_Valid;
13516657Snate@binkert.org}
13526657Snate@binkert.org''')
13536657Snate@binkert.org        code.write(path, "%s_Transitions.cc" % self.ident)
13546657Snate@binkert.org
13556657Snate@binkert.org
13566657Snate@binkert.org    # **************************
13576657Snate@binkert.org    # ******* HTML Files *******
13586657Snate@binkert.org    # **************************
13597007Snate@binkert.org    def frameRef(self, click_href, click_target, over_href, over_num, text):
13606999Snate@binkert.org        code = self.symtab.codeFormatter(fix_newlines=False)
13617007Snate@binkert.org        code("""<A href=\"$click_href\" target=\"$click_target\" onmouseover=\"
13627007Snate@binkert.org    if (parent.frames[$over_num].location != parent.location + '$over_href') {
13637007Snate@binkert.org        parent.frames[$over_num].location='$over_href'
13647007Snate@binkert.org    }\">
13657007Snate@binkert.org    ${{html.formatShorthand(text)}}
13667007Snate@binkert.org    </A>""")
13676657Snate@binkert.org        return str(code)
13686657Snate@binkert.org
13696657Snate@binkert.org    def writeHTMLFiles(self, path):
13706657Snate@binkert.org        # Create table with no row hilighted
13716657Snate@binkert.org        self.printHTMLTransitions(path, None)
13726657Snate@binkert.org
13736657Snate@binkert.org        # Generate transition tables
13746657Snate@binkert.org        for state in self.states.itervalues():
13756657Snate@binkert.org            self.printHTMLTransitions(path, state)
13766657Snate@binkert.org
13776657Snate@binkert.org        # Generate action descriptions
13786657Snate@binkert.org        for action in self.actions.itervalues():
13796657Snate@binkert.org            name = "%s_action_%s.html" % (self.ident, action.ident)
13806657Snate@binkert.org            code = html.createSymbol(action, "Action")
13816657Snate@binkert.org            code.write(path, name)
13826657Snate@binkert.org
13836657Snate@binkert.org        # Generate state descriptions
13846657Snate@binkert.org        for state in self.states.itervalues():
13856657Snate@binkert.org            name = "%s_State_%s.html" % (self.ident, state.ident)
13866657Snate@binkert.org            code = html.createSymbol(state, "State")
13876657Snate@binkert.org            code.write(path, name)
13886657Snate@binkert.org
13896657Snate@binkert.org        # Generate event descriptions
13906657Snate@binkert.org        for event in self.events.itervalues():
13916657Snate@binkert.org            name = "%s_Event_%s.html" % (self.ident, event.ident)
13926657Snate@binkert.org            code = html.createSymbol(event, "Event")
13936657Snate@binkert.org            code.write(path, name)
13946657Snate@binkert.org
13956657Snate@binkert.org    def printHTMLTransitions(self, path, active_state):
13966999Snate@binkert.org        code = self.symtab.codeFormatter()
13976657Snate@binkert.org
13986657Snate@binkert.org        code('''
13997007Snate@binkert.org<HTML>
14007007Snate@binkert.org<BODY link="blue" vlink="blue">
14016657Snate@binkert.org
14026657Snate@binkert.org<H1 align="center">${{html.formatShorthand(self.short)}}:
14036657Snate@binkert.org''')
14046657Snate@binkert.org        code.indent()
14056657Snate@binkert.org        for i,machine in enumerate(self.symtab.getAllType(StateMachine)):
14066657Snate@binkert.org            mid = machine.ident
14076657Snate@binkert.org            if i != 0:
14086657Snate@binkert.org                extra = " - "
14096657Snate@binkert.org            else:
14106657Snate@binkert.org                extra = ""
14116657Snate@binkert.org            if machine == self:
14126657Snate@binkert.org                code('$extra$mid')
14136657Snate@binkert.org            else:
14146657Snate@binkert.org                code('$extra<A target="Table" href="${mid}_table.html">$mid</A>')
14156657Snate@binkert.org        code.dedent()
14166657Snate@binkert.org
14176657Snate@binkert.org        code("""
14186657Snate@binkert.org</H1>
14196657Snate@binkert.org
14206657Snate@binkert.org<TABLE border=1>
14216657Snate@binkert.org<TR>
14226657Snate@binkert.org  <TH> </TH>
14236657Snate@binkert.org""")
14246657Snate@binkert.org
14256657Snate@binkert.org        for event in self.events.itervalues():
14266657Snate@binkert.org            href = "%s_Event_%s.html" % (self.ident, event.ident)
14276657Snate@binkert.org            ref = self.frameRef(href, "Status", href, "1", event.short)
14286657Snate@binkert.org            code('<TH bgcolor=white>$ref</TH>')
14296657Snate@binkert.org
14306657Snate@binkert.org        code('</TR>')
14316657Snate@binkert.org        # -- Body of table
14326657Snate@binkert.org        for state in self.states.itervalues():
14336657Snate@binkert.org            # -- Each row
14346657Snate@binkert.org            if state == active_state:
14356657Snate@binkert.org                color = "yellow"
14366657Snate@binkert.org            else:
14376657Snate@binkert.org                color = "white"
14386657Snate@binkert.org
14396657Snate@binkert.org            click = "%s_table_%s.html" % (self.ident, state.ident)
14406657Snate@binkert.org            over = "%s_State_%s.html" % (self.ident, state.ident)
14416657Snate@binkert.org            text = html.formatShorthand(state.short)
14426657Snate@binkert.org            ref = self.frameRef(click, "Table", over, "1", state.short)
14436657Snate@binkert.org            code('''
14446657Snate@binkert.org<TR>
14456657Snate@binkert.org  <TH bgcolor=$color>$ref</TH>
14466657Snate@binkert.org''')
14476657Snate@binkert.org
14486657Snate@binkert.org            # -- One column for each event
14496657Snate@binkert.org            for event in self.events.itervalues():
14506657Snate@binkert.org                trans = self.table.get((state,event), None)
14516657Snate@binkert.org                if trans is None:
14526657Snate@binkert.org                    # This is the no transition case
14536657Snate@binkert.org                    if state == active_state:
14546657Snate@binkert.org                        color = "#C0C000"
14556657Snate@binkert.org                    else:
14566657Snate@binkert.org                        color = "lightgrey"
14576657Snate@binkert.org
14586657Snate@binkert.org                    code('<TD bgcolor=$color>&nbsp;</TD>')
14596657Snate@binkert.org                    continue
14606657Snate@binkert.org
14616657Snate@binkert.org                next = trans.nextState
14626657Snate@binkert.org                stall_action = False
14636657Snate@binkert.org
14646657Snate@binkert.org                # -- Get the actions
14656657Snate@binkert.org                for action in trans.actions:
14666657Snate@binkert.org                    if action.ident == "z_stall" or \
14676657Snate@binkert.org                       action.ident == "zz_recycleMandatoryQueue":
14686657Snate@binkert.org                        stall_action = True
14696657Snate@binkert.org
14706657Snate@binkert.org                # -- Print out "actions/next-state"
14716657Snate@binkert.org                if stall_action:
14726657Snate@binkert.org                    if state == active_state:
14736657Snate@binkert.org                        color = "#C0C000"
14746657Snate@binkert.org                    else:
14756657Snate@binkert.org                        color = "lightgrey"
14766657Snate@binkert.org
14776657Snate@binkert.org                elif active_state and next.ident == active_state.ident:
14786657Snate@binkert.org                    color = "aqua"
14796657Snate@binkert.org                elif state == active_state:
14806657Snate@binkert.org                    color = "yellow"
14816657Snate@binkert.org                else:
14826657Snate@binkert.org                    color = "white"
14836657Snate@binkert.org
14846657Snate@binkert.org                code('<TD bgcolor=$color>')
14856657Snate@binkert.org                for action in trans.actions:
14866657Snate@binkert.org                    href = "%s_action_%s.html" % (self.ident, action.ident)
14876657Snate@binkert.org                    ref = self.frameRef(href, "Status", href, "1",
14886657Snate@binkert.org                                        action.short)
14897007Snate@binkert.org                    code('  $ref')
14906657Snate@binkert.org                if next != state:
14916657Snate@binkert.org                    if trans.actions:
14926657Snate@binkert.org                        code('/')
14936657Snate@binkert.org                    click = "%s_table_%s.html" % (self.ident, next.ident)
14946657Snate@binkert.org                    over = "%s_State_%s.html" % (self.ident, next.ident)
14956657Snate@binkert.org                    ref = self.frameRef(click, "Table", over, "1", next.short)
14966657Snate@binkert.org                    code("$ref")
14977007Snate@binkert.org                code("</TD>")
14986657Snate@binkert.org
14996657Snate@binkert.org            # -- Each row
15006657Snate@binkert.org            if state == active_state:
15016657Snate@binkert.org                color = "yellow"
15026657Snate@binkert.org            else:
15036657Snate@binkert.org                color = "white"
15046657Snate@binkert.org
15056657Snate@binkert.org            click = "%s_table_%s.html" % (self.ident, state.ident)
15066657Snate@binkert.org            over = "%s_State_%s.html" % (self.ident, state.ident)
15076657Snate@binkert.org            ref = self.frameRef(click, "Table", over, "1", state.short)
15086657Snate@binkert.org            code('''
15096657Snate@binkert.org  <TH bgcolor=$color>$ref</TH>
15106657Snate@binkert.org</TR>
15116657Snate@binkert.org''')
15126657Snate@binkert.org        code('''
151310917Sbrandon.potter@amd.com<!- Column footer->
15146657Snate@binkert.org<TR>
15156657Snate@binkert.org  <TH> </TH>
15166657Snate@binkert.org''')
15176657Snate@binkert.org
15186657Snate@binkert.org        for event in self.events.itervalues():
15196657Snate@binkert.org            href = "%s_Event_%s.html" % (self.ident, event.ident)
15206657Snate@binkert.org            ref = self.frameRef(href, "Status", href, "1", event.short)
15216657Snate@binkert.org            code('<TH bgcolor=white>$ref</TH>')
15226657Snate@binkert.org        code('''
15236657Snate@binkert.org</TR>
15246657Snate@binkert.org</TABLE>
15256657Snate@binkert.org</BODY></HTML>
15266657Snate@binkert.org''')
15276657Snate@binkert.org
15286657Snate@binkert.org
15296657Snate@binkert.org        if active_state:
15306657Snate@binkert.org            name = "%s_table_%s.html" % (self.ident, active_state.ident)
15316657Snate@binkert.org        else:
15326657Snate@binkert.org            name = "%s_table.html" % self.ident
15336657Snate@binkert.org        code.write(path, name)
15346657Snate@binkert.org
15356657Snate@binkert.org__all__ = [ "StateMachine" ]
1536