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
55 # Data members in the State Machine that have been declared before
56 # the opening brace '{' of the machine. Note that these along with
57 # the members in self.objects form the entire set of data members.
58 self.config_parameters = config_parameters
59
60 self.prefetchers = []
61
62 for param in config_parameters:
63 if param.pointer:
64 var = Var(symtab, param.ident, location, param.type_ast.type,
65 "(*m_%s_ptr)" % param.ident, {}, self)
66 else:
67 var = Var(symtab, param.ident, location, param.type_ast.type,

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

74
75 self.states = orderdict()
76 self.events = orderdict()
77 self.actions = orderdict()
78 self.request_types = orderdict()
79 self.transitions = []
80 self.in_ports = []
81 self.functions = []
82
83 # Data members in the State Machine that have been declared inside
84 # the {} machine. Note that these along with the config params
85 # form the entire set of data members of the machine.
86 self.objects = []
87 self.TBEType = None
88 self.EntryType = None
89
90 def __repr__(self):
91 return "[StateMachine: %s]" % self.ident
92
93 def addState(self, state):

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

204''')
205 code.indent()
206 for param in self.config_parameters:
207 dflt_str = ''
208
209 if param.rvalue is not None:
210 dflt_str = str(param.rvalue.inline()) + ', '
211
212 if param.type_ast.type.c_ident == "MessageBuffer":
213 if param["network"] == "To":
214 code('${{param.ident}} = MasterPort(${dflt_str}"")')
215 else:
216 code('${{param.ident}} = SlavePort(${dflt_str}"")')
217
218 elif python_class_map.has_key(param.type_ast.type.c_ident):
219 python_type = python_class_map[param.type_ast.type.c_ident]
220 code('${{param.ident}} = Param.${{python_type}}(${dflt_str}"")')
221
222 else:
223 self.error("Unknown c++ to python class conversion for c++ " \
224 "type: '%s'. Please update the python_class_map " \
225 "in StateMachine.py", param.type_ast.type.c_ident)
226 code.dedent()

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

251#include "mem/protocol/Types.hh"
252#include "mem/ruby/common/Consumer.hh"
253#include "mem/ruby/common/Global.hh"
254#include "mem/ruby/slicc_interface/AbstractController.hh"
255#include "params/$c_ident.hh"
256''')
257
258 seen_types = set()
259 for var in self.objects:
260 if var.type.ident not in seen_types and not var.type.isPrimitive:
261 code('#include "mem/protocol/${{var.type.c_ident}}.hh"')
262 seen_types.add(var.type.ident)
263
264 # for adding information to the protocol debug trace
265 code('''
266extern std::stringstream ${ident}_transitionComment;
267
268class $c_ident : public AbstractController
269{
270 public:
271 typedef ${c_ident}Params Params;
272 $c_ident(const Params *p);
273 static int getNumControllers();
274 void init();
275
276 MessageBuffer* getMandatoryQueue() const;
277 void setNetQueue(const std::string& name, MessageBuffer *b);
278
279 void print(std::ostream& out) const;
280 void wakeup();
281 void resetStats();
282 void regStats();
283 void collateStats();
284
285 void recordCacheTrace(int cntrl, CacheRecorder* tr);

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

349// Internal functions
350''')
351
352 for func in self.functions:
353 proto = func.prototype
354 if proto:
355 code('$proto')
356
357 if self.EntryType != None:
358 code('''
359
360// Set and Reset for cache_entry variable
361void set_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, AbstractCacheEntry* m_new_cache_entry);
362void unset_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr);
363''')
364

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

411 code.write(path, '%s.hh' % c_ident)
412
413 def printControllerCC(self, path, includes):
414 '''Output the actions for performing the actions'''
415
416 code = self.symtab.codeFormatter()
417 ident = self.ident
418 c_ident = "%s_Controller" % self.ident
419
420 code('''
421/** \\file $c_ident.cc
422 *
423 * Auto generated C++ code started by $__file__:$__line__
424 * Created by slicc definition of Module "${{self.short}}"
425 */
426

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

492 code.indent()
493
494 #
495 # After initializing the universal machine parameters, initialize the
496 # this machines config parameters. Also if these configuration params
497 # include a sequencer, connect the it to the controller.
498 #
499 for param in self.config_parameters:
500
501 # Do not initialize messgage buffers since they are initialized
502 # when the port based connections are made.
503 if param.type_ast.type.c_ident == "MessageBuffer":
504 continue
505
506 if param.pointer:
507 code('m_${{param.ident}}_ptr = p->${{param.ident}};')
508 else:
509 code('m_${{param.ident}} = p->${{param.ident}};')
510
511 if re.compile("sequencer").search(param.ident):
512 code('m_${{param.ident}}_ptr->setController(this);')
513
514 for var in self.objects:
515 if var.ident.find("mandatoryQueue") >= 0:
516 code('''
517m_${{var.ident}}_ptr = new ${{var.type.c_ident}}();
518m_${{var.ident}}_ptr->setReceiver(this);
519''')
520
521 code('''
522
523for (int state = 0; state < ${ident}_State_NUM; state++) {
524 for (int event = 0; event < ${ident}_Event_NUM; event++) {
525 m_possible[state][event] = false;
526 m_counters[state][event] = 0;
527 }
528}
529for (int event = 0; event < ${ident}_Event_NUM; event++) {
530 m_event_counters[event] = 0;
531}
532''')
533 code.dedent()
534 code('''
535}
536
537void
538$c_ident::setNetQueue(const std::string& name, MessageBuffer *b)
539{
540 MachineType machine_type = string_to_MachineType("${{self.ident}}");
541 int base M5_VAR_USED = MachineType_base_number(machine_type);
542
543''')
544 code.indent()
545
546 # set for maintaining the vnet, direction pairs already seen for this
547 # machine. This map helps in implementing the check for avoiding
548 # multiple message buffers being mapped to the same vnet.
549 vnet_dir_set = set()
550
551 for var in self.config_parameters:
552 if "network" in var:
553 vtype = var.type_ast.type
554 vid = "m_%s_ptr" % var.ident
555
556 code('''
557if ("${{var.ident}}" == name) {
558 $vid = b;
559 assert($vid != NULL);
560''')
561 code.indent()
562 # Network port object
563 network = var["network"]
564 ordered = var["ordered"]
565
566 if "virtual_network" in var:
567 vnet = var["virtual_network"]
568 vnet_type = var["vnet_type"]
569
570 assert (vnet, network) not in vnet_dir_set
571 vnet_dir_set.add((vnet,network))
572
573 code('''
574m_net_ptr->set${network}NetQueue(m_version + base, $ordered, $vnet,
575 "$vnet_type", b);
576''')
577 # Set the end
578 if network == "To":
579 code('$vid->setSender(this);')
580 else:
581 code('$vid->setReceiver(this);')
582
583 # Set ordering
584 code('$vid->setOrdering(${{var["ordered"]}});')
585
586 # Set randomization
587 if "random" in var:
588 # A buffer
589 code('$vid->setRandomization(${{var["random"]}});')
590
591 # Set Priority
592 if "rank" in var:
593 code('$vid->setPriority(${{var["rank"]}})')
594
595 # Set buffer size
596 code('$vid->resize(m_buffer_size);')
597
598 if "recycle_latency" in var:
599 code('$vid->setRecycleLatency( ' \
600 'Cycles(${{var["recycle_latency"]}}));')
601 else:
602 code('$vid->setRecycleLatency(m_recycle_latency);')
603
604 # set description (may be overriden later by port def)
605 code('''
606$vid->setDescription("[Version " + to_string(m_version) + ", ${ident}, name=${{var.ident}}]");
607''')
608 code.dedent()
609 code('}\n')
610
611 code.dedent()
612 code('''
613}
614
615void
616$c_ident::init()
617{
618 // initialize objects
619
620''')
621
622 code.indent()
623
624 for var in self.objects:
625 vtype = var.type
626 vid = "m_%s_ptr" % var.ident
627 if "network" not in var:
628 # Not a network port object
629 if "primitive" in vtype:
630 code('$vid = new ${{vtype.c_ident}};')
631 if "default" in var:

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

667 code('$vid->setSender(this);')
668 code('$vid->setReceiver(this);')
669 elif vtype.c_ident == "TimerTable":
670 code('$vid->setClockObj(this);')
671 elif var.ident.find("optionalQueue") >= 0:
672 code('$vid->setSender(this);')
673 code('$vid->setReceiver(this);')
674
675 if vtype.isBuffer:
676 if "recycle_latency" in var:
677 code('$vid->setRecycleLatency( ' \
678 'Cycles(${{var["recycle_latency"]}}));')
679 else:
680 code('$vid->setRecycleLatency(m_recycle_latency);')
681
682 # Set the prefetchers

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

994$c_ident::functionalReadBuffers(PacketPtr& pkt)
995{
996''')
997 for var in self.objects:
998 vtype = var.type
999 if vtype.isBuffer:
1000 vid = "m_%s_ptr" % var.ident
1001 code('if ($vid->functionalRead(pkt)) { return true; }')
1002
1003 for var in self.config_parameters:
1004 vtype = var.type_ast.type
1005 if vtype.isBuffer:
1006 vid = "m_%s_ptr" % var.ident
1007 code('if ($vid->functionalRead(pkt)) { return true; }')
1008
1009 code('''
1010 return false;
1011}
1012''')
1013
1014 # Function for functional writes to messages buffered in the controller
1015 code('''
1016uint32_t
1017$c_ident::functionalWriteBuffers(PacketPtr& pkt)
1018{
1019 uint32_t num_functional_writes = 0;
1020''')
1021 for var in self.objects:
1022 vtype = var.type
1023 if vtype.isBuffer:
1024 vid = "m_%s_ptr" % var.ident
1025 code('num_functional_writes += $vid->functionalWrite(pkt);')
1026
1027 for var in self.config_parameters:
1028 vtype = var.type_ast.type
1029 if vtype.isBuffer:
1030 vid = "m_%s_ptr" % var.ident
1031 code('num_functional_writes += $vid->functionalWrite(pkt);')
1032
1033 code('''
1034 return num_functional_writes;
1035}
1036''')
1037
1038 code.write(path, "%s.cc" % c_ident)
1039
1040 def printCWakeup(self, path, includes):
1041 '''Output the wakeup loop for the events'''
1042
1043 code = self.symtab.codeFormatter()
1044 ident = self.ident
1045

--- 505 unchanged lines hidden ---