00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "torc/generic/om/DumpRestoreConfig.hpp"
00017
00018 #ifndef HAVE_CONFIG_H
00019 #include "torc/generic/config.h"
00020 #endif
00021
00022
00023 #include <boost/bind.hpp>
00024 #include <boost/mem_fn.hpp>
00025 #ifdef GENOM_SERIALIZATION
00026 #include <boost/archive/binary_iarchive.hpp>
00027 #include <boost/archive/binary_oarchive.hpp>
00028 #include <boost/serialization/base_object.hpp>
00029 #include <boost/serialization/is_abstract.hpp>
00030 #include <boost/serialization/map.hpp>
00031 #include <boost/serialization/shared_ptr.hpp>
00032 #endif //GENOM_SERIALIZATION
00033
00034 #include "torc/generic/om/Instance.hpp"
00035 #include "torc/generic/util/Log.hpp"
00036 #include "torc/generic/om/Net.hpp"
00037 #include "torc/generic/om/Parameter.hpp"
00038 #include "torc/generic/om/ParameterMap.hpp"
00039 #include "torc/generic/om/Port.hpp"
00040 #include "torc/generic/om/PortReference.hpp"
00041 #include "torc/generic/om/View.hpp"
00042 #include "torc/generic/om/Cell.hpp"
00043
00044 namespace torc {
00045
00046 namespace generic {
00047
00048 #ifdef GENOM_SERIALIZATION
00049 class RestoredInstanceUpdater {
00050 public:
00051 void
00052 operator()( const InstanceSharedPtr &inInst
00053 ) const throw(Error) {
00054 try
00055 {
00056 inInst->setParent( mView );
00057 inInst->restoreMaster();
00058 }
00059 catch( Error &e )
00060 {
00061 e.setCurrentLocation(
00062 __FUNCTION__, __FILE__, __LINE__ );
00063 throw;
00064 }
00065 }
00066
00067 RestoredInstanceUpdater( const ViewSharedPtr &inView )
00068 : mView( inView ) {
00069 }
00070 private:
00071 ViewSharedPtr mView;
00072 };
00073 #endif //GENOM_SERIALIZATION
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 ViewSharedPtr
00086 View::Factory::newViewPtr( const std::string &inName,
00087 const CellSharedPtr &inCellPtr,
00088 const View::Type &inViewType,
00089 const std::string &inOriginalName ) throw(Error) {
00090 try
00091 {
00092 ViewSharedPtr newView;
00093 create( newView );
00094 newView->setName(inName);
00095 newView->setParent( inCellPtr );
00096 newView->setType( inViewType );
00097 newView->setOriginalName( inOriginalName );
00098 inCellPtr->addView( newView );
00099 return newView;
00100 }
00101 catch( Error &e )
00102 {
00103 e.setCurrentLocation(
00104 __FUNCTION__, __FILE__, __LINE__ );
00105 throw;
00106 }
00107 }
00108
00109 void
00110 View::accept(BaseVisitor & inoutVisitor) throw(Error) {
00111 try
00112 {
00113 runVisitor( *this, inoutVisitor );
00114 }
00115 catch( Error &e )
00116 {
00117 e.setCurrentLocation(
00118 __FUNCTION__, __FILE__, __LINE__ );
00119 throw;
00120 }
00121 }
00122
00123 ParameterMapSharedPtr
00124 View::getParameters() throw(Error) {
00125 if( !mParameters->isContextRegistered( mMyContext ) )
00126 {
00127 mParameters->registerContext( mMyContext );
00128 }
00129 return mParameters;
00130 }
00131
00132
00133
00134
00135
00136
00137 void
00138 View::setType(const View::Type & inSource) throw() {
00139 mType = inSource;
00140 }
00141
00142
00143
00144
00145
00146
00147 void
00148 View::setInstances(
00149 const std::vector< InstanceSharedPtr > & inSource) throw(Error) {
00150 std::vector< InstanceSharedPtr >::const_iterator instance = inSource.begin();
00151 std::vector< InstanceSharedPtr >::const_iterator end = inSource.end();
00152 for(; instance != end; ++instance )
00153 {
00154 try
00155 {
00156 addInstance( *instance );
00157 }
00158 catch( Error &e )
00159 {
00160 e.setCurrentLocation(
00161 __FUNCTION__, __FILE__, __LINE__ );
00162 throw;
00163 }
00164 }
00165 }
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176 void
00177 View::addInstance(
00178 const InstanceSharedPtr & inInstance) throw(Error) {
00179 if( !inInstance )
00180 {
00181 Error e( eMessageIdErrorPointerToItemDoesNotExist,
00182 __FUNCTION__, __FILE__, __LINE__ );
00183 e.saveContextData("Pointer to the instance object does not exist", inInstance);
00184 throw e;
00185 }
00186 std::string name = inInstance->getName();
00187 if( name.empty() )
00188 {
00189 Error e( eMessageIdErrorEmptyItemName,
00190 __FUNCTION__, __FILE__, __LINE__ );
00191 e.saveContextData("Empty Instance name", name);
00192 throw e;
00193 }
00194 if( false == mInstanceSymTab.set( name, inInstance ) )
00195 {
00196 Error e( eMessageIdErrorItemAlreadyExists,
00197 __FUNCTION__, __FILE__, __LINE__ );
00198 e.saveContextData("Instance name", name);
00199 throw e;
00200 }
00201 inInstance->setParent( getSharedThis() );
00202 }
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 InstanceSharedPtr
00214 View::findInstance(const std::string &inName) throw() {
00215 if( inName.empty() )
00216 {
00217 Error e( eMessageIdErrorEmptyItemName,
00218 __FUNCTION__, __FILE__, __LINE__ );
00219 e.saveContextData("Instance name", inName);
00220 throw e;
00221 }
00222 InstanceSharedPtr instance;
00223 mInstanceSymTab.get( inName, instance );
00224 return instance;
00225 }
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 void
00236 View::removeInstance(const std::string &inName) throw(Error) {
00237 if( inName.empty() )
00238 {
00239 Error e( eMessageIdErrorEmptyItemName,
00240 __FUNCTION__, __FILE__, __LINE__ );
00241 e.saveContextData("Instance name", inName);
00242 throw e;
00243 }
00244 InstanceSharedPtr instance = findInstance( inName );
00245 if( instance )
00246 {
00247 std::vector<PortReferenceSharedPtr> refs;
00248 instance->getPortReferences( refs );
00249 for_each( refs.begin(), refs.end(),
00250 boost::bind( boost::mem_fn(
00251 &Connectable::disconnect), _1));
00252 if( false == mInstanceSymTab.remove( inName ) )
00253 {
00254 Error e( eMessageIdErrorItemNotFound,
00255 __FUNCTION__, __FILE__, __LINE__ );
00256 e.saveContextData("Instance name", inName);
00257 throw e;
00258 }
00259 }
00260 else
00261 {
00262 Error e( eMessageIdErrorItemNotFound,
00263 __FUNCTION__, __FILE__, __LINE__ );
00264 e.saveContextData("Instance name", inName);
00265 throw e;
00266 }
00267 }
00268
00269
00270
00271
00272
00273
00274 void
00275 View::setNets(
00276 const std::vector< NetSharedPtr > & inSource) throw(Error) {
00277 std::vector< NetSharedPtr >::const_iterator net
00278 = inSource.begin();
00279 std::vector< NetSharedPtr >::const_iterator end
00280 = inSource.end();
00281 for(; net != end; ++net )
00282 {
00283 try
00284 {
00285 addNet( *net );
00286 }
00287 catch( Error &e )
00288 {
00289 e.setCurrentLocation(
00290 __FUNCTION__, __FILE__, __LINE__ );
00291 throw;
00292 }
00293 }
00294 }
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304 void
00305 View::addNet(const NetSharedPtr & inNet) throw(Error) {
00306 if( !inNet )
00307 {
00308 return;
00309 }
00310 std::string name = inNet->getName();
00311 if( name.empty() )
00312 {
00313 Error e( eMessageIdErrorEmptyItemName,
00314 __FUNCTION__, __FILE__, __LINE__ );
00315 e.saveContextData("Net name", name);
00316 throw e;
00317 }
00318 if( false == mNetSymTab.set( name, inNet ) )
00319 {
00320 Error e( eMessageIdErrorItemAlreadyExists,
00321 __FUNCTION__, __FILE__, __LINE__ );
00322 e.saveContextData("Net name", name);
00323 throw e;
00324 }
00325 inNet->setParent( getSharedThis() );
00326 }
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336 NetSharedPtr
00337 View::findNet(const std::string &inName) throw() {
00338 if( inName.empty() )
00339 {
00340 Error e( eMessageIdErrorEmptyItemName,
00341 __FUNCTION__, __FILE__, __LINE__ );
00342 e.saveContextData("Net name not found", inName);
00343 throw e;
00344 }
00345 NetSharedPtr net;
00346 mNetSymTab.get( inName, net );
00347 return net;
00348 }
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358 void
00359 View::removeNet(const std::string &inName) throw(Error) {
00360 if( inName.empty() )
00361 {
00362 Error e( eMessageIdErrorEmptyItemName,
00363 __FUNCTION__, __FILE__, __LINE__ );
00364 e.saveContextData("Net name", inName);
00365 throw e;
00366 }
00367 if( false == mNetSymTab.remove( inName ) )
00368 {
00369 Error e( eMessageIdErrorItemNotFound,
00370 __FUNCTION__, __FILE__, __LINE__ );
00371 e.saveContextData("Net name", inName);
00372 throw e;
00373 }
00374 }
00375
00376
00377
00378
00379
00380
00381 void
00382 View::setPorts(const std::vector< PortSharedPtr > &inSource) throw(Error) {
00383 std::vector< PortSharedPtr >::const_iterator port = inSource.begin();
00384 std::vector< PortSharedPtr >::const_iterator end = inSource.end();
00385 for(;port != end; ++port)
00386 {
00387 try
00388 {
00389 addPort( *port );
00390 }
00391 catch( Error &e )
00392 {
00393 e.setCurrentLocation(
00394 __FUNCTION__, __FILE__, __LINE__ );
00395 throw;
00396 }
00397 }
00398
00399 }
00400
00401
00402
00403
00404
00405
00406
00407
00408 void
00409 View::addPort(
00410 const PortSharedPtr &inPort) throw(Error) {
00411 if( !inPort )
00412 {
00413 return;
00414 }
00415 std::string name = inPort->getName();
00416 if( name.empty() )
00417 {
00418 Error e( eMessageIdErrorEmptyItemName,
00419 __FUNCTION__, __FILE__, __LINE__ );
00420 e.saveContextData("Port name", name);
00421 throw e;
00422 }
00423 if( false == mPortSymTab.set( name, inPort ) )
00424 {
00425 Error e( eMessageIdErrorItemAlreadyExists,
00426 __FUNCTION__, __FILE__, __LINE__ );
00427 e.saveContextData("Port name", name);
00428 throw e;
00429 }
00430 inPort->setParent( getSharedThis() );
00431 }
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442 PortSharedPtr
00443 View::findPort(const std::string &inName) throw() {
00444 if( inName.empty() )
00445 {
00446 Error e( eMessageIdErrorEmptyItemName,
00447 __FUNCTION__, __FILE__, __LINE__ );
00448 e.saveContextData("Port name", inName);
00449 throw e;
00450 }
00451 PortSharedPtr port;
00452 mPortSymTab.get( inName, port );
00453 return port;
00454 }
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464 void
00465 View::removePort(const std::string &inName) throw(Error)
00466 {
00467 if( inName.empty() )
00468 {
00469 Error e( eMessageIdErrorEmptyItemName,
00470 __FUNCTION__, __FILE__, __LINE__ );
00471 e.saveContextData("Port name", inName);
00472 throw e;
00473 }
00474 if( false == mPortSymTab.remove( inName ) )
00475 {
00476 Error e( eMessageIdErrorItemNotFound,
00477 __FUNCTION__, __FILE__, __LINE__ );
00478 e.saveContextData("Port name", inName);
00479 throw e;
00480 }
00481 }
00482
00483 void
00484 View::setNonNetlistViewData( const std::string &inData) throw() {
00485 mNonNetlistViewData = inData;
00486 }
00487
00488
00489
00490
00491
00492
00493
00494 void
00495 View::setPermutables(
00496 const std::vector< PermutableSharedPtr > & inSource) throw(Error) {
00497 std::vector< PermutableSharedPtr >::const_iterator entry = inSource.begin();
00498 std::vector< PermutableSharedPtr >::const_iterator end = inSource.end();
00499 for(; entry != end; ++entry )
00500 {
00501 try
00502 {
00503 addPermutable( *entry );
00504 }
00505 catch( Error &e )
00506 {
00507 e.setCurrentLocation(
00508 __FUNCTION__, __FILE__, __LINE__ );
00509 throw;
00510 }
00511 }
00512 }
00513
00514
00515
00516
00517
00518
00519
00520 bool
00521 View::addPermutable(
00522 const PermutableSharedPtr & inPermutable ) throw(Error) {
00523 if( !inPermutable )
00524 {
00525 Error e( eMessageIdErrorPointerToItemDoesNotExist,
00526 __FUNCTION__, __FILE__, __LINE__ );
00527 e.saveContextData("Pointer to the permutable object does not exist", inPermutable);
00528 throw e;
00529 }
00530 if( inPermutable ) {
00531 mPermutables.push_back( inPermutable );
00532 return true;
00533 }
00534 else {
00535 return false;
00536 }
00537 }
00538
00539
00540
00541
00542
00543
00544
00545 void
00546 View::setInterfaceJoinedInfos( const std::vector< InterfaceJoinedInfoSharedPtr >
00547 & inSource ) throw(Error) {
00548 std::vector< InterfaceJoinedInfoSharedPtr >::const_iterator entry = inSource.begin();
00549 std::vector< InterfaceJoinedInfoSharedPtr >::const_iterator end = inSource.end();
00550 for(; entry != end; ++entry )
00551 {
00552 try
00553 {
00554 addInterfaceJoinedInfo( *entry );
00555 }
00556 catch( Error &e )
00557 {
00558 e.setCurrentLocation(
00559 __FUNCTION__, __FILE__, __LINE__ );
00560 throw;
00561 }
00562 }
00563 }
00564
00565
00566
00567
00568
00569
00570
00571 bool
00572 View::addInterfaceJoinedInfo(
00573 const InterfaceJoinedInfoSharedPtr & inJoinedInfo ) throw(Error) {
00574 if( !inJoinedInfo )
00575 {
00576 Error e( eMessageIdErrorPointerToItemDoesNotExist,
00577 __FUNCTION__, __FILE__, __LINE__ );
00578 e.saveContextData("Pointer to the joined info object does not exist", inJoinedInfo);
00579 throw e;
00580 }
00581 if( inJoinedInfo ) {
00582 mInterfaceJoinedInfos.push_back( inJoinedInfo );
00583 return true;
00584 }
00585 else {
00586 return false;
00587 }
00588 }
00589
00590
00591
00592
00593
00594
00595
00596
00597 void
00598 View::setInterfaceAttributes(
00599 const InterfaceAttributesSharedPtr & inSource) throw() {
00600 mAttributes = inSource;
00601 }
00602
00603
00604
00605
00606
00607
00608 void
00609 View::setSimulate(const SimulateSharedPtr & inSource ) throw() {
00610 mSimulate = inSource;
00611 }
00612
00613
00614
00615
00616
00617
00618 void
00619 View::setTiming(const TimingSharedPtr & inSource ) throw() {
00620 mTiming = inSource;
00621 }
00622
00623
00624 View::View()
00625 : Commentable(),
00626 Extern(),
00627 Nameable(),
00628 ParentedObject<Cell>(),
00629 PropertyContainer(),
00630 Renamable(),
00631 SelfReferencing<View>(),
00632 Visitable(),
00633 UserDataContainer(),
00634 StatusContainer(),
00635 mParameters( new ParameterMap() ),
00636 mMyContext( mParameters->getNewContext() ),
00637 mInstanceSymTab(),
00638 mNetSymTab(),
00639 mPortSymTab(),
00640 mType(eTypeNetlist),
00641 mPermutables(),
00642 mInterfaceJoinedInfos(),
00643 mAttributes(),
00644 mSimulate(),
00645 mTiming() {
00646 }
00647
00648 View::~View() throw() {
00649 if( !getName().empty() )
00650 {
00651 log("View %s is being destroyed.\n",
00652 getName().c_str());
00653 }
00654 mNetSymTab.applyOnAll( boost::bind( boost::mem_fn(
00655 &Net::disconnect), _1 ));
00656 mNetSymTab.clear();
00657 mPortSymTab.clear();
00658 mInstanceSymTab.clear();
00659 mPermutables.clear();
00660 mInterfaceJoinedInfos.clear();
00661 }
00662
00663 #ifdef GENOM_SERIALIZATION
00664 template<class Archive> void
00665 View::load( Archive &ar, unsigned int ) {
00666 ar & boost::serialization::base_object<Extern>( *this );
00667 ar & boost::serialization::base_object<Nameable>( *this );
00668 ar & boost::serialization::base_object<PropertyContainer>(*this);
00669 ar & boost::serialization::base_object<Renamable>(*this);
00670 ar & boost::serialization::base_object<
00671 SelfReferencing<View> >(*this);
00672 ar & boost::serialization::base_object<Visitable>(*this);
00673 ar & mInstanceSymTab;
00674 ar & mNetSymTab;
00675 ar & mPortSymTab;
00676 ar & mType;
00677 std::map< std::string,ParameterSharedPtr > params;
00678 ar & params;
00679 mParameters->registerContext( mMyContext );
00680 std::map< std::string,ParameterSharedPtr >::iterator
00681 it = params.begin();
00682 std::map< std::string,ParameterSharedPtr >::iterator
00683 end = params.end();
00684 for(; it != end; ++it )
00685 {
00686 mParameters->set( mMyContext, (*it).first, (*it).second );
00687 }
00688 }
00689
00690 template<class Archive> void
00691 View::save( Archive &ar, unsigned int ) const {
00692 ar & boost::serialization::base_object<Extern>( *this );
00693 ar & boost::serialization::base_object<Nameable>( *this );
00694 ar & boost::serialization::base_object<PropertyContainer>(*this);
00695 ar & boost::serialization::base_object<Renamable>(*this);
00696 ar & boost::serialization::base_object<
00697 SelfReferencing<View> >(*this);
00698 ar & boost::serialization::base_object<Visitable>(*this);
00699 ar & mInstanceSymTab;
00700 ar & mNetSymTab;
00701 ar & mPortSymTab;
00702 ar & mType;
00703 std::map< std::string,ParameterSharedPtr > params;
00704 mParameters->getAllParameters( mMyContext, params );
00705 ar & params;
00706 }
00707
00708 void
00709 View::restoreActions() throw(Error) {
00710 try
00711 {
00712 mInstanceSymTab.applyOnAll(
00713 RestoredInstanceUpdater( getSharedThis() ) );
00714 mInstanceSymTab.applyOnAll( boost::bind( boost::mem_fn(
00715 &Net::setParent ), _1, getSharedThis()));
00716 mInstanceSymTab.applyOnAll( boost::bind( boost::mem_fn(
00717 &Port::setParent ), _1, getSharedThis()));
00718 }
00719 catch( Error &e )
00720 {
00721 e.setCurrentLocation(
00722 __FUNCTION__, __FILE__, __LINE__ );
00723 throw;
00724 }
00725 }
00726
00727
00728 template void
00729 View::load<boost::archive::binary_iarchive>(
00730 boost::archive::binary_iarchive & ar, const unsigned int);
00731
00732 template void
00733 View::save<boost::archive::binary_oarchive>(
00734 boost::archive::binary_oarchive & ar, const unsigned int) const;
00735
00736 #endif //GENOM_SERIALIZATION
00737
00738
00739 }
00740
00741 }