StateMachine.py revision 7567
16657Snate@binkert.org# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 26657Snate@binkert.org# Copyright (c) 2009 The Hewlett-Packard Development Company 36657Snate@binkert.org# All rights reserved. 46657Snate@binkert.org# 56657Snate@binkert.org# Redistribution and use in source and binary forms, with or without 66657Snate@binkert.org# modification, are permitted provided that the following conditions are 76657Snate@binkert.org# met: redistributions of source code must retain the above copyright 86657Snate@binkert.org# notice, this list of conditions and the following disclaimer; 96657Snate@binkert.org# redistributions in binary form must reproduce the above copyright 106657Snate@binkert.org# notice, this list of conditions and the following disclaimer in the 116657Snate@binkert.org# documentation and/or other materials provided with the distribution; 126657Snate@binkert.org# neither the name of the copyright holders nor the names of its 136657Snate@binkert.org# contributors may be used to endorse or promote products derived from 146657Snate@binkert.org# this software without specific prior written permission. 156657Snate@binkert.org# 166657Snate@binkert.org# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176657Snate@binkert.org# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186657Snate@binkert.org# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196657Snate@binkert.org# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206657Snate@binkert.org# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216657Snate@binkert.org# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226657Snate@binkert.org# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236657Snate@binkert.org# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246657Snate@binkert.org# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256657Snate@binkert.org# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266657Snate@binkert.org# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276657Snate@binkert.org 286999Snate@binkert.orgfrom m5.util import orderdict 296657Snate@binkert.org 306657Snate@binkert.orgfrom slicc.symbols.Symbol import Symbol 316657Snate@binkert.orgfrom slicc.symbols.Var import Var 326657Snate@binkert.orgimport slicc.generate.html as html 336657Snate@binkert.org 346882SBrad.Beckmann@amd.compython_class_map = {"int": "Int", 357055Snate@binkert.org "std::string": "String", 366882SBrad.Beckmann@amd.com "bool": "Bool", 376882SBrad.Beckmann@amd.com "CacheMemory": "RubyCache", 386882SBrad.Beckmann@amd.com "Sequencer": "RubySequencer", 396882SBrad.Beckmann@amd.com "DirectoryMemory": "RubyDirectoryMemory", 406882SBrad.Beckmann@amd.com "MemoryControl": "RubyMemoryControl", 416888SBrad.Beckmann@amd.com "DMASequencer": "DMASequencer" 426882SBrad.Beckmann@amd.com } 436882SBrad.Beckmann@amd.com 446657Snate@binkert.orgclass StateMachine(Symbol): 456657Snate@binkert.org def __init__(self, symtab, ident, location, pairs, config_parameters): 466657Snate@binkert.org super(StateMachine, self).__init__(symtab, ident, location, pairs) 476657Snate@binkert.org self.table = None 486657Snate@binkert.org self.config_parameters = config_parameters 496657Snate@binkert.org for param in config_parameters: 506882SBrad.Beckmann@amd.com if param.pointer: 516882SBrad.Beckmann@amd.com var = Var(symtab, param.name, location, param.type_ast.type, 526882SBrad.Beckmann@amd.com "(*m_%s_ptr)" % param.name, {}, self) 536882SBrad.Beckmann@amd.com else: 546882SBrad.Beckmann@amd.com var = Var(symtab, param.name, location, param.type_ast.type, 556882SBrad.Beckmann@amd.com "m_%s" % param.name, {}, self) 566657Snate@binkert.org self.symtab.registerSym(param.name, var) 576657Snate@binkert.org 586657Snate@binkert.org self.states = orderdict() 596657Snate@binkert.org self.events = orderdict() 606657Snate@binkert.org self.actions = orderdict() 616657Snate@binkert.org self.transitions = [] 626657Snate@binkert.org self.in_ports = [] 636657Snate@binkert.org self.functions = [] 646657Snate@binkert.org self.objects = [] 656657Snate@binkert.org 666657Snate@binkert.org self.message_buffer_names = [] 676657Snate@binkert.org 686657Snate@binkert.org def __repr__(self): 696657Snate@binkert.org return "[StateMachine: %s]" % self.ident 706657Snate@binkert.org 716657Snate@binkert.org def addState(self, state): 726657Snate@binkert.org assert self.table is None 736657Snate@binkert.org self.states[state.ident] = state 746657Snate@binkert.org 756657Snate@binkert.org def addEvent(self, event): 766657Snate@binkert.org assert self.table is None 776657Snate@binkert.org self.events[event.ident] = event 786657Snate@binkert.org 796657Snate@binkert.org def addAction(self, action): 806657Snate@binkert.org assert self.table is None 816657Snate@binkert.org 826657Snate@binkert.org # Check for duplicate action 836657Snate@binkert.org for other in self.actions.itervalues(): 846657Snate@binkert.org if action.ident == other.ident: 856779SBrad.Beckmann@amd.com action.warning("Duplicate action definition: %s" % action.ident) 866657Snate@binkert.org action.error("Duplicate action definition: %s" % action.ident) 876657Snate@binkert.org if action.short == other.short: 886657Snate@binkert.org other.warning("Duplicate action shorthand: %s" % other.ident) 896657Snate@binkert.org other.warning(" shorthand = %s" % other.short) 906657Snate@binkert.org action.warning("Duplicate action shorthand: %s" % action.ident) 916657Snate@binkert.org action.error(" shorthand = %s" % action.short) 926657Snate@binkert.org 936657Snate@binkert.org self.actions[action.ident] = action 946657Snate@binkert.org 956657Snate@binkert.org def addTransition(self, trans): 966657Snate@binkert.org assert self.table is None 976657Snate@binkert.org self.transitions.append(trans) 986657Snate@binkert.org 996657Snate@binkert.org def addInPort(self, var): 1006657Snate@binkert.org self.in_ports.append(var) 1016657Snate@binkert.org 1026657Snate@binkert.org def addFunc(self, func): 1036657Snate@binkert.org # register func in the symbol table 1046657Snate@binkert.org self.symtab.registerSym(str(func), func) 1056657Snate@binkert.org self.functions.append(func) 1066657Snate@binkert.org 1076657Snate@binkert.org def addObject(self, obj): 1086657Snate@binkert.org self.objects.append(obj) 1096657Snate@binkert.org 1106657Snate@binkert.org # Needs to be called before accessing the table 1116657Snate@binkert.org def buildTable(self): 1126657Snate@binkert.org assert self.table is None 1136657Snate@binkert.org 1146657Snate@binkert.org table = {} 1156657Snate@binkert.org 1166657Snate@binkert.org for trans in self.transitions: 1176657Snate@binkert.org # Track which actions we touch so we know if we use them 1186657Snate@binkert.org # all -- really this should be done for all symbols as 1196657Snate@binkert.org # part of the symbol table, then only trigger it for 1206657Snate@binkert.org # Actions, States, Events, etc. 1216657Snate@binkert.org 1226657Snate@binkert.org for action in trans.actions: 1236657Snate@binkert.org action.used = True 1246657Snate@binkert.org 1256657Snate@binkert.org index = (trans.state, trans.event) 1266657Snate@binkert.org if index in table: 1276657Snate@binkert.org table[index].warning("Duplicate transition: %s" % table[index]) 1286657Snate@binkert.org trans.error("Duplicate transition: %s" % trans) 1296657Snate@binkert.org table[index] = trans 1306657Snate@binkert.org 1316657Snate@binkert.org # Look at all actions to make sure we used them all 1326657Snate@binkert.org for action in self.actions.itervalues(): 1336657Snate@binkert.org if not action.used: 1346657Snate@binkert.org error_msg = "Unused action: %s" % action.ident 1356657Snate@binkert.org if "desc" in action: 1366657Snate@binkert.org error_msg += ", " + action.desc 1376657Snate@binkert.org action.warning(error_msg) 1386657Snate@binkert.org self.table = table 1396657Snate@binkert.org 1406657Snate@binkert.org def writeCodeFiles(self, path): 1416877Ssteve.reinhardt@amd.com self.printControllerPython(path) 1426657Snate@binkert.org self.printControllerHH(path) 1436657Snate@binkert.org self.printControllerCC(path) 1446657Snate@binkert.org self.printCSwitch(path) 1456657Snate@binkert.org self.printCWakeup(path) 1466657Snate@binkert.org self.printProfilerCC(path) 1476657Snate@binkert.org self.printProfilerHH(path) 1487542SBrad.Beckmann@amd.com self.printProfileDumperCC(path) 1497542SBrad.Beckmann@amd.com self.printProfileDumperHH(path) 1506657Snate@binkert.org 1516657Snate@binkert.org for func in self.functions: 1526657Snate@binkert.org func.writeCodeFiles(path) 1536657Snate@binkert.org 1546877Ssteve.reinhardt@amd.com def printControllerPython(self, path): 1556999Snate@binkert.org code = self.symtab.codeFormatter() 1566877Ssteve.reinhardt@amd.com ident = self.ident 1576877Ssteve.reinhardt@amd.com py_ident = "%s_Controller" % ident 1586877Ssteve.reinhardt@amd.com c_ident = "%s_Controller" % self.ident 1596877Ssteve.reinhardt@amd.com code(''' 1606877Ssteve.reinhardt@amd.comfrom m5.params import * 1616877Ssteve.reinhardt@amd.comfrom m5.SimObject import SimObject 1626877Ssteve.reinhardt@amd.comfrom Controller import RubyController 1636877Ssteve.reinhardt@amd.com 1646877Ssteve.reinhardt@amd.comclass $py_ident(RubyController): 1656877Ssteve.reinhardt@amd.com type = '$py_ident' 1666877Ssteve.reinhardt@amd.com''') 1676877Ssteve.reinhardt@amd.com code.indent() 1686877Ssteve.reinhardt@amd.com for param in self.config_parameters: 1696877Ssteve.reinhardt@amd.com dflt_str = '' 1706877Ssteve.reinhardt@amd.com if param.default is not None: 1716877Ssteve.reinhardt@amd.com dflt_str = str(param.default) + ', ' 1726882SBrad.Beckmann@amd.com if python_class_map.has_key(param.type_ast.type.c_ident): 1736882SBrad.Beckmann@amd.com python_type = python_class_map[param.type_ast.type.c_ident] 1746882SBrad.Beckmann@amd.com code('${{param.name}} = Param.${{python_type}}(${dflt_str}"")') 1756882SBrad.Beckmann@amd.com else: 1766882SBrad.Beckmann@amd.com self.error("Unknown c++ to python class conversion for c++ " \ 1776882SBrad.Beckmann@amd.com "type: '%s'. Please update the python_class_map " \ 1786882SBrad.Beckmann@amd.com "in StateMachine.py", param.type_ast.type.c_ident) 1796877Ssteve.reinhardt@amd.com code.dedent() 1806877Ssteve.reinhardt@amd.com code.write(path, '%s.py' % py_ident) 1816877Ssteve.reinhardt@amd.com 1826877Ssteve.reinhardt@amd.com 1836657Snate@binkert.org def printControllerHH(self, path): 1846657Snate@binkert.org '''Output the method declarations for the class declaration''' 1856999Snate@binkert.org code = self.symtab.codeFormatter() 1866657Snate@binkert.org ident = self.ident 1876657Snate@binkert.org c_ident = "%s_Controller" % self.ident 1886657Snate@binkert.org 1896657Snate@binkert.org self.message_buffer_names = [] 1906657Snate@binkert.org 1916657Snate@binkert.org code(''' 1927007Snate@binkert.org/** \\file $c_ident.hh 1936657Snate@binkert.org * 1946657Snate@binkert.org * Auto generated C++ code started by $__file__:$__line__ 1956657Snate@binkert.org * Created by slicc definition of Module "${{self.short}}" 1966657Snate@binkert.org */ 1976657Snate@binkert.org 1987007Snate@binkert.org#ifndef __${ident}_CONTROLLER_HH__ 1997007Snate@binkert.org#define __${ident}_CONTROLLER_HH__ 2006657Snate@binkert.org 2017002Snate@binkert.org#include <iostream> 2027002Snate@binkert.org#include <sstream> 2037002Snate@binkert.org#include <string> 2047002Snate@binkert.org 2056877Ssteve.reinhardt@amd.com#include "params/$c_ident.hh" 2066877Ssteve.reinhardt@amd.com 2076657Snate@binkert.org#include "mem/ruby/common/Global.hh" 2086657Snate@binkert.org#include "mem/ruby/common/Consumer.hh" 2096657Snate@binkert.org#include "mem/ruby/slicc_interface/AbstractController.hh" 2106657Snate@binkert.org#include "mem/protocol/TransitionResult.hh" 2116657Snate@binkert.org#include "mem/protocol/Types.hh" 2126657Snate@binkert.org#include "mem/protocol/${ident}_Profiler.hh" 2137542SBrad.Beckmann@amd.com#include "mem/protocol/${ident}_ProfileDumper.hh" 2146657Snate@binkert.org''') 2156657Snate@binkert.org 2166657Snate@binkert.org seen_types = set() 2176657Snate@binkert.org for var in self.objects: 2186793SBrad.Beckmann@amd.com if var.type.ident not in seen_types and not var.type.isPrimitive: 2196657Snate@binkert.org code('#include "mem/protocol/${{var.type.c_ident}}.hh"') 2206657Snate@binkert.org seen_types.add(var.type.ident) 2216657Snate@binkert.org 2226657Snate@binkert.org # for adding information to the protocol debug trace 2236657Snate@binkert.org code(''' 2247002Snate@binkert.orgextern std::stringstream ${ident}_transitionComment; 2256657Snate@binkert.org 2267007Snate@binkert.orgclass $c_ident : public AbstractController 2277007Snate@binkert.org{ 2287007Snate@binkert.org// the coherence checker needs to call isBlockExclusive() and isBlockShared() 2297007Snate@binkert.org// making the Chip a friend class is an easy way to do this for now 2307007Snate@binkert.org 2316657Snate@binkert.orgpublic: 2326877Ssteve.reinhardt@amd.com typedef ${c_ident}Params Params; 2336877Ssteve.reinhardt@amd.com $c_ident(const Params *p); 2346657Snate@binkert.org static int getNumControllers(); 2356877Ssteve.reinhardt@amd.com void init(); 2366657Snate@binkert.org MessageBuffer* getMandatoryQueue() const; 2376657Snate@binkert.org const int & getVersion() const; 2387002Snate@binkert.org const std::string toString() const; 2397002Snate@binkert.org const std::string getName() const; 2406657Snate@binkert.org const MachineType getMachineType() const; 2417567SBrad.Beckmann@amd.com void stallBuffer(MessageBuffer* buf, Address addr); 2427567SBrad.Beckmann@amd.com void wakeUpBuffers(Address addr); 2436881SBrad.Beckmann@amd.com void initNetworkPtr(Network* net_ptr) { m_net_ptr = net_ptr; } 2447002Snate@binkert.org void print(std::ostream& out) const; 2457002Snate@binkert.org void printConfig(std::ostream& out) const; 2466657Snate@binkert.org void wakeup(); 2477002Snate@binkert.org void printStats(std::ostream& out) const; 2486902SBrad.Beckmann@amd.com void clearStats(); 2496863Sdrh5@cs.wisc.edu void blockOnQueue(Address addr, MessageBuffer* port); 2506863Sdrh5@cs.wisc.edu void unblock(Address addr); 2517007Snate@binkert.org 2526657Snate@binkert.orgprivate: 2536657Snate@binkert.org''') 2546657Snate@binkert.org 2556657Snate@binkert.org code.indent() 2566657Snate@binkert.org # added by SS 2576657Snate@binkert.org for param in self.config_parameters: 2586882SBrad.Beckmann@amd.com if param.pointer: 2596882SBrad.Beckmann@amd.com code('${{param.type_ast.type}}* m_${{param.ident}}_ptr;') 2606882SBrad.Beckmann@amd.com else: 2616882SBrad.Beckmann@amd.com code('${{param.type_ast.type}} m_${{param.ident}};') 2626657Snate@binkert.org 2636657Snate@binkert.org code(''' 2646657Snate@binkert.orgint m_number_of_TBEs; 2656657Snate@binkert.org 2667007Snate@binkert.orgTransitionResult doTransition(${ident}_Event event, 2677007Snate@binkert.org ${ident}_State state, 2687007Snate@binkert.org const Address& addr); 2697007Snate@binkert.org 2707007Snate@binkert.orgTransitionResult doTransitionWorker(${ident}_Event event, 2717007Snate@binkert.org ${ident}_State state, 2727007Snate@binkert.org ${ident}_State& next_state, 2737007Snate@binkert.org const Address& addr); 2747007Snate@binkert.org 2757002Snate@binkert.orgstd::string m_name; 2766657Snate@binkert.orgint m_transitions_per_cycle; 2776657Snate@binkert.orgint m_buffer_size; 2786657Snate@binkert.orgint m_recycle_latency; 2797055Snate@binkert.orgstd::map<std::string, std::string> m_cfg; 2806657Snate@binkert.orgNodeID m_version; 2816657Snate@binkert.orgNetwork* m_net_ptr; 2826657Snate@binkert.orgMachineID m_machineID; 2836863Sdrh5@cs.wisc.edubool m_is_blocking; 2847055Snate@binkert.orgstd::map<Address, MessageBuffer*> m_block_map; 2857567SBrad.Beckmann@amd.comtypedef std::vector<MessageBuffer*> MsgVecType; 2867567SBrad.Beckmann@amd.comtypedef m5::hash_map< Address, MsgVecType* > WaitingBufType; 2877567SBrad.Beckmann@amd.comWaitingBufType m_waiting_buffers; 2887567SBrad.Beckmann@amd.comint m_max_in_port_rank; 2897567SBrad.Beckmann@amd.comint m_cur_in_port_rank; 2907542SBrad.Beckmann@amd.comstatic ${ident}_ProfileDumper s_profileDumper; 2917542SBrad.Beckmann@amd.com${ident}_Profiler m_profiler; 2926657Snate@binkert.orgstatic int m_num_controllers; 2937007Snate@binkert.org 2946657Snate@binkert.org// Internal functions 2956657Snate@binkert.org''') 2966657Snate@binkert.org 2976657Snate@binkert.org for func in self.functions: 2986657Snate@binkert.org proto = func.prototype 2996657Snate@binkert.org if proto: 3006657Snate@binkert.org code('$proto') 3016657Snate@binkert.org 3026657Snate@binkert.org code(''' 3036657Snate@binkert.org 3046657Snate@binkert.org// Actions 3056657Snate@binkert.org''') 3066657Snate@binkert.org for action in self.actions.itervalues(): 3076657Snate@binkert.org code('/** \\brief ${{action.desc}} */') 3086657Snate@binkert.org code('void ${{action.ident}}(const Address& addr);') 3096657Snate@binkert.org 3106657Snate@binkert.org # the controller internal variables 3116657Snate@binkert.org code(''' 3126657Snate@binkert.org 3137007Snate@binkert.org// Objects 3146657Snate@binkert.org''') 3156657Snate@binkert.org for var in self.objects: 3166657Snate@binkert.org th = var.get("template_hack", "") 3176657Snate@binkert.org code('${{var.type.c_ident}}$th* m_${{var.c_ident}}_ptr;') 3186657Snate@binkert.org 3196657Snate@binkert.org if var.type.ident == "MessageBuffer": 3206657Snate@binkert.org self.message_buffer_names.append("m_%s_ptr" % var.c_ident) 3216657Snate@binkert.org 3226657Snate@binkert.org code.dedent() 3236657Snate@binkert.org code('};') 3247007Snate@binkert.org code('#endif // __${ident}_CONTROLLER_H__') 3256657Snate@binkert.org code.write(path, '%s.hh' % c_ident) 3266657Snate@binkert.org 3276657Snate@binkert.org def printControllerCC(self, path): 3286657Snate@binkert.org '''Output the actions for performing the actions''' 3296657Snate@binkert.org 3306999Snate@binkert.org code = self.symtab.codeFormatter() 3316657Snate@binkert.org ident = self.ident 3326657Snate@binkert.org c_ident = "%s_Controller" % self.ident 3336657Snate@binkert.org 3346657Snate@binkert.org code(''' 3357007Snate@binkert.org/** \\file $c_ident.cc 3366657Snate@binkert.org * 3376657Snate@binkert.org * Auto generated C++ code started by $__file__:$__line__ 3386657Snate@binkert.org * Created by slicc definition of Module "${{self.short}}" 3396657Snate@binkert.org */ 3406657Snate@binkert.org 3417002Snate@binkert.org#include <sstream> 3427002Snate@binkert.org#include <string> 3437002Snate@binkert.org 3447056Snate@binkert.org#include "base/cprintf.hh" 3456657Snate@binkert.org#include "mem/protocol/${ident}_Controller.hh" 3466657Snate@binkert.org#include "mem/protocol/${ident}_State.hh" 3476657Snate@binkert.org#include "mem/protocol/${ident}_Event.hh" 3486657Snate@binkert.org#include "mem/protocol/Types.hh" 3497056Snate@binkert.org#include "mem/ruby/common/Global.hh" 3507056Snate@binkert.org#include "mem/ruby/slicc_interface/RubySlicc_includes.hh" 3516657Snate@binkert.org#include "mem/ruby/system/System.hh" 3527002Snate@binkert.org 3537002Snate@binkert.orgusing namespace std; 3546657Snate@binkert.org''') 3556657Snate@binkert.org 3566657Snate@binkert.org # include object classes 3576657Snate@binkert.org seen_types = set() 3586657Snate@binkert.org for var in self.objects: 3596793SBrad.Beckmann@amd.com if var.type.ident not in seen_types and not var.type.isPrimitive: 3606657Snate@binkert.org code('#include "mem/protocol/${{var.type.c_ident}}.hh"') 3616657Snate@binkert.org seen_types.add(var.type.ident) 3626657Snate@binkert.org 3636657Snate@binkert.org code(''' 3646877Ssteve.reinhardt@amd.com$c_ident * 3656877Ssteve.reinhardt@amd.com${c_ident}Params::create() 3666877Ssteve.reinhardt@amd.com{ 3676877Ssteve.reinhardt@amd.com return new $c_ident(this); 3686877Ssteve.reinhardt@amd.com} 3696877Ssteve.reinhardt@amd.com 3706657Snate@binkert.orgint $c_ident::m_num_controllers = 0; 3717542SBrad.Beckmann@amd.com${ident}_ProfileDumper $c_ident::s_profileDumper; 3726657Snate@binkert.org 3737007Snate@binkert.org// for adding information to the protocol debug trace 3746657Snate@binkert.orgstringstream ${ident}_transitionComment; 3756657Snate@binkert.org#define APPEND_TRANSITION_COMMENT(str) (${ident}_transitionComment << str) 3767007Snate@binkert.org 3776657Snate@binkert.org/** \\brief constructor */ 3786877Ssteve.reinhardt@amd.com$c_ident::$c_ident(const Params *p) 3796877Ssteve.reinhardt@amd.com : AbstractController(p) 3806657Snate@binkert.org{ 3816877Ssteve.reinhardt@amd.com m_version = p->version; 3826877Ssteve.reinhardt@amd.com m_transitions_per_cycle = p->transitions_per_cycle; 3836877Ssteve.reinhardt@amd.com m_buffer_size = p->buffer_size; 3846877Ssteve.reinhardt@amd.com m_recycle_latency = p->recycle_latency; 3856877Ssteve.reinhardt@amd.com m_number_of_TBEs = p->number_of_TBEs; 3866969SBrad.Beckmann@amd.com m_is_blocking = false; 3876657Snate@binkert.org''') 3887567SBrad.Beckmann@amd.com # 3897567SBrad.Beckmann@amd.com # max_port_rank is used to size vectors and thus should be one plus the 3907567SBrad.Beckmann@amd.com # largest port rank 3917567SBrad.Beckmann@amd.com # 3927567SBrad.Beckmann@amd.com max_port_rank = self.in_ports[0].pairs["max_port_rank"] + 1 3937567SBrad.Beckmann@amd.com code(' m_max_in_port_rank = $max_port_rank;') 3946657Snate@binkert.org code.indent() 3956882SBrad.Beckmann@amd.com 3966882SBrad.Beckmann@amd.com # 3976882SBrad.Beckmann@amd.com # After initializing the universal machine parameters, initialize the 3986882SBrad.Beckmann@amd.com # this machines config parameters. Also detemine if these configuration 3996882SBrad.Beckmann@amd.com # params include a sequencer. This information will be used later for 4006882SBrad.Beckmann@amd.com # contecting the sequencer back to the L1 cache controller. 4016882SBrad.Beckmann@amd.com # 4026882SBrad.Beckmann@amd.com contains_sequencer = False 4036877Ssteve.reinhardt@amd.com for param in self.config_parameters: 4046888SBrad.Beckmann@amd.com if param.name == "sequencer" or param.name == "dma_sequencer": 4056882SBrad.Beckmann@amd.com contains_sequencer = True 4066882SBrad.Beckmann@amd.com if param.pointer: 4076882SBrad.Beckmann@amd.com code('m_${{param.name}}_ptr = p->${{param.name}};') 4086882SBrad.Beckmann@amd.com else: 4096882SBrad.Beckmann@amd.com code('m_${{param.name}} = p->${{param.name}};') 4106882SBrad.Beckmann@amd.com 4116882SBrad.Beckmann@amd.com # 4126882SBrad.Beckmann@amd.com # For the l1 cache controller, add the special atomic support which 4136882SBrad.Beckmann@amd.com # includes passing the sequencer a pointer to the controller. 4146882SBrad.Beckmann@amd.com # 4156882SBrad.Beckmann@amd.com if self.ident == "L1Cache": 4166882SBrad.Beckmann@amd.com if not contains_sequencer: 4176882SBrad.Beckmann@amd.com self.error("The L1Cache controller must include the sequencer " \ 4186882SBrad.Beckmann@amd.com "configuration parameter") 4196882SBrad.Beckmann@amd.com 4206882SBrad.Beckmann@amd.com code(''' 4216882SBrad.Beckmann@amd.comm_sequencer_ptr->setController(this); 4226882SBrad.Beckmann@amd.com''') 4236888SBrad.Beckmann@amd.com # 4246888SBrad.Beckmann@amd.com # For the DMA controller, pass the sequencer a pointer to the 4256888SBrad.Beckmann@amd.com # controller. 4266888SBrad.Beckmann@amd.com # 4276888SBrad.Beckmann@amd.com if self.ident == "DMA": 4286888SBrad.Beckmann@amd.com if not contains_sequencer: 4296888SBrad.Beckmann@amd.com self.error("The DMA controller must include the sequencer " \ 4306888SBrad.Beckmann@amd.com "configuration parameter") 4316657Snate@binkert.org 4326888SBrad.Beckmann@amd.com code(''' 4336888SBrad.Beckmann@amd.comm_dma_sequencer_ptr->setController(this); 4346888SBrad.Beckmann@amd.com''') 4356888SBrad.Beckmann@amd.com 4366657Snate@binkert.org code('m_num_controllers++;') 4376657Snate@binkert.org for var in self.objects: 4386657Snate@binkert.org if var.ident.find("mandatoryQueue") >= 0: 4396657Snate@binkert.org code('m_${{var.c_ident}}_ptr = new ${{var.type.c_ident}}();') 4406657Snate@binkert.org 4416657Snate@binkert.org code.dedent() 4426657Snate@binkert.org code(''' 4436657Snate@binkert.org} 4446657Snate@binkert.org 4457007Snate@binkert.orgvoid 4467007Snate@binkert.org$c_ident::init() 4476657Snate@binkert.org{ 4487007Snate@binkert.org MachineType machine_type; 4497007Snate@binkert.org int base; 4507007Snate@binkert.org 4516657Snate@binkert.org m_machineID.type = MachineType_${ident}; 4526657Snate@binkert.org m_machineID.num = m_version; 4536657Snate@binkert.org 4547007Snate@binkert.org // initialize objects 4557542SBrad.Beckmann@amd.com m_profiler.setVersion(m_version); 4567542SBrad.Beckmann@amd.com s_profileDumper.registerProfiler(&m_profiler); 4577007Snate@binkert.org 4586657Snate@binkert.org''') 4596657Snate@binkert.org 4606657Snate@binkert.org code.indent() 4616657Snate@binkert.org for var in self.objects: 4626657Snate@binkert.org vtype = var.type 4636657Snate@binkert.org vid = "m_%s_ptr" % var.c_ident 4646657Snate@binkert.org if "network" not in var: 4656657Snate@binkert.org # Not a network port object 4666657Snate@binkert.org if "primitive" in vtype: 4676657Snate@binkert.org code('$vid = new ${{vtype.c_ident}};') 4686657Snate@binkert.org if "default" in var: 4696657Snate@binkert.org code('(*$vid) = ${{var["default"]}};') 4706657Snate@binkert.org else: 4716657Snate@binkert.org # Normal Object 4726657Snate@binkert.org # added by SS 4736657Snate@binkert.org if "factory" in var: 4746657Snate@binkert.org code('$vid = ${{var["factory"]}};') 4756657Snate@binkert.org elif var.ident.find("mandatoryQueue") < 0: 4766657Snate@binkert.org th = var.get("template_hack", "") 4776657Snate@binkert.org expr = "%s = new %s%s" % (vid, vtype.c_ident, th) 4786657Snate@binkert.org 4796657Snate@binkert.org args = "" 4806657Snate@binkert.org if "non_obj" not in vtype and not vtype.isEnumeration: 4816657Snate@binkert.org if expr.find("TBETable") >= 0: 4826657Snate@binkert.org args = "m_number_of_TBEs" 4836657Snate@binkert.org else: 4846657Snate@binkert.org args = var.get("constructor_hack", "") 4856657Snate@binkert.org 4867007Snate@binkert.org code('$expr($args);') 4876657Snate@binkert.org 4886657Snate@binkert.org code('assert($vid != NULL);') 4896657Snate@binkert.org 4906657Snate@binkert.org if "default" in var: 4917007Snate@binkert.org code('*$vid = ${{var["default"]}}; // Object default') 4926657Snate@binkert.org elif "default" in vtype: 4937007Snate@binkert.org comment = "Type %s default" % vtype.ident 4947007Snate@binkert.org code('*$vid = ${{vtype["default"]}}; // $comment') 4956657Snate@binkert.org 4966657Snate@binkert.org # Set ordering 4976657Snate@binkert.org if "ordered" in var and "trigger_queue" not in var: 4986657Snate@binkert.org # A buffer 4996657Snate@binkert.org code('$vid->setOrdering(${{var["ordered"]}});') 5006657Snate@binkert.org 5016657Snate@binkert.org # Set randomization 5026657Snate@binkert.org if "random" in var: 5036657Snate@binkert.org # A buffer 5046657Snate@binkert.org code('$vid->setRandomization(${{var["random"]}});') 5056657Snate@binkert.org 5066657Snate@binkert.org # Set Priority 5076657Snate@binkert.org if vtype.isBuffer and \ 5086657Snate@binkert.org "rank" in var and "trigger_queue" not in var: 5096657Snate@binkert.org code('$vid->setPriority(${{var["rank"]}});') 5107566SBrad.Beckmann@amd.com 5116657Snate@binkert.org else: 5126657Snate@binkert.org # Network port object 5136657Snate@binkert.org network = var["network"] 5146657Snate@binkert.org ordered = var["ordered"] 5156657Snate@binkert.org vnet = var["virtual_network"] 5166657Snate@binkert.org 5176657Snate@binkert.org assert var.machine is not None 5186657Snate@binkert.org code(''' 5197007Snate@binkert.orgmachine_type = string_to_MachineType("${{var.machine.ident}}"); 5207007Snate@binkert.orgbase = MachineType_base_number(machine_type); 5217007Snate@binkert.org$vid = m_net_ptr->get${network}NetQueue(m_version + base, $ordered, $vnet); 5226657Snate@binkert.org''') 5236657Snate@binkert.org 5246657Snate@binkert.org code('assert($vid != NULL);') 5256657Snate@binkert.org 5266657Snate@binkert.org # Set ordering 5276657Snate@binkert.org if "ordered" in var: 5286657Snate@binkert.org # A buffer 5296657Snate@binkert.org code('$vid->setOrdering(${{var["ordered"]}});') 5306657Snate@binkert.org 5316657Snate@binkert.org # Set randomization 5326657Snate@binkert.org if "random" in var: 5336657Snate@binkert.org # A buffer 5346657Snate@binkert.org code('$vid->setRandomization(${{var["random"]}})') 5356657Snate@binkert.org 5366657Snate@binkert.org # Set Priority 5376657Snate@binkert.org if "rank" in var: 5386657Snate@binkert.org code('$vid->setPriority(${{var["rank"]}})') 5396657Snate@binkert.org 5406657Snate@binkert.org # Set buffer size 5416657Snate@binkert.org if vtype.isBuffer: 5426657Snate@binkert.org code(''' 5436657Snate@binkert.orgif (m_buffer_size > 0) { 5447454Snate@binkert.org $vid->resize(m_buffer_size); 5456657Snate@binkert.org} 5466657Snate@binkert.org''') 5476657Snate@binkert.org 5486657Snate@binkert.org # set description (may be overriden later by port def) 5497007Snate@binkert.org code(''' 5507056Snate@binkert.org$vid->setDescription("[Version " + to_string(m_version) + ", ${ident}, name=${{var.c_ident}}]"); 5517007Snate@binkert.org 5527007Snate@binkert.org''') 5536657Snate@binkert.org 5547566SBrad.Beckmann@amd.com if vtype.isBuffer: 5557566SBrad.Beckmann@amd.com if "recycle_latency" in var: 5567566SBrad.Beckmann@amd.com code('$vid->setRecycleLatency(${{var["recycle_latency"]}});') 5577566SBrad.Beckmann@amd.com else: 5587566SBrad.Beckmann@amd.com code('$vid->setRecycleLatency(m_recycle_latency);') 5597566SBrad.Beckmann@amd.com 5607566SBrad.Beckmann@amd.com 5616657Snate@binkert.org # Set the queue consumers 5626657Snate@binkert.org code.insert_newline() 5636657Snate@binkert.org for port in self.in_ports: 5646657Snate@binkert.org code('${{port.code}}.setConsumer(this);') 5656657Snate@binkert.org 5666657Snate@binkert.org # Set the queue descriptions 5676657Snate@binkert.org code.insert_newline() 5686657Snate@binkert.org for port in self.in_ports: 5697056Snate@binkert.org code('${{port.code}}.setDescription("[Version " + to_string(m_version) + ", $ident, $port]");') 5706657Snate@binkert.org 5716657Snate@binkert.org # Initialize the transition profiling 5726657Snate@binkert.org code.insert_newline() 5736657Snate@binkert.org for trans in self.transitions: 5746657Snate@binkert.org # Figure out if we stall 5756657Snate@binkert.org stall = False 5766657Snate@binkert.org for action in trans.actions: 5776657Snate@binkert.org if action.ident == "z_stall": 5786657Snate@binkert.org stall = True 5796657Snate@binkert.org 5806657Snate@binkert.org # Only possible if it is not a 'z' case 5816657Snate@binkert.org if not stall: 5826657Snate@binkert.org state = "%s_State_%s" % (self.ident, trans.state.ident) 5836657Snate@binkert.org event = "%s_Event_%s" % (self.ident, trans.event.ident) 5847542SBrad.Beckmann@amd.com code('m_profiler.possibleTransition($state, $event);') 5856657Snate@binkert.org 5866657Snate@binkert.org code.dedent() 5876657Snate@binkert.org code('}') 5886657Snate@binkert.org 5896657Snate@binkert.org has_mandatory_q = False 5906657Snate@binkert.org for port in self.in_ports: 5916657Snate@binkert.org if port.code.find("mandatoryQueue_ptr") >= 0: 5926657Snate@binkert.org has_mandatory_q = True 5936657Snate@binkert.org 5946657Snate@binkert.org if has_mandatory_q: 5956657Snate@binkert.org mq_ident = "m_%s_mandatoryQueue_ptr" % self.ident 5966657Snate@binkert.org else: 5976657Snate@binkert.org mq_ident = "NULL" 5986657Snate@binkert.org 5996657Snate@binkert.org code(''' 6007007Snate@binkert.orgint 6017007Snate@binkert.org$c_ident::getNumControllers() 6027007Snate@binkert.org{ 6036657Snate@binkert.org return m_num_controllers; 6046657Snate@binkert.org} 6056657Snate@binkert.org 6067007Snate@binkert.orgMessageBuffer* 6077007Snate@binkert.org$c_ident::getMandatoryQueue() const 6087007Snate@binkert.org{ 6096657Snate@binkert.org return $mq_ident; 6106657Snate@binkert.org} 6116657Snate@binkert.org 6127007Snate@binkert.orgconst int & 6137007Snate@binkert.org$c_ident::getVersion() const 6147007Snate@binkert.org{ 6156657Snate@binkert.org return m_version; 6166657Snate@binkert.org} 6176657Snate@binkert.org 6187007Snate@binkert.orgconst string 6197007Snate@binkert.org$c_ident::toString() const 6207007Snate@binkert.org{ 6216657Snate@binkert.org return "$c_ident"; 6226657Snate@binkert.org} 6236657Snate@binkert.org 6247007Snate@binkert.orgconst string 6257007Snate@binkert.org$c_ident::getName() const 6267007Snate@binkert.org{ 6276657Snate@binkert.org return m_name; 6286657Snate@binkert.org} 6297007Snate@binkert.org 6307007Snate@binkert.orgconst MachineType 6317007Snate@binkert.org$c_ident::getMachineType() const 6327007Snate@binkert.org{ 6336657Snate@binkert.org return MachineType_${ident}; 6346657Snate@binkert.org} 6356657Snate@binkert.org 6367007Snate@binkert.orgvoid 6377567SBrad.Beckmann@amd.com$c_ident::stallBuffer(MessageBuffer* buf, Address addr) 6387567SBrad.Beckmann@amd.com{ 6397567SBrad.Beckmann@amd.com if (m_waiting_buffers.count(addr) == 0) { 6407567SBrad.Beckmann@amd.com MsgVecType* msgVec = new MsgVecType; 6417567SBrad.Beckmann@amd.com msgVec->resize(m_max_in_port_rank, NULL); 6427567SBrad.Beckmann@amd.com m_waiting_buffers[addr] = msgVec; 6437567SBrad.Beckmann@amd.com } 6447567SBrad.Beckmann@amd.com (*(m_waiting_buffers[addr]))[m_cur_in_port_rank] = buf; 6457567SBrad.Beckmann@amd.com} 6467567SBrad.Beckmann@amd.com 6477567SBrad.Beckmann@amd.comvoid 6487567SBrad.Beckmann@amd.com$c_ident::wakeUpBuffers(Address addr) 6497567SBrad.Beckmann@amd.com{ 6507567SBrad.Beckmann@amd.com // 6517567SBrad.Beckmann@amd.com // Wake up all possible lower rank (i.e. lower priority) buffers that could 6527567SBrad.Beckmann@amd.com // be waiting on this message. 6537567SBrad.Beckmann@amd.com // 6547567SBrad.Beckmann@amd.com for (int in_port_rank = m_cur_in_port_rank - 1; 6557567SBrad.Beckmann@amd.com in_port_rank >= 0; 6567567SBrad.Beckmann@amd.com in_port_rank--) { 6577567SBrad.Beckmann@amd.com if ((*(m_waiting_buffers[addr]))[in_port_rank] != NULL) { 6587567SBrad.Beckmann@amd.com (*(m_waiting_buffers[addr]))[in_port_rank]->reanalyzeMessages(addr); 6597567SBrad.Beckmann@amd.com } 6607567SBrad.Beckmann@amd.com } 6617567SBrad.Beckmann@amd.com delete m_waiting_buffers[addr]; 6627567SBrad.Beckmann@amd.com m_waiting_buffers.erase(addr); 6637567SBrad.Beckmann@amd.com} 6647567SBrad.Beckmann@amd.com 6657567SBrad.Beckmann@amd.comvoid 6667007Snate@binkert.org$c_ident::blockOnQueue(Address addr, MessageBuffer* port) 6677007Snate@binkert.org{ 6686863Sdrh5@cs.wisc.edu m_is_blocking = true; 6696863Sdrh5@cs.wisc.edu m_block_map[addr] = port; 6706863Sdrh5@cs.wisc.edu} 6717007Snate@binkert.org 6727007Snate@binkert.orgvoid 6737007Snate@binkert.org$c_ident::unblock(Address addr) 6747007Snate@binkert.org{ 6756863Sdrh5@cs.wisc.edu m_block_map.erase(addr); 6766863Sdrh5@cs.wisc.edu if (m_block_map.size() == 0) { 6776863Sdrh5@cs.wisc.edu m_is_blocking = false; 6786863Sdrh5@cs.wisc.edu } 6796863Sdrh5@cs.wisc.edu} 6806863Sdrh5@cs.wisc.edu 6817007Snate@binkert.orgvoid 6827007Snate@binkert.org$c_ident::print(ostream& out) const 6837007Snate@binkert.org{ 6847007Snate@binkert.org out << "[$c_ident " << m_version << "]"; 6857007Snate@binkert.org} 6866657Snate@binkert.org 6877007Snate@binkert.orgvoid 6887007Snate@binkert.org$c_ident::printConfig(ostream& out) const 6897007Snate@binkert.org{ 6906657Snate@binkert.org out << "$c_ident config: " << m_name << endl; 6916657Snate@binkert.org out << " version: " << m_version << endl; 6927007Snate@binkert.org map<string, string>::const_iterator it; 6937007Snate@binkert.org for (it = m_cfg.begin(); it != m_cfg.end(); it++) 6947007Snate@binkert.org out << " " << it->first << ": " << it->second << endl; 6956657Snate@binkert.org} 6966657Snate@binkert.org 6977007Snate@binkert.orgvoid 6987007Snate@binkert.org$c_ident::printStats(ostream& out) const 6997007Snate@binkert.org{ 7006902SBrad.Beckmann@amd.com''') 7016902SBrad.Beckmann@amd.com # 7026902SBrad.Beckmann@amd.com # Cache and Memory Controllers have specific profilers associated with 7036902SBrad.Beckmann@amd.com # them. Print out these stats before dumping state transition stats. 7046902SBrad.Beckmann@amd.com # 7056902SBrad.Beckmann@amd.com for param in self.config_parameters: 7066902SBrad.Beckmann@amd.com if param.type_ast.type.ident == "CacheMemory" or \ 7077025SBrad.Beckmann@amd.com param.type_ast.type.ident == "DirectoryMemory" or \ 7086902SBrad.Beckmann@amd.com param.type_ast.type.ident == "MemoryControl": 7096902SBrad.Beckmann@amd.com assert(param.pointer) 7106902SBrad.Beckmann@amd.com code(' m_${{param.ident}}_ptr->printStats(out);') 7116902SBrad.Beckmann@amd.com 7126902SBrad.Beckmann@amd.com code(''' 7137542SBrad.Beckmann@amd.com if (m_version == 0) { 7147542SBrad.Beckmann@amd.com s_profileDumper.dumpStats(out); 7157542SBrad.Beckmann@amd.com } 7166902SBrad.Beckmann@amd.com} 7176902SBrad.Beckmann@amd.com 7186902SBrad.Beckmann@amd.comvoid $c_ident::clearStats() { 7196902SBrad.Beckmann@amd.com''') 7206902SBrad.Beckmann@amd.com # 7216902SBrad.Beckmann@amd.com # Cache and Memory Controllers have specific profilers associated with 7226902SBrad.Beckmann@amd.com # them. These stats must be cleared too. 7236902SBrad.Beckmann@amd.com # 7246902SBrad.Beckmann@amd.com for param in self.config_parameters: 7256902SBrad.Beckmann@amd.com if param.type_ast.type.ident == "CacheMemory" or \ 7266902SBrad.Beckmann@amd.com param.type_ast.type.ident == "MemoryControl": 7276902SBrad.Beckmann@amd.com assert(param.pointer) 7286902SBrad.Beckmann@amd.com code(' m_${{param.ident}}_ptr->clearStats();') 7296902SBrad.Beckmann@amd.com 7306902SBrad.Beckmann@amd.com code(''' 7317542SBrad.Beckmann@amd.com m_profiler.clearStats(); 7326902SBrad.Beckmann@amd.com} 7336902SBrad.Beckmann@amd.com 7346657Snate@binkert.org// Actions 7356657Snate@binkert.org''') 7366657Snate@binkert.org 7376657Snate@binkert.org for action in self.actions.itervalues(): 7386657Snate@binkert.org if "c_code" not in action: 7396657Snate@binkert.org continue 7406657Snate@binkert.org 7416657Snate@binkert.org code(''' 7426657Snate@binkert.org/** \\brief ${{action.desc}} */ 7437007Snate@binkert.orgvoid 7447007Snate@binkert.org$c_ident::${{action.ident}}(const Address& addr) 7456657Snate@binkert.org{ 7466657Snate@binkert.org DEBUG_MSG(GENERATED_COMP, HighPrio, "executing"); 7476657Snate@binkert.org ${{action["c_code"]}} 7486657Snate@binkert.org} 7496657Snate@binkert.org 7506657Snate@binkert.org''') 7516657Snate@binkert.org code.write(path, "%s.cc" % c_ident) 7526657Snate@binkert.org 7536657Snate@binkert.org def printCWakeup(self, path): 7546657Snate@binkert.org '''Output the wakeup loop for the events''' 7556657Snate@binkert.org 7566999Snate@binkert.org code = self.symtab.codeFormatter() 7576657Snate@binkert.org ident = self.ident 7586657Snate@binkert.org 7596657Snate@binkert.org code(''' 7606657Snate@binkert.org// Auto generated C++ code started by $__file__:$__line__ 7616657Snate@binkert.org// ${ident}: ${{self.short}} 7626657Snate@binkert.org 7637007Snate@binkert.org#include "base/misc.hh" 7646657Snate@binkert.org#include "mem/ruby/common/Global.hh" 7656657Snate@binkert.org#include "mem/ruby/slicc_interface/RubySlicc_includes.hh" 7666657Snate@binkert.org#include "mem/protocol/${ident}_Controller.hh" 7676657Snate@binkert.org#include "mem/protocol/${ident}_State.hh" 7686657Snate@binkert.org#include "mem/protocol/${ident}_Event.hh" 7696657Snate@binkert.org#include "mem/protocol/Types.hh" 7706657Snate@binkert.org#include "mem/ruby/system/System.hh" 7716657Snate@binkert.org 7727055Snate@binkert.orgusing namespace std; 7737055Snate@binkert.org 7747007Snate@binkert.orgvoid 7757007Snate@binkert.org${ident}_Controller::wakeup() 7766657Snate@binkert.org{ 7777007Snate@binkert.org // DEBUG_EXPR(GENERATED_COMP, MedPrio, *this); 7787007Snate@binkert.org // DEBUG_EXPR(GENERATED_COMP, MedPrio, g_eventQueue_ptr->getTime()); 7796657Snate@binkert.org 7806657Snate@binkert.org int counter = 0; 7816657Snate@binkert.org while (true) { 7826657Snate@binkert.org // Some cases will put us into an infinite loop without this limit 7836657Snate@binkert.org assert(counter <= m_transitions_per_cycle); 7846657Snate@binkert.org if (counter == m_transitions_per_cycle) { 7857007Snate@binkert.org // Count how often we are fully utilized 7867007Snate@binkert.org g_system_ptr->getProfiler()->controllerBusy(m_machineID); 7877007Snate@binkert.org 7887007Snate@binkert.org // Wakeup in another cycle and try again 7897007Snate@binkert.org g_eventQueue_ptr->scheduleEvent(this, 1); 7906657Snate@binkert.org break; 7916657Snate@binkert.org } 7926657Snate@binkert.org''') 7936657Snate@binkert.org 7946657Snate@binkert.org code.indent() 7956657Snate@binkert.org code.indent() 7966657Snate@binkert.org 7976657Snate@binkert.org # InPorts 7986657Snate@binkert.org # 7996657Snate@binkert.org for port in self.in_ports: 8006657Snate@binkert.org code.indent() 8016657Snate@binkert.org code('// ${ident}InPort $port') 8027567SBrad.Beckmann@amd.com if port.pairs.has_key("rank"): 8037567SBrad.Beckmann@amd.com code('m_cur_in_port_rank = ${{port.pairs["rank"]}};') 8047567SBrad.Beckmann@amd.com else: 8057567SBrad.Beckmann@amd.com code('m_cur_in_port_rank = 0;') 8066657Snate@binkert.org code('${{port["c_code_in_port"]}}') 8076657Snate@binkert.org code.dedent() 8086657Snate@binkert.org 8096657Snate@binkert.org code('') 8106657Snate@binkert.org 8116657Snate@binkert.org code.dedent() 8126657Snate@binkert.org code.dedent() 8136657Snate@binkert.org code(''' 8146657Snate@binkert.org break; // If we got this far, we have nothing left todo 8156657Snate@binkert.org } 8167007Snate@binkert.org // g_eventQueue_ptr->scheduleEvent(this, 1); 8177007Snate@binkert.org // DEBUG_NEWLINE(GENERATED_COMP, MedPrio); 8186657Snate@binkert.org} 8196657Snate@binkert.org''') 8206657Snate@binkert.org 8216657Snate@binkert.org code.write(path, "%s_Wakeup.cc" % self.ident) 8226657Snate@binkert.org 8236657Snate@binkert.org def printCSwitch(self, path): 8246657Snate@binkert.org '''Output switch statement for transition table''' 8256657Snate@binkert.org 8266999Snate@binkert.org code = self.symtab.codeFormatter() 8276657Snate@binkert.org ident = self.ident 8286657Snate@binkert.org 8296657Snate@binkert.org code(''' 8306657Snate@binkert.org// Auto generated C++ code started by $__file__:$__line__ 8316657Snate@binkert.org// ${ident}: ${{self.short}} 8326657Snate@binkert.org 8336657Snate@binkert.org#include "mem/ruby/common/Global.hh" 8346657Snate@binkert.org#include "mem/protocol/${ident}_Controller.hh" 8356657Snate@binkert.org#include "mem/protocol/${ident}_State.hh" 8366657Snate@binkert.org#include "mem/protocol/${ident}_Event.hh" 8376657Snate@binkert.org#include "mem/protocol/Types.hh" 8386657Snate@binkert.org#include "mem/ruby/system/System.hh" 8396657Snate@binkert.org 8406657Snate@binkert.org#define HASH_FUN(state, event) ((int(state)*${ident}_Event_NUM)+int(event)) 8416657Snate@binkert.org 8426657Snate@binkert.org#define GET_TRANSITION_COMMENT() (${ident}_transitionComment.str()) 8436657Snate@binkert.org#define CLEAR_TRANSITION_COMMENT() (${ident}_transitionComment.str("")) 8446657Snate@binkert.org 8457007Snate@binkert.orgTransitionResult 8467007Snate@binkert.org${ident}_Controller::doTransition(${ident}_Event event, 8477007Snate@binkert.org ${ident}_State state, 8487007Snate@binkert.org const Address &addr) 8496657Snate@binkert.org{ 8506657Snate@binkert.org ${ident}_State next_state = state; 8516657Snate@binkert.org 8526657Snate@binkert.org DEBUG_NEWLINE(GENERATED_COMP, MedPrio); 8536657Snate@binkert.org DEBUG_MSG(GENERATED_COMP, MedPrio, *this); 8546657Snate@binkert.org DEBUG_EXPR(GENERATED_COMP, MedPrio, g_eventQueue_ptr->getTime()); 8556657Snate@binkert.org DEBUG_EXPR(GENERATED_COMP, MedPrio,state); 8566657Snate@binkert.org DEBUG_EXPR(GENERATED_COMP, MedPrio,event); 8576657Snate@binkert.org DEBUG_EXPR(GENERATED_COMP, MedPrio,addr); 8586657Snate@binkert.org 8597007Snate@binkert.org TransitionResult result = 8607007Snate@binkert.org doTransitionWorker(event, state, next_state, addr); 8616657Snate@binkert.org 8626657Snate@binkert.org if (result == TransitionResult_Valid) { 8636657Snate@binkert.org DEBUG_EXPR(GENERATED_COMP, MedPrio, next_state); 8646657Snate@binkert.org DEBUG_NEWLINE(GENERATED_COMP, MedPrio); 8657542SBrad.Beckmann@amd.com m_profiler.countTransition(state, event); 8666657Snate@binkert.org if (Debug::getProtocolTrace()) { 8677007Snate@binkert.org g_system_ptr->getProfiler()->profileTransition("${ident}", 8687007Snate@binkert.org m_version, addr, 8696657Snate@binkert.org ${ident}_State_to_string(state), 8706657Snate@binkert.org ${ident}_Event_to_string(event), 8717007Snate@binkert.org ${ident}_State_to_string(next_state), 8727007Snate@binkert.org GET_TRANSITION_COMMENT()); 8736657Snate@binkert.org } 8746657Snate@binkert.org CLEAR_TRANSITION_COMMENT(); 8756657Snate@binkert.org ${ident}_setState(addr, next_state); 8766657Snate@binkert.org 8776657Snate@binkert.org } else if (result == TransitionResult_ResourceStall) { 8786657Snate@binkert.org if (Debug::getProtocolTrace()) { 8797007Snate@binkert.org g_system_ptr->getProfiler()->profileTransition("${ident}", 8807007Snate@binkert.org m_version, addr, 8816657Snate@binkert.org ${ident}_State_to_string(state), 8826657Snate@binkert.org ${ident}_Event_to_string(event), 8836657Snate@binkert.org ${ident}_State_to_string(next_state), 8846657Snate@binkert.org "Resource Stall"); 8856657Snate@binkert.org } 8866657Snate@binkert.org } else if (result == TransitionResult_ProtocolStall) { 8876657Snate@binkert.org DEBUG_MSG(GENERATED_COMP, HighPrio, "stalling"); 8886657Snate@binkert.org DEBUG_NEWLINE(GENERATED_COMP, MedPrio); 8896657Snate@binkert.org if (Debug::getProtocolTrace()) { 8907007Snate@binkert.org g_system_ptr->getProfiler()->profileTransition("${ident}", 8917007Snate@binkert.org m_version, addr, 8926657Snate@binkert.org ${ident}_State_to_string(state), 8936657Snate@binkert.org ${ident}_Event_to_string(event), 8946657Snate@binkert.org ${ident}_State_to_string(next_state), 8956657Snate@binkert.org "Protocol Stall"); 8966657Snate@binkert.org } 8976657Snate@binkert.org } 8986657Snate@binkert.org 8996657Snate@binkert.org return result; 9006657Snate@binkert.org} 9016657Snate@binkert.org 9027007Snate@binkert.orgTransitionResult 9037007Snate@binkert.org${ident}_Controller::doTransitionWorker(${ident}_Event event, 9047007Snate@binkert.org ${ident}_State state, 9057007Snate@binkert.org ${ident}_State& next_state, 9067007Snate@binkert.org const Address& addr) 9076657Snate@binkert.org{ 9086657Snate@binkert.org switch(HASH_FUN(state, event)) { 9096657Snate@binkert.org''') 9106657Snate@binkert.org 9116657Snate@binkert.org # This map will allow suppress generating duplicate code 9126657Snate@binkert.org cases = orderdict() 9136657Snate@binkert.org 9146657Snate@binkert.org for trans in self.transitions: 9156657Snate@binkert.org case_string = "%s_State_%s, %s_Event_%s" % \ 9166657Snate@binkert.org (self.ident, trans.state.ident, self.ident, trans.event.ident) 9176657Snate@binkert.org 9186999Snate@binkert.org case = self.symtab.codeFormatter() 9196657Snate@binkert.org # Only set next_state if it changes 9206657Snate@binkert.org if trans.state != trans.nextState: 9216657Snate@binkert.org ns_ident = trans.nextState.ident 9226657Snate@binkert.org case('next_state = ${ident}_State_${ns_ident};') 9236657Snate@binkert.org 9246657Snate@binkert.org actions = trans.actions 9256657Snate@binkert.org 9266657Snate@binkert.org # Check for resources 9276657Snate@binkert.org case_sorter = [] 9286657Snate@binkert.org res = trans.resources 9296657Snate@binkert.org for key,val in res.iteritems(): 9306657Snate@binkert.org if key.type.ident != "DNUCAStopTable": 9316657Snate@binkert.org val = ''' 9327007Snate@binkert.orgif (!%s.areNSlotsAvailable(%s)) 9336657Snate@binkert.org return TransitionResult_ResourceStall; 9346657Snate@binkert.org''' % (key.code, val) 9356657Snate@binkert.org case_sorter.append(val) 9366657Snate@binkert.org 9376657Snate@binkert.org 9386657Snate@binkert.org # Emit the code sequences in a sorted order. This makes the 9396657Snate@binkert.org # output deterministic (without this the output order can vary 9406657Snate@binkert.org # since Map's keys() on a vector of pointers is not deterministic 9416657Snate@binkert.org for c in sorted(case_sorter): 9426657Snate@binkert.org case("$c") 9436657Snate@binkert.org 9446657Snate@binkert.org # Figure out if we stall 9456657Snate@binkert.org stall = False 9466657Snate@binkert.org for action in actions: 9476657Snate@binkert.org if action.ident == "z_stall": 9486657Snate@binkert.org stall = True 9496657Snate@binkert.org break 9506657Snate@binkert.org 9516657Snate@binkert.org if stall: 9526657Snate@binkert.org case('return TransitionResult_ProtocolStall;') 9536657Snate@binkert.org else: 9546657Snate@binkert.org for action in actions: 9556657Snate@binkert.org case('${{action.ident}}(addr);') 9566657Snate@binkert.org case('return TransitionResult_Valid;') 9576657Snate@binkert.org 9586657Snate@binkert.org case = str(case) 9596657Snate@binkert.org 9606657Snate@binkert.org # Look to see if this transition code is unique. 9616657Snate@binkert.org if case not in cases: 9626657Snate@binkert.org cases[case] = [] 9636657Snate@binkert.org 9646657Snate@binkert.org cases[case].append(case_string) 9656657Snate@binkert.org 9666657Snate@binkert.org # Walk through all of the unique code blocks and spit out the 9676657Snate@binkert.org # corresponding case statement elements 9686657Snate@binkert.org for case,transitions in cases.iteritems(): 9696657Snate@binkert.org # Iterative over all the multiple transitions that share 9706657Snate@binkert.org # the same code 9716657Snate@binkert.org for trans in transitions: 9726657Snate@binkert.org code(' case HASH_FUN($trans):') 9736657Snate@binkert.org code(' $case') 9746657Snate@binkert.org 9756657Snate@binkert.org code(''' 9766657Snate@binkert.org default: 9776657Snate@binkert.org WARN_EXPR(m_version); 9786657Snate@binkert.org WARN_EXPR(g_eventQueue_ptr->getTime()); 9796657Snate@binkert.org WARN_EXPR(addr); 9806657Snate@binkert.org WARN_EXPR(event); 9816657Snate@binkert.org WARN_EXPR(state); 9826657Snate@binkert.org ERROR_MSG(\"Invalid transition\"); 9836657Snate@binkert.org } 9846657Snate@binkert.org return TransitionResult_Valid; 9856657Snate@binkert.org} 9866657Snate@binkert.org''') 9876657Snate@binkert.org code.write(path, "%s_Transitions.cc" % self.ident) 9886657Snate@binkert.org 9897542SBrad.Beckmann@amd.com def printProfileDumperHH(self, path): 9907542SBrad.Beckmann@amd.com code = self.symtab.codeFormatter() 9917542SBrad.Beckmann@amd.com ident = self.ident 9927542SBrad.Beckmann@amd.com 9937542SBrad.Beckmann@amd.com code(''' 9947542SBrad.Beckmann@amd.com// Auto generated C++ code started by $__file__:$__line__ 9957542SBrad.Beckmann@amd.com// ${ident}: ${{self.short}} 9967542SBrad.Beckmann@amd.com 9977542SBrad.Beckmann@amd.com#ifndef __${ident}_PROFILE_DUMPER_HH__ 9987542SBrad.Beckmann@amd.com#define __${ident}_PROFILE_DUMPER_HH__ 9997542SBrad.Beckmann@amd.com 10007542SBrad.Beckmann@amd.com#include <iostream> 10017542SBrad.Beckmann@amd.com#include <vector> 10027542SBrad.Beckmann@amd.com 10037542SBrad.Beckmann@amd.com#include "${ident}_Profiler.hh" 10047542SBrad.Beckmann@amd.com#include "${ident}_Event.hh" 10057542SBrad.Beckmann@amd.com 10067542SBrad.Beckmann@amd.comtypedef std::vector<${ident}_Profiler *> ${ident}_profilers; 10077542SBrad.Beckmann@amd.com 10087542SBrad.Beckmann@amd.comclass ${ident}_ProfileDumper 10097542SBrad.Beckmann@amd.com{ 10107542SBrad.Beckmann@amd.com public: 10117542SBrad.Beckmann@amd.com ${ident}_ProfileDumper(); 10127542SBrad.Beckmann@amd.com void registerProfiler(${ident}_Profiler* profiler); 10137542SBrad.Beckmann@amd.com void dumpStats(std::ostream& out) const; 10147542SBrad.Beckmann@amd.com 10157542SBrad.Beckmann@amd.com private: 10167542SBrad.Beckmann@amd.com ${ident}_profilers m_profilers; 10177542SBrad.Beckmann@amd.com}; 10187542SBrad.Beckmann@amd.com 10197542SBrad.Beckmann@amd.com#endif // __${ident}_PROFILE_DUMPER_HH__ 10207542SBrad.Beckmann@amd.com''') 10217542SBrad.Beckmann@amd.com code.write(path, "%s_ProfileDumper.hh" % self.ident) 10227542SBrad.Beckmann@amd.com 10237542SBrad.Beckmann@amd.com def printProfileDumperCC(self, path): 10247542SBrad.Beckmann@amd.com code = self.symtab.codeFormatter() 10257542SBrad.Beckmann@amd.com ident = self.ident 10267542SBrad.Beckmann@amd.com 10277542SBrad.Beckmann@amd.com code(''' 10287542SBrad.Beckmann@amd.com// Auto generated C++ code started by $__file__:$__line__ 10297542SBrad.Beckmann@amd.com// ${ident}: ${{self.short}} 10307542SBrad.Beckmann@amd.com 10317542SBrad.Beckmann@amd.com#include "mem/protocol/${ident}_ProfileDumper.hh" 10327542SBrad.Beckmann@amd.com 10337542SBrad.Beckmann@amd.com${ident}_ProfileDumper::${ident}_ProfileDumper() 10347542SBrad.Beckmann@amd.com{ 10357542SBrad.Beckmann@amd.com} 10367542SBrad.Beckmann@amd.com 10377542SBrad.Beckmann@amd.comvoid 10387542SBrad.Beckmann@amd.com${ident}_ProfileDumper::registerProfiler(${ident}_Profiler* profiler) 10397542SBrad.Beckmann@amd.com{ 10407542SBrad.Beckmann@amd.com m_profilers.push_back(profiler); 10417542SBrad.Beckmann@amd.com} 10427542SBrad.Beckmann@amd.com 10437542SBrad.Beckmann@amd.comvoid 10447542SBrad.Beckmann@amd.com${ident}_ProfileDumper::dumpStats(std::ostream& out) const 10457542SBrad.Beckmann@amd.com{ 10467542SBrad.Beckmann@amd.com out << " --- ${ident} ---\\n"; 10477542SBrad.Beckmann@amd.com out << " - Event Counts -\\n"; 10487542SBrad.Beckmann@amd.com for (${ident}_Event event = ${ident}_Event_FIRST; 10497542SBrad.Beckmann@amd.com event < ${ident}_Event_NUM; 10507542SBrad.Beckmann@amd.com ++event) { 10517542SBrad.Beckmann@amd.com out << (${ident}_Event) event << " ["; 10527542SBrad.Beckmann@amd.com uint64 total = 0; 10537542SBrad.Beckmann@amd.com for (int i = 0; i < m_profilers.size(); i++) { 10547542SBrad.Beckmann@amd.com out << m_profilers[i]->getEventCount(event) << " "; 10557542SBrad.Beckmann@amd.com total += m_profilers[i]->getEventCount(event); 10567542SBrad.Beckmann@amd.com } 10577542SBrad.Beckmann@amd.com out << "] " << total << "\\n"; 10587542SBrad.Beckmann@amd.com } 10597542SBrad.Beckmann@amd.com out << "\\n"; 10607542SBrad.Beckmann@amd.com out << " - Transitions -\\n"; 10617542SBrad.Beckmann@amd.com for (${ident}_State state = ${ident}_State_FIRST; 10627542SBrad.Beckmann@amd.com state < ${ident}_State_NUM; 10637542SBrad.Beckmann@amd.com ++state) { 10647542SBrad.Beckmann@amd.com for (${ident}_Event event = ${ident}_Event_FIRST; 10657542SBrad.Beckmann@amd.com event < ${ident}_Event_NUM; 10667542SBrad.Beckmann@amd.com ++event) { 10677542SBrad.Beckmann@amd.com if (m_profilers[0]->isPossible(state, event)) { 10687542SBrad.Beckmann@amd.com out << (${ident}_State) state << " " 10697542SBrad.Beckmann@amd.com << (${ident}_Event) event << " ["; 10707542SBrad.Beckmann@amd.com uint64 total = 0; 10717542SBrad.Beckmann@amd.com for (int i = 0; i < m_profilers.size(); i++) { 10727542SBrad.Beckmann@amd.com out << m_profilers[i]->getTransitionCount(state, event) << " "; 10737542SBrad.Beckmann@amd.com total += m_profilers[i]->getTransitionCount(state, event); 10747542SBrad.Beckmann@amd.com } 10757542SBrad.Beckmann@amd.com out << "] " << total << "\\n"; 10767542SBrad.Beckmann@amd.com } 10777542SBrad.Beckmann@amd.com } 10787542SBrad.Beckmann@amd.com out << "\\n"; 10797542SBrad.Beckmann@amd.com } 10807542SBrad.Beckmann@amd.com} 10817542SBrad.Beckmann@amd.com''') 10827542SBrad.Beckmann@amd.com code.write(path, "%s_ProfileDumper.cc" % self.ident) 10837542SBrad.Beckmann@amd.com 10846657Snate@binkert.org def printProfilerHH(self, path): 10856999Snate@binkert.org code = self.symtab.codeFormatter() 10866657Snate@binkert.org ident = self.ident 10876657Snate@binkert.org 10886657Snate@binkert.org code(''' 10896657Snate@binkert.org// Auto generated C++ code started by $__file__:$__line__ 10906657Snate@binkert.org// ${ident}: ${{self.short}} 10916657Snate@binkert.org 10927542SBrad.Beckmann@amd.com#ifndef __${ident}_PROFILER_HH__ 10937542SBrad.Beckmann@amd.com#define __${ident}_PROFILER_HH__ 10946657Snate@binkert.org 10957002Snate@binkert.org#include <iostream> 10967002Snate@binkert.org 10976657Snate@binkert.org#include "mem/ruby/common/Global.hh" 10986657Snate@binkert.org#include "mem/protocol/${ident}_State.hh" 10996657Snate@binkert.org#include "mem/protocol/${ident}_Event.hh" 11006657Snate@binkert.org 11017007Snate@binkert.orgclass ${ident}_Profiler 11027007Snate@binkert.org{ 11036657Snate@binkert.org public: 11046657Snate@binkert.org ${ident}_Profiler(); 11056657Snate@binkert.org void setVersion(int version); 11066657Snate@binkert.org void countTransition(${ident}_State state, ${ident}_Event event); 11076657Snate@binkert.org void possibleTransition(${ident}_State state, ${ident}_Event event); 11087542SBrad.Beckmann@amd.com uint64 getEventCount(${ident}_Event event); 11097542SBrad.Beckmann@amd.com bool isPossible(${ident}_State state, ${ident}_Event event); 11107542SBrad.Beckmann@amd.com uint64 getTransitionCount(${ident}_State state, ${ident}_Event event); 11116657Snate@binkert.org void clearStats(); 11126657Snate@binkert.org 11136657Snate@binkert.org private: 11146657Snate@binkert.org int m_counters[${ident}_State_NUM][${ident}_Event_NUM]; 11156657Snate@binkert.org int m_event_counters[${ident}_Event_NUM]; 11166657Snate@binkert.org bool m_possible[${ident}_State_NUM][${ident}_Event_NUM]; 11176657Snate@binkert.org int m_version; 11186657Snate@binkert.org}; 11196657Snate@binkert.org 11207007Snate@binkert.org#endif // __${ident}_PROFILER_HH__ 11216657Snate@binkert.org''') 11226657Snate@binkert.org code.write(path, "%s_Profiler.hh" % self.ident) 11236657Snate@binkert.org 11246657Snate@binkert.org def printProfilerCC(self, path): 11256999Snate@binkert.org code = self.symtab.codeFormatter() 11266657Snate@binkert.org ident = self.ident 11276657Snate@binkert.org 11286657Snate@binkert.org code(''' 11296657Snate@binkert.org// Auto generated C++ code started by $__file__:$__line__ 11306657Snate@binkert.org// ${ident}: ${{self.short}} 11316657Snate@binkert.org 11326657Snate@binkert.org#include "mem/protocol/${ident}_Profiler.hh" 11336657Snate@binkert.org 11346657Snate@binkert.org${ident}_Profiler::${ident}_Profiler() 11356657Snate@binkert.org{ 11366657Snate@binkert.org for (int state = 0; state < ${ident}_State_NUM; state++) { 11376657Snate@binkert.org for (int event = 0; event < ${ident}_Event_NUM; event++) { 11386657Snate@binkert.org m_possible[state][event] = false; 11396657Snate@binkert.org m_counters[state][event] = 0; 11406657Snate@binkert.org } 11416657Snate@binkert.org } 11426657Snate@binkert.org for (int event = 0; event < ${ident}_Event_NUM; event++) { 11436657Snate@binkert.org m_event_counters[event] = 0; 11446657Snate@binkert.org } 11456657Snate@binkert.org} 11467007Snate@binkert.org 11477007Snate@binkert.orgvoid 11487007Snate@binkert.org${ident}_Profiler::setVersion(int version) 11496657Snate@binkert.org{ 11506657Snate@binkert.org m_version = version; 11516657Snate@binkert.org} 11527007Snate@binkert.org 11537007Snate@binkert.orgvoid 11547007Snate@binkert.org${ident}_Profiler::clearStats() 11556657Snate@binkert.org{ 11566657Snate@binkert.org for (int state = 0; state < ${ident}_State_NUM; state++) { 11576657Snate@binkert.org for (int event = 0; event < ${ident}_Event_NUM; event++) { 11586657Snate@binkert.org m_counters[state][event] = 0; 11596657Snate@binkert.org } 11606657Snate@binkert.org } 11616657Snate@binkert.org 11626657Snate@binkert.org for (int event = 0; event < ${ident}_Event_NUM; event++) { 11636657Snate@binkert.org m_event_counters[event] = 0; 11646657Snate@binkert.org } 11656657Snate@binkert.org} 11667007Snate@binkert.orgvoid 11677007Snate@binkert.org${ident}_Profiler::countTransition(${ident}_State state, ${ident}_Event event) 11686657Snate@binkert.org{ 11696657Snate@binkert.org assert(m_possible[state][event]); 11706657Snate@binkert.org m_counters[state][event]++; 11716657Snate@binkert.org m_event_counters[event]++; 11726657Snate@binkert.org} 11737007Snate@binkert.orgvoid 11747007Snate@binkert.org${ident}_Profiler::possibleTransition(${ident}_State state, 11757007Snate@binkert.org ${ident}_Event event) 11766657Snate@binkert.org{ 11776657Snate@binkert.org m_possible[state][event] = true; 11786657Snate@binkert.org} 11797007Snate@binkert.org 11807542SBrad.Beckmann@amd.comuint64 11817542SBrad.Beckmann@amd.com${ident}_Profiler::getEventCount(${ident}_Event event) 11826657Snate@binkert.org{ 11837542SBrad.Beckmann@amd.com return m_event_counters[event]; 11847542SBrad.Beckmann@amd.com} 11857002Snate@binkert.org 11867542SBrad.Beckmann@amd.combool 11877542SBrad.Beckmann@amd.com${ident}_Profiler::isPossible(${ident}_State state, ${ident}_Event event) 11887542SBrad.Beckmann@amd.com{ 11897542SBrad.Beckmann@amd.com return m_possible[state][event]; 11906657Snate@binkert.org} 11917542SBrad.Beckmann@amd.com 11927542SBrad.Beckmann@amd.comuint64 11937542SBrad.Beckmann@amd.com${ident}_Profiler::getTransitionCount(${ident}_State state, 11947542SBrad.Beckmann@amd.com ${ident}_Event event) 11957542SBrad.Beckmann@amd.com{ 11967542SBrad.Beckmann@amd.com return m_counters[state][event]; 11977542SBrad.Beckmann@amd.com} 11987542SBrad.Beckmann@amd.com 11996657Snate@binkert.org''') 12006657Snate@binkert.org code.write(path, "%s_Profiler.cc" % self.ident) 12016657Snate@binkert.org 12026657Snate@binkert.org # ************************** 12036657Snate@binkert.org # ******* HTML Files ******* 12046657Snate@binkert.org # ************************** 12057007Snate@binkert.org def frameRef(self, click_href, click_target, over_href, over_num, text): 12066999Snate@binkert.org code = self.symtab.codeFormatter(fix_newlines=False) 12077007Snate@binkert.org code("""<A href=\"$click_href\" target=\"$click_target\" onmouseover=\" 12087007Snate@binkert.org if (parent.frames[$over_num].location != parent.location + '$over_href') { 12097007Snate@binkert.org parent.frames[$over_num].location='$over_href' 12107007Snate@binkert.org }\"> 12117007Snate@binkert.org ${{html.formatShorthand(text)}} 12127007Snate@binkert.org </A>""") 12136657Snate@binkert.org return str(code) 12146657Snate@binkert.org 12156657Snate@binkert.org def writeHTMLFiles(self, path): 12166657Snate@binkert.org # Create table with no row hilighted 12176657Snate@binkert.org self.printHTMLTransitions(path, None) 12186657Snate@binkert.org 12196657Snate@binkert.org # Generate transition tables 12206657Snate@binkert.org for state in self.states.itervalues(): 12216657Snate@binkert.org self.printHTMLTransitions(path, state) 12226657Snate@binkert.org 12236657Snate@binkert.org # Generate action descriptions 12246657Snate@binkert.org for action in self.actions.itervalues(): 12256657Snate@binkert.org name = "%s_action_%s.html" % (self.ident, action.ident) 12266657Snate@binkert.org code = html.createSymbol(action, "Action") 12276657Snate@binkert.org code.write(path, name) 12286657Snate@binkert.org 12296657Snate@binkert.org # Generate state descriptions 12306657Snate@binkert.org for state in self.states.itervalues(): 12316657Snate@binkert.org name = "%s_State_%s.html" % (self.ident, state.ident) 12326657Snate@binkert.org code = html.createSymbol(state, "State") 12336657Snate@binkert.org code.write(path, name) 12346657Snate@binkert.org 12356657Snate@binkert.org # Generate event descriptions 12366657Snate@binkert.org for event in self.events.itervalues(): 12376657Snate@binkert.org name = "%s_Event_%s.html" % (self.ident, event.ident) 12386657Snate@binkert.org code = html.createSymbol(event, "Event") 12396657Snate@binkert.org code.write(path, name) 12406657Snate@binkert.org 12416657Snate@binkert.org def printHTMLTransitions(self, path, active_state): 12426999Snate@binkert.org code = self.symtab.codeFormatter() 12436657Snate@binkert.org 12446657Snate@binkert.org code(''' 12457007Snate@binkert.org<HTML> 12467007Snate@binkert.org<BODY link="blue" vlink="blue"> 12476657Snate@binkert.org 12486657Snate@binkert.org<H1 align="center">${{html.formatShorthand(self.short)}}: 12496657Snate@binkert.org''') 12506657Snate@binkert.org code.indent() 12516657Snate@binkert.org for i,machine in enumerate(self.symtab.getAllType(StateMachine)): 12526657Snate@binkert.org mid = machine.ident 12536657Snate@binkert.org if i != 0: 12546657Snate@binkert.org extra = " - " 12556657Snate@binkert.org else: 12566657Snate@binkert.org extra = "" 12576657Snate@binkert.org if machine == self: 12586657Snate@binkert.org code('$extra$mid') 12596657Snate@binkert.org else: 12606657Snate@binkert.org code('$extra<A target="Table" href="${mid}_table.html">$mid</A>') 12616657Snate@binkert.org code.dedent() 12626657Snate@binkert.org 12636657Snate@binkert.org code(""" 12646657Snate@binkert.org</H1> 12656657Snate@binkert.org 12666657Snate@binkert.org<TABLE border=1> 12676657Snate@binkert.org<TR> 12686657Snate@binkert.org <TH> </TH> 12696657Snate@binkert.org""") 12706657Snate@binkert.org 12716657Snate@binkert.org for event in self.events.itervalues(): 12726657Snate@binkert.org href = "%s_Event_%s.html" % (self.ident, event.ident) 12736657Snate@binkert.org ref = self.frameRef(href, "Status", href, "1", event.short) 12746657Snate@binkert.org code('<TH bgcolor=white>$ref</TH>') 12756657Snate@binkert.org 12766657Snate@binkert.org code('</TR>') 12776657Snate@binkert.org # -- Body of table 12786657Snate@binkert.org for state in self.states.itervalues(): 12796657Snate@binkert.org # -- Each row 12806657Snate@binkert.org if state == active_state: 12816657Snate@binkert.org color = "yellow" 12826657Snate@binkert.org else: 12836657Snate@binkert.org color = "white" 12846657Snate@binkert.org 12856657Snate@binkert.org click = "%s_table_%s.html" % (self.ident, state.ident) 12866657Snate@binkert.org over = "%s_State_%s.html" % (self.ident, state.ident) 12876657Snate@binkert.org text = html.formatShorthand(state.short) 12886657Snate@binkert.org ref = self.frameRef(click, "Table", over, "1", state.short) 12896657Snate@binkert.org code(''' 12906657Snate@binkert.org<TR> 12916657Snate@binkert.org <TH bgcolor=$color>$ref</TH> 12926657Snate@binkert.org''') 12936657Snate@binkert.org 12946657Snate@binkert.org # -- One column for each event 12956657Snate@binkert.org for event in self.events.itervalues(): 12966657Snate@binkert.org trans = self.table.get((state,event), None) 12976657Snate@binkert.org if trans is None: 12986657Snate@binkert.org # This is the no transition case 12996657Snate@binkert.org if state == active_state: 13006657Snate@binkert.org color = "#C0C000" 13016657Snate@binkert.org else: 13026657Snate@binkert.org color = "lightgrey" 13036657Snate@binkert.org 13046657Snate@binkert.org code('<TD bgcolor=$color> </TD>') 13056657Snate@binkert.org continue 13066657Snate@binkert.org 13076657Snate@binkert.org next = trans.nextState 13086657Snate@binkert.org stall_action = False 13096657Snate@binkert.org 13106657Snate@binkert.org # -- Get the actions 13116657Snate@binkert.org for action in trans.actions: 13126657Snate@binkert.org if action.ident == "z_stall" or \ 13136657Snate@binkert.org action.ident == "zz_recycleMandatoryQueue": 13146657Snate@binkert.org stall_action = True 13156657Snate@binkert.org 13166657Snate@binkert.org # -- Print out "actions/next-state" 13176657Snate@binkert.org if stall_action: 13186657Snate@binkert.org if state == active_state: 13196657Snate@binkert.org color = "#C0C000" 13206657Snate@binkert.org else: 13216657Snate@binkert.org color = "lightgrey" 13226657Snate@binkert.org 13236657Snate@binkert.org elif active_state and next.ident == active_state.ident: 13246657Snate@binkert.org color = "aqua" 13256657Snate@binkert.org elif state == active_state: 13266657Snate@binkert.org color = "yellow" 13276657Snate@binkert.org else: 13286657Snate@binkert.org color = "white" 13296657Snate@binkert.org 13306657Snate@binkert.org code('<TD bgcolor=$color>') 13316657Snate@binkert.org for action in trans.actions: 13326657Snate@binkert.org href = "%s_action_%s.html" % (self.ident, action.ident) 13336657Snate@binkert.org ref = self.frameRef(href, "Status", href, "1", 13346657Snate@binkert.org action.short) 13357007Snate@binkert.org code(' $ref') 13366657Snate@binkert.org if next != state: 13376657Snate@binkert.org if trans.actions: 13386657Snate@binkert.org code('/') 13396657Snate@binkert.org click = "%s_table_%s.html" % (self.ident, next.ident) 13406657Snate@binkert.org over = "%s_State_%s.html" % (self.ident, next.ident) 13416657Snate@binkert.org ref = self.frameRef(click, "Table", over, "1", next.short) 13426657Snate@binkert.org code("$ref") 13437007Snate@binkert.org code("</TD>") 13446657Snate@binkert.org 13456657Snate@binkert.org # -- Each row 13466657Snate@binkert.org if state == active_state: 13476657Snate@binkert.org color = "yellow" 13486657Snate@binkert.org else: 13496657Snate@binkert.org color = "white" 13506657Snate@binkert.org 13516657Snate@binkert.org click = "%s_table_%s.html" % (self.ident, state.ident) 13526657Snate@binkert.org over = "%s_State_%s.html" % (self.ident, state.ident) 13536657Snate@binkert.org ref = self.frameRef(click, "Table", over, "1", state.short) 13546657Snate@binkert.org code(''' 13556657Snate@binkert.org <TH bgcolor=$color>$ref</TH> 13566657Snate@binkert.org</TR> 13576657Snate@binkert.org''') 13586657Snate@binkert.org code(''' 13597007Snate@binkert.org<!- Column footer-> 13606657Snate@binkert.org<TR> 13616657Snate@binkert.org <TH> </TH> 13626657Snate@binkert.org''') 13636657Snate@binkert.org 13646657Snate@binkert.org for event in self.events.itervalues(): 13656657Snate@binkert.org href = "%s_Event_%s.html" % (self.ident, event.ident) 13666657Snate@binkert.org ref = self.frameRef(href, "Status", href, "1", event.short) 13676657Snate@binkert.org code('<TH bgcolor=white>$ref</TH>') 13686657Snate@binkert.org code(''' 13696657Snate@binkert.org</TR> 13706657Snate@binkert.org</TABLE> 13716657Snate@binkert.org</BODY></HTML> 13726657Snate@binkert.org''') 13736657Snate@binkert.org 13746657Snate@binkert.org 13756657Snate@binkert.org if active_state: 13766657Snate@binkert.org name = "%s_table_%s.html" % (self.ident, active_state.ident) 13776657Snate@binkert.org else: 13786657Snate@binkert.org name = "%s_table.html" % self.ident 13796657Snate@binkert.org code.write(path, name) 13806657Snate@binkert.org 13816657Snate@binkert.org__all__ = [ "StateMachine" ] 1382