sc_export.cpp revision 12027:1eb7dc7aa10b
112027Sjungma@eit.uni-kl.de/***************************************************************************** 212027Sjungma@eit.uni-kl.de 312027Sjungma@eit.uni-kl.de Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 412027Sjungma@eit.uni-kl.de more contributor license agreements. See the NOTICE file distributed 512027Sjungma@eit.uni-kl.de with this work for additional information regarding copyright ownership. 612027Sjungma@eit.uni-kl.de Accellera licenses this file to you under the Apache License, Version 2.0 712027Sjungma@eit.uni-kl.de (the "License"); you may not use this file except in compliance with the 812027Sjungma@eit.uni-kl.de License. You may obtain a copy of the License at 912027Sjungma@eit.uni-kl.de 1012027Sjungma@eit.uni-kl.de http://www.apache.org/licenses/LICENSE-2.0 1112027Sjungma@eit.uni-kl.de 1212027Sjungma@eit.uni-kl.de Unless required by applicable law or agreed to in writing, software 1312027Sjungma@eit.uni-kl.de distributed under the License is distributed on an "AS IS" BASIS, 1412027Sjungma@eit.uni-kl.de WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 1512027Sjungma@eit.uni-kl.de implied. See the License for the specific language governing 1612027Sjungma@eit.uni-kl.de permissions and limitations under the License. 1712027Sjungma@eit.uni-kl.de 1812027Sjungma@eit.uni-kl.de *****************************************************************************/ 1912027Sjungma@eit.uni-kl.de 2012027Sjungma@eit.uni-kl.de/***************************************************************************** 2112027Sjungma@eit.uni-kl.de 2212027Sjungma@eit.uni-kl.de sc_export.cpp -- 2312027Sjungma@eit.uni-kl.de 2412027Sjungma@eit.uni-kl.de Original Author: Bishnupriya Bhattachary, Cadence, Design Systems, 2512027Sjungma@eit.uni-kl.de 25 August, 2003 2612027Sjungma@eit.uni-kl.de 2712027Sjungma@eit.uni-kl.de CHANGE LOG IS AT THE END OF THE FILE 2812027Sjungma@eit.uni-kl.de *****************************************************************************/ 2912027Sjungma@eit.uni-kl.de 3012027Sjungma@eit.uni-kl.de#include "sysc/communication/sc_export.h" 3112027Sjungma@eit.uni-kl.de#include "sysc/kernel/sc_simcontext.h" 3212027Sjungma@eit.uni-kl.de#include "sysc/kernel/sc_module.h" 3312027Sjungma@eit.uni-kl.de#include "sysc/kernel/sc_object_int.h" 3412027Sjungma@eit.uni-kl.de 3512027Sjungma@eit.uni-kl.denamespace sc_core { 3612027Sjungma@eit.uni-kl.de 3712027Sjungma@eit.uni-kl.de// ---------------------------------------------------------------------------- 3812027Sjungma@eit.uni-kl.de// CLASS : sc_export_base 3912027Sjungma@eit.uni-kl.de// 4012027Sjungma@eit.uni-kl.de// ---------------------------------------------------------------------------- 4112027Sjungma@eit.uni-kl.de 4212027Sjungma@eit.uni-kl.desc_export_base::sc_export_base() : sc_object(sc_gen_unique_name("export")) 4312027Sjungma@eit.uni-kl.de{ 4412027Sjungma@eit.uni-kl.de simcontext()->get_export_registry()->insert(this); 4512027Sjungma@eit.uni-kl.de} 4612027Sjungma@eit.uni-kl.de 4712027Sjungma@eit.uni-kl.desc_export_base::sc_export_base(const char* name_) : sc_object(name_) 4812027Sjungma@eit.uni-kl.de{ 4912027Sjungma@eit.uni-kl.de simcontext()->get_export_registry()->insert(this); 5012027Sjungma@eit.uni-kl.de} 5112027Sjungma@eit.uni-kl.de 5212027Sjungma@eit.uni-kl.desc_export_base::~sc_export_base() 5312027Sjungma@eit.uni-kl.de{ 5412027Sjungma@eit.uni-kl.de simcontext()->get_export_registry()->remove(this); 5512027Sjungma@eit.uni-kl.de} 5612027Sjungma@eit.uni-kl.de 5712027Sjungma@eit.uni-kl.de// called by construction_done() (does nothing by default) 5812027Sjungma@eit.uni-kl.de 5912027Sjungma@eit.uni-kl.devoid 6012027Sjungma@eit.uni-kl.desc_export_base::before_end_of_elaboration() 6112027Sjungma@eit.uni-kl.de{ 6212027Sjungma@eit.uni-kl.de} 6312027Sjungma@eit.uni-kl.de 6412027Sjungma@eit.uni-kl.de// called when construction is done 6512027Sjungma@eit.uni-kl.de 6612027Sjungma@eit.uni-kl.devoid 6712027Sjungma@eit.uni-kl.desc_export_base::construction_done() 6812027Sjungma@eit.uni-kl.de{ 6912027Sjungma@eit.uni-kl.de if ( get_interface() == 0 ) 7012027Sjungma@eit.uni-kl.de { 7112027Sjungma@eit.uni-kl.de report_error( SC_ID_SC_EXPORT_NOT_BOUND_AFTER_CONSTRUCTION_, 0); 7212027Sjungma@eit.uni-kl.de } 7312027Sjungma@eit.uni-kl.de 7412027Sjungma@eit.uni-kl.de sc_module* parent = static_cast<sc_module*>( get_parent_object() ); 7512027Sjungma@eit.uni-kl.de sc_object::hierarchy_scope scope( parent ); 7612027Sjungma@eit.uni-kl.de before_end_of_elaboration(); 7712027Sjungma@eit.uni-kl.de} 7812027Sjungma@eit.uni-kl.de 7912027Sjungma@eit.uni-kl.de// called by elaboration_done() (does nothing by default) 8012027Sjungma@eit.uni-kl.de 8112027Sjungma@eit.uni-kl.devoid 8212027Sjungma@eit.uni-kl.desc_export_base::end_of_elaboration() 8312027Sjungma@eit.uni-kl.de{} 8412027Sjungma@eit.uni-kl.de 8512027Sjungma@eit.uni-kl.de// called when elaboration is done 8612027Sjungma@eit.uni-kl.de 8712027Sjungma@eit.uni-kl.devoid 8812027Sjungma@eit.uni-kl.desc_export_base::elaboration_done() 8912027Sjungma@eit.uni-kl.de{ 9012027Sjungma@eit.uni-kl.de sc_module* parent = static_cast<sc_module*>( get_parent_object() ); 9112027Sjungma@eit.uni-kl.de sc_object::hierarchy_scope scope( parent ); 9212027Sjungma@eit.uni-kl.de end_of_elaboration(); 9312027Sjungma@eit.uni-kl.de} 9412027Sjungma@eit.uni-kl.de 9512027Sjungma@eit.uni-kl.de// called by start_simulation (does nothing) 9612027Sjungma@eit.uni-kl.de 9712027Sjungma@eit.uni-kl.devoid 9812027Sjungma@eit.uni-kl.desc_export_base::start_of_simulation() 9912027Sjungma@eit.uni-kl.de{} 10012027Sjungma@eit.uni-kl.de 10112027Sjungma@eit.uni-kl.de// called before simulation starts 10212027Sjungma@eit.uni-kl.de 10312027Sjungma@eit.uni-kl.devoid 10412027Sjungma@eit.uni-kl.desc_export_base::start_simulation() 10512027Sjungma@eit.uni-kl.de{ 10612027Sjungma@eit.uni-kl.de sc_module* parent = static_cast<sc_module*>( get_parent_object() ); 10712027Sjungma@eit.uni-kl.de sc_object::hierarchy_scope scope( parent ); 10812027Sjungma@eit.uni-kl.de start_of_simulation(); 10912027Sjungma@eit.uni-kl.de} 11012027Sjungma@eit.uni-kl.de 11112027Sjungma@eit.uni-kl.de// called by simulation_done (does nothing) 11212027Sjungma@eit.uni-kl.de 11312027Sjungma@eit.uni-kl.devoid 11412027Sjungma@eit.uni-kl.desc_export_base::end_of_simulation() 11512027Sjungma@eit.uni-kl.de{} 11612027Sjungma@eit.uni-kl.de 11712027Sjungma@eit.uni-kl.de// called after simulation ends 11812027Sjungma@eit.uni-kl.de 11912027Sjungma@eit.uni-kl.devoid 12012027Sjungma@eit.uni-kl.desc_export_base::simulation_done() 12112027Sjungma@eit.uni-kl.de{ 12212027Sjungma@eit.uni-kl.de sc_module* parent = static_cast<sc_module*>( get_parent_object() ); 12312027Sjungma@eit.uni-kl.de sc_object::hierarchy_scope scope( parent ); 12412027Sjungma@eit.uni-kl.de end_of_simulation(); 12512027Sjungma@eit.uni-kl.de} 12612027Sjungma@eit.uni-kl.de 12712027Sjungma@eit.uni-kl.devoid 12812027Sjungma@eit.uni-kl.desc_export_base::report_error( const char* id, const char* add_msg ) const 12912027Sjungma@eit.uni-kl.de{ 13012027Sjungma@eit.uni-kl.de char msg[BUFSIZ]; 13112027Sjungma@eit.uni-kl.de if( add_msg != 0 ) { 13212027Sjungma@eit.uni-kl.de std::sprintf( msg, "%s: export '%s' (%s)", add_msg, name(), kind() ); 13312027Sjungma@eit.uni-kl.de } else { 13412027Sjungma@eit.uni-kl.de std::sprintf( msg, "export '%s' (%s)", name(), kind() ); 13512027Sjungma@eit.uni-kl.de } 13612027Sjungma@eit.uni-kl.de SC_REPORT_ERROR( id, msg ); 13712027Sjungma@eit.uni-kl.de} 13812027Sjungma@eit.uni-kl.de 13912027Sjungma@eit.uni-kl.de 14012027Sjungma@eit.uni-kl.de// ---------------------------------------------------------------------------- 14112027Sjungma@eit.uni-kl.de// CLASS : sc_export_registry 14212027Sjungma@eit.uni-kl.de// 14312027Sjungma@eit.uni-kl.de// Registry for all exports. 144// FOR INTERNAL USE ONLY! 145// ---------------------------------------------------------------------------- 146 147void 148sc_export_registry::insert( sc_export_base* export_ ) 149{ 150 if( sc_is_running() ) { 151 export_->report_error(SC_ID_INSERT_EXPORT_, "simulation running"); 152 } 153 154 if( m_simc->elaboration_done() ) { 155 export_->report_error(SC_ID_INSERT_EXPORT_, "elaboration done"); 156 } 157 158 159#ifdef DEBUG_SYSTEMC 160 // check if port_ is already inserted 161 for( int i = size() - 1; i >= 0; -- i ) { 162 if( export_ == m_export_vec[i] ) { 163 export_->report_error( SC_ID_INSERT_EXPORT_, 164 "export already inserted "); 165 } 166 } 167#endif 168 169/* 170 //TBD: maybe we want to do this stuf for later 171 172 // append the port to the current module's vector of ports 173 sc_module* curr_module = m_simc->hierarchy_curr(); 174 if( curr_module == 0 ) { 175 port_->report_error( SC_ID_PORT_OUTSIDE_MODULE_ ); 176 } 177 curr_module->append_port( port_ ); 178*/ 179 180 // insert 181 m_export_vec.push_back( export_ ); 182} 183 184void 185sc_export_registry::remove( sc_export_base* export_ ) 186{ 187 if (size()==0) return; 188 int i; 189 for( i = size() - 1; i >= 0; -- i ) { 190 if( export_ == m_export_vec[i] ) { 191 break; 192 } 193 } 194 if( i == -1 ) { 195 export_->report_error( SC_ID_SC_EXPORT_NOT_REGISTERED_ ); 196 } 197 198 // remove 199 m_export_vec[i] = m_export_vec[size() - 1]; 200 m_export_vec.resize(size()-1); 201} 202 203// constructor 204 205sc_export_registry::sc_export_registry( sc_simcontext& simc_ ) 206: m_construction_done(0), 207 m_export_vec(), 208 m_simc( &simc_ ) 209{ 210} 211 212 213// destructor 214 215sc_export_registry::~sc_export_registry() 216{ 217} 218 219// called when construction is done 220 221bool 222sc_export_registry::construction_done() 223{ 224 if( m_construction_done == size() ) 225 // nothing has been updated 226 return true; 227 228 for( int i = size()-1; i >= m_construction_done; --i ) { 229 m_export_vec[i]->construction_done(); 230 } 231 232 m_construction_done = size(); 233 return false; 234} 235 236// called when elaboration is done 237 238void 239sc_export_registry::elaboration_done() 240{ 241 for( int i = size() - 1; i >= 0; -- i ) { 242 m_export_vec[i]->elaboration_done(); 243 } 244} 245 246// called before simulation begins 247 248void 249sc_export_registry::start_simulation() 250{ 251 for( int i = size() - 1; i >= 0; -- i ) { 252 m_export_vec[i]->start_simulation(); 253 } 254} 255 256void 257sc_export_registry::simulation_done() 258{ 259 for( int i = size() - 1; i >= 0; -- i ) { 260 m_export_vec[i]->simulation_done(); 261 } 262} 263 264} // namespace sc_core 265 266// $Log: sc_export.cpp,v $ 267// Revision 1.8 2011/08/26 20:45:40 acg 268// Andy Goodrich: moved the modification log to the end of the file to 269// eliminate source line number skew when check-ins are done. 270// 271// Revision 1.7 2011/08/24 22:05:36 acg 272// Torsten Maehne: initialization changes to remove warnings. 273// 274// Revision 1.6 2011/05/09 04:07:37 acg 275// Philipp A. Hartmann: 276// (1) Restore hierarchy in all phase callbacks. 277// (2) Ensure calls to before_end_of_elaboration. 278// 279// Revision 1.5 2011/02/18 20:31:05 acg 280// Philipp A. Hartmann: added error messages for calls that cannot be done 281// after elaboration. 282// 283// Revision 1.4 2011/02/18 20:23:45 acg 284// Andy Goodrich: Copyright update. 285// 286// Revision 1.3 2011/02/18 20:07:04 acg 287// Philipp A. Hartmann: Patch to revert to sprintf from snprintf to keep 288// some versions of MSVC happy. 289// 290// Revision 1.2 2011/02/14 17:50:16 acg 291// Andy Goodrich: testing for sc_port and sc_export instantiations during 292// end of elaboration and issuing appropriate error messages. 293// 294// Revision 1.1.1.1 2006/12/15 20:20:04 acg 295// SystemC 2.3 296// 297// Revision 1.4 2006/01/26 21:00:50 acg 298// Andy Goodrich: conversion to use sc_event::notify(SC_ZERO_TIME) instead of 299// sc_event::notify_delayed() 300// 301// Revision 1.3 2006/01/13 18:47:42 acg 302// Added $Log command so that CVS comments are reproduced in the source. 303// 304 305// Taf! 306