Deleted Added
sdiff udiff text old ( 10308:8c0870dbae5c ) new ( 10311:ad9c042dce54 )
full compact
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;

--- 37 unchanged lines hidden (view full) ---

46 "Prefetcher":"Prefetcher",
47 "Cycles":"Cycles",
48 }
49
50class StateMachine(Symbol):
51 def __init__(self, symtab, ident, location, pairs, config_parameters):
52 super(StateMachine, self).__init__(symtab, ident, location, pairs)
53 self.table = None
54 self.config_parameters = config_parameters
55 self.prefetchers = []
56
57 for param in config_parameters:
58 if param.pointer:
59 var = Var(symtab, param.ident, location, param.type_ast.type,
60 "(*m_%s_ptr)" % param.ident, {}, self)
61 else:
62 var = Var(symtab, param.ident, location, param.type_ast.type,

--- 6 unchanged lines hidden (view full) ---

69
70 self.states = orderdict()
71 self.events = orderdict()
72 self.actions = orderdict()
73 self.request_types = orderdict()
74 self.transitions = []
75 self.in_ports = []
76 self.functions = []
77 self.objects = []
78 self.TBEType = None
79 self.EntryType = None
80
81 def __repr__(self):
82 return "[StateMachine: %s]" % self.ident
83
84 def addState(self, state):

--- 110 unchanged lines hidden (view full) ---

195''')
196 code.indent()
197 for param in self.config_parameters:
198 dflt_str = ''
199
200 if param.rvalue is not None:
201 dflt_str = str(param.rvalue.inline()) + ', '
202
203 if python_class_map.has_key(param.type_ast.type.c_ident):
204 python_type = python_class_map[param.type_ast.type.c_ident]
205 code('${{param.ident}} = Param.${{python_type}}(${dflt_str}"")')
206
207 else:
208 self.error("Unknown c++ to python class conversion for c++ " \
209 "type: '%s'. Please update the python_class_map " \
210 "in StateMachine.py", param.type_ast.type.c_ident)
211 code.dedent()

--- 24 unchanged lines hidden (view full) ---

236#include "mem/protocol/Types.hh"
237#include "mem/ruby/common/Consumer.hh"
238#include "mem/ruby/common/Global.hh"
239#include "mem/ruby/slicc_interface/AbstractController.hh"
240#include "params/$c_ident.hh"
241''')
242
243 seen_types = set()
244 has_peer = False
245 for var in self.objects:
246 if var.type.ident not in seen_types and not var.type.isPrimitive:
247 code('#include "mem/protocol/${{var.type.c_ident}}.hh"')
248 if "network" in var and "physical_network" in var:
249 has_peer = True
250 seen_types.add(var.type.ident)
251
252 # for adding information to the protocol debug trace
253 code('''
254extern std::stringstream ${ident}_transitionComment;
255
256class $c_ident : public AbstractController
257{
258 public:
259 typedef ${c_ident}Params Params;
260 $c_ident(const Params *p);
261 static int getNumControllers();
262 void init();
263 MessageBuffer* getMandatoryQueue() const;
264
265 void print(std::ostream& out) const;
266 void wakeup();
267 void resetStats();
268 void regStats();
269 void collateStats();
270
271 void recordCacheTrace(int cntrl, CacheRecorder* tr);

--- 63 unchanged lines hidden (view full) ---

335// Internal functions
336''')
337
338 for func in self.functions:
339 proto = func.prototype
340 if proto:
341 code('$proto')
342
343 if has_peer:
344 code('void getQueuesFromPeer(AbstractController *);')
345 if self.EntryType != None:
346 code('''
347
348// Set and Reset for cache_entry variable
349void set_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, AbstractCacheEntry* m_new_cache_entry);
350void unset_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr);
351''')
352

--- 46 unchanged lines hidden (view full) ---

399 code.write(path, '%s.hh' % c_ident)
400
401 def printControllerCC(self, path, includes):
402 '''Output the actions for performing the actions'''
403
404 code = self.symtab.codeFormatter()
405 ident = self.ident
406 c_ident = "%s_Controller" % self.ident
407 has_peer = False
408
409 code('''
410/** \\file $c_ident.cc
411 *
412 * Auto generated C++ code started by $__file__:$__line__
413 * Created by slicc definition of Module "${{self.short}}"
414 */
415

--- 65 unchanged lines hidden (view full) ---

481 code.indent()
482
483 #
484 # After initializing the universal machine parameters, initialize the
485 # this machines config parameters. Also if these configuration params
486 # include a sequencer, connect the it to the controller.
487 #
488 for param in self.config_parameters:
489 if param.pointer:
490 code('m_${{param.ident}}_ptr = p->${{param.ident}};')
491 else:
492 code('m_${{param.ident}} = p->${{param.ident}};')
493 if re.compile("sequencer").search(param.ident):
494 code('m_${{param.ident}}_ptr->setController(this);')
495
496 for var in self.objects:
497 if var.ident.find("mandatoryQueue") >= 0:
498 code('''
499m_${{var.ident}}_ptr = new ${{var.type.c_ident}}();
500m_${{var.ident}}_ptr->setReceiver(this);
501''')
502 else:
503 if "network" in var and "physical_network" in var and \
504 var["network"] == "To":
505 has_peer = True
506 code('''
507m_${{var.ident}}_ptr = new ${{var.type.c_ident}}();
508peerQueueMap[${{var["physical_network"]}}] = m_${{var.ident}}_ptr;
509m_${{var.ident}}_ptr->setSender(this);
510''')
511
512 code('''
513if (p->peer != NULL)
514 connectWithPeer(p->peer);
515
516for (int state = 0; state < ${ident}_State_NUM; state++) {
517 for (int event = 0; event < ${ident}_Event_NUM; event++) {
518 m_possible[state][event] = false;
519 m_counters[state][event] = 0;
520 }
521}
522for (int event = 0; event < ${ident}_Event_NUM; event++) {
523 m_event_counters[event] = 0;
524}
525''')
526 code.dedent()
527 code('''
528}
529
530void
531$c_ident::init()
532{
533 MachineType machine_type = string_to_MachineType("${{var.machine.ident}}");
534 int base M5_VAR_USED = MachineType_base_number(machine_type);
535
536 // initialize objects
537
538''')
539
540 code.indent()
541 for var in self.objects:
542 vtype = var.type
543 vid = "m_%s_ptr" % var.ident
544 if "network" not in var:
545 # Not a network port object
546 if "primitive" in vtype:
547 code('$vid = new ${{vtype.c_ident}};')
548 if "default" in var:

--- 35 unchanged lines hidden (view full) ---

584 code('$vid->setSender(this);')
585 code('$vid->setReceiver(this);')
586 elif vtype.c_ident == "TimerTable":
587 code('$vid->setClockObj(this);')
588 elif var.ident.find("optionalQueue") >= 0:
589 code('$vid->setSender(this);')
590 code('$vid->setReceiver(this);')
591
592 else:
593 # Network port object
594 network = var["network"]
595 ordered = var["ordered"]
596
597 if "virtual_network" in var:
598 vnet = var["virtual_network"]
599 vnet_type = var["vnet_type"]
600
601 assert var.machine is not None
602 code('''
603$vid = m_net_ptr->get${network}NetQueue(m_version + base, $ordered, $vnet, "$vnet_type");
604assert($vid != NULL);
605''')
606
607 # Set the end
608 if network == "To":
609 code('$vid->setSender(this);')
610 else:
611 code('$vid->setReceiver(this);')
612
613 # Set ordering
614 if "ordered" in var:
615 # A buffer
616 code('$vid->setOrdering(${{var["ordered"]}});')
617
618 # Set randomization
619 if "random" in var:
620 # A buffer
621 code('$vid->setRandomization(${{var["random"]}});')
622
623 # Set Priority
624 if "rank" in var:
625 code('$vid->setPriority(${{var["rank"]}})')
626
627 # Set buffer size
628 if vtype.isBuffer:
629 code('''
630if (m_buffer_size > 0) {
631 $vid->resize(m_buffer_size);
632}
633''')
634
635 # set description (may be overriden later by port def)
636 code('''
637$vid->setDescription("[Version " + to_string(m_version) + ", ${ident}, name=${{var.ident}}]");
638
639''')
640
641 if vtype.isBuffer:
642 if "recycle_latency" in var:
643 code('$vid->setRecycleLatency( ' \
644 'Cycles(${{var["recycle_latency"]}}));')
645 else:
646 code('$vid->setRecycleLatency(m_recycle_latency);')
647
648 # Set the prefetchers

--- 311 unchanged lines hidden (view full) ---

960$c_ident::functionalReadBuffers(PacketPtr& pkt)
961{
962''')
963 for var in self.objects:
964 vtype = var.type
965 if vtype.isBuffer:
966 vid = "m_%s_ptr" % var.ident
967 code('if ($vid->functionalRead(pkt)) { return true; }')
968 code('''
969 return false;
970}
971''')
972
973 # Function for functional writes to messages buffered in the controller
974 code('''
975uint32_t
976$c_ident::functionalWriteBuffers(PacketPtr& pkt)
977{
978 uint32_t num_functional_writes = 0;
979''')
980 for var in self.objects:
981 vtype = var.type
982 if vtype.isBuffer:
983 vid = "m_%s_ptr" % var.ident
984 code('num_functional_writes += $vid->functionalWrite(pkt);')
985 code('''
986 return num_functional_writes;
987}
988''')
989
990 # Check if this controller has a peer, if yes then write the
991 # function for connecting to the peer.
992 if has_peer:
993 code('''
994
995void
996$c_ident::getQueuesFromPeer(AbstractController *peer)
997{
998''')
999 for var in self.objects:
1000 if "network" in var and "physical_network" in var and \
1001 var["network"] == "From":
1002 code('''
1003m_${{var.ident}}_ptr = peer->getPeerQueue(${{var["physical_network"]}});
1004assert(m_${{var.ident}}_ptr != NULL);
1005m_${{var.ident}}_ptr->setReceiver(this);
1006
1007''')
1008 code('}')
1009
1010 code.write(path, "%s.cc" % c_ident)
1011
1012 def printCWakeup(self, path, includes):
1013 '''Output the wakeup loop for the events'''
1014
1015 code = self.symtab.codeFormatter()
1016 ident = self.ident
1017

--- 505 unchanged lines hidden ---