113 sc_attr_base* module_indicator;
116 Module() : sc_module(sc_gen_unique_name(
"module")), clk(
"clk"), rst(
"rst") {
118 module_indicator =
new sc_attr_base(
"match_module");
119 this->add_attribute(*module_indicator);
122 Module(sc_module_name nm) : sc_module(nm), clk(
"clk"), rst(
"rst") {
124 module_indicator =
new sc_attr_base(
"match_module");
125 this->add_attribute(*module_indicator);
131 delete module_indicator;
139 std::map<std::string, uint64> stats_;
147 bool IsModule(sc_object* obj) {
151 if(!obj->kind() || !obj->name())
155 return (obj->get_attribute(
"match_module") != 0);
157 std::string objName = obj->name();
158 return ((strncmp(obj->kind(),
"sc_module", 9) == 0) &&
159 (objName.find(
"dummyPortManager") == std::string::npos ) &&
160 (objName.find(
"rocket") == std::string::npos ) &&
161 (objName.find(
"router") == std::string::npos )
168 std::vector<Module*> GetChildren() {
169 std::vector<sc_object*> children = get_child_objects();
170 std::vector<Module*> result;
172 if(children.size() != 0) {
173 for (
unsigned i = 0; i < children.size(); i++) {
174 if (IsModule(children[i])) {
175 result.push_back((
Module*)(children[i]));
185 void IncrStat(
const std::string& name,
unsigned int num = 1) {
187 stats_[name] = stats_[name] + num;
191 void IncrStatIndexed(
const std::string& name,
unsigned int idx,
192 unsigned int num = 1) {
194 std::stringstream final_name;
195 final_name << name <<
"_" << idx;
196 stats_[final_name.str()] = stats_[final_name.str()] + num;
205 tracer_.SetCurrentLevel(l);
206 tracer_ << sc_time_stamp() <<
": ";
207 if (get_parent() != NULL) {
208 if (get_parent()->get_parent() != NULL) {
209 if (get_parent()->get_parent()->get_parent() != NULL) {
210 if (get_parent()->get_parent()->get_parent()->get_parent() != NULL) {
211 if (get_parent()->get_parent()->get_parent()->get_parent()->get_parent() != NULL) {
212 if (strncmp(get_parent()->get_parent()->get_parent()->get_parent()->get_parent()->basename(),
"", 1)) {
213 tracer_ << get_parent()->get_parent()->get_parent()->get_parent()->get_parent()->basename() <<
".";
217 if (strncmp(get_parent()->get_parent()->get_parent()->get_parent()->basename(),
"", 1)) {
218 tracer_ << get_parent()->get_parent()->get_parent()->get_parent()->basename() <<
".";
222 if (strncmp(get_parent()->get_parent()->get_parent()->basename(),
"", 1)) {
223 tracer_ << get_parent()->get_parent()->get_parent()->basename() <<
".";
227 if (strncmp(get_parent()->get_parent()->basename(),
"", 1)) {
228 tracer_ << get_parent()->get_parent()->basename() <<
".";
232 if (strncmp(get_parent()->basename(),
"", 1)) {
233 tracer_ << get_parent()->basename() <<
".";
236 if (strncmp(basename(),
"", 1)) {
237 tracer_ << basename() <<
": ";
243 Tracer& ASSERT(
bool cond) {
247 tracer_.SetCurrentLevel(tracer_.GetTraceLevel());
251 tracer_.SetCurrentLevel(tracer_.GetTraceLevel() + 1);
253 tracer_ <<
"ASSERTION FAILURE: ";
254 tracer_ << sc_time_stamp() <<
": ";
255 if (strncmp(name(),
"", 1)) {
256 tracer_ << name() <<
": ";
263 void SetTraceLevel(
int l) {
265 tracer_.SetTraceLevel(l);
266 std::vector<Module*> children = GetChildren();
267 for (
unsigned int i = 0; i < children.size(); i++) {
268 children[i]->SetTraceLevel(l);
274 void RecordEvent(
const std::string& name, uint64 param = 0) {
281 void PrintStats(std::ostream& ofile,
unsigned int lvl,
Module* aggregator) {
283 for (std::map<std::string, uint64>::iterator it = stats_.begin();
284 it != stats_.end(); it++) {
286 ofile << it->first <<
": " << it->second << std::endl;
289 aggregator->IncrStat(it->first, it->second);
293 void Indent(std::ostream& ofile,
unsigned int lvl) {
295 for (
unsigned int x = 0; x < 2 * lvl; x++) {
304 return (stats_.size() != 0);
309 bool ChildrenHaveStats() {
310 bool has_stats =
false;
312 std::vector<Module*> children = GetChildren();
313 if(children.size() != 0) {
314 for (
unsigned int x = 0; x < children.size(); x++) {
315 has_stats |= children[x]->HasStats();
317 has_stats |= children[x]->ChildrenHaveStats();
324 void DumpStats(std::ostream& ofile,
unsigned int lvl,
Module* aggregator) {
326 if (!HasStats() && !ChildrenHaveStats()) {
331 ofile << name() <<
":" << std::endl;
332 Module* final_aggregator = ChildrenHaveStats() ? NULL : aggregator;
334 PrintStats(ofile, lvl + 1, final_aggregator);
336 std::vector<Module*> children = GetChildren();
338 if (ChildrenHaveStats()) {
340 for (
unsigned int x = 0; x < children.size(); x++) {
341 children[x]->DumpStats(ofile, lvl + 1,
this);
346 ofile <<
"Totals:" << std::endl;
347 PrintStats(ofile, 1, aggregator);
349 Indent(ofile, lvl + 1);
350 ofile <<
"Sub-totals (" << name() <<
"):" << std::endl;
351 PrintStats(ofile, lvl + 2, aggregator);
356 static const unsigned int width = 0;
357 template <
unsigned int Size>
358 void Marshall(Marshaller<Size>& m) {