# HG changeset patch # User Nathan Binkert <n...@binkert.org> # Date 1250457436 25200 # Node ID df4b8439bf23f13e4f1793d0dd928bec40cae2c4 # Parent a5771f288585269e01b3a7dd3029e8fd5d551764 slicc: Change the code generation so that the generated code is easier to read
diff --git a/src/mem/pyslicc/slicc/ast/PeekStatementAST.py b/src/mem/pyslicc/slicc/ast/PeekStatementAST.py --- a/src/mem/pyslicc/slicc/ast/PeekStatementAST.py +++ b/src/mem/pyslicc/slicc/ast/PeekStatementAST.py @@ -59,9 +59,10 @@ qcode = self.queue_name.var.code code(''' { + // Declare message const $mtid* in_msg_ptr; in_msg_ptr = dynamic_cast<const $mtid *>(($qcode).${{self.method}}()); - assert(in_msg_ptr != NULL); + assert(in_msg_ptr != NULL); // Check the cast result ''') # The other statements diff --git a/src/mem/pyslicc/slicc/generate/html.py b/src/mem/pyslicc/slicc/generate/html.py --- a/src/mem/pyslicc/slicc/generate/html.py +++ b/src/mem/pyslicc/slicc/generate/html.py @@ -29,9 +29,11 @@ def createSymbol(symbol, title): code = code_formatter() - code('''<HTML><BODY><BIG> -$title: -${{formatShorthand(symbol.short)}} - ${{symbol.desc}}</BIG></BODY></HTML>''') + code(''' +<HTML><BODY><BIG> +$title: ${{formatShorthand(symbol.short)}} - ${{symbol.desc}} +</BIG></BODY></HTML> +''') return code def formatShorthand(short): diff --git a/src/mem/pyslicc/slicc/symbols/Func.py b/src/mem/pyslicc/slicc/symbols/Func.py --- a/src/mem/pyslicc/slicc/symbols/Func.py +++ b/src/mem/pyslicc/slicc/symbols/Func.py @@ -97,7 +97,8 @@ params = ', '.join(self.param_strings) code(''' -$return_type ${klass}::${{self.c_ident}}($params) +$return_type +${klass}::${{self.c_ident}}($params) { ${{self.body}} } diff --git a/src/mem/pyslicc/slicc/symbols/StateMachine.py b/src/mem/pyslicc/slicc/symbols/StateMachine.py --- a/src/mem/pyslicc/slicc/symbols/StateMachine.py +++ b/src/mem/pyslicc/slicc/symbols/StateMachine.py @@ -143,14 +143,14 @@ 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 "mem/ruby/common/Global.hh" #include "mem/ruby/common/Consumer.hh" @@ -170,9 +170,14 @@ code(''' extern stringstream ${ident}_transitionComment; -class $c_ident : public AbstractController { +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 + #ifdef CHECK_COHERENCE #endif /* CHECK_COHERENCE */ + public: $c_ident(const string & name); static int getNumControllers(); @@ -187,6 +192,7 @@ void wakeup(); void printStats(ostream& out) const { s_profiler.dumpStats(out); } void clearStats() { s_profiler.clearStats(); } + private: ''') @@ -202,8 +208,15 @@ 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); + string m_name; int m_transitions_per_cycle; int m_buffer_size; @@ -214,6 +227,7 @@ MachineID m_machineID; ${ident}_Profiler s_profiler; static int m_num_controllers; + // Internal functions ''') @@ -233,7 +247,7 @@ # the controller internal variables code(''' -// Object +// Objects ''') for var in self.objects: th = var.get("template_hack", "") @@ -244,7 +258,7 @@ code.dedent() code('};') - code('#endif // ${ident}_CONTROLLER_H') + code('#endif // __${ident}_CONTROLLER_H__') code.write(path, '%s.hh' % c_ident) def printControllerCC(self, path): @@ -255,7 +269,7 @@ 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}}" @@ -280,8 +294,10 @@ code(''' 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 string &name) : m_name(name) @@ -303,7 +319,8 @@ code(''' } -void $c_ident::init(Network *net_ptr, const vector<string> &argv) +void +$c_ident::init(Network *net_ptr, const vector<string> &argv) { for (size_t i = 0; i < argv.size(); i += 2) { if (argv[i] == "version") @@ -312,8 +329,12 @@ m_transitions_per_cycle = atoi(argv[i+1].c_str()); else if (argv[i] == "buffer_size") m_buffer_size = atoi(argv[i+1].c_str()); + // added by SS else if (argv[i] == "recycle_latency") m_recycle_latency = atoi(argv[i+1].c_str()); + // added by SS --> for latency + // for loop on latency_vector to check with argv[i] and assign + // the value to the related m_latency ... else if (argv[i] == "number_of_TBEs") m_number_of_TBEs = atoi(argv[i+1].c_str()); ''') @@ -334,12 +355,14 @@ m_net_ptr = net_ptr; m_machineID.type = MachineType_${ident}; m_machineID.num = m_version; + + // make configuration array for (size_t i = 0; i < argv.size(); i += 2) { if (argv[i] != "version") m_cfg[argv[i]] = argv[i+1]; } - // Objects + // initialize objects s_profiler.setVersion(m_version); ''') @@ -368,18 +391,16 @@ 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: @@ -403,7 +424,9 @@ 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); +MachineType machine_type = string_to_MachineType("${{var.machine.ident}}"); +int base = MachineType_base_number(machine_type); +$vid = m_net_ptr->get${network}NetQueue(m_version + base, $ordered, $vnet); ''') code('assert($vid != NULL);') @@ -476,37 +499,56 @@ 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::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; } // Actions @@ -518,7 +560,8 @@ 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"); ''') @@ -571,16 +614,22 @@ #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; } ''') @@ -616,25 +665,22 @@ if (!servicing_atomic) { if (locked_read_request == Address(-1)) { locked_read_request = addr; + } else if (addr == locked_read_request) { + ; // do nothing + } else { + panic("should never be here if servicing one request at a time") } - else if (addr == locked_read_request) { - ; // do nothing - } - else { - assert(0); // should never be here if servicing one request at a time - } - } - else if (addr != locked_read_request) { + } else if (addr != locked_read_request) { // this is probably caused by shift optimizations locked_read_request = addr; } -} -else { +} else { if (locked_read_request != Address(-1)) { locked_read_request = Address(-1); servicing_atomic = false; } } + if (!postpone) { ''' @@ -659,7 +705,7 @@ if ((((*m_L1Cache_forwardToCache_ptr)).isReady())) { const RequestMsg* in_msg_ptr; in_msg_ptr = dynamic_cast<const RequestMsg*>(((*m_L1Cache_forwardToCache_ptr)).peek()); - if ((servicing_atomic && locked_read_request == ((*in_msg_ptr)).m_Address)) { + if (servicing_atomic && locked_read_request == in_msg_ptr->m_Address) { postpone = true; } } @@ -682,6 +728,8 @@ code(''' break; // If we got this far, we have nothing left todo } + // g_eventQueue_ptr->scheduleEvent(this, 1); + // DEBUG_NEWLINE(GENERATED_COMP, MedPrio); } ''') @@ -709,8 +757,10 @@ #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; @@ -721,24 +771,28 @@ 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), @@ -748,7 +802,8 @@ 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), @@ -759,8 +814,11 @@ 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)) { ''') @@ -786,9 +844,8 @@ 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) @@ -828,9 +885,7 @@ # the same code for trans in transitions: code(' case HASH_FUN($trans):') - code(' {') code(' $case') - code(' }') code(''' default: @@ -854,14 +909,15 @@ // 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 "mem/ruby/common/Global.hh" #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); @@ -877,7 +933,7 @@ int m_version; }; -#endif // ${ident}_PROFILER_H +#endif // __${ident}_PROFILER_HH__ ''') code.write(path, "%s_Profiler.hh" % self.ident) @@ -903,11 +959,15 @@ 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++) { @@ -919,17 +979,22 @@ 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(ostream& out) const + +void +${ident}_Profiler::dumpStats(ostream& out) const { out << " --- ${ident} " << m_version << " ---" << endl; out << " - Event Counts -" << endl; @@ -943,7 +1008,8 @@ 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 << " <-- "; } @@ -959,10 +1025,14 @@ # ************************** # ******* 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 = code_formatter(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): @@ -995,7 +1065,8 @@ code = code_formatter() code(''' -<HTML><BODY link="blue" vlink="blue"> +<HTML> +<BODY link="blue" vlink="blue"> <H1 align="center">${{html.formatShorthand(self.short)}}: ''') @@ -1079,13 +1150,12 @@ 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('/') @@ -1093,8 +1163,7 @@ 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: @@ -1110,6 +1179,7 @@ </TR> ''') code(''' +<!- Column footer-> <TR> <TH> </TH> ''') diff --git a/src/mem/pyslicc/slicc/symbols/SymbolTable.py b/src/mem/pyslicc/slicc/symbols/SymbolTable.py --- a/src/mem/pyslicc/slicc/symbols/SymbolTable.py +++ b/src/mem/pyslicc/slicc/symbols/SymbolTable.py @@ -147,9 +147,12 @@ class Network; class AbstractController; -class ControllerFactory { +class ControllerFactory +{ public: - static AbstractController *createController(const std::string &controller_type, const std::string &name); + static AbstractController * + createController(const std::string &controller_type, + const std::string &name); }; #endif // CONTROLLERFACTORY_H''') code.write(path, "ControllerFactory.hh") @@ -171,7 +174,10 @@ controller_types.append(symbol.ident) code(''' -AbstractController *ControllerFactory::createController(const std::string &controller_type, const std::string &name) { +AbstractController * +ControllerFactory::createController(const std::string &controller_type, + const std::string &name) +{ ''') for ct in controller_types: @@ -181,7 +187,7 @@ ''') code(''' - assert(0); // invalid controller type + panic("invalid controller type"); return NULL; } ''') diff --git a/src/mem/pyslicc/slicc/symbols/Type.py b/src/mem/pyslicc/slicc/symbols/Type.py --- a/src/mem/pyslicc/slicc/symbols/Type.py +++ b/src/mem/pyslicc/slicc/symbols/Type.py @@ -195,8 +195,8 @@ * 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 "mem/ruby/common/Global.hh" #include "mem/gems_common/Allocator.hh" @@ -212,17 +212,14 @@ 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(): @@ -239,9 +236,6 @@ code.dedent() code('}') - # ******** Default destructor ******** - code('~${{self.c_ident}}() { };') - # ******** Full init constructor ******** if not self.isGlobal: params = ', '.join('const %s& local_%s' % \ @@ -265,7 +259,9 @@ # create a static factory method if "interface" in self: code(''' -static ${{self["interface"]}}* create() { +static ${{self["interface"]}}* +create() +{ return new ${{self.c_ident}}(); } ''') @@ -276,10 +272,29 @@ 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: @@ -290,7 +305,11 @@ /** \\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 @@ -300,7 +319,11 @@ /** \\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 @@ -308,7 +331,11 @@ 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(ostream& out) const;') @@ -332,28 +359,28 @@ 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;') code.dedent() code('};') code(''' // Output operator declaration -ostream& operator<<(ostream& out, const ${{self.c_ident}}& obj); +ostream& +operator<<(ostream& out, const ${{self.c_ident}}& obj); // Output operator definition -extern inline -ostream& operator<<(ostream& out, const ${{self.c_ident}}& obj) +extern inline ostream& +operator<<(ostream& out, const ${{self.c_ident}}& obj) { obj.print(out); out << flush; return out; } -#endif // ${{self.c_ident}}_H +#endif // __${{self.c_ident}}_HH__ ''') code.write(path, "%s.hh" % self.c_ident) @@ -374,7 +401,8 @@ 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}}: "; ''') @@ -402,11 +430,13 @@ * * 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 "mem/ruby/common/Global.hh" +// Class definition /** \\enum ${{self.c_ident}} * \\brief ${{self.desc}} */ @@ -425,8 +455,14 @@ code(''' ${{self.c_ident}}_NUM }; + +// Code to convert from a string to the enumeration ${{self.c_ident}} string_to_${{self.c_ident}}(const string& str); + +// Code to convert state to a string 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); ''') @@ -446,7 +482,7 @@ code(''' ostream& operator<<(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) @@ -469,14 +505,18 @@ 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) { ''') @@ -496,17 +536,19 @@ } } -${{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(''' @@ -516,7 +558,10 @@ } } -${{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); } @@ -526,12 +571,14 @@ # 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) { ''') @@ -556,9 +603,10 @@ /** \\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) { ''') @@ -583,7 +631,8 @@ * * \\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) { @@ -608,7 +657,8 @@ /** \\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) { ''') _______________________________________________ m5-dev mailing list m5-dev@m5sim.org http://m5sim.org/mailman/listinfo/m5-dev