self.message_buffer_names = []
code('''
-/** \\file $ident.hh
+/** \\file $c_ident.hh
*
* Auto generated C++ code started by $__file__:$__line__
* Created by slicc definition of Module "${{self.short}}"
*/
-#ifndef ${ident}_CONTROLLER_H
-#define ${ident}_CONTROLLER_H
+#ifndef __${ident}_CONTROLLER_HH__
+#define __${ident}_CONTROLLER_HH__
#include <iostream>
#include <sstream>
code('''
extern std::stringstream ${ident}_transitionComment;
-class $c_ident : public AbstractController {
-#ifdef CHECK_COHERENCE
-#endif /* CHECK_COHERENCE */
+class $c_ident : public AbstractController
+{
+// the coherence checker needs to call isBlockExclusive() and isBlockShared()
+// making the Chip a friend class is an easy way to do this for now
+
public:
typedef ${c_ident}Params Params;
$c_ident(const Params *p);
void clearStats();
void blockOnQueue(Address addr, MessageBuffer* port);
void unblock(Address addr);
+
private:
''')
code('''
int m_number_of_TBEs;
-TransitionResult doTransition(${ident}_Event event, ${ident}_State state, const Address& addr); // in ${ident}_Transitions.cc
-TransitionResult doTransitionWorker(${ident}_Event event, ${ident}_State state, ${ident}_State& next_state, const Address& addr); // in ${ident}_Transitions.cc
+TransitionResult doTransition(${ident}_Event event,
+ ${ident}_State state,
+ const Address& addr);
+
+TransitionResult doTransitionWorker(${ident}_Event event,
+ ${ident}_State state,
+ ${ident}_State& next_state,
+ const Address& addr);
+
std::string m_name;
int m_transitions_per_cycle;
int m_buffer_size;
map< Address, MessageBuffer* > m_block_map;
${ident}_Profiler s_profiler;
static int m_num_controllers;
+
// Internal functions
''')
# the controller internal variables
code('''
-// Object
+// Objects
''')
for var in self.objects:
th = var.get("template_hack", "")
code.dedent()
code('};')
- code('#endif // ${ident}_CONTROLLER_H')
+ code('#endif // __${ident}_CONTROLLER_H__')
code.write(path, '%s.hh' % c_ident)
def printControllerCC(self, path):
c_ident = "%s_Controller" % self.ident
code('''
-/** \\file $ident.cc
+/** \\file $c_ident.cc
*
* Auto generated C++ code started by $__file__:$__line__
* Created by slicc definition of Module "${{self.short}}"
return new $c_ident(this);
}
-
int $c_ident::m_num_controllers = 0;
+// for adding information to the protocol debug trace
stringstream ${ident}_transitionComment;
#define APPEND_TRANSITION_COMMENT(str) (${ident}_transitionComment << str)
+
/** \\brief constructor */
$c_ident::$c_ident(const Params *p)
: AbstractController(p)
code('''
}
-void $c_ident::init()
+void
+$c_ident::init()
{
+ MachineType machine_type;
+ int base;
+
m_machineID.type = MachineType_${ident};
m_machineID.num = m_version;
- // Objects
+ // initialize objects
s_profiler.setVersion(m_version);
+
''')
code.indent()
args = "m_number_of_TBEs"
else:
args = var.get("constructor_hack", "")
- args = "(%s)" % args
- code('$expr$args;')
- else:
- code(';')
+ code('$expr($args);')
code('assert($vid != NULL);')
if "default" in var:
- code('(*$vid) = ${{var["default"]}}; // Object default')
+ code('*$vid = ${{var["default"]}}; // Object default')
elif "default" in vtype:
- code('(*$vid) = ${{vtype["default"]}}; // Type ${{vtype.ident}} default')
+ comment = "Type %s default" % vtype.ident
+ code('*$vid = ${{vtype["default"]}}; // $comment')
# Set ordering
if "ordered" in var and "trigger_queue" not in var:
assert var.machine is not None
code('''
-$vid = m_net_ptr->get${network}NetQueue(m_version+MachineType_base_number(string_to_MachineType("${{var.machine.ident}}")), $ordered, $vnet);
+machine_type = string_to_MachineType("${{var.machine.ident}}");
+base = MachineType_base_number(machine_type);
+$vid = m_net_ptr->get${network}NetQueue(m_version + base, $ordered, $vnet);
''')
code('assert($vid != NULL);')
''')
# set description (may be overriden later by port def)
- code('$vid->setDescription("[Version " + int_to_string(m_version) + ", ${ident}, name=${{var.c_ident}}]");')
+ code('''
+$vid->setDescription("[Version " + int_to_string(m_version) + ", ${ident}, name=${{var.c_ident}}]");
+
+''')
# Set the queue consumers
code.insert_newline()
mq_ident = "NULL"
code('''
-int $c_ident::getNumControllers() {
+int
+$c_ident::getNumControllers()
+{
return m_num_controllers;
}
-MessageBuffer* $c_ident::getMandatoryQueue() const {
+MessageBuffer*
+$c_ident::getMandatoryQueue() const
+{
return $mq_ident;
}
-const int & $c_ident::getVersion() const{
+const int &
+$c_ident::getVersion() const
+{
return m_version;
}
-const string $c_ident::toString() const{
+const string
+$c_ident::toString() const
+{
return "$c_ident";
}
-const string $c_ident::getName() const{
+const string
+$c_ident::getName() const
+{
return m_name;
}
-const MachineType $c_ident::getMachineType() const{
+
+const MachineType
+$c_ident::getMachineType() const
+{
return MachineType_${ident};
}
-void $c_ident::blockOnQueue(Address addr, MessageBuffer* port) {
+void
+$c_ident::blockOnQueue(Address addr, MessageBuffer* port)
+{
m_is_blocking = true;
m_block_map[addr] = port;
}
-void $c_ident::unblock(Address addr) {
+
+void
+$c_ident::unblock(Address addr)
+{
m_block_map.erase(addr);
if (m_block_map.size() == 0) {
m_is_blocking = false;
}
}
-void $c_ident::print(ostream& out) const { out << "[$c_ident " << m_version << "]"; }
+void
+$c_ident::print(ostream& out) const
+{
+ out << "[$c_ident " << m_version << "]";
+}
-void $c_ident::printConfig(ostream& out) const {
+void
+$c_ident::printConfig(ostream& out) const
+{
out << "$c_ident config: " << m_name << endl;
out << " version: " << m_version << endl;
- for (map<string, string>::const_iterator it = m_cfg.begin(); it != m_cfg.end(); it++) {
- out << " " << (*it).first << ": " << (*it).second << endl;
- }
+ map<string, string>::const_iterator it;
+ for (it = m_cfg.begin(); it != m_cfg.end(); it++)
+ out << " " << it->first << ": " << it->second << endl;
}
-void $c_ident::printStats(ostream& out) const {
+void
+$c_ident::printStats(ostream& out) const
+{
''')
#
# Cache and Memory Controllers have specific profilers associated with
code('''
/** \\brief ${{action.desc}} */
-void $c_ident::${{action.ident}}(const Address& addr)
+void
+$c_ident::${{action.ident}}(const Address& addr)
{
DEBUG_MSG(GENERATED_COMP, HighPrio, "executing");
${{action["c_code"]}}
// Auto generated C++ code started by $__file__:$__line__
// ${ident}: ${{self.short}}
+#include "base/misc.hh"
#include "mem/ruby/common/Global.hh"
#include "mem/ruby/slicc_interface/RubySlicc_includes.hh"
#include "mem/protocol/${ident}_Controller.hh"
#include "mem/protocol/Types.hh"
#include "mem/ruby/system/System.hh"
-void ${ident}_Controller::wakeup()
+void
+${ident}_Controller::wakeup()
{
+ // DEBUG_EXPR(GENERATED_COMP, MedPrio, *this);
+ // DEBUG_EXPR(GENERATED_COMP, MedPrio, g_eventQueue_ptr->getTime());
int counter = 0;
while (true) {
// Some cases will put us into an infinite loop without this limit
assert(counter <= m_transitions_per_cycle);
if (counter == m_transitions_per_cycle) {
- g_system_ptr->getProfiler()->controllerBusy(m_machineID); // Count how often we\'re fully utilized
- g_eventQueue_ptr->scheduleEvent(this, 1); // Wakeup in another cycle and try again
+ // Count how often we are fully utilized
+ g_system_ptr->getProfiler()->controllerBusy(m_machineID);
+
+ // Wakeup in another cycle and try again
+ g_eventQueue_ptr->scheduleEvent(this, 1);
break;
}
''')
code('''
break; // If we got this far, we have nothing left todo
}
+ // g_eventQueue_ptr->scheduleEvent(this, 1);
+ // DEBUG_NEWLINE(GENERATED_COMP, MedPrio);
}
''')
#define GET_TRANSITION_COMMENT() (${ident}_transitionComment.str())
#define CLEAR_TRANSITION_COMMENT() (${ident}_transitionComment.str(""))
-TransitionResult ${ident}_Controller::doTransition(${ident}_Event event, ${ident}_State state, const Address& addr
-)
+TransitionResult
+${ident}_Controller::doTransition(${ident}_Event event,
+ ${ident}_State state,
+ const Address &addr)
{
${ident}_State next_state = state;
DEBUG_EXPR(GENERATED_COMP, MedPrio,event);
DEBUG_EXPR(GENERATED_COMP, MedPrio,addr);
- TransitionResult result = doTransitionWorker(event, state, next_state, addr);
+ TransitionResult result =
+ doTransitionWorker(event, state, next_state, addr);
if (result == TransitionResult_Valid) {
DEBUG_EXPR(GENERATED_COMP, MedPrio, next_state);
DEBUG_NEWLINE(GENERATED_COMP, MedPrio);
s_profiler.countTransition(state, event);
if (Debug::getProtocolTrace()) {
- g_system_ptr->getProfiler()->profileTransition("${ident}", m_version, addr,
+ g_system_ptr->getProfiler()->profileTransition("${ident}",
+ m_version, addr,
${ident}_State_to_string(state),
${ident}_Event_to_string(event),
- ${ident}_State_to_string(next_state), GET_TRANSITION_COMMENT());
+ ${ident}_State_to_string(next_state),
+ GET_TRANSITION_COMMENT());
}
CLEAR_TRANSITION_COMMENT();
${ident}_setState(addr, next_state);
} else if (result == TransitionResult_ResourceStall) {
if (Debug::getProtocolTrace()) {
- g_system_ptr->getProfiler()->profileTransition("${ident}", m_version, addr,
+ g_system_ptr->getProfiler()->profileTransition("${ident}",
+ m_version, addr,
${ident}_State_to_string(state),
${ident}_Event_to_string(event),
${ident}_State_to_string(next_state),
DEBUG_MSG(GENERATED_COMP, HighPrio, "stalling");
DEBUG_NEWLINE(GENERATED_COMP, MedPrio);
if (Debug::getProtocolTrace()) {
- g_system_ptr->getProfiler()->profileTransition("${ident}", m_version, addr,
+ g_system_ptr->getProfiler()->profileTransition("${ident}",
+ m_version, addr,
${ident}_State_to_string(state),
${ident}_Event_to_string(event),
${ident}_State_to_string(next_state),
return result;
}
-TransitionResult ${ident}_Controller::doTransitionWorker(${ident}_Event event, ${ident}_State state, ${ident}_State& next_state, const Address& addr
-)
+TransitionResult
+${ident}_Controller::doTransitionWorker(${ident}_Event event,
+ ${ident}_State state,
+ ${ident}_State& next_state,
+ const Address& addr)
{
switch(HASH_FUN(state, event)) {
''')
for key,val in res.iteritems():
if key.type.ident != "DNUCAStopTable":
val = '''
-if (!%s.areNSlotsAvailable(%s)) {
+if (!%s.areNSlotsAvailable(%s))
return TransitionResult_ResourceStall;
-}
''' % (key.code, val)
case_sorter.append(val)
# the same code
for trans in transitions:
code(' case HASH_FUN($trans):')
- code(' {')
code(' $case')
- code(' }')
code('''
default:
// Auto generated C++ code started by $__file__:$__line__
// ${ident}: ${{self.short}}
-#ifndef ${ident}_PROFILER_H
-#define ${ident}_PROFILER_H
+#ifndef __${ident}_PROFILER_HH_
+#define __${ident}_PROFILER_HH_
#include <iostream>
#include "mem/protocol/${ident}_State.hh"
#include "mem/protocol/${ident}_Event.hh"
-class ${ident}_Profiler {
+class ${ident}_Profiler
+{
public:
${ident}_Profiler();
void setVersion(int version);
int m_version;
};
-#endif // ${ident}_PROFILER_H
+#endif // __${ident}_PROFILER_HH__
''')
code.write(path, "%s_Profiler.hh" % self.ident)
m_event_counters[event] = 0;
}
}
-void ${ident}_Profiler::setVersion(int version)
+
+void
+${ident}_Profiler::setVersion(int version)
{
m_version = version;
}
-void ${ident}_Profiler::clearStats()
+
+void
+${ident}_Profiler::clearStats()
{
for (int state = 0; state < ${ident}_State_NUM; state++) {
for (int event = 0; event < ${ident}_Event_NUM; event++) {
m_event_counters[event] = 0;
}
}
-void ${ident}_Profiler::countTransition(${ident}_State state, ${ident}_Event event)
+void
+${ident}_Profiler::countTransition(${ident}_State state, ${ident}_Event event)
{
assert(m_possible[state][event]);
m_counters[state][event]++;
m_event_counters[event]++;
}
-void ${ident}_Profiler::possibleTransition(${ident}_State state, ${ident}_Event event)
+void
+${ident}_Profiler::possibleTransition(${ident}_State state,
+ ${ident}_Event event)
{
m_possible[state][event] = true;
}
-void ${ident}_Profiler::dumpStats(std::ostream& out) const
+
+void
+${ident}_Profiler::dumpStats(std::ostream& out) const
{
using namespace std;
for (int event = 0; event < ${ident}_Event_NUM; event++) {
if (m_possible[state][event]) {
int count = m_counters[state][event];
- out << (${ident}_State) state << " " << (${ident}_Event) event << " " << count;
+ out << (${ident}_State) state << " "
+ << (${ident}_Event) event << " " << count;
if (count == 0) {
out << " <-- ";
}
# **************************
# ******* HTML Files *******
# **************************
- def frameRef(self, click_href, click_target, over_href, over_target_num,
- text):
+ def frameRef(self, click_href, click_target, over_href, over_num, text):
code = self.symtab.codeFormatter(fix_newlines=False)
- code("""<A href=\"$click_href\" target=\"$click_target\" onMouseOver=\"if (parent.frames[$over_target_num].location != parent.location + '$over_href') { parent.frames[$over_target_num].location='$over_href' }\" >${{html.formatShorthand(text)}}</A>""")
+ code("""<A href=\"$click_href\" target=\"$click_target\" onmouseover=\"
+ if (parent.frames[$over_num].location != parent.location + '$over_href') {
+ parent.frames[$over_num].location='$over_href'
+ }\">
+ ${{html.formatShorthand(text)}}
+ </A>""")
return str(code)
def writeHTMLFiles(self, path):
code = self.symtab.codeFormatter()
code('''
-<HTML><BODY link="blue" vlink="blue">
+<HTML>
+<BODY link="blue" vlink="blue">
<H1 align="center">${{html.formatShorthand(self.short)}}:
''')
else:
color = "white"
- fix = code.nofix()
code('<TD bgcolor=$color>')
for action in trans.actions:
href = "%s_action_%s.html" % (self.ident, action.ident)
ref = self.frameRef(href, "Status", href, "1",
action.short)
- code(' $ref\n')
+ code(' $ref')
if next != state:
if trans.actions:
code('/')
over = "%s_State_%s.html" % (self.ident, next.ident)
ref = self.frameRef(click, "Table", over, "1", next.short)
code("$ref")
- code("</TD>\n")
- code.fix(fix)
+ code("</TD>")
# -- Each row
if state == active_state:
</TR>
''')
code('''
+<!- Column footer->
<TR>
<TH> </TH>
''')
* Auto generated C++ code started by $__file__:$__line__
*/
-#ifndef ${{self.c_ident}}_H
-#define ${{self.c_ident}}_H
+#ifndef __${{self.c_ident}}_HH__
+#define __${{self.c_ident}}_HH__
#include <iostream>
parent = " : public %s" % self["interface"]
code('''
-$klass ${{self.c_ident}}$parent {
+$klass ${{self.c_ident}}$parent
+{
public:
${{self.c_ident}}()
+ {
''', klass="class")
- # Call superclass constructor
- if "interface" in self:
- code(' : ${{self["interface"]}}()')
-
code.indent()
- code("{")
if not self.isGlobal:
code.indent()
for dm in self.data_members.values():
code.dedent()
code('}')
- # ******** Default destructor ********
- code('~${{self.c_ident}}() { };')
-
# ******** Full init constructor ********
if not self.isGlobal:
params = [ 'const %s& local_%s' % (dm.type.c_ident, dm.ident) \
# create a static factory method
if "interface" in self:
code('''
-static ${{self["interface"]}}* create() {
+static ${{self["interface"]}}*
+create()
+{
return new ${{self.c_ident}}();
}
''')
if self.isMessage:
code('''
-Message* clone() const { checkAllocator(); return s_allocator_ptr->allocate(*this); }
-void destroy() { checkAllocator(); s_allocator_ptr->deallocate(this); }
+Message *
+clone() const
+{
+ checkAllocator();
+ return s_allocator_ptr->allocate(*this);
+}
+
+void
+destroy()
+{
+ checkAllocator();
+ s_allocator_ptr->deallocate(this);
+}
+
static Allocator<${{self.c_ident}}>* s_allocator_ptr;
-static void checkAllocator() { if (s_allocator_ptr == NULL) { s_allocator_ptr = new Allocator<${{self.c_ident}}>; }}
+
+static void
+checkAllocator()
+{
+ if (s_allocator_ptr == NULL) {
+ s_allocator_ptr = new Allocator<${{self.c_ident}}>;
+ }
+}
''')
if not self.isGlobal:
/** \\brief Const accessor method for ${{dm.ident}} field.
* \\return ${{dm.ident}} field
*/
-const ${{dm.type.c_ident}}& get${{dm.ident}}() const { return m_${{dm.ident}}; }
+const ${{dm.type.c_ident}}&
+get${{dm.ident}}() const
+{
+ return m_${{dm.ident}};
+}
''')
# Non-const Get methods for each field
/** \\brief Non-const accessor method for ${{dm.ident}} field.
* \\return ${{dm.ident}} field
*/
-${{dm.type.c_ident}}& get${{dm.ident}}() { return m_${{dm.ident}}; }
+${{dm.type.c_ident}}&
+get${{dm.ident}}()
+{
+ return m_${{dm.ident}};
+}
''')
#Set methods for each field
for dm in self.data_members.values():
code('''
/** \\brief Mutator method for ${{dm.ident}} field */
-void set${{dm.ident}}(const ${{dm.type.c_ident}}& local_${{dm.ident}}) { m_${{dm.ident}} = local_${{dm.ident}}; }
+void
+set${{dm.ident}}(const ${{dm.type.c_ident}}& local_${{dm.ident}})
+{
+ m_${{dm.ident}} = local_${{dm.ident}};
+}
''')
code('void print(std::ostream& out) const;')
assert self.isGlobal
init = " = %s" % (dm.init_code)
- desc = ""
if "desc" in dm:
- desc = '/**< %s */' % dm["desc"]
+ code('/** ${{dm["desc"]}} */')
- code('$const${{dm.type.c_ident}} m_${{dm.ident}}$init; $desc')
+ code('$const${{dm.type.c_ident}} m_${{dm.ident}}$init;')
if self.isMessage:
code('unsigned proc_id;')
code('''
// Output operator declaration
-std::ostream& operator<<(std::ostream& out, const ${{self.c_ident}}& obj);
+std::ostream&
+operator<<(std::ostream& out, const ${{self.c_ident}}& obj);
// Output operator definition
-extern inline
-std::ostream& operator<<(std::ostream& out, const ${{self.c_ident}}& obj)
+extern inline std::ostream&
+operator<<(std::ostream& out, const ${{self.c_ident}}& obj)
{
obj.print(out);
out << std::flush;
return out;
}
-#endif // ${{self.c_ident}}_H
+#endif // __${{self.c_ident}}_HH__
''')
code.write(path, "%s.hh" % self.c_ident)
code('Allocator<${{self.c_ident}}>* ${{self.c_ident}}::s_allocator_ptr = NULL;')
code('''
/** \\brief Print the state of this object */
-void ${{self.c_ident}}::print(ostream& out) const
+void
+${{self.c_ident}}::print(ostream& out) const
{
out << "[${{self.c_ident}}: ";
''')
*
* Auto generated C++ code started by $__file__:$__line__
*/
-#ifndef ${{self.c_ident}}_H
-#define ${{self.c_ident}}_H
+
+#ifndef __${{self.c_ident}}_HH__
+#define __${{self.c_ident}}_HH__
#include <iostream>
#include <string>
#include "mem/ruby/common/Global.hh"
+// Class definition
/** \\enum ${{self.c_ident}}
* \\brief ${{self.desc}}
*/
code('''
${{self.c_ident}}_NUM
};
+
+// Code to convert from a string to the enumeration
${{self.c_ident}} string_to_${{self.c_ident}}(const std::string& str);
+
+// Code to convert state to a string
std::string ${{self.c_ident}}_to_string(const ${{self.c_ident}}& obj);
+
+// Code to increment an enumeration type
${{self.c_ident}} &operator++(${{self.c_ident}} &e);
''')
code('''
std::ostream& operator<<(std::ostream& out, const ${{self.c_ident}}& obj);
-#endif // ${{self.c_ident}}_H
+#endif // __${{self.c_ident}}_HH__
''')
code.write(path, "%s.hh" % self.c_ident)
code('#include "mem/protocol/${{enum.ident}}_Controller.hh"')
code('''
-ostream& operator<<(ostream& out, const ${{self.c_ident}}& obj)
+// Code for output operator
+ostream&
+operator<<(ostream& out, const ${{self.c_ident}}& obj)
{
out << ${{self.c_ident}}_to_string(obj);
out << flush;
return out;
}
-string ${{self.c_ident}}_to_string(const ${{self.c_ident}}& obj)
+// Code to convert state to a string
+string
+${{self.c_ident}}_to_string(const ${{self.c_ident}}& obj)
{
switch(obj) {
''')
}
}
-${{self.c_ident}} string_to_${{self.c_ident}}(const string& str)
+// Code to convert from a string to the enumeration
+${{self.c_ident}}
+string_to_${{self.c_ident}}(const string& str)
{
''')
# For each field
+ start = ""
code.indent()
- code("if (false) {")
- start = "} else "
for enum in self.enums.itervalues():
code('${start}if (str == "${{enum.ident}}") {')
code(' return ${{self.c_ident}}_${{enum.ident}};')
+ start = "} else "
code.dedent()
code('''
}
}
-${{self.c_ident}}& operator++(${{self.c_ident}}& e) {
+// Code to increment an enumeration type
+${{self.c_ident}}&
+operator++(${{self.c_ident}}& e)
+{
assert(e < ${{self.c_ident}}_NUM);
return e = ${{self.c_ident}}(e+1);
}
# components for each Machine
if self.isMachineType:
code('''
-/** \\brief returns the base vector index for each machine type to be used by NetDest
+/** \\brief returns the base vector index for each machine type to be
+ * used by NetDest
*
* \\return the base vector index for each machine type to be used by NetDest
* \\see NetDest.hh
*/
-int ${{self.c_ident}}_base_level(const ${{self.c_ident}}& obj)
+int
+${{self.c_ident}}_base_level(const ${{self.c_ident}}& obj)
{
switch(obj) {
''')
/** \\brief returns the machine type for each base vector index used by NetDest
*
- * \\return the MachineTYpe
+ * \\return the MachineType
*/
-MachineType ${{self.c_ident}}_from_base_level(int type)
+MachineType
+${{self.c_ident}}_from_base_level(int type)
{
switch(type) {
''')
*
* \\return the base number of components for each machine
*/
-int ${{self.c_ident}}_base_number(const ${{self.c_ident}}& obj)
+int
+${{self.c_ident}}_base_number(const ${{self.c_ident}}& obj)
{
int base = 0;
switch(obj) {
/** \\brief returns the total number of components for each machine
* \\return the total number of components for each machine
*/
-int ${{self.c_ident}}_base_count(const ${{self.c_ident}}& obj)
+int
+${{self.c_ident}}_base_count(const ${{self.c_ident}}& obj)
{
switch(obj) {
''')