112855Sgabeblack@google.com/***************************************************************************** 212855Sgabeblack@google.com 312855Sgabeblack@google.com Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 412855Sgabeblack@google.com more contributor license agreements. See the NOTICE file distributed 512855Sgabeblack@google.com with this work for additional information regarding copyright ownership. 612855Sgabeblack@google.com Accellera licenses this file to you under the Apache License, Version 2.0 712855Sgabeblack@google.com (the "License"); you may not use this file except in compliance with the 812855Sgabeblack@google.com License. You may obtain a copy of the License at 912855Sgabeblack@google.com 1012855Sgabeblack@google.com http://www.apache.org/licenses/LICENSE-2.0 1112855Sgabeblack@google.com 1212855Sgabeblack@google.com Unless required by applicable law or agreed to in writing, software 1312855Sgabeblack@google.com distributed under the License is distributed on an "AS IS" BASIS, 1412855Sgabeblack@google.com WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 1512855Sgabeblack@google.com implied. See the License for the specific language governing 1612855Sgabeblack@google.com permissions and limitations under the License. 1712855Sgabeblack@google.com 1812855Sgabeblack@google.com *****************************************************************************/ 1912855Sgabeblack@google.com 2012855Sgabeblack@google.com/***************************************************************************** 2112855Sgabeblack@google.com 2212855Sgabeblack@google.com sc_report -- caching of report in process context 2312855Sgabeblack@google.com 2412855Sgabeblack@google.com Original Author: Ulli Holtmann, Synopsys, Inc., Jan 2003 2512855Sgabeblack@google.com 2612855Sgabeblack@google.com *****************************************************************************/ 2712855Sgabeblack@google.com 2812855Sgabeblack@google.com/***************************************************************************** 2912855Sgabeblack@google.com 3012855Sgabeblack@google.com MODIFICATION LOG - modifiers, enter your name, affiliation, date and 3112855Sgabeblack@google.com changes you are making here. 3212855Sgabeblack@google.com 3312855Sgabeblack@google.com Name, Affiliation, Date: 3412855Sgabeblack@google.com Description of Modification: 3512855Sgabeblack@google.com 3612855Sgabeblack@google.com *****************************************************************************/ 3712855Sgabeblack@google.com 3812855Sgabeblack@google.com#include <systemc.h> 3912855Sgabeblack@google.com 4012855Sgabeblack@google.com 4112855Sgabeblack@google.com/* 4212855Sgabeblack@google.com 4312855Sgabeblack@google.com id1 has actions: display, cache 4412855Sgabeblack@google.com id2 has actions: display 4512855Sgabeblack@google.com 4612855Sgabeblack@google.com Issue report in this order in the following contextes: 4712855Sgabeblack@google.com 4812855Sgabeblack@google.com retrieve report from thread1 -> no report 4912855Sgabeblack@google.com retrieve report from method1 -> no report 5012855Sgabeblack@google.com retrieve report from global -> no report 5112855Sgabeblack@google.com 5212855Sgabeblack@google.com info/id1/a -> thread1 5312855Sgabeblack@google.com warning/id1/b -> method1 5412855Sgabeblack@google.com info/id1/c -> global 5512855Sgabeblack@google.com warning/id1/d -> thread2 5612855Sgabeblack@google.com info/id1/e -> method2 5712855Sgabeblack@google.com 5812855Sgabeblack@google.com info/id2/f -> thread1 5912855Sgabeblack@google.com warning/id2/g -> method1 6012855Sgabeblack@google.com info/id2/h -> global 6112855Sgabeblack@google.com warning/id2/i -> thread2 6212855Sgabeblack@google.com info/id2/j -> method2 6312855Sgabeblack@google.com 6412855Sgabeblack@google.com retrieve report from thread1 -> info/id1/a 6512855Sgabeblack@google.com retrieve report from method1 -> warning/id1/b 6612855Sgabeblack@google.com retrieve report from global -> info/id1/c 6712855Sgabeblack@google.com retrieve report from thread2 -> no report 6812855Sgabeblack@google.com retrieve report from method2 -> no report 6912855Sgabeblack@google.com*/ 7012855Sgabeblack@google.com 7112855Sgabeblack@google.com 7212855Sgabeblack@google.comstatic const char* severity2str[] = { 7312855Sgabeblack@google.com "INFO", "WARNING", "ERROR", "FATAL", "UNKNOWN_SEVERITY" 7412855Sgabeblack@google.com}; 7512855Sgabeblack@google.com 7612855Sgabeblack@google.comvoid dump_cached_report(const char* ctx) 7712855Sgabeblack@google.com{ 7812855Sgabeblack@google.com sc_report* report = sc_report_handler::get_cached_report(); 7912855Sgabeblack@google.com cout << sc_time_stamp() 8012855Sgabeblack@google.com << " from context '" << ctx << "' "; 8112855Sgabeblack@google.com if (report) { 8212855Sgabeblack@google.com cout << report->get_msg_type() 8312855Sgabeblack@google.com << " " << severity2str[ report->get_severity() ] << endl 8412855Sgabeblack@google.com << " msg=" << report->get_msg() 8512855Sgabeblack@google.com << " file=" << report->get_file_name() 8612855Sgabeblack@google.com << " line " << report->get_line_number() 8712855Sgabeblack@google.com << " time=" << report->get_time(); 8812855Sgabeblack@google.com const char* name = report->get_process_name(); 8912855Sgabeblack@google.com cout << " process=" << (name ? name : "<none>") << endl; 9012855Sgabeblack@google.com } else { 9112855Sgabeblack@google.com cout << "<no cached report>\n"; 9212855Sgabeblack@google.com } 9312855Sgabeblack@google.com sc_report_handler::clear_cached_report(); 9412855Sgabeblack@google.com} 9512855Sgabeblack@google.com 9612855Sgabeblack@google.comSC_MODULE( M ) 9712855Sgabeblack@google.com{ 9812855Sgabeblack@google.com sc_in<bool> emit; // 1: emit, 0: dump cahced report 9912855Sgabeblack@google.com sc_in<const char*> id; 10012855Sgabeblack@google.com sc_in<bool> ofs; 10112855Sgabeblack@google.com sc_event t1, t2, m1, m2; 10212855Sgabeblack@google.com 10312855Sgabeblack@google.com SC_CTOR( M ) { 10412855Sgabeblack@google.com SC_THREAD( thread1 ); 10512855Sgabeblack@google.com sensitive << t1; 10612855Sgabeblack@google.com dont_initialize(); 10712855Sgabeblack@google.com 10812855Sgabeblack@google.com SC_THREAD( thread2 ); 10912855Sgabeblack@google.com sensitive << t2; 11012855Sgabeblack@google.com dont_initialize(); 11112855Sgabeblack@google.com 11212855Sgabeblack@google.com SC_METHOD( method1 ); 11312855Sgabeblack@google.com sensitive << m1; 11412855Sgabeblack@google.com dont_initialize(); 11512855Sgabeblack@google.com 11612855Sgabeblack@google.com SC_METHOD( method2 ); 11712855Sgabeblack@google.com sensitive << m2; 11812855Sgabeblack@google.com dont_initialize(); 11912855Sgabeblack@google.com } 12012855Sgabeblack@google.com void thread1() { 12112855Sgabeblack@google.com while(1) { 12212855Sgabeblack@google.com if (emit) 12312855Sgabeblack@google.com sc_report_handler::report(SC_INFO, id.read(), "aa"+ofs, "file_t1", 110+ofs); 12412855Sgabeblack@google.com else 12512855Sgabeblack@google.com dump_cached_report("t1"); 12612855Sgabeblack@google.com wait(); 12712855Sgabeblack@google.com } 12812855Sgabeblack@google.com } 12912855Sgabeblack@google.com void method1() { 13012855Sgabeblack@google.com if (emit) 13112855Sgabeblack@google.com sc_report_handler::report(SC_WARNING, id.read(), "bb"+ofs, "file_m1", 210+ofs); 13212855Sgabeblack@google.com else 13312855Sgabeblack@google.com dump_cached_report("m1"); 13412855Sgabeblack@google.com } 13512855Sgabeblack@google.com void thread2() { 13612855Sgabeblack@google.com while(1) { 13712855Sgabeblack@google.com if (emit) 13812855Sgabeblack@google.com sc_report_handler::report(SC_WARNING, id.read(), "dd"+ofs, "file_t2", 120+ofs); 13912855Sgabeblack@google.com else 14012855Sgabeblack@google.com dump_cached_report("t2"); 14112855Sgabeblack@google.com wait(); 14212855Sgabeblack@google.com } 14312855Sgabeblack@google.com } 14412855Sgabeblack@google.com void method2() { 14512855Sgabeblack@google.com if (emit) 14612855Sgabeblack@google.com sc_report_handler::report(SC_INFO, id.read(), "ee"+ofs, "file_m2", 220+ofs); 14712855Sgabeblack@google.com else 14812855Sgabeblack@google.com dump_cached_report("m2"); 14912855Sgabeblack@google.com } 15012855Sgabeblack@google.com}; 15112855Sgabeblack@google.com 15212855Sgabeblack@google.com 15312855Sgabeblack@google.comint sc_main(int,char**) 15412855Sgabeblack@google.com{ 15512855Sgabeblack@google.com sc_report_handler::set_actions( "ID1", SC_DISPLAY | SC_CACHE_REPORT ); 15612855Sgabeblack@google.com sc_report_handler::set_actions( "ID2", SC_DISPLAY ); 15712855Sgabeblack@google.com 15812855Sgabeblack@google.com sc_signal<bool> emit; 15912855Sgabeblack@google.com sc_signal<const char*> ID; 16012855Sgabeblack@google.com sc_signal<bool> ofs; 16112855Sgabeblack@google.com M uut("M"); 16212855Sgabeblack@google.com uut( emit,ID,ofs ); 16312855Sgabeblack@google.com 16412855Sgabeblack@google.com emit = 0; 16512855Sgabeblack@google.com ID="ID3"; 16612855Sgabeblack@google.com ofs=0; 16712855Sgabeblack@google.com sc_start( 1,SC_NS ); 16812855Sgabeblack@google.com 16912855Sgabeblack@google.com // dump initial cached reports 17012855Sgabeblack@google.com cout << "Initial status:\n"; 17112855Sgabeblack@google.com uut.t1.notify(); 17212855Sgabeblack@google.com uut.m1.notify(); 17312855Sgabeblack@google.com uut.t2.notify(); 17412855Sgabeblack@google.com uut.m2.notify(); 17512855Sgabeblack@google.com dump_cached_report("global"); 17612855Sgabeblack@google.com sc_start( 1, SC_NS ); 17712855Sgabeblack@google.com 17812855Sgabeblack@google.com // emit report ID1 everywhere 17912855Sgabeblack@google.com emit = 1; 18012855Sgabeblack@google.com ID="ID1"; 18112855Sgabeblack@google.com sc_start( 1,SC_NS ); 18212855Sgabeblack@google.com cout << "\n\nEmit ID1\n"; 18312855Sgabeblack@google.com uut.t1.notify(); 18412855Sgabeblack@google.com uut.m1.notify(); 18512855Sgabeblack@google.com sc_start( 1, SC_NS ); 18612855Sgabeblack@google.com sc_report_handler::report(SC_INFO, ID.read(), "cc", "file_g", 300); 18712855Sgabeblack@google.com uut.t2.notify(); 18812855Sgabeblack@google.com uut.m2.notify(); 18912855Sgabeblack@google.com sc_start( 1, SC_NS ); 19012855Sgabeblack@google.com 19112855Sgabeblack@google.com // emit report ID2 everywhere 19212855Sgabeblack@google.com cout << "\n\nEmit ID2\n"; 19312855Sgabeblack@google.com emit = 1; 19412855Sgabeblack@google.com ID="ID2"; 19512855Sgabeblack@google.com ofs=1; 19612855Sgabeblack@google.com sc_start( 1,SC_NS ); 19712855Sgabeblack@google.com uut.t1.notify(); 19812855Sgabeblack@google.com uut.m1.notify(); 19912855Sgabeblack@google.com sc_start( 1, SC_NS ); 20012855Sgabeblack@google.com sc_report_handler::report(SC_INFO, ID.read(), "c", "file_g", 310); 20112855Sgabeblack@google.com uut.t2.notify(); 20212855Sgabeblack@google.com uut.m2.notify(); 20312855Sgabeblack@google.com sc_start( 1, SC_NS ); 20412855Sgabeblack@google.com 20512855Sgabeblack@google.com // dump cached reports: should be all ID1 20612855Sgabeblack@google.com emit = 0; 20712855Sgabeblack@google.com sc_start( 1,SC_NS ); 20812855Sgabeblack@google.com cout << "\n\nStatus:\n"; 20912855Sgabeblack@google.com uut.t1.notify(); 21012855Sgabeblack@google.com uut.t2.notify(); 21112855Sgabeblack@google.com uut.m1.notify(); 21212855Sgabeblack@google.com uut.m2.notify(); 21312855Sgabeblack@google.com dump_cached_report("global"); 21412855Sgabeblack@google.com sc_start( 1, SC_NS ); 21512855Sgabeblack@google.com 21612855Sgabeblack@google.com // dump cached reports again 21712855Sgabeblack@google.com // (should be all empty because dump clears cached report) 21812855Sgabeblack@google.com cout << "\n\nStatus:\n"; 21912855Sgabeblack@google.com uut.t1.notify(); 22012855Sgabeblack@google.com uut.t2.notify(); 22112855Sgabeblack@google.com uut.m1.notify(); 22212855Sgabeblack@google.com uut.m2.notify(); 22312855Sgabeblack@google.com dump_cached_report("global"); 22412855Sgabeblack@google.com sc_start( 1, SC_NS ); 22512855Sgabeblack@google.com 22612855Sgabeblack@google.com return 0; 22712855Sgabeblack@google.com} 228