StateMachine.py (6863:21fbf0412e0d) | StateMachine.py (6877:2a1a3d916ca8) |
---|---|
1# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 2# Copyright (c) 2009 The Hewlett-Packard Development Company 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions are 7# met: redistributions of source code must retain the above copyright 8# notice, this list of conditions and the following disclaimer; --- 110 unchanged lines hidden (view full) --- 119 if not action.used: 120 error_msg = "Unused action: %s" % action.ident 121 if "desc" in action: 122 error_msg += ", " + action.desc 123 action.warning(error_msg) 124 self.table = table 125 126 def writeCodeFiles(self, path): | 1# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 2# Copyright (c) 2009 The Hewlett-Packard Development Company 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions are 7# met: redistributions of source code must retain the above copyright 8# notice, this list of conditions and the following disclaimer; --- 110 unchanged lines hidden (view full) --- 119 if not action.used: 120 error_msg = "Unused action: %s" % action.ident 121 if "desc" in action: 122 error_msg += ", " + action.desc 123 action.warning(error_msg) 124 self.table = table 125 126 def writeCodeFiles(self, path): |
127 self.printControllerPython(path) |
|
127 self.printControllerHH(path) 128 self.printControllerCC(path) 129 self.printCSwitch(path) 130 self.printCWakeup(path) 131 self.printProfilerCC(path) 132 self.printProfilerHH(path) 133 134 for func in self.functions: 135 func.writeCodeFiles(path) 136 | 128 self.printControllerHH(path) 129 self.printControllerCC(path) 130 self.printCSwitch(path) 131 self.printCWakeup(path) 132 self.printProfilerCC(path) 133 self.printProfilerHH(path) 134 135 for func in self.functions: 136 func.writeCodeFiles(path) 137 |
138 def printControllerPython(self, path): 139 code = code_formatter() 140 ident = self.ident 141 py_ident = "%s_Controller" % ident 142 c_ident = "%s_Controller" % self.ident 143 code(''' 144from m5.params import * 145from m5.SimObject import SimObject 146from Controller import RubyController 147 148class $py_ident(RubyController): 149 type = '$py_ident' 150''') 151 code.indent() 152 for param in self.config_parameters: 153 dflt_str = '' 154 if param.default is not None: 155 dflt_str = str(param.default) + ', ' 156 code('${{param.name}} = Param.Int(${dflt_str}"")') 157 code.dedent() 158 code.write(path, '%s.py' % py_ident) 159 160 |
|
137 def printControllerHH(self, path): 138 '''Output the method declarations for the class declaration''' 139 code = code_formatter() 140 ident = self.ident 141 c_ident = "%s_Controller" % self.ident 142 143 self.message_buffer_names = [] 144 145 code(''' 146/** \\file $ident.hh 147 * 148 * Auto generated C++ code started by $__file__:$__line__ 149 * Created by slicc definition of Module "${{self.short}}" 150 */ 151 152#ifndef ${ident}_CONTROLLER_H 153#define ${ident}_CONTROLLER_H 154 | 161 def printControllerHH(self, path): 162 '''Output the method declarations for the class declaration''' 163 code = code_formatter() 164 ident = self.ident 165 c_ident = "%s_Controller" % self.ident 166 167 self.message_buffer_names = [] 168 169 code(''' 170/** \\file $ident.hh 171 * 172 * Auto generated C++ code started by $__file__:$__line__ 173 * Created by slicc definition of Module "${{self.short}}" 174 */ 175 176#ifndef ${ident}_CONTROLLER_H 177#define ${ident}_CONTROLLER_H 178 |
179#include "params/$c_ident.hh" 180 |
|
155#include "mem/ruby/common/Global.hh" 156#include "mem/ruby/common/Consumer.hh" 157#include "mem/ruby/slicc_interface/AbstractController.hh" 158#include "mem/protocol/TransitionResult.hh" 159#include "mem/protocol/Types.hh" 160#include "mem/protocol/${ident}_Profiler.hh" 161''') 162 --- 6 unchanged lines hidden (view full) --- 169 # for adding information to the protocol debug trace 170 code(''' 171extern stringstream ${ident}_transitionComment; 172 173class $c_ident : public AbstractController { 174#ifdef CHECK_COHERENCE 175#endif /* CHECK_COHERENCE */ 176public: | 181#include "mem/ruby/common/Global.hh" 182#include "mem/ruby/common/Consumer.hh" 183#include "mem/ruby/slicc_interface/AbstractController.hh" 184#include "mem/protocol/TransitionResult.hh" 185#include "mem/protocol/Types.hh" 186#include "mem/protocol/${ident}_Profiler.hh" 187''') 188 --- 6 unchanged lines hidden (view full) --- 195 # for adding information to the protocol debug trace 196 code(''' 197extern stringstream ${ident}_transitionComment; 198 199class $c_ident : public AbstractController { 200#ifdef CHECK_COHERENCE 201#endif /* CHECK_COHERENCE */ 202public: |
177 $c_ident(const string & name); | 203 typedef ${c_ident}Params Params; 204 $c_ident(const Params *p); |
178 static int getNumControllers(); | 205 static int getNumControllers(); |
179 void init(Network* net_ptr, const vector<string> & argv); | 206 void init(); |
180 MessageBuffer* getMandatoryQueue() const; 181 const int & getVersion() const; 182 const string toString() const; 183 const string getName() const; 184 const MachineType getMachineType() const; 185 void print(ostream& out) const; 186 void printConfig(ostream& out) const; 187 void wakeup(); --- 85 unchanged lines hidden (view full) --- 273 # include object classes 274 seen_types = set() 275 for var in self.objects: 276 if var.type.ident not in seen_types and not var.type.isPrimitive: 277 code('#include "mem/protocol/${{var.type.c_ident}}.hh"') 278 seen_types.add(var.type.ident) 279 280 code(''' | 207 MessageBuffer* getMandatoryQueue() const; 208 const int & getVersion() const; 209 const string toString() const; 210 const string getName() const; 211 const MachineType getMachineType() const; 212 void print(ostream& out) const; 213 void printConfig(ostream& out) const; 214 void wakeup(); --- 85 unchanged lines hidden (view full) --- 300 # include object classes 301 seen_types = set() 302 for var in self.objects: 303 if var.type.ident not in seen_types and not var.type.isPrimitive: 304 code('#include "mem/protocol/${{var.type.c_ident}}.hh"') 305 seen_types.add(var.type.ident) 306 307 code(''' |
308$c_ident * 309${c_ident}Params::create() 310{ 311 return new $c_ident(this); 312} 313 314 |
|
281int $c_ident::m_num_controllers = 0; 282 283stringstream ${ident}_transitionComment; 284#define APPEND_TRANSITION_COMMENT(str) (${ident}_transitionComment << str) 285/** \\brief constructor */ | 315int $c_ident::m_num_controllers = 0; 316 317stringstream ${ident}_transitionComment; 318#define APPEND_TRANSITION_COMMENT(str) (${ident}_transitionComment << str) 319/** \\brief constructor */ |
286$c_ident::$c_ident(const string &name) 287 : m_name(name) | 320$c_ident::$c_ident(const Params *p) 321 : AbstractController(p) |
288{ | 322{ |
323 m_version = p->version; 324 m_transitions_per_cycle = p->transitions_per_cycle; 325 m_buffer_size = p->buffer_size; 326 m_recycle_latency = p->recycle_latency; 327 m_number_of_TBEs = p->number_of_TBEs; |
|
289''') 290 code.indent() | 328''') 329 code.indent() |
330 for param in self.config_parameters: 331 code('m_${{param.name}} = p->${{param.name}};') |
|
291 292 code('m_num_controllers++;') 293 for var in self.objects: 294 if var.ident.find("mandatoryQueue") >= 0: 295 code('m_${{var.c_ident}}_ptr = new ${{var.type.c_ident}}();') 296 297 code.dedent() 298 code(''' 299} 300 | 332 333 code('m_num_controllers++;') 334 for var in self.objects: 335 if var.ident.find("mandatoryQueue") >= 0: 336 code('m_${{var.c_ident}}_ptr = new ${{var.type.c_ident}}();') 337 338 code.dedent() 339 code(''' 340} 341 |
301void $c_ident::init(Network *net_ptr, const vector<string> &argv) | 342void $c_ident::init() |
302{ | 343{ |
303 for (size_t i = 0; i < argv.size(); i += 2) { 304 if (argv[i] == "version") 305 m_version = atoi(argv[i+1].c_str()); 306 else if (argv[i] == "transitions_per_cycle") 307 m_transitions_per_cycle = atoi(argv[i+1].c_str()); 308 else if (argv[i] == "buffer_size") 309 m_buffer_size = atoi(argv[i+1].c_str()); 310 else if (argv[i] == "recycle_latency") 311 m_recycle_latency = atoi(argv[i+1].c_str()); 312 else if (argv[i] == "number_of_TBEs") 313 m_number_of_TBEs = atoi(argv[i+1].c_str()); 314''') 315 316 code.indent() 317 code.indent() 318 for param in self.config_parameters: 319 code('else if (argv[i] == "${{param.name}}")') 320 if param.type_ast.type.ident == "int": 321 code(' m_${{param.name}} = atoi(argv[i+1].c_str());') 322 elif param.type_ast.type.ident == "bool": 323 code(' m_${{param.name}} = string_to_bool(argv[i+1]);') 324 else: 325 self.error("only int and bool parameters are "\ 326 "currently supported") 327 code.dedent() 328 code.dedent() 329 code(''' 330 } 331 332 m_net_ptr = net_ptr; | |
333 m_machineID.type = MachineType_${ident}; 334 m_machineID.num = m_version; | 344 m_machineID.type = MachineType_${ident}; 345 m_machineID.num = m_version; |
335 for (size_t i = 0; i < argv.size(); i += 2) { 336 if (argv[i] != "version") 337 m_cfg[argv[i]] = argv[i+1]; 338 } | |
339 340 // Objects 341 s_profiler.setVersion(m_version); 342''') 343 344 code.indent() 345 for var in self.objects: 346 vtype = var.type --- 692 unchanged lines hidden --- | 346 347 // Objects 348 s_profiler.setVersion(m_version); 349''') 350 351 code.indent() 352 for var in self.objects: 353 vtype = var.type --- 692 unchanged lines hidden --- |