test01.cpp revision 12855:588919e0e4aa
1/***************************************************************************** 2 3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 4 more contributor license agreements. See the NOTICE file distributed 5 with this work for additional information regarding copyright ownership. 6 Accellera licenses this file to you under the Apache License, Version 2.0 7 (the "License"); you may not use this file except in compliance with the 8 License. You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 15 implied. See the License for the specific language governing 16 permissions and limitations under the License. 17 18 *****************************************************************************/ 19 20/***************************************************************************** 21 22 test01.cpp -- 23 24 Original Author: Andy Goodrich, Forte Design Systems 25 26 *****************************************************************************/ 27 28/***************************************************************************** 29 30 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 31 changes you are making here. 32 33 Name, Affiliation, Date: 34 Description of Modification: 35 36 *****************************************************************************/ 37 38#include "systemc.h" 39 40void dump_signals(const char* module_name) 41{ 42 sc_simcontext* c_p = sc_get_curr_simcontext(); 43 unsigned int mod_name_len = strlen(module_name); 44 sc_object* obj_p; 45 const char* obj_name_p; 46 47 48 for (obj_p = c_p->first_object(); obj_p; obj_p=c_p->next_object()) 49 { 50 obj_name_p = obj_p->name(); 51 if ( strlen(obj_name_p) > mod_name_len && 52 !strncmp(obj_p->name(),module_name, mod_name_len) && 53 !strcmp(obj_p->kind(),"sc_signal") ) 54 { 55 cout << " " << obj_p->name() << ": " << obj_p->kind() << endl; 56 } 57 } 58 cout << endl; 59} 60 61SC_MODULE(A) 62{ 63 SC_CTOR(A) : a("a"), b("b"), c("c") 64 { 65 } 66 sc_signal<int> a, b, c; 67 sc_in_clk m_clk; 68 sc_signal<int> x, y, z; 69}; 70 71 72SC_MODULE(TB) 73{ 74 SC_CTOR(TB) 75 { 76 SC_METHOD(sync); 77 sensitive << m_clk.pos(); 78 dont_initialize(); 79 } 80 void sync() 81 { 82 cout << "Internal: " << endl; 83 dump_signals("a"); 84 } 85 sc_in_clk m_clk; 86}; 87 88int sc_main(int argc, char* argv[]) 89{ 90 sc_clock clock; 91 sc_signal<int> dummy; 92 A module_a("a"); 93 TB tb("tb"); 94 module_a.m_clk(clock); 95 tb.m_clk(clock); 96 97 cout << "External: " << endl; 98 dump_signals(module_a.name()); 99 sc_start(1, SC_NS); 100 101 102 cerr << "Program completed" << endl; 103 return 0; 104} 105