StateMachine.py revision 10962
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"]:
1477839Snilay@cs.wisc.edu            if self.EntryType != None:
1487839Snilay@cs.wisc.edu                self.error("Multiple AbstractCacheEntry types in a " \
1497839Snilay@cs.wisc.edu                           "single machine.");
1507839Snilay@cs.wisc.edu            self.EntryType = type
1517839Snilay@cs.wisc.edu
1526657Snate@binkert.org    # Needs to be called before accessing the table
1536657Snate@binkert.org    def buildTable(self):
1546657Snate@binkert.org        assert self.table is None
1556657Snate@binkert.org
1566657Snate@binkert.org        table = {}
1576657Snate@binkert.org
1586657Snate@binkert.org        for trans in self.transitions:
1596657Snate@binkert.org            # Track which actions we touch so we know if we use them
1606657Snate@binkert.org            # all -- really this should be done for all symbols as
1616657Snate@binkert.org            # part of the symbol table, then only trigger it for
1626657Snate@binkert.org            # Actions, States, Events, etc.
1636657Snate@binkert.org
1646657Snate@binkert.org            for action in trans.actions:
1656657Snate@binkert.org                action.used = True
1666657Snate@binkert.org
1676657Snate@binkert.org            index = (trans.state, trans.event)
1686657Snate@binkert.org            if index in table:
1696657Snate@binkert.org                table[index].warning("Duplicate transition: %s" % table[index])
1706657Snate@binkert.org                trans.error("Duplicate transition: %s" % trans)
1716657Snate@binkert.org            table[index] = trans
1726657Snate@binkert.org
1736657Snate@binkert.org        # Look at all actions to make sure we used them all
1746657Snate@binkert.org        for action in self.actions.itervalues():
1756657Snate@binkert.org            if not action.used:
1766657Snate@binkert.org                error_msg = "Unused action: %s" % action.ident
1776657Snate@binkert.org                if "desc" in action:
1786657Snate@binkert.org                    error_msg += ", "  + action.desc
1796657Snate@binkert.org                action.warning(error_msg)
1806657Snate@binkert.org        self.table = table
1816657Snate@binkert.org
1829219Spower.jg@gmail.com    def writeCodeFiles(self, path, includes):
1836877Ssteve.reinhardt@amd.com        self.printControllerPython(path)
1846657Snate@binkert.org        self.printControllerHH(path)
1859219Spower.jg@gmail.com        self.printControllerCC(path, includes)
1866657Snate@binkert.org        self.printCSwitch(path)
1879219Spower.jg@gmail.com        self.printCWakeup(path, includes)
1886657Snate@binkert.org
1896877Ssteve.reinhardt@amd.com    def printControllerPython(self, path):
1906999Snate@binkert.org        code = self.symtab.codeFormatter()
1916877Ssteve.reinhardt@amd.com        ident = self.ident
19210308Snilay@cs.wisc.edu
1936877Ssteve.reinhardt@amd.com        py_ident = "%s_Controller" % ident
1946877Ssteve.reinhardt@amd.com        c_ident = "%s_Controller" % self.ident
19510308Snilay@cs.wisc.edu
1966877Ssteve.reinhardt@amd.com        code('''
1976877Ssteve.reinhardt@amd.comfrom m5.params import *
1986877Ssteve.reinhardt@amd.comfrom m5.SimObject import SimObject
1996877Ssteve.reinhardt@amd.comfrom Controller import RubyController
2006877Ssteve.reinhardt@amd.com
2016877Ssteve.reinhardt@amd.comclass $py_ident(RubyController):
2026877Ssteve.reinhardt@amd.com    type = '$py_ident'
2039338SAndreas.Sandberg@arm.com    cxx_header = 'mem/protocol/${c_ident}.hh'
2046877Ssteve.reinhardt@amd.com''')
2056877Ssteve.reinhardt@amd.com        code.indent()
2066877Ssteve.reinhardt@amd.com        for param in self.config_parameters:
2076877Ssteve.reinhardt@amd.com            dflt_str = ''
20810308Snilay@cs.wisc.edu
20910308Snilay@cs.wisc.edu            if param.rvalue is not None:
21010308Snilay@cs.wisc.edu                dflt_str = str(param.rvalue.inline()) + ', '
21110308Snilay@cs.wisc.edu
21210311Snilay@cs.wisc.edu            if param.type_ast.type.c_ident == "MessageBuffer":
21310311Snilay@cs.wisc.edu                if param["network"] == "To":
21410311Snilay@cs.wisc.edu                    code('${{param.ident}} = MasterPort(${dflt_str}"")')
21510311Snilay@cs.wisc.edu                else:
21610311Snilay@cs.wisc.edu                    code('${{param.ident}} = SlavePort(${dflt_str}"")')
21710311Snilay@cs.wisc.edu
21810311Snilay@cs.wisc.edu            elif python_class_map.has_key(param.type_ast.type.c_ident):
2196882SBrad.Beckmann@amd.com                python_type = python_class_map[param.type_ast.type.c_ident]
22010308Snilay@cs.wisc.edu                code('${{param.ident}} = Param.${{python_type}}(${dflt_str}"")')
22110308Snilay@cs.wisc.edu
2226882SBrad.Beckmann@amd.com            else:
2236882SBrad.Beckmann@amd.com                self.error("Unknown c++ to python class conversion for c++ " \
2246882SBrad.Beckmann@amd.com                           "type: '%s'. Please update the python_class_map " \
2256882SBrad.Beckmann@amd.com                           "in StateMachine.py", param.type_ast.type.c_ident)
2266877Ssteve.reinhardt@amd.com        code.dedent()
2276877Ssteve.reinhardt@amd.com        code.write(path, '%s.py' % py_ident)
22810917Sbrandon.potter@amd.com
2296877Ssteve.reinhardt@amd.com
2306657Snate@binkert.org    def printControllerHH(self, path):
2316657Snate@binkert.org        '''Output the method declarations for the class declaration'''
2326999Snate@binkert.org        code = self.symtab.codeFormatter()
2336657Snate@binkert.org        ident = self.ident
2346657Snate@binkert.org        c_ident = "%s_Controller" % self.ident
2356657Snate@binkert.org
2366657Snate@binkert.org        code('''
2377007Snate@binkert.org/** \\file $c_ident.hh
2386657Snate@binkert.org *
2396657Snate@binkert.org * Auto generated C++ code started by $__file__:$__line__
2406657Snate@binkert.org * Created by slicc definition of Module "${{self.short}}"
2416657Snate@binkert.org */
2426657Snate@binkert.org
2437007Snate@binkert.org#ifndef __${ident}_CONTROLLER_HH__
2447007Snate@binkert.org#define __${ident}_CONTROLLER_HH__
2456657Snate@binkert.org
2467002Snate@binkert.org#include <iostream>
2477002Snate@binkert.org#include <sstream>
2487002Snate@binkert.org#include <string>
2497002Snate@binkert.org
2506657Snate@binkert.org#include "mem/protocol/TransitionResult.hh"
2516657Snate@binkert.org#include "mem/protocol/Types.hh"
2528229Snate@binkert.org#include "mem/ruby/common/Consumer.hh"
2538229Snate@binkert.org#include "mem/ruby/slicc_interface/AbstractController.hh"
2548229Snate@binkert.org#include "params/$c_ident.hh"
2556657Snate@binkert.org''')
2566657Snate@binkert.org
2576657Snate@binkert.org        seen_types = set()
2586657Snate@binkert.org        for var in self.objects:
2596793SBrad.Beckmann@amd.com            if var.type.ident not in seen_types and not var.type.isPrimitive:
2606657Snate@binkert.org                code('#include "mem/protocol/${{var.type.c_ident}}.hh"')
26110311Snilay@cs.wisc.edu                seen_types.add(var.type.ident)
2626657Snate@binkert.org
2636657Snate@binkert.org        # for adding information to the protocol debug trace
2646657Snate@binkert.org        code('''
2657002Snate@binkert.orgextern std::stringstream ${ident}_transitionComment;
2666657Snate@binkert.org
2677007Snate@binkert.orgclass $c_ident : public AbstractController
2687007Snate@binkert.org{
2699271Snilay@cs.wisc.edu  public:
2706877Ssteve.reinhardt@amd.com    typedef ${c_ident}Params Params;
2716877Ssteve.reinhardt@amd.com    $c_ident(const Params *p);
2726657Snate@binkert.org    static int getNumControllers();
2736877Ssteve.reinhardt@amd.com    void init();
27410311Snilay@cs.wisc.edu
2756657Snate@binkert.org    MessageBuffer* getMandatoryQueue() const;
27610311Snilay@cs.wisc.edu    void setNetQueue(const std::string& name, MessageBuffer *b);
2779745Snilay@cs.wisc.edu
2787002Snate@binkert.org    void print(std::ostream& out) const;
2796657Snate@binkert.org    void wakeup();
28010012Snilay@cs.wisc.edu    void resetStats();
2819745Snilay@cs.wisc.edu    void regStats();
2829745Snilay@cs.wisc.edu    void collateStats();
2839745Snilay@cs.wisc.edu
2848683Snilay@cs.wisc.edu    void recordCacheTrace(int cntrl, CacheRecorder* tr);
2858683Snilay@cs.wisc.edu    Sequencer* getSequencer() const;
2867007Snate@binkert.org
28710524Snilay@cs.wisc.edu    int functionalWriteBuffers(PacketPtr&);
2889302Snilay@cs.wisc.edu
2899745Snilay@cs.wisc.edu    void countTransition(${ident}_State state, ${ident}_Event event);
2909745Snilay@cs.wisc.edu    void possibleTransition(${ident}_State state, ${ident}_Event event);
2919745Snilay@cs.wisc.edu    uint64 getEventCount(${ident}_Event event);
2929745Snilay@cs.wisc.edu    bool isPossible(${ident}_State state, ${ident}_Event event);
2939745Snilay@cs.wisc.edu    uint64 getTransitionCount(${ident}_State state, ${ident}_Event event);
2949745Snilay@cs.wisc.edu
2956657Snate@binkert.orgprivate:
2966657Snate@binkert.org''')
2976657Snate@binkert.org
2986657Snate@binkert.org        code.indent()
2996657Snate@binkert.org        # added by SS
3006657Snate@binkert.org        for param in self.config_parameters:
3016882SBrad.Beckmann@amd.com            if param.pointer:
3026882SBrad.Beckmann@amd.com                code('${{param.type_ast.type}}* m_${{param.ident}}_ptr;')
3036882SBrad.Beckmann@amd.com            else:
3046882SBrad.Beckmann@amd.com                code('${{param.type_ast.type}} m_${{param.ident}};')
3056657Snate@binkert.org
3066657Snate@binkert.org        code('''
3077007Snate@binkert.orgTransitionResult doTransition(${ident}_Event event,
3087839Snilay@cs.wisc.edu''')
3097839Snilay@cs.wisc.edu
3107839Snilay@cs.wisc.edu        if self.EntryType != None:
3117839Snilay@cs.wisc.edu            code('''
3127839Snilay@cs.wisc.edu                              ${{self.EntryType.c_ident}}* m_cache_entry_ptr,
3137839Snilay@cs.wisc.edu''')
3147839Snilay@cs.wisc.edu        if self.TBEType != None:
3157839Snilay@cs.wisc.edu            code('''
3167839Snilay@cs.wisc.edu                              ${{self.TBEType.c_ident}}* m_tbe_ptr,
3177839Snilay@cs.wisc.edu''')
3187839Snilay@cs.wisc.edu
3197839Snilay@cs.wisc.edu        code('''
32010010Snilay@cs.wisc.edu                              const Address addr);
3217007Snate@binkert.org
3227007Snate@binkert.orgTransitionResult doTransitionWorker(${ident}_Event event,
3237007Snate@binkert.org                                    ${ident}_State state,
3247007Snate@binkert.org                                    ${ident}_State& next_state,
3257839Snilay@cs.wisc.edu''')
3267839Snilay@cs.wisc.edu
3277839Snilay@cs.wisc.edu        if self.TBEType != None:
3287839Snilay@cs.wisc.edu            code('''
3297839Snilay@cs.wisc.edu                                    ${{self.TBEType.c_ident}}*& m_tbe_ptr,
3307839Snilay@cs.wisc.edu''')
3317839Snilay@cs.wisc.edu        if self.EntryType != None:
3327839Snilay@cs.wisc.edu            code('''
3337839Snilay@cs.wisc.edu                                    ${{self.EntryType.c_ident}}*& m_cache_entry_ptr,
3347839Snilay@cs.wisc.edu''')
3357839Snilay@cs.wisc.edu
3367839Snilay@cs.wisc.edu        code('''
3377007Snate@binkert.org                                    const Address& addr);
3387007Snate@binkert.org
3399745Snilay@cs.wisc.eduint m_counters[${ident}_State_NUM][${ident}_Event_NUM];
3409745Snilay@cs.wisc.eduint m_event_counters[${ident}_Event_NUM];
3419745Snilay@cs.wisc.edubool m_possible[${ident}_State_NUM][${ident}_Event_NUM];
3429745Snilay@cs.wisc.edu
3439745Snilay@cs.wisc.edustatic std::vector<Stats::Vector *> eventVec;
3449745Snilay@cs.wisc.edustatic std::vector<std::vector<Stats::Vector *> > transVec;
3456657Snate@binkert.orgstatic int m_num_controllers;
3467007Snate@binkert.org
3476657Snate@binkert.org// Internal functions
3486657Snate@binkert.org''')
3496657Snate@binkert.org
3506657Snate@binkert.org        for func in self.functions:
3516657Snate@binkert.org            proto = func.prototype
3526657Snate@binkert.org            if proto:
3536657Snate@binkert.org                code('$proto')
3546657Snate@binkert.org
3557839Snilay@cs.wisc.edu        if self.EntryType != None:
3567839Snilay@cs.wisc.edu            code('''
3577839Snilay@cs.wisc.edu
3587839Snilay@cs.wisc.edu// Set and Reset for cache_entry variable
3597839Snilay@cs.wisc.eduvoid set_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, AbstractCacheEntry* m_new_cache_entry);
3607839Snilay@cs.wisc.eduvoid unset_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr);
3617839Snilay@cs.wisc.edu''')
3627839Snilay@cs.wisc.edu
3637839Snilay@cs.wisc.edu        if self.TBEType != None:
3647839Snilay@cs.wisc.edu            code('''
3657839Snilay@cs.wisc.edu
3667839Snilay@cs.wisc.edu// Set and Reset for tbe variable
3677839Snilay@cs.wisc.eduvoid set_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr, ${ident}_TBE* m_new_tbe);
3687839Snilay@cs.wisc.eduvoid unset_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr);
3697839Snilay@cs.wisc.edu''')
3707839Snilay@cs.wisc.edu
37110121Snilay@cs.wisc.edu        # Prototype the actions that the controller can take
3726657Snate@binkert.org        code('''
3736657Snate@binkert.org
3746657Snate@binkert.org// Actions
3756657Snate@binkert.org''')
3767839Snilay@cs.wisc.edu        if self.TBEType != None and self.EntryType != None:
3777839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
3787839Snilay@cs.wisc.edu                code('/** \\brief ${{action.desc}} */')
37910121Snilay@cs.wisc.edu                code('void ${{action.ident}}(${{self.TBEType.c_ident}}*& '
38010121Snilay@cs.wisc.edu                     'm_tbe_ptr, ${{self.EntryType.c_ident}}*& '
38110121Snilay@cs.wisc.edu                     'm_cache_entry_ptr, const Address& addr);')
3827839Snilay@cs.wisc.edu        elif self.TBEType != None:
3837839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
3847839Snilay@cs.wisc.edu                code('/** \\brief ${{action.desc}} */')
38510121Snilay@cs.wisc.edu                code('void ${{action.ident}}(${{self.TBEType.c_ident}}*& '
38610121Snilay@cs.wisc.edu                     'm_tbe_ptr, const Address& addr);')
3877839Snilay@cs.wisc.edu        elif self.EntryType != None:
3887839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
3897839Snilay@cs.wisc.edu                code('/** \\brief ${{action.desc}} */')
39010121Snilay@cs.wisc.edu                code('void ${{action.ident}}(${{self.EntryType.c_ident}}*& '
39110121Snilay@cs.wisc.edu                     'm_cache_entry_ptr, const Address& addr);')
3927839Snilay@cs.wisc.edu        else:
3937839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
3947839Snilay@cs.wisc.edu                code('/** \\brief ${{action.desc}} */')
3957839Snilay@cs.wisc.edu                code('void ${{action.ident}}(const Address& addr);')
3966657Snate@binkert.org
3976657Snate@binkert.org        # the controller internal variables
3986657Snate@binkert.org        code('''
3996657Snate@binkert.org
4007007Snate@binkert.org// Objects
4016657Snate@binkert.org''')
4026657Snate@binkert.org        for var in self.objects:
4039273Snilay@cs.wisc.edu            th = var.get("template", "")
40410305Snilay@cs.wisc.edu            code('${{var.type.c_ident}}$th* m_${{var.ident}}_ptr;')
4056657Snate@binkert.org
4066657Snate@binkert.org        code.dedent()
4076657Snate@binkert.org        code('};')
4087007Snate@binkert.org        code('#endif // __${ident}_CONTROLLER_H__')
4096657Snate@binkert.org        code.write(path, '%s.hh' % c_ident)
4106657Snate@binkert.org
4119219Spower.jg@gmail.com    def printControllerCC(self, path, includes):
4126657Snate@binkert.org        '''Output the actions for performing the actions'''
4136657Snate@binkert.org
4146999Snate@binkert.org        code = self.symtab.codeFormatter()
4156657Snate@binkert.org        ident = self.ident
4166657Snate@binkert.org        c_ident = "%s_Controller" % self.ident
4176657Snate@binkert.org
4186657Snate@binkert.org        code('''
4197007Snate@binkert.org/** \\file $c_ident.cc
4206657Snate@binkert.org *
4216657Snate@binkert.org * Auto generated C++ code started by $__file__:$__line__
4226657Snate@binkert.org * Created by slicc definition of Module "${{self.short}}"
4236657Snate@binkert.org */
4246657Snate@binkert.org
4258946Sandreas.hansson@arm.com#include <sys/types.h>
4268946Sandreas.hansson@arm.com#include <unistd.h>
4278946Sandreas.hansson@arm.com
4287832Snate@binkert.org#include <cassert>
4297002Snate@binkert.org#include <sstream>
4307002Snate@binkert.org#include <string>
4317002Snate@binkert.org
4328641Snate@binkert.org#include "base/compiler.hh"
4337056Snate@binkert.org#include "base/cprintf.hh"
4348232Snate@binkert.org#include "debug/RubyGenerated.hh"
4358232Snate@binkert.org#include "debug/RubySlicc.hh"
4366657Snate@binkert.org#include "mem/protocol/${ident}_Controller.hh"
4378229Snate@binkert.org#include "mem/protocol/${ident}_Event.hh"
4386657Snate@binkert.org#include "mem/protocol/${ident}_State.hh"
4396657Snate@binkert.org#include "mem/protocol/Types.hh"
4406657Snate@binkert.org#include "mem/ruby/system/System.hh"
4419219Spower.jg@gmail.com''')
4429219Spower.jg@gmail.com        for include_path in includes:
4439219Spower.jg@gmail.com            code('#include "${{include_path}}"')
4449219Spower.jg@gmail.com
4459219Spower.jg@gmail.com        code('''
4467002Snate@binkert.org
4477002Snate@binkert.orgusing namespace std;
4486657Snate@binkert.org''')
4496657Snate@binkert.org
4506657Snate@binkert.org        # include object classes
4516657Snate@binkert.org        seen_types = set()
4526657Snate@binkert.org        for var in self.objects:
4536793SBrad.Beckmann@amd.com            if var.type.ident not in seen_types and not var.type.isPrimitive:
4546657Snate@binkert.org                code('#include "mem/protocol/${{var.type.c_ident}}.hh"')
4556657Snate@binkert.org            seen_types.add(var.type.ident)
4566657Snate@binkert.org
45710121Snilay@cs.wisc.edu        num_in_ports = len(self.in_ports)
45810121Snilay@cs.wisc.edu
4596657Snate@binkert.org        code('''
4606877Ssteve.reinhardt@amd.com$c_ident *
4616877Ssteve.reinhardt@amd.com${c_ident}Params::create()
4626877Ssteve.reinhardt@amd.com{
4636877Ssteve.reinhardt@amd.com    return new $c_ident(this);
4646877Ssteve.reinhardt@amd.com}
4656877Ssteve.reinhardt@amd.com
4666657Snate@binkert.orgint $c_ident::m_num_controllers = 0;
4679745Snilay@cs.wisc.edustd::vector<Stats::Vector *>  $c_ident::eventVec;
4689745Snilay@cs.wisc.edustd::vector<std::vector<Stats::Vector *> >  $c_ident::transVec;
4696657Snate@binkert.org
4707007Snate@binkert.org// for adding information to the protocol debug trace
4716657Snate@binkert.orgstringstream ${ident}_transitionComment;
4729801Snilay@cs.wisc.edu
4739801Snilay@cs.wisc.edu#ifndef NDEBUG
4746657Snate@binkert.org#define APPEND_TRANSITION_COMMENT(str) (${ident}_transitionComment << str)
4759801Snilay@cs.wisc.edu#else
4769801Snilay@cs.wisc.edu#define APPEND_TRANSITION_COMMENT(str) do {} while (0)
4779801Snilay@cs.wisc.edu#endif
4787007Snate@binkert.org
4796657Snate@binkert.org/** \\brief constructor */
4806877Ssteve.reinhardt@amd.com$c_ident::$c_ident(const Params *p)
4816877Ssteve.reinhardt@amd.com    : AbstractController(p)
4826657Snate@binkert.org{
48310078Snilay@cs.wisc.edu    m_machineID.type = MachineType_${ident};
48410078Snilay@cs.wisc.edu    m_machineID.num = m_version;
48510121Snilay@cs.wisc.edu    m_num_controllers++;
48610121Snilay@cs.wisc.edu
48710121Snilay@cs.wisc.edu    m_in_ports = $num_in_ports;
4886657Snate@binkert.org''')
4896657Snate@binkert.org        code.indent()
4906882SBrad.Beckmann@amd.com
4916882SBrad.Beckmann@amd.com        #
4926882SBrad.Beckmann@amd.com        # After initializing the universal machine parameters, initialize the
49310121Snilay@cs.wisc.edu        # this machines config parameters.  Also if these configuration params
49410121Snilay@cs.wisc.edu        # include a sequencer, connect the it to the controller.
4956882SBrad.Beckmann@amd.com        #
4966877Ssteve.reinhardt@amd.com        for param in self.config_parameters:
49710311Snilay@cs.wisc.edu
49810311Snilay@cs.wisc.edu            # Do not initialize messgage buffers since they are initialized
49910311Snilay@cs.wisc.edu            # when the port based connections are made.
50010311Snilay@cs.wisc.edu            if param.type_ast.type.c_ident == "MessageBuffer":
50110311Snilay@cs.wisc.edu                continue
50210311Snilay@cs.wisc.edu
5036882SBrad.Beckmann@amd.com            if param.pointer:
50410308Snilay@cs.wisc.edu                code('m_${{param.ident}}_ptr = p->${{param.ident}};')
5056882SBrad.Beckmann@amd.com            else:
50610308Snilay@cs.wisc.edu                code('m_${{param.ident}} = p->${{param.ident}};')
50710311Snilay@cs.wisc.edu
50810308Snilay@cs.wisc.edu            if re.compile("sequencer").search(param.ident):
50910308Snilay@cs.wisc.edu                code('m_${{param.ident}}_ptr->setController(this);')
51010917Sbrandon.potter@amd.com
5116657Snate@binkert.org        for var in self.objects:
5126657Snate@binkert.org            if var.ident.find("mandatoryQueue") >= 0:
5139508Snilay@cs.wisc.edu                code('''
51410305Snilay@cs.wisc.edum_${{var.ident}}_ptr = new ${{var.type.c_ident}}();
51510305Snilay@cs.wisc.edum_${{var.ident}}_ptr->setReceiver(this);
5169508Snilay@cs.wisc.edu''')
5176657Snate@binkert.org
5189595Snilay@cs.wisc.edu        code('''
5199745Snilay@cs.wisc.edu
5209745Snilay@cs.wisc.edufor (int state = 0; state < ${ident}_State_NUM; state++) {
5219745Snilay@cs.wisc.edu    for (int event = 0; event < ${ident}_Event_NUM; event++) {
5229745Snilay@cs.wisc.edu        m_possible[state][event] = false;
5239745Snilay@cs.wisc.edu        m_counters[state][event] = 0;
5249745Snilay@cs.wisc.edu    }
5259745Snilay@cs.wisc.edu}
5269745Snilay@cs.wisc.edufor (int event = 0; event < ${ident}_Event_NUM; event++) {
5279745Snilay@cs.wisc.edu    m_event_counters[event] = 0;
5289745Snilay@cs.wisc.edu}
5299595Snilay@cs.wisc.edu''')
5306657Snate@binkert.org        code.dedent()
5316657Snate@binkert.org        code('''
5326657Snate@binkert.org}
5336657Snate@binkert.org
5347007Snate@binkert.orgvoid
53510311Snilay@cs.wisc.edu$c_ident::setNetQueue(const std::string& name, MessageBuffer *b)
53610311Snilay@cs.wisc.edu{
53710311Snilay@cs.wisc.edu    MachineType machine_type = string_to_MachineType("${{self.ident}}");
53810311Snilay@cs.wisc.edu    int base M5_VAR_USED = MachineType_base_number(machine_type);
53910311Snilay@cs.wisc.edu
54010311Snilay@cs.wisc.edu''')
54110311Snilay@cs.wisc.edu        code.indent()
54210311Snilay@cs.wisc.edu
54310311Snilay@cs.wisc.edu        # set for maintaining the vnet, direction pairs already seen for this
54410311Snilay@cs.wisc.edu        # machine.  This map helps in implementing the check for avoiding
54510311Snilay@cs.wisc.edu        # multiple message buffers being mapped to the same vnet.
54610311Snilay@cs.wisc.edu        vnet_dir_set = set()
54710311Snilay@cs.wisc.edu
54810311Snilay@cs.wisc.edu        for var in self.config_parameters:
54910311Snilay@cs.wisc.edu            if "network" in var:
55010311Snilay@cs.wisc.edu                vtype = var.type_ast.type
55110311Snilay@cs.wisc.edu                vid = "m_%s_ptr" % var.ident
55210311Snilay@cs.wisc.edu
55310311Snilay@cs.wisc.edu                code('''
55410311Snilay@cs.wisc.eduif ("${{var.ident}}" == name) {
55510311Snilay@cs.wisc.edu    $vid = b;
55610311Snilay@cs.wisc.edu    assert($vid != NULL);
55710311Snilay@cs.wisc.edu''')
55810311Snilay@cs.wisc.edu                code.indent()
55910311Snilay@cs.wisc.edu                # Network port object
56010311Snilay@cs.wisc.edu                network = var["network"]
56110311Snilay@cs.wisc.edu                ordered =  var["ordered"]
56210311Snilay@cs.wisc.edu
56310311Snilay@cs.wisc.edu                if "virtual_network" in var:
56410311Snilay@cs.wisc.edu                    vnet = var["virtual_network"]
56510311Snilay@cs.wisc.edu                    vnet_type = var["vnet_type"]
56610311Snilay@cs.wisc.edu
56710311Snilay@cs.wisc.edu                    assert (vnet, network) not in vnet_dir_set
56810311Snilay@cs.wisc.edu                    vnet_dir_set.add((vnet,network))
56910311Snilay@cs.wisc.edu
57010311Snilay@cs.wisc.edu                    code('''
57110311Snilay@cs.wisc.edum_net_ptr->set${network}NetQueue(m_version + base, $ordered, $vnet,
57210311Snilay@cs.wisc.edu                                 "$vnet_type", b);
57310311Snilay@cs.wisc.edu''')
57410311Snilay@cs.wisc.edu                # Set the end
57510311Snilay@cs.wisc.edu                if network == "To":
57610311Snilay@cs.wisc.edu                    code('$vid->setSender(this);')
57710311Snilay@cs.wisc.edu                else:
57810311Snilay@cs.wisc.edu                    code('$vid->setReceiver(this);')
57910311Snilay@cs.wisc.edu
58010311Snilay@cs.wisc.edu                # Set ordering
58110311Snilay@cs.wisc.edu                code('$vid->setOrdering(${{var["ordered"]}});')
58210311Snilay@cs.wisc.edu
58310311Snilay@cs.wisc.edu                # Set randomization
58410311Snilay@cs.wisc.edu                if "random" in var:
58510311Snilay@cs.wisc.edu                    # A buffer
58610311Snilay@cs.wisc.edu                    code('$vid->setRandomization(${{var["random"]}});')
58710311Snilay@cs.wisc.edu
58810311Snilay@cs.wisc.edu                # Set Priority
58910311Snilay@cs.wisc.edu                if "rank" in var:
59010311Snilay@cs.wisc.edu                    code('$vid->setPriority(${{var["rank"]}})')
59110311Snilay@cs.wisc.edu
59210311Snilay@cs.wisc.edu                # Set buffer size
59310311Snilay@cs.wisc.edu                code('$vid->resize(m_buffer_size);')
59410311Snilay@cs.wisc.edu
59510311Snilay@cs.wisc.edu                if "recycle_latency" in var:
59610311Snilay@cs.wisc.edu                    code('$vid->setRecycleLatency( ' \
59710311Snilay@cs.wisc.edu                         'Cycles(${{var["recycle_latency"]}}));')
59810311Snilay@cs.wisc.edu                else:
59910311Snilay@cs.wisc.edu                    code('$vid->setRecycleLatency(m_recycle_latency);')
60010311Snilay@cs.wisc.edu
60110311Snilay@cs.wisc.edu                # set description (may be overriden later by port def)
60210311Snilay@cs.wisc.edu                code('''
60310311Snilay@cs.wisc.edu$vid->setDescription("[Version " + to_string(m_version) + ", ${ident}, name=${{var.ident}}]");
60410311Snilay@cs.wisc.edu''')
60510311Snilay@cs.wisc.edu                code.dedent()
60610311Snilay@cs.wisc.edu                code('}\n')
60710311Snilay@cs.wisc.edu
60810311Snilay@cs.wisc.edu        code.dedent()
60910311Snilay@cs.wisc.edu        code('''
61010311Snilay@cs.wisc.edu}
61110311Snilay@cs.wisc.edu
61210311Snilay@cs.wisc.eduvoid
6137007Snate@binkert.org$c_ident::init()
6146657Snate@binkert.org{
6157007Snate@binkert.org    // initialize objects
6167007Snate@binkert.org
6176657Snate@binkert.org''')
6186657Snate@binkert.org
6196657Snate@binkert.org        code.indent()
62010311Snilay@cs.wisc.edu
6216657Snate@binkert.org        for var in self.objects:
6226657Snate@binkert.org            vtype = var.type
62310305Snilay@cs.wisc.edu            vid = "m_%s_ptr" % var.ident
6246657Snate@binkert.org            if "network" not in var:
6256657Snate@binkert.org                # Not a network port object
6266657Snate@binkert.org                if "primitive" in vtype:
6276657Snate@binkert.org                    code('$vid = new ${{vtype.c_ident}};')
6286657Snate@binkert.org                    if "default" in var:
6296657Snate@binkert.org                        code('(*$vid) = ${{var["default"]}};')
6306657Snate@binkert.org                else:
6316657Snate@binkert.org                    # Normal Object
6329595Snilay@cs.wisc.edu                    if var.ident.find("mandatoryQueue") < 0:
6339273Snilay@cs.wisc.edu                        th = var.get("template", "")
6346657Snate@binkert.org                        expr = "%s  = new %s%s" % (vid, vtype.c_ident, th)
6356657Snate@binkert.org                        args = ""
6366657Snate@binkert.org                        if "non_obj" not in vtype and not vtype.isEnumeration:
6379364Snilay@cs.wisc.edu                            args = var.get("constructor", "")
6387007Snate@binkert.org                        code('$expr($args);')
6396657Snate@binkert.org
6406657Snate@binkert.org                    code('assert($vid != NULL);')
6416657Snate@binkert.org
6426657Snate@binkert.org                    if "default" in var:
6437007Snate@binkert.org                        code('*$vid = ${{var["default"]}}; // Object default')
6446657Snate@binkert.org                    elif "default" in vtype:
6457007Snate@binkert.org                        comment = "Type %s default" % vtype.ident
6467007Snate@binkert.org                        code('*$vid = ${{vtype["default"]}}; // $comment')
6476657Snate@binkert.org
6486657Snate@binkert.org                    # Set ordering
6499508Snilay@cs.wisc.edu                    if "ordered" in var:
6506657Snate@binkert.org                        # A buffer
6516657Snate@binkert.org                        code('$vid->setOrdering(${{var["ordered"]}});')
6526657Snate@binkert.org
6536657Snate@binkert.org                    # Set randomization
6546657Snate@binkert.org                    if "random" in var:
6556657Snate@binkert.org                        # A buffer
6566657Snate@binkert.org                        code('$vid->setRandomization(${{var["random"]}});')
6576657Snate@binkert.org
6586657Snate@binkert.org                    # Set Priority
6599508Snilay@cs.wisc.edu                    if vtype.isBuffer and "rank" in var:
6606657Snate@binkert.org                        code('$vid->setPriority(${{var["rank"]}});')
6617566SBrad.Beckmann@amd.com
6629508Snilay@cs.wisc.edu                    # Set sender and receiver for trigger queue
6639508Snilay@cs.wisc.edu                    if var.ident.find("triggerQueue") >= 0:
6649508Snilay@cs.wisc.edu                        code('$vid->setSender(this);')
6659508Snilay@cs.wisc.edu                        code('$vid->setReceiver(this);')
6669508Snilay@cs.wisc.edu                    elif vtype.c_ident == "TimerTable":
6679508Snilay@cs.wisc.edu                        code('$vid->setClockObj(this);')
6689604Snilay@cs.wisc.edu                    elif var.ident.find("optionalQueue") >= 0:
6699604Snilay@cs.wisc.edu                        code('$vid->setSender(this);')
6709604Snilay@cs.wisc.edu                        code('$vid->setReceiver(this);')
6719508Snilay@cs.wisc.edu
6727566SBrad.Beckmann@amd.com            if vtype.isBuffer:
6737566SBrad.Beckmann@amd.com                if "recycle_latency" in var:
6749499Snilay@cs.wisc.edu                    code('$vid->setRecycleLatency( ' \
6759499Snilay@cs.wisc.edu                         'Cycles(${{var["recycle_latency"]}}));')
6767566SBrad.Beckmann@amd.com                else:
6777566SBrad.Beckmann@amd.com                    code('$vid->setRecycleLatency(m_recycle_latency);')
6787566SBrad.Beckmann@amd.com
6799366Snilay@cs.wisc.edu        # Set the prefetchers
6809366Snilay@cs.wisc.edu        code()
6819366Snilay@cs.wisc.edu        for prefetcher in self.prefetchers:
6829366Snilay@cs.wisc.edu            code('${{prefetcher.code}}.setController(this);')
6837566SBrad.Beckmann@amd.com
6847672Snate@binkert.org        code()
6856657Snate@binkert.org        for port in self.in_ports:
6869465Snilay@cs.wisc.edu            # Set the queue consumers
6876657Snate@binkert.org            code('${{port.code}}.setConsumer(this);')
6889465Snilay@cs.wisc.edu            # Set the queue descriptions
6897056Snate@binkert.org            code('${{port.code}}.setDescription("[Version " + to_string(m_version) + ", $ident, $port]");')
6906657Snate@binkert.org
6916657Snate@binkert.org        # Initialize the transition profiling
6927672Snate@binkert.org        code()
6936657Snate@binkert.org        for trans in self.transitions:
6946657Snate@binkert.org            # Figure out if we stall
6956657Snate@binkert.org            stall = False
6966657Snate@binkert.org            for action in trans.actions:
6976657Snate@binkert.org                if action.ident == "z_stall":
6986657Snate@binkert.org                    stall = True
6996657Snate@binkert.org
7006657Snate@binkert.org            # Only possible if it is not a 'z' case
7016657Snate@binkert.org            if not stall:
7026657Snate@binkert.org                state = "%s_State_%s" % (self.ident, trans.state.ident)
7036657Snate@binkert.org                event = "%s_Event_%s" % (self.ident, trans.event.ident)
7049745Snilay@cs.wisc.edu                code('possibleTransition($state, $event);')
7056657Snate@binkert.org
7066657Snate@binkert.org        code.dedent()
7079496Snilay@cs.wisc.edu        code('''
7089496Snilay@cs.wisc.edu    AbstractController::init();
70910012Snilay@cs.wisc.edu    resetStats();
7109496Snilay@cs.wisc.edu}
7119496Snilay@cs.wisc.edu''')
7126657Snate@binkert.org
71310121Snilay@cs.wisc.edu        mq_ident = "NULL"
7146657Snate@binkert.org        for port in self.in_ports:
7156657Snate@binkert.org            if port.code.find("mandatoryQueue_ptr") >= 0:
71610305Snilay@cs.wisc.edu                mq_ident = "m_mandatoryQueue_ptr"
7176657Snate@binkert.org
7188683Snilay@cs.wisc.edu        seq_ident = "NULL"
7198683Snilay@cs.wisc.edu        for param in self.config_parameters:
72010308Snilay@cs.wisc.edu            if param.ident == "sequencer":
7218683Snilay@cs.wisc.edu                assert(param.pointer)
72210308Snilay@cs.wisc.edu                seq_ident = "m_%s_ptr" % param.ident
7238683Snilay@cs.wisc.edu
7246657Snate@binkert.org        code('''
7259745Snilay@cs.wisc.edu
7269745Snilay@cs.wisc.eduvoid
7279745Snilay@cs.wisc.edu$c_ident::regStats()
7289745Snilay@cs.wisc.edu{
72910012Snilay@cs.wisc.edu    AbstractController::regStats();
73010012Snilay@cs.wisc.edu
7319745Snilay@cs.wisc.edu    if (m_version == 0) {
7329745Snilay@cs.wisc.edu        for (${ident}_Event event = ${ident}_Event_FIRST;
7339745Snilay@cs.wisc.edu             event < ${ident}_Event_NUM; ++event) {
7349745Snilay@cs.wisc.edu            Stats::Vector *t = new Stats::Vector();
7359745Snilay@cs.wisc.edu            t->init(m_num_controllers);
73610919Sbrandon.potter@amd.com            t->name(params()->ruby_system->name() + ".${c_ident}." +
73710012Snilay@cs.wisc.edu                ${ident}_Event_to_string(event));
7389745Snilay@cs.wisc.edu            t->flags(Stats::pdf | Stats::total | Stats::oneline |
7399745Snilay@cs.wisc.edu                     Stats::nozero);
7409745Snilay@cs.wisc.edu
7419745Snilay@cs.wisc.edu            eventVec.push_back(t);
7429745Snilay@cs.wisc.edu        }
7439745Snilay@cs.wisc.edu
7449745Snilay@cs.wisc.edu        for (${ident}_State state = ${ident}_State_FIRST;
7459745Snilay@cs.wisc.edu             state < ${ident}_State_NUM; ++state) {
7469745Snilay@cs.wisc.edu
7479745Snilay@cs.wisc.edu            transVec.push_back(std::vector<Stats::Vector *>());
7489745Snilay@cs.wisc.edu
7499745Snilay@cs.wisc.edu            for (${ident}_Event event = ${ident}_Event_FIRST;
7509745Snilay@cs.wisc.edu                 event < ${ident}_Event_NUM; ++event) {
7519745Snilay@cs.wisc.edu
7529745Snilay@cs.wisc.edu                Stats::Vector *t = new Stats::Vector();
7539745Snilay@cs.wisc.edu                t->init(m_num_controllers);
75410919Sbrandon.potter@amd.com                t->name(params()->ruby_system->name() + ".${c_ident}." +
75510012Snilay@cs.wisc.edu                        ${ident}_State_to_string(state) +
7569745Snilay@cs.wisc.edu                        "." + ${ident}_Event_to_string(event));
7579745Snilay@cs.wisc.edu
7589745Snilay@cs.wisc.edu                t->flags(Stats::pdf | Stats::total | Stats::oneline |
7599745Snilay@cs.wisc.edu                         Stats::nozero);
7609745Snilay@cs.wisc.edu                transVec[state].push_back(t);
7619745Snilay@cs.wisc.edu            }
7629745Snilay@cs.wisc.edu        }
7639745Snilay@cs.wisc.edu    }
7649745Snilay@cs.wisc.edu}
7659745Snilay@cs.wisc.edu
7669745Snilay@cs.wisc.eduvoid
7679745Snilay@cs.wisc.edu$c_ident::collateStats()
7689745Snilay@cs.wisc.edu{
7699745Snilay@cs.wisc.edu    for (${ident}_Event event = ${ident}_Event_FIRST;
7709745Snilay@cs.wisc.edu         event < ${ident}_Event_NUM; ++event) {
7719745Snilay@cs.wisc.edu        for (unsigned int i = 0; i < m_num_controllers; ++i) {
77210920Sbrandon.potter@amd.com            RubySystem *rs = params()->ruby_system;
7739745Snilay@cs.wisc.edu            std::map<uint32_t, AbstractController *>::iterator it =
77410920Sbrandon.potter@amd.com                     rs->m_abstract_controls[MachineType_${ident}].find(i);
77510920Sbrandon.potter@amd.com            assert(it != rs->m_abstract_controls[MachineType_${ident}].end());
7769745Snilay@cs.wisc.edu            (*eventVec[event])[i] =
7779745Snilay@cs.wisc.edu                (($c_ident *)(*it).second)->getEventCount(event);
7789745Snilay@cs.wisc.edu        }
7799745Snilay@cs.wisc.edu    }
7809745Snilay@cs.wisc.edu
7819745Snilay@cs.wisc.edu    for (${ident}_State state = ${ident}_State_FIRST;
7829745Snilay@cs.wisc.edu         state < ${ident}_State_NUM; ++state) {
7839745Snilay@cs.wisc.edu
7849745Snilay@cs.wisc.edu        for (${ident}_Event event = ${ident}_Event_FIRST;
7859745Snilay@cs.wisc.edu             event < ${ident}_Event_NUM; ++event) {
7869745Snilay@cs.wisc.edu
7879745Snilay@cs.wisc.edu            for (unsigned int i = 0; i < m_num_controllers; ++i) {
78810920Sbrandon.potter@amd.com                RubySystem *rs = params()->ruby_system;
7899745Snilay@cs.wisc.edu                std::map<uint32_t, AbstractController *>::iterator it =
79010920Sbrandon.potter@amd.com                         rs->m_abstract_controls[MachineType_${ident}].find(i);
79110920Sbrandon.potter@amd.com                assert(it != rs->m_abstract_controls[MachineType_${ident}].end());
7929745Snilay@cs.wisc.edu                (*transVec[state][event])[i] =
7939745Snilay@cs.wisc.edu                    (($c_ident *)(*it).second)->getTransitionCount(state, event);
7949745Snilay@cs.wisc.edu            }
7959745Snilay@cs.wisc.edu        }
7969745Snilay@cs.wisc.edu    }
7979745Snilay@cs.wisc.edu}
7989745Snilay@cs.wisc.edu
7999745Snilay@cs.wisc.eduvoid
8009745Snilay@cs.wisc.edu$c_ident::countTransition(${ident}_State state, ${ident}_Event event)
8019745Snilay@cs.wisc.edu{
8029745Snilay@cs.wisc.edu    assert(m_possible[state][event]);
8039745Snilay@cs.wisc.edu    m_counters[state][event]++;
8049745Snilay@cs.wisc.edu    m_event_counters[event]++;
8059745Snilay@cs.wisc.edu}
8069745Snilay@cs.wisc.eduvoid
8079745Snilay@cs.wisc.edu$c_ident::possibleTransition(${ident}_State state,
8089745Snilay@cs.wisc.edu                             ${ident}_Event event)
8099745Snilay@cs.wisc.edu{
8109745Snilay@cs.wisc.edu    m_possible[state][event] = true;
8119745Snilay@cs.wisc.edu}
8129745Snilay@cs.wisc.edu
8139745Snilay@cs.wisc.eduuint64
8149745Snilay@cs.wisc.edu$c_ident::getEventCount(${ident}_Event event)
8159745Snilay@cs.wisc.edu{
8169745Snilay@cs.wisc.edu    return m_event_counters[event];
8179745Snilay@cs.wisc.edu}
8189745Snilay@cs.wisc.edu
8199745Snilay@cs.wisc.edubool
8209745Snilay@cs.wisc.edu$c_ident::isPossible(${ident}_State state, ${ident}_Event event)
8219745Snilay@cs.wisc.edu{
8229745Snilay@cs.wisc.edu    return m_possible[state][event];
8239745Snilay@cs.wisc.edu}
8249745Snilay@cs.wisc.edu
8259745Snilay@cs.wisc.eduuint64
8269745Snilay@cs.wisc.edu$c_ident::getTransitionCount(${ident}_State state,
8279745Snilay@cs.wisc.edu                             ${ident}_Event event)
8289745Snilay@cs.wisc.edu{
8299745Snilay@cs.wisc.edu    return m_counters[state][event];
8309745Snilay@cs.wisc.edu}
8319745Snilay@cs.wisc.edu
8327007Snate@binkert.orgint
8337007Snate@binkert.org$c_ident::getNumControllers()
8347007Snate@binkert.org{
8356657Snate@binkert.org    return m_num_controllers;
8366657Snate@binkert.org}
8376657Snate@binkert.org
8387007Snate@binkert.orgMessageBuffer*
8397007Snate@binkert.org$c_ident::getMandatoryQueue() const
8407007Snate@binkert.org{
8416657Snate@binkert.org    return $mq_ident;
8426657Snate@binkert.org}
8436657Snate@binkert.org
8448683Snilay@cs.wisc.eduSequencer*
8458683Snilay@cs.wisc.edu$c_ident::getSequencer() const
8468683Snilay@cs.wisc.edu{
8478683Snilay@cs.wisc.edu    return $seq_ident;
8488683Snilay@cs.wisc.edu}
8498683Snilay@cs.wisc.edu
8507007Snate@binkert.orgvoid
8517007Snate@binkert.org$c_ident::print(ostream& out) const
8527007Snate@binkert.org{
8537007Snate@binkert.org    out << "[$c_ident " << m_version << "]";
8547007Snate@binkert.org}
8556657Snate@binkert.org
85610012Snilay@cs.wisc.eduvoid $c_ident::resetStats()
8579745Snilay@cs.wisc.edu{
8589745Snilay@cs.wisc.edu    for (int state = 0; state < ${ident}_State_NUM; state++) {
8599745Snilay@cs.wisc.edu        for (int event = 0; event < ${ident}_Event_NUM; event++) {
8609745Snilay@cs.wisc.edu            m_counters[state][event] = 0;
8619745Snilay@cs.wisc.edu        }
8629745Snilay@cs.wisc.edu    }
8636902SBrad.Beckmann@amd.com
8649745Snilay@cs.wisc.edu    for (int event = 0; event < ${ident}_Event_NUM; event++) {
8659745Snilay@cs.wisc.edu        m_event_counters[event] = 0;
8669745Snilay@cs.wisc.edu    }
8679745Snilay@cs.wisc.edu
86810012Snilay@cs.wisc.edu    AbstractController::resetStats();
8696902SBrad.Beckmann@amd.com}
8707839Snilay@cs.wisc.edu''')
8717839Snilay@cs.wisc.edu
8727839Snilay@cs.wisc.edu        if self.EntryType != None:
8737839Snilay@cs.wisc.edu            code('''
8747839Snilay@cs.wisc.edu
8757839Snilay@cs.wisc.edu// Set and Reset for cache_entry variable
8767839Snilay@cs.wisc.eduvoid
8777839Snilay@cs.wisc.edu$c_ident::set_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, AbstractCacheEntry* m_new_cache_entry)
8787839Snilay@cs.wisc.edu{
8797839Snilay@cs.wisc.edu  m_cache_entry_ptr = (${{self.EntryType.c_ident}}*)m_new_cache_entry;
8807839Snilay@cs.wisc.edu}
8817839Snilay@cs.wisc.edu
8827839Snilay@cs.wisc.eduvoid
8837839Snilay@cs.wisc.edu$c_ident::unset_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr)
8847839Snilay@cs.wisc.edu{
8857839Snilay@cs.wisc.edu  m_cache_entry_ptr = 0;
8867839Snilay@cs.wisc.edu}
8877839Snilay@cs.wisc.edu''')
8887839Snilay@cs.wisc.edu
8897839Snilay@cs.wisc.edu        if self.TBEType != None:
8907839Snilay@cs.wisc.edu            code('''
8917839Snilay@cs.wisc.edu
8927839Snilay@cs.wisc.edu// Set and Reset for tbe variable
8937839Snilay@cs.wisc.eduvoid
8947839Snilay@cs.wisc.edu$c_ident::set_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr, ${{self.TBEType.c_ident}}* m_new_tbe)
8957839Snilay@cs.wisc.edu{
8967839Snilay@cs.wisc.edu  m_tbe_ptr = m_new_tbe;
8977839Snilay@cs.wisc.edu}
8987839Snilay@cs.wisc.edu
8997839Snilay@cs.wisc.eduvoid
9007839Snilay@cs.wisc.edu$c_ident::unset_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr)
9017839Snilay@cs.wisc.edu{
9027839Snilay@cs.wisc.edu  m_tbe_ptr = NULL;
9037839Snilay@cs.wisc.edu}
9047839Snilay@cs.wisc.edu''')
9057839Snilay@cs.wisc.edu
9067839Snilay@cs.wisc.edu        code('''
9076902SBrad.Beckmann@amd.com
9088683Snilay@cs.wisc.eduvoid
9098683Snilay@cs.wisc.edu$c_ident::recordCacheTrace(int cntrl, CacheRecorder* tr)
9108683Snilay@cs.wisc.edu{
9118683Snilay@cs.wisc.edu''')
9128683Snilay@cs.wisc.edu        #
9138683Snilay@cs.wisc.edu        # Record cache contents for all associated caches.
9148683Snilay@cs.wisc.edu        #
9158683Snilay@cs.wisc.edu        code.indent()
9168683Snilay@cs.wisc.edu        for param in self.config_parameters:
9178683Snilay@cs.wisc.edu            if param.type_ast.type.ident == "CacheMemory":
9188683Snilay@cs.wisc.edu                assert(param.pointer)
9198683Snilay@cs.wisc.edu                code('m_${{param.ident}}_ptr->recordCacheContents(cntrl, tr);')
9208683Snilay@cs.wisc.edu
9218683Snilay@cs.wisc.edu        code.dedent()
9228683Snilay@cs.wisc.edu        code('''
9238683Snilay@cs.wisc.edu}
9248683Snilay@cs.wisc.edu
9256657Snate@binkert.org// Actions
9266657Snate@binkert.org''')
9277839Snilay@cs.wisc.edu        if self.TBEType != None and self.EntryType != None:
9287839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
9297839Snilay@cs.wisc.edu                if "c_code" not in action:
9307839Snilay@cs.wisc.edu                 continue
9316657Snate@binkert.org
9327839Snilay@cs.wisc.edu                code('''
9337839Snilay@cs.wisc.edu/** \\brief ${{action.desc}} */
9347839Snilay@cs.wisc.eduvoid
9357839Snilay@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)
9367839Snilay@cs.wisc.edu{
9378055Sksewell@umich.edu    DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n");
9387839Snilay@cs.wisc.edu    ${{action["c_code"]}}
9397839Snilay@cs.wisc.edu}
9406657Snate@binkert.org
9417839Snilay@cs.wisc.edu''')
9427839Snilay@cs.wisc.edu        elif self.TBEType != None:
9437839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
9447839Snilay@cs.wisc.edu                if "c_code" not in action:
9457839Snilay@cs.wisc.edu                 continue
9467839Snilay@cs.wisc.edu
9477839Snilay@cs.wisc.edu                code('''
9487839Snilay@cs.wisc.edu/** \\brief ${{action.desc}} */
9497839Snilay@cs.wisc.eduvoid
9507839Snilay@cs.wisc.edu$c_ident::${{action.ident}}(${{self.TBEType.c_ident}}*& m_tbe_ptr, const Address& addr)
9517839Snilay@cs.wisc.edu{
9528055Sksewell@umich.edu    DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n");
9537839Snilay@cs.wisc.edu    ${{action["c_code"]}}
9547839Snilay@cs.wisc.edu}
9557839Snilay@cs.wisc.edu
9567839Snilay@cs.wisc.edu''')
9577839Snilay@cs.wisc.edu        elif self.EntryType != None:
9587839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
9597839Snilay@cs.wisc.edu                if "c_code" not in action:
9607839Snilay@cs.wisc.edu                 continue
9617839Snilay@cs.wisc.edu
9627839Snilay@cs.wisc.edu                code('''
9637839Snilay@cs.wisc.edu/** \\brief ${{action.desc}} */
9647839Snilay@cs.wisc.eduvoid
9657839Snilay@cs.wisc.edu$c_ident::${{action.ident}}(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, const Address& addr)
9667839Snilay@cs.wisc.edu{
9678055Sksewell@umich.edu    DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n");
9687839Snilay@cs.wisc.edu    ${{action["c_code"]}}
9697839Snilay@cs.wisc.edu}
9707839Snilay@cs.wisc.edu
9717839Snilay@cs.wisc.edu''')
9727839Snilay@cs.wisc.edu        else:
9737839Snilay@cs.wisc.edu            for action in self.actions.itervalues():
9747839Snilay@cs.wisc.edu                if "c_code" not in action:
9757839Snilay@cs.wisc.edu                 continue
9767839Snilay@cs.wisc.edu
9777839Snilay@cs.wisc.edu                code('''
9786657Snate@binkert.org/** \\brief ${{action.desc}} */
9797007Snate@binkert.orgvoid
9807007Snate@binkert.org$c_ident::${{action.ident}}(const Address& addr)
9816657Snate@binkert.org{
9828055Sksewell@umich.edu    DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n");
9836657Snate@binkert.org    ${{action["c_code"]}}
9846657Snate@binkert.org}
9856657Snate@binkert.org
9866657Snate@binkert.org''')
9878478Snilay@cs.wisc.edu        for func in self.functions:
9888478Snilay@cs.wisc.edu            code(func.generateCode())
9898478Snilay@cs.wisc.edu
9909302Snilay@cs.wisc.edu        # Function for functional writes to messages buffered in the controller
9919302Snilay@cs.wisc.edu        code('''
99210524Snilay@cs.wisc.eduint
9939302Snilay@cs.wisc.edu$c_ident::functionalWriteBuffers(PacketPtr& pkt)
9949302Snilay@cs.wisc.edu{
99510524Snilay@cs.wisc.edu    int num_functional_writes = 0;
9969302Snilay@cs.wisc.edu''')
9979302Snilay@cs.wisc.edu        for var in self.objects:
9989302Snilay@cs.wisc.edu            vtype = var.type
9999302Snilay@cs.wisc.edu            if vtype.isBuffer:
100010305Snilay@cs.wisc.edu                vid = "m_%s_ptr" % var.ident
10019302Snilay@cs.wisc.edu                code('num_functional_writes += $vid->functionalWrite(pkt);')
100210311Snilay@cs.wisc.edu
100310311Snilay@cs.wisc.edu        for var in self.config_parameters:
100410311Snilay@cs.wisc.edu            vtype = var.type_ast.type
100510311Snilay@cs.wisc.edu            if vtype.isBuffer:
100610311Snilay@cs.wisc.edu                vid = "m_%s_ptr" % var.ident
100710311Snilay@cs.wisc.edu                code('num_functional_writes += $vid->functionalWrite(pkt);')
100810311Snilay@cs.wisc.edu
10099302Snilay@cs.wisc.edu        code('''
10109302Snilay@cs.wisc.edu    return num_functional_writes;
10119302Snilay@cs.wisc.edu}
10129302Snilay@cs.wisc.edu''')
10139302Snilay@cs.wisc.edu
10146657Snate@binkert.org        code.write(path, "%s.cc" % c_ident)
10156657Snate@binkert.org
10169219Spower.jg@gmail.com    def printCWakeup(self, path, includes):
10176657Snate@binkert.org        '''Output the wakeup loop for the events'''
10186657Snate@binkert.org
10196999Snate@binkert.org        code = self.symtab.codeFormatter()
10206657Snate@binkert.org        ident = self.ident
10216657Snate@binkert.org
10229104Shestness@cs.utexas.edu        outputRequest_types = True
10239104Shestness@cs.utexas.edu        if len(self.request_types) == 0:
10249104Shestness@cs.utexas.edu            outputRequest_types = False
10259104Shestness@cs.utexas.edu
10266657Snate@binkert.org        code('''
10276657Snate@binkert.org// Auto generated C++ code started by $__file__:$__line__
10286657Snate@binkert.org// ${ident}: ${{self.short}}
10296657Snate@binkert.org
10308946Sandreas.hansson@arm.com#include <sys/types.h>
10318946Sandreas.hansson@arm.com#include <unistd.h>
10328946Sandreas.hansson@arm.com
10337832Snate@binkert.org#include <cassert>
10347832Snate@binkert.org
10357007Snate@binkert.org#include "base/misc.hh"
10368232Snate@binkert.org#include "debug/RubySlicc.hh"
10378229Snate@binkert.org#include "mem/protocol/${ident}_Controller.hh"
10388229Snate@binkert.org#include "mem/protocol/${ident}_Event.hh"
10398229Snate@binkert.org#include "mem/protocol/${ident}_State.hh"
10409104Shestness@cs.utexas.edu''')
10419104Shestness@cs.utexas.edu
10429104Shestness@cs.utexas.edu        if outputRequest_types:
10439104Shestness@cs.utexas.edu            code('''#include "mem/protocol/${ident}_RequestType.hh"''')
10449104Shestness@cs.utexas.edu
10459104Shestness@cs.utexas.edu        code('''
10468229Snate@binkert.org#include "mem/protocol/Types.hh"
10476657Snate@binkert.org#include "mem/ruby/system/System.hh"
10489219Spower.jg@gmail.com''')
10499219Spower.jg@gmail.com
10509219Spower.jg@gmail.com
10519219Spower.jg@gmail.com        for include_path in includes:
10529219Spower.jg@gmail.com            code('#include "${{include_path}}"')
10539219Spower.jg@gmail.com
10549219Spower.jg@gmail.com        code('''
10556657Snate@binkert.org
10567055Snate@binkert.orgusing namespace std;
10577055Snate@binkert.org
10587007Snate@binkert.orgvoid
10597007Snate@binkert.org${ident}_Controller::wakeup()
10606657Snate@binkert.org{
10616657Snate@binkert.org    int counter = 0;
10626657Snate@binkert.org    while (true) {
10636657Snate@binkert.org        // Some cases will put us into an infinite loop without this limit
10646657Snate@binkert.org        assert(counter <= m_transitions_per_cycle);
10656657Snate@binkert.org        if (counter == m_transitions_per_cycle) {
10667007Snate@binkert.org            // Count how often we are fully utilized
10679496Snilay@cs.wisc.edu            m_fully_busy_cycles++;
10687007Snate@binkert.org
10697007Snate@binkert.org            // Wakeup in another cycle and try again
10709499Snilay@cs.wisc.edu            scheduleEvent(Cycles(1));
10716657Snate@binkert.org            break;
10726657Snate@binkert.org        }
10736657Snate@binkert.org''')
10746657Snate@binkert.org
10756657Snate@binkert.org        code.indent()
10766657Snate@binkert.org        code.indent()
10776657Snate@binkert.org
10786657Snate@binkert.org        # InPorts
10796657Snate@binkert.org        #
10806657Snate@binkert.org        for port in self.in_ports:
10816657Snate@binkert.org            code.indent()
10826657Snate@binkert.org            code('// ${ident}InPort $port')
10837567SBrad.Beckmann@amd.com            if port.pairs.has_key("rank"):
10849996Snilay@cs.wisc.edu                code('m_cur_in_port = ${{port.pairs["rank"]}};')
10857567SBrad.Beckmann@amd.com            else:
10869996Snilay@cs.wisc.edu                code('m_cur_in_port = 0;')
10876657Snate@binkert.org            code('${{port["c_code_in_port"]}}')
10886657Snate@binkert.org            code.dedent()
10896657Snate@binkert.org
10906657Snate@binkert.org            code('')
10916657Snate@binkert.org
10926657Snate@binkert.org        code.dedent()
10936657Snate@binkert.org        code.dedent()
10946657Snate@binkert.org        code('''
10956657Snate@binkert.org        break;  // If we got this far, we have nothing left todo
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"
11226657Snate@binkert.org#include "mem/ruby/system/System.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('''
114110010Snilay@cs.wisc.edu                                  const Address 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
11737839Snilay@cs.wisc.edu        code('''
11746657Snate@binkert.org
117510305Snilay@cs.wisc.eduif (result == TransitionResult_Valid) {
117610305Snilay@cs.wisc.edu    DPRINTF(RubyGenerated, "next_state: %s\\n",
117710305Snilay@cs.wisc.edu            ${ident}_State_to_string(next_state));
117810305Snilay@cs.wisc.edu    countTransition(state, event);
117910305Snilay@cs.wisc.edu
118010305Snilay@cs.wisc.edu    DPRINTFR(ProtocolTrace, "%15d %3s %10s%20s %6s>%-6s %s %s\\n",
118110305Snilay@cs.wisc.edu             curTick(), m_version, "${ident}",
118210305Snilay@cs.wisc.edu             ${ident}_Event_to_string(event),
118310305Snilay@cs.wisc.edu             ${ident}_State_to_string(state),
118410305Snilay@cs.wisc.edu             ${ident}_State_to_string(next_state),
118510305Snilay@cs.wisc.edu             addr, GET_TRANSITION_COMMENT());
118610305Snilay@cs.wisc.edu
118710305Snilay@cs.wisc.edu    CLEAR_TRANSITION_COMMENT();
11887839Snilay@cs.wisc.edu''')
11897839Snilay@cs.wisc.edu        if self.TBEType != None and self.EntryType != None:
11908337Snilay@cs.wisc.edu            code('setState(m_tbe_ptr, m_cache_entry_ptr, addr, next_state);')
11918341Snilay@cs.wisc.edu            code('setAccessPermission(m_cache_entry_ptr, addr, next_state);')
11927839Snilay@cs.wisc.edu        elif self.TBEType != None:
11938337Snilay@cs.wisc.edu            code('setState(m_tbe_ptr, addr, next_state);')
11948341Snilay@cs.wisc.edu            code('setAccessPermission(addr, next_state);')
11957839Snilay@cs.wisc.edu        elif self.EntryType != None:
11968337Snilay@cs.wisc.edu            code('setState(m_cache_entry_ptr, addr, next_state);')
11978341Snilay@cs.wisc.edu            code('setAccessPermission(m_cache_entry_ptr, addr, next_state);')
11987839Snilay@cs.wisc.edu        else:
11998337Snilay@cs.wisc.edu            code('setState(addr, next_state);')
12008341Snilay@cs.wisc.edu            code('setAccessPermission(addr, next_state);')
12017839Snilay@cs.wisc.edu
12027839Snilay@cs.wisc.edu        code('''
120310305Snilay@cs.wisc.edu} else if (result == TransitionResult_ResourceStall) {
120410305Snilay@cs.wisc.edu    DPRINTFR(ProtocolTrace, "%15s %3s %10s%20s %6s>%-6s %s %s\\n",
120510305Snilay@cs.wisc.edu             curTick(), m_version, "${ident}",
120610305Snilay@cs.wisc.edu             ${ident}_Event_to_string(event),
120710305Snilay@cs.wisc.edu             ${ident}_State_to_string(state),
120810305Snilay@cs.wisc.edu             ${ident}_State_to_string(next_state),
120910305Snilay@cs.wisc.edu             addr, "Resource Stall");
121010305Snilay@cs.wisc.edu} else if (result == TransitionResult_ProtocolStall) {
121110305Snilay@cs.wisc.edu    DPRINTF(RubyGenerated, "stalling\\n");
121210305Snilay@cs.wisc.edu    DPRINTFR(ProtocolTrace, "%15s %3s %10s%20s %6s>%-6s %s %s\\n",
121310305Snilay@cs.wisc.edu             curTick(), m_version, "${ident}",
121410305Snilay@cs.wisc.edu             ${ident}_Event_to_string(event),
121510305Snilay@cs.wisc.edu             ${ident}_State_to_string(state),
121610305Snilay@cs.wisc.edu             ${ident}_State_to_string(next_state),
121710305Snilay@cs.wisc.edu             addr, "Protocol Stall");
121810305Snilay@cs.wisc.edu}
12196657Snate@binkert.org
122010305Snilay@cs.wisc.edureturn result;
122110305Snilay@cs.wisc.edu''')
122210305Snilay@cs.wisc.edu        code.dedent()
122310305Snilay@cs.wisc.edu        code('''
12246657Snate@binkert.org}
12256657Snate@binkert.org
12267007Snate@binkert.orgTransitionResult
12277007Snate@binkert.org${ident}_Controller::doTransitionWorker(${ident}_Event event,
12287007Snate@binkert.org                                        ${ident}_State state,
12297007Snate@binkert.org                                        ${ident}_State& next_state,
12307839Snilay@cs.wisc.edu''')
12317839Snilay@cs.wisc.edu
12327839Snilay@cs.wisc.edu        if self.TBEType != None:
12337839Snilay@cs.wisc.edu            code('''
12347839Snilay@cs.wisc.edu                                        ${{self.TBEType.c_ident}}*& m_tbe_ptr,
12357839Snilay@cs.wisc.edu''')
12367839Snilay@cs.wisc.edu        if self.EntryType != None:
12377839Snilay@cs.wisc.edu                  code('''
12387839Snilay@cs.wisc.edu                                        ${{self.EntryType.c_ident}}*& m_cache_entry_ptr,
12397839Snilay@cs.wisc.edu''')
12407839Snilay@cs.wisc.edu        code('''
12417007Snate@binkert.org                                        const Address& addr)
12426657Snate@binkert.org{
12436657Snate@binkert.org    switch(HASH_FUN(state, event)) {
12446657Snate@binkert.org''')
12456657Snate@binkert.org
12466657Snate@binkert.org        # This map will allow suppress generating duplicate code
12476657Snate@binkert.org        cases = orderdict()
12486657Snate@binkert.org
12496657Snate@binkert.org        for trans in self.transitions:
12506657Snate@binkert.org            case_string = "%s_State_%s, %s_Event_%s" % \
12516657Snate@binkert.org                (self.ident, trans.state.ident, self.ident, trans.event.ident)
12526657Snate@binkert.org
12536999Snate@binkert.org            case = self.symtab.codeFormatter()
12546657Snate@binkert.org            # Only set next_state if it changes
12556657Snate@binkert.org            if trans.state != trans.nextState:
12566657Snate@binkert.org                ns_ident = trans.nextState.ident
12576657Snate@binkert.org                case('next_state = ${ident}_State_${ns_ident};')
12586657Snate@binkert.org
12596657Snate@binkert.org            actions = trans.actions
12609104Shestness@cs.utexas.edu            request_types = trans.request_types
12616657Snate@binkert.org
12626657Snate@binkert.org            # Check for resources
12636657Snate@binkert.org            case_sorter = []
12646657Snate@binkert.org            res = trans.resources
12656657Snate@binkert.org            for key,val in res.iteritems():
126610228Snilay@cs.wisc.edu                val = '''
12677007Snate@binkert.orgif (!%s.areNSlotsAvailable(%s))
12686657Snate@binkert.org    return TransitionResult_ResourceStall;
12696657Snate@binkert.org''' % (key.code, val)
12706657Snate@binkert.org                case_sorter.append(val)
12716657Snate@binkert.org
12729105SBrad.Beckmann@amd.com            # Check all of the request_types for resource constraints
12739105SBrad.Beckmann@amd.com            for request_type in request_types:
12749105SBrad.Beckmann@amd.com                val = '''
12759105SBrad.Beckmann@amd.comif (!checkResourceAvailable(%s_RequestType_%s, addr)) {
12769105SBrad.Beckmann@amd.com    return TransitionResult_ResourceStall;
12779105SBrad.Beckmann@amd.com}
12789105SBrad.Beckmann@amd.com''' % (self.ident, request_type.ident)
12799105SBrad.Beckmann@amd.com                case_sorter.append(val)
12806657Snate@binkert.org
12816657Snate@binkert.org            # Emit the code sequences in a sorted order.  This makes the
12826657Snate@binkert.org            # output deterministic (without this the output order can vary
12836657Snate@binkert.org            # since Map's keys() on a vector of pointers is not deterministic
12846657Snate@binkert.org            for c in sorted(case_sorter):
12856657Snate@binkert.org                case("$c")
12866657Snate@binkert.org
12879104Shestness@cs.utexas.edu            # Record access types for this transition
12889104Shestness@cs.utexas.edu            for request_type in request_types:
12899104Shestness@cs.utexas.edu                case('recordRequestType(${ident}_RequestType_${{request_type.ident}}, addr);')
12909104Shestness@cs.utexas.edu
12916657Snate@binkert.org            # Figure out if we stall
12926657Snate@binkert.org            stall = False
12936657Snate@binkert.org            for action in actions:
12946657Snate@binkert.org                if action.ident == "z_stall":
12956657Snate@binkert.org                    stall = True
12966657Snate@binkert.org                    break
12976657Snate@binkert.org
12986657Snate@binkert.org            if stall:
12996657Snate@binkert.org                case('return TransitionResult_ProtocolStall;')
13006657Snate@binkert.org            else:
13017839Snilay@cs.wisc.edu                if self.TBEType != None and self.EntryType != None:
13027839Snilay@cs.wisc.edu                    for action in actions:
13037839Snilay@cs.wisc.edu                        case('${{action.ident}}(m_tbe_ptr, m_cache_entry_ptr, addr);')
13047839Snilay@cs.wisc.edu                elif self.TBEType != None:
13057839Snilay@cs.wisc.edu                    for action in actions:
13067839Snilay@cs.wisc.edu                        case('${{action.ident}}(m_tbe_ptr, addr);')
13077839Snilay@cs.wisc.edu                elif self.EntryType != None:
13087839Snilay@cs.wisc.edu                    for action in actions:
13097839Snilay@cs.wisc.edu                        case('${{action.ident}}(m_cache_entry_ptr, addr);')
13107839Snilay@cs.wisc.edu                else:
13117839Snilay@cs.wisc.edu                    for action in actions:
13127839Snilay@cs.wisc.edu                        case('${{action.ident}}(addr);')
13136657Snate@binkert.org                case('return TransitionResult_Valid;')
13146657Snate@binkert.org
13156657Snate@binkert.org            case = str(case)
13166657Snate@binkert.org
13176657Snate@binkert.org            # Look to see if this transition code is unique.
13186657Snate@binkert.org            if case not in cases:
13196657Snate@binkert.org                cases[case] = []
13206657Snate@binkert.org
13216657Snate@binkert.org            cases[case].append(case_string)
13226657Snate@binkert.org
13236657Snate@binkert.org        # Walk through all of the unique code blocks and spit out the
13246657Snate@binkert.org        # corresponding case statement elements
13256657Snate@binkert.org        for case,transitions in cases.iteritems():
13266657Snate@binkert.org            # Iterative over all the multiple transitions that share
13276657Snate@binkert.org            # the same code
13286657Snate@binkert.org            for trans in transitions:
13296657Snate@binkert.org                code('  case HASH_FUN($trans):')
133010305Snilay@cs.wisc.edu            code('    $case\n')
13316657Snate@binkert.org
13326657Snate@binkert.org        code('''
13336657Snate@binkert.org      default:
133410962SBrad.Beckmann@amd.com        panic("Invalid transition\\n"
13358159SBrad.Beckmann@amd.com              "%s time: %d addr: %s event: %s state: %s\\n",
13369465Snilay@cs.wisc.edu              name(), curCycle(), addr, event, state);
13376657Snate@binkert.org    }
133810305Snilay@cs.wisc.edu
13396657Snate@binkert.org    return TransitionResult_Valid;
13406657Snate@binkert.org}
13416657Snate@binkert.org''')
13426657Snate@binkert.org        code.write(path, "%s_Transitions.cc" % self.ident)
13436657Snate@binkert.org
13446657Snate@binkert.org
13456657Snate@binkert.org    # **************************
13466657Snate@binkert.org    # ******* HTML Files *******
13476657Snate@binkert.org    # **************************
13487007Snate@binkert.org    def frameRef(self, click_href, click_target, over_href, over_num, text):
13496999Snate@binkert.org        code = self.symtab.codeFormatter(fix_newlines=False)
13507007Snate@binkert.org        code("""<A href=\"$click_href\" target=\"$click_target\" onmouseover=\"
13517007Snate@binkert.org    if (parent.frames[$over_num].location != parent.location + '$over_href') {
13527007Snate@binkert.org        parent.frames[$over_num].location='$over_href'
13537007Snate@binkert.org    }\">
13547007Snate@binkert.org    ${{html.formatShorthand(text)}}
13557007Snate@binkert.org    </A>""")
13566657Snate@binkert.org        return str(code)
13576657Snate@binkert.org
13586657Snate@binkert.org    def writeHTMLFiles(self, path):
13596657Snate@binkert.org        # Create table with no row hilighted
13606657Snate@binkert.org        self.printHTMLTransitions(path, None)
13616657Snate@binkert.org
13626657Snate@binkert.org        # Generate transition tables
13636657Snate@binkert.org        for state in self.states.itervalues():
13646657Snate@binkert.org            self.printHTMLTransitions(path, state)
13656657Snate@binkert.org
13666657Snate@binkert.org        # Generate action descriptions
13676657Snate@binkert.org        for action in self.actions.itervalues():
13686657Snate@binkert.org            name = "%s_action_%s.html" % (self.ident, action.ident)
13696657Snate@binkert.org            code = html.createSymbol(action, "Action")
13706657Snate@binkert.org            code.write(path, name)
13716657Snate@binkert.org
13726657Snate@binkert.org        # Generate state descriptions
13736657Snate@binkert.org        for state in self.states.itervalues():
13746657Snate@binkert.org            name = "%s_State_%s.html" % (self.ident, state.ident)
13756657Snate@binkert.org            code = html.createSymbol(state, "State")
13766657Snate@binkert.org            code.write(path, name)
13776657Snate@binkert.org
13786657Snate@binkert.org        # Generate event descriptions
13796657Snate@binkert.org        for event in self.events.itervalues():
13806657Snate@binkert.org            name = "%s_Event_%s.html" % (self.ident, event.ident)
13816657Snate@binkert.org            code = html.createSymbol(event, "Event")
13826657Snate@binkert.org            code.write(path, name)
13836657Snate@binkert.org
13846657Snate@binkert.org    def printHTMLTransitions(self, path, active_state):
13856999Snate@binkert.org        code = self.symtab.codeFormatter()
13866657Snate@binkert.org
13876657Snate@binkert.org        code('''
13887007Snate@binkert.org<HTML>
13897007Snate@binkert.org<BODY link="blue" vlink="blue">
13906657Snate@binkert.org
13916657Snate@binkert.org<H1 align="center">${{html.formatShorthand(self.short)}}:
13926657Snate@binkert.org''')
13936657Snate@binkert.org        code.indent()
13946657Snate@binkert.org        for i,machine in enumerate(self.symtab.getAllType(StateMachine)):
13956657Snate@binkert.org            mid = machine.ident
13966657Snate@binkert.org            if i != 0:
13976657Snate@binkert.org                extra = " - "
13986657Snate@binkert.org            else:
13996657Snate@binkert.org                extra = ""
14006657Snate@binkert.org            if machine == self:
14016657Snate@binkert.org                code('$extra$mid')
14026657Snate@binkert.org            else:
14036657Snate@binkert.org                code('$extra<A target="Table" href="${mid}_table.html">$mid</A>')
14046657Snate@binkert.org        code.dedent()
14056657Snate@binkert.org
14066657Snate@binkert.org        code("""
14076657Snate@binkert.org</H1>
14086657Snate@binkert.org
14096657Snate@binkert.org<TABLE border=1>
14106657Snate@binkert.org<TR>
14116657Snate@binkert.org  <TH> </TH>
14126657Snate@binkert.org""")
14136657Snate@binkert.org
14146657Snate@binkert.org        for event in self.events.itervalues():
14156657Snate@binkert.org            href = "%s_Event_%s.html" % (self.ident, event.ident)
14166657Snate@binkert.org            ref = self.frameRef(href, "Status", href, "1", event.short)
14176657Snate@binkert.org            code('<TH bgcolor=white>$ref</TH>')
14186657Snate@binkert.org
14196657Snate@binkert.org        code('</TR>')
14206657Snate@binkert.org        # -- Body of table
14216657Snate@binkert.org        for state in self.states.itervalues():
14226657Snate@binkert.org            # -- Each row
14236657Snate@binkert.org            if state == active_state:
14246657Snate@binkert.org                color = "yellow"
14256657Snate@binkert.org            else:
14266657Snate@binkert.org                color = "white"
14276657Snate@binkert.org
14286657Snate@binkert.org            click = "%s_table_%s.html" % (self.ident, state.ident)
14296657Snate@binkert.org            over = "%s_State_%s.html" % (self.ident, state.ident)
14306657Snate@binkert.org            text = html.formatShorthand(state.short)
14316657Snate@binkert.org            ref = self.frameRef(click, "Table", over, "1", state.short)
14326657Snate@binkert.org            code('''
14336657Snate@binkert.org<TR>
14346657Snate@binkert.org  <TH bgcolor=$color>$ref</TH>
14356657Snate@binkert.org''')
14366657Snate@binkert.org
14376657Snate@binkert.org            # -- One column for each event
14386657Snate@binkert.org            for event in self.events.itervalues():
14396657Snate@binkert.org                trans = self.table.get((state,event), None)
14406657Snate@binkert.org                if trans is None:
14416657Snate@binkert.org                    # This is the no transition case
14426657Snate@binkert.org                    if state == active_state:
14436657Snate@binkert.org                        color = "#C0C000"
14446657Snate@binkert.org                    else:
14456657Snate@binkert.org                        color = "lightgrey"
14466657Snate@binkert.org
14476657Snate@binkert.org                    code('<TD bgcolor=$color>&nbsp;</TD>')
14486657Snate@binkert.org                    continue
14496657Snate@binkert.org
14506657Snate@binkert.org                next = trans.nextState
14516657Snate@binkert.org                stall_action = False
14526657Snate@binkert.org
14536657Snate@binkert.org                # -- Get the actions
14546657Snate@binkert.org                for action in trans.actions:
14556657Snate@binkert.org                    if action.ident == "z_stall" or \
14566657Snate@binkert.org                       action.ident == "zz_recycleMandatoryQueue":
14576657Snate@binkert.org                        stall_action = True
14586657Snate@binkert.org
14596657Snate@binkert.org                # -- Print out "actions/next-state"
14606657Snate@binkert.org                if stall_action:
14616657Snate@binkert.org                    if state == active_state:
14626657Snate@binkert.org                        color = "#C0C000"
14636657Snate@binkert.org                    else:
14646657Snate@binkert.org                        color = "lightgrey"
14656657Snate@binkert.org
14666657Snate@binkert.org                elif active_state and next.ident == active_state.ident:
14676657Snate@binkert.org                    color = "aqua"
14686657Snate@binkert.org                elif state == active_state:
14696657Snate@binkert.org                    color = "yellow"
14706657Snate@binkert.org                else:
14716657Snate@binkert.org                    color = "white"
14726657Snate@binkert.org
14736657Snate@binkert.org                code('<TD bgcolor=$color>')
14746657Snate@binkert.org                for action in trans.actions:
14756657Snate@binkert.org                    href = "%s_action_%s.html" % (self.ident, action.ident)
14766657Snate@binkert.org                    ref = self.frameRef(href, "Status", href, "1",
14776657Snate@binkert.org                                        action.short)
14787007Snate@binkert.org                    code('  $ref')
14796657Snate@binkert.org                if next != state:
14806657Snate@binkert.org                    if trans.actions:
14816657Snate@binkert.org                        code('/')
14826657Snate@binkert.org                    click = "%s_table_%s.html" % (self.ident, next.ident)
14836657Snate@binkert.org                    over = "%s_State_%s.html" % (self.ident, next.ident)
14846657Snate@binkert.org                    ref = self.frameRef(click, "Table", over, "1", next.short)
14856657Snate@binkert.org                    code("$ref")
14867007Snate@binkert.org                code("</TD>")
14876657Snate@binkert.org
14886657Snate@binkert.org            # -- Each row
14896657Snate@binkert.org            if state == active_state:
14906657Snate@binkert.org                color = "yellow"
14916657Snate@binkert.org            else:
14926657Snate@binkert.org                color = "white"
14936657Snate@binkert.org
14946657Snate@binkert.org            click = "%s_table_%s.html" % (self.ident, state.ident)
14956657Snate@binkert.org            over = "%s_State_%s.html" % (self.ident, state.ident)
14966657Snate@binkert.org            ref = self.frameRef(click, "Table", over, "1", state.short)
14976657Snate@binkert.org            code('''
14986657Snate@binkert.org  <TH bgcolor=$color>$ref</TH>
14996657Snate@binkert.org</TR>
15006657Snate@binkert.org''')
15016657Snate@binkert.org        code('''
150210917Sbrandon.potter@amd.com<!- Column footer->
15036657Snate@binkert.org<TR>
15046657Snate@binkert.org  <TH> </TH>
15056657Snate@binkert.org''')
15066657Snate@binkert.org
15076657Snate@binkert.org        for event in self.events.itervalues():
15086657Snate@binkert.org            href = "%s_Event_%s.html" % (self.ident, event.ident)
15096657Snate@binkert.org            ref = self.frameRef(href, "Status", href, "1", event.short)
15106657Snate@binkert.org            code('<TH bgcolor=white>$ref</TH>')
15116657Snate@binkert.org        code('''
15126657Snate@binkert.org</TR>
15136657Snate@binkert.org</TABLE>
15146657Snate@binkert.org</BODY></HTML>
15156657Snate@binkert.org''')
15166657Snate@binkert.org
15176657Snate@binkert.org
15186657Snate@binkert.org        if active_state:
15196657Snate@binkert.org            name = "%s_table_%s.html" % (self.ident, active_state.ident)
15206657Snate@binkert.org        else:
15216657Snate@binkert.org            name = "%s_table.html" % self.ident
15226657Snate@binkert.org        code.write(path, name)
15236657Snate@binkert.org
15246657Snate@binkert.org__all__ = [ "StateMachine" ]
1525