diff --git a/include/trick/DMTCP.hh b/include/trick/DMTCP.hh index 79b7ada6..52f92c8e 100644 --- a/include/trick/DMTCP.hh +++ b/include/trick/DMTCP.hh @@ -43,7 +43,7 @@ namespace Trick { std::string splitFilename( const std::string& str ); unsigned int dmtcp_ckpt_complete; - std::priority_queue dmtcp_checkpoint_jobs_queue ; + std::priority_queue dmtcp_checkpoint_jobs_queue ; // ** ignore this for checkpointing virtual int write_s_job_execution( FILE * fp ) ; virtual int instrument_job_before(Trick::JobData * instrument_job) ; diff --git a/include/trick/DataRecordGroup.hh b/include/trick/DataRecordGroup.hh index 2a46cc3b..424d37b7 100644 --- a/include/trick/DataRecordGroup.hh +++ b/include/trick/DataRecordGroup.hh @@ -94,7 +94,7 @@ namespace Trick { char ** variable_alias ; /** trick_units(--) */ /** Vector of buffers - one for every variable added with Trick::DataRecordGroup::add_variable.\n */ - std::vector rec_buffer; /**< trick_io(*io) trick_units(--) */ + std::vector rec_buffer; /**< trick_io(**) trick_units(--) */ /** Number of change variable names to save in a checkpoint.\n */ unsigned int num_change_variable_names ; /** trick_units(--) */ @@ -104,7 +104,7 @@ namespace Trick { char ** change_variable_alias ; /** trick_units(--) */ /** Vector of buffers - one for every change variable added with Trick::DataRecordGroup::add_change_variable.\n */ - std::vector change_buffer; /**< trick_io(*io) trick_units(--) */ + std::vector change_buffer; /**< trick_io(**) trick_units(--) */ /** Maximum records to hold in memory before writing.\n */ unsigned int max_num; /**< trick_io(*io) trick_units(--) */ diff --git a/include/trick/EventManager.hh b/include/trick/EventManager.hh index 68107a00..ee0b3dec 100644 --- a/include/trick/EventManager.hh +++ b/include/trick/EventManager.hh @@ -149,10 +149,10 @@ namespace Trick { unsigned int num_active_events ; /**< trick_io(*io) trick_units(--) */ /** All of the event processors, one per thread. */ - std::vector< Trick::EventProcessor * > event_processors ; + std::vector< Trick::EventProcessor * > event_processors ; /**< trick_io(**) */ /** All of the events that have been attached to jobs */ - std::vector< Trick::EventInstrument * > events_instrumented ; + std::vector< Trick::EventInstrument * > events_instrumented ; /**< trick_io(**) */ /** @brief Add user's event to manager's list of events; don't add it if it's already in list. diff --git a/include/trick/Executive.hh b/include/trick/Executive.hh index c2613826..640e1036 100644 --- a/include/trick/Executive.hh +++ b/include/trick/Executive.hh @@ -244,13 +244,7 @@ namespace Trick { int num_sim_objects ; /**< trick_units(--) */ /** List of all sim_objects that have been added to scheduler through add_sim_object().\n */ - std::vector sim_objects ; /**< trick_io(**) */ - - /** Count of how many sim_objects are written to the checkpoint.\n */ - int num_sim_objects_in_checkpoint ; /**< trick_units(--) */ - - /** Contains same info as the sim_objects vector but in a checkpointable form\n */ - Trick::SimObject ** sim_objects_for_checkpoint ; /**< trick_units(--) */ + std::vector sim_objects ; /**< trick_io(*io) trick_units(--) */ /** List of other schedulers in thes sim.\n */ std::vector other_schedulers ; /**< trick_io(**) */ diff --git a/include/trick/FrameDataRecordGroup.hh b/include/trick/FrameDataRecordGroup.hh index 6495394f..0bfb6763 100644 --- a/include/trick/FrameDataRecordGroup.hh +++ b/include/trick/FrameDataRecordGroup.hh @@ -56,7 +56,7 @@ namespace Trick { unsigned int thread_id ; /** Jobs this group is recording */ - std::vector< Trick::JobData *> rec_jobs ; + std::vector< Trick::JobData *> rec_jobs ; // trick_io(**) /** Time value to record with main frame. The main frame has already incremented time by the time data record is called. We need to record the time of the previous frame. */ diff --git a/include/trick/FrameLog.hh b/include/trick/FrameLog.hh index c4de9de6..7a443ec1 100644 --- a/include/trick/FrameLog.hh +++ b/include/trick/FrameLog.hh @@ -37,7 +37,7 @@ namespace Trick { bool frame_log_flag ; /**< trick_io(*io) trick_units(--) */ /** Data recording groups for logging user jobs.\n */ - std::vector< Trick::FrameDataRecordGroup *> drg_users ; /**< trick_io(*io) trick_units(--) */ + std::vector< Trick::FrameDataRecordGroup *> drg_users ; /**< trick_io(**) trick_units(--) */ /** Data recording group for logging trick jobs.\n */ Trick::FrameDataRecordGroup * drg_trick; /**< trick_io(*io) trick_units(--) */ /** Data recording group for logging frame/overrun time.\n trick_units(--) */ diff --git a/include/trick/IntegLoopScheduler.hh b/include/trick/IntegLoopScheduler.hh index 92df8c82..9cc5e3ea 100644 --- a/include/trick/IntegLoopScheduler.hh +++ b/include/trick/IntegLoopScheduler.hh @@ -107,7 +107,7 @@ namespace Trick { * The sim objects integrated by this IntegLoopScheduler. * This is public so it can be checkpointed and restored. */ - SimObjectVector sim_objects; //!< trick_io(**) + SimObjectVector sim_objects; //!< trick_io(*io) trick_units(--) // Member functions @@ -379,7 +379,7 @@ namespace Trick { /** * Empty a job queue in anticipation of the queue being rebuilt. - */ + */ void clear_queue (Trick::ScheduledJobQueue & job_queue); /** @@ -387,7 +387,7 @@ namespace Trick { * @return Iterator pointing to the object, * or to sim_objects.end() if not found. * @param sim_obj Object to be found. - */ + */ SimObjectVector::iterator find_sim_object ( Trick::SimObject & sim_obj); diff --git a/include/trick/IntegLoopSimObject.hh b/include/trick/IntegLoopSimObject.hh index eb7d6c1c..6d5c966d 100644 --- a/include/trick/IntegLoopSimObject.hh +++ b/include/trick/IntegLoopSimObject.hh @@ -1,3 +1,7 @@ +/* + PURPOSE: + (Trick Integration sim object) +*/ #ifndef INTEG_LOOP_SIMOBJECT_HH #define INTEG_LOOP_SIMOBJECT_HH @@ -15,7 +19,7 @@ class IntegLoopSimObject : public Trick::SimObject { public: - Trick::IntegLoopScheduler integ_sched ; + Trick::IntegLoopScheduler integ_sched ; // trick_io(*io) IntegLoopSimObject() : integ_sched(0.01, this) { add_jobs(0.01, 0) ; @@ -41,7 +45,6 @@ class IntegLoopSimObject : public Trick::SimObject { virtual int call_function( Trick::JobData * curr_job ) ; virtual double call_function_double( Trick::JobData * curr_job ) ; - Trick::Integrator * getIntegrator( Integrator_type Alg, unsigned int State_size ) { return integ_sched.getIntegrator(Alg , State_size) ; } diff --git a/include/trick/Master.hh b/include/trick/Master.hh index 7b43526f..c22ae057 100644 --- a/include/trick/Master.hh +++ b/include/trick/Master.hh @@ -203,7 +203,7 @@ namespace Trick { int num_slaves ; /**< trick_units(--) */ /** Vector of slaves tracked by the master.\n */ - std::vector< Trick::SlaveInfo * > slaves ; /**< trick_units(--) */ + std::vector< Trick::SlaveInfo * > slaves ; /**< trick_io(**) trick_units(--) */ /** @brief @userdesc Command to enable the master/slave synchronization. diff --git a/include/trick/MemoryManager.hh b/include/trick/MemoryManager.hh index 350df233..221a3441 100644 --- a/include/trick/MemoryManager.hh +++ b/include/trick/MemoryManager.hh @@ -1,3 +1,8 @@ +/* + PURPOSE: + (Memory Manager.) +*/ + #ifndef MEMORYMANAGEMENT_HH #define MEMORYMANAGEMENT_HH @@ -533,13 +538,13 @@ namespace Trick { @param addr The Address. */ ALLOC_INFO* get_alloc_info_of( void* addr); - + /** Get information for the allocation starting at the specified address. @param addr The Address. */ ALLOC_INFO* get_alloc_info_at( void* addr); - + /** Names an allocation in the ALLOC_INFO map to the incoming name. @param addr The Address. @@ -547,13 +552,21 @@ namespace Trick { */ int set_name_at( void* addr, const char * name); + /** + Adds a name of an allocation to the dependency list of allocations that are to be checkpointed. + This call is used by standard template library functions that create new allocations and + dependencies during the checkpoint process. + @param name The name of the allocation. + */ + void add_checkpoint_alloc_dependency(const char * name); + /** Opens a handle to the shared library file. The handles are used to look for io_src functions. @param name The name of the file to open. */ int add_shared_library_symbols( const char * file_name ); - + std::vector dlhandles ; /**< ** dynamic loader handle left open for all dl (dlsym) calls */ /** @@ -654,37 +667,61 @@ namespace Trick { bool hexfloat_checkpoint; /**< -- true = Represent floating point values as hexidecimal to preserve precision. false= Normal. */ bool expanded_arrays; /**< -- true = array element values are set in separate assignments. */ - ALLOC_INFO_MAP alloc_info_map; /**< -- Map of key-value pairs for each of the managed allocations. */ - VARIABLE_MAP variable_map; /**< -- Map of key-value pairs for each named-allocations. */ - ENUMERATION_MAP enumeration_map; /**< -- Enumeration map. */ - pthread_mutex_t mm_mutex; /**< -- Mutex to control access to memory manager maps */ + ALLOC_INFO_MAP alloc_info_map; /**< ** Map of key-value pairs for each of the managed allocations. */ + VARIABLE_MAP variable_map; /**< ** Map of key-value pairs for each named-allocations. */ + ENUMERATION_MAP enumeration_map; /**< ** Enumeration map. */ + pthread_mutex_t mm_mutex; /**< ** Mutex to control access to memory manager maps */ int alloc_info_map_counter ; /**< ** counter to assign unique ids to allocations as they are added to map */ int extern_alloc_info_map_counter ; /**< ** counter to assign unique ids to allocations as they are added to map */ + std::vector dependencies; /**< ** list of allocations used in a checkpoint. */ + std::vector stl_dependencies; /**< ** list of allocations known to be STL checkpoint allocations */ - void write_checkpoint( std::ostream& out_s, std::vector& dependencies); + void execute_checkpoint( std::ostream& out_s ); + + /** + Walks through allocation and allocates space for STLs + FIXME: I NEED DOCUMENTATION! + */ + void get_stl_dependencies( ALLOC_INFO* alloc_info ); + void get_stl_dependencies_in_class( std::string name, char* address, ATTRIBUTES* attr) ; + void get_stl_dependencies_in_arrayed_class( std::string name, + char* address, ATTRIBUTES* attr, int curr_dim, int offset) ; + void get_stl_dependencies_in_intrinsic( std::string name, + void* address, ATTRIBUTES* attr, int curr_dim, int offset) ; + + /** + Walks through allocations and restores STLs + FIXME: I NEED DOCUMENTATION! + */ + void restore_stls( ALLOC_INFO* alloc_info ); + void restore_stls_in_class( std::string name, char* address, ATTRIBUTES* attr) ; + void restore_stls_in_arrayed_class( std::string name, + char* address, ATTRIBUTES* attr, int curr_dim, int offset) ; + void restore_stls_in_intrinsic( std::string name, + void* address, ATTRIBUTES* attr, int curr_dim, int offset) ; /** FIXME: I NEED DOCUMENTATION! */ - void get_alloc_deps_in_allocation(std::vector& dependencies, ALLOC_INFO* alloc_info ); + void get_alloc_deps_in_allocation( ALLOC_INFO* alloc_info ); /** FIXME: I NEED DOCUMENTATION! */ - void get_alloc_deps_in_allocation( std::vector& dependencies, const char* var_name ); + void get_alloc_deps_in_allocation( const char* var_name ); /** FIXME: I NEED DOCUMENTATION! */ - void get_alloc_deps_in_class( std::vector& dependencies, char* address, ATTRIBUTES* attr); + void get_alloc_deps_in_class( char* address, ATTRIBUTES* attr); /** FIXME: I NEED DOCUMENTATION! */ - void get_alloc_deps_in_arrayed_class( std::vector& dependencies, char* address, ATTRIBUTES* attr, int curr_dim, int offset); + void get_alloc_deps_in_arrayed_class( char* address, ATTRIBUTES* attr, int curr_dim, int offset); /** FIXME: I NEED DOCUMENTATION! */ - void get_alloc_deps_in_intrinsic( std::vector& dependencies, void* address, ATTRIBUTES* attr, int curr_dim, int offset); + void get_alloc_deps_in_intrinsic( void* address, ATTRIBUTES* attr, int curr_dim, int offset); std::set< std::string > primitive_types ; /**< ** Names of primitive types. Used in add_attr_info */ std::map< std::string , std::string > template_name_map ; /**< ** Templates names => mangled attr names */ diff --git a/include/trick/MonteCarlo.hh b/include/trick/MonteCarlo.hh index bd87593f..b8a47867 100644 --- a/include/trick/MonteCarlo.hh +++ b/include/trick/MonteCarlo.hh @@ -339,19 +339,19 @@ namespace Trick { TCDevice data_connection_device; /**< \n trick_units(--) */ /** Runs to be dispatched. */ - std::deque runs; /**< \n trick_units(--) */ + std::deque runs; /**< \n trick_io(**) trick_units(--) */ /** Failed runs. */ - std::deque failed_runs; /**< \n trick_units(--) */ + std::deque failed_runs; /**< \n trick_io(**) trick_units(--) */ /** Valid ranges. */ - std::vector run_ranges; /**< \n trick_units(--) */ + std::vector run_ranges; /**< \n trick_io(**) trick_units(--) */ /** Variables. */ - std::vector variables; /**< \n trick_units(--) */ + std::vector variables; /**< \n trick_io(**) trick_units(--) */ /** Slaves. */ - std::vector slaves; /**< \n trick_units(--) */ + std::vector slaves; /**< \n trick_io(**) trick_units(--) */ /** Number of slaves. Exists for Variable Server access. */ int num_slaves; /**< \n trick_units(--) */ diff --git a/include/trick/UnitTest.hh b/include/trick/UnitTest.hh index 347e77fa..84cc7d8c 100644 --- a/include/trick/UnitTest.hh +++ b/include/trick/UnitTest.hh @@ -60,7 +60,7 @@ namespace Trick { std::string file_name ; /**< trick_units(--) trick_io(*i) */ /** Keeps lists of test results keyed by test_suite name.\n*/ - std::map< std::string , TestSuite > test_suites ; + std::map< std::string , TestSuite > test_suites ; // ** ignore /** @brief The constructor. diff --git a/include/trick/VariableServer.hh b/include/trick/VariableServer.hh index 479f0722..309ba6c3 100644 --- a/include/trick/VariableServer.hh +++ b/include/trick/VariableServer.hh @@ -276,16 +276,16 @@ namespace Trick { to this map by suspendPreCheckpointReload(). resumePostCheckpointReload() restores the pause state from this map. */ - std::map thread_pause_state_store; + std::map thread_pause_state_store; // ** ignore this /** Map thread id to the VariableServerThread object.\n */ - std::map < pthread_t , VariableServerThread * > var_server_threads ; + std::map < pthread_t , VariableServerThread * > var_server_threads ; /**< trick_io(**) */ /** Mutex to ensure only one thread manipulates the map of var_server_threads\n */ pthread_mutex_t map_mutex ; /**< trick_io(**) */ /** Map of additional listen threads created by create_tcp_socket.\n */ - std::map < pthread_t , VariableServerListenThread * > additional_listen_threads ; + std::map < pthread_t , VariableServerListenThread * > additional_listen_threads ; /**< trick_io(**) */ } ; diff --git a/include/trick/attributes.h b/include/trick/attributes.h index 3d6ead19..03f2b9b7 100644 --- a/include/trick/attributes.h +++ b/include/trick/attributes.h @@ -119,6 +119,11 @@ typedef struct ATTRIBUTES_tag { INDEX index[TRICK_MAX_INDEX]; /**< -- An array of array-index information or bit-field information. Is only meaningful if num_index > 0 or if type is a bit field type. */ + void (*checkpoint_stl)(void * start_address, const char * obj_name , const char * var_name) ; + void (*post_checkpoint_stl)(void * start_address, const char * obj_name , const char * var_name) ; + void (*restore_stl)(void * start_address, const char * obj_name , const char * var_name) ; + void (*clear_stl)(void * start_address) ; + } ATTRIBUTES; typedef struct { diff --git a/include/trick/checkpoint_is_stl_container.hh b/include/trick/checkpoint_is_stl_container.hh new file mode 100644 index 00000000..4b4da6ee --- /dev/null +++ b/include/trick/checkpoint_is_stl_container.hh @@ -0,0 +1,44 @@ +/* + PURPOSE: (Test if item is an STL) +*/ + +#ifndef CHECKPOINT_IS_STL_CONTAINER +#define CHECKPOINT_IS_STL_CONTAINER + +#include +#include +#include +#include + +template +struct is_stl_container { + static const bool value = false; +}; + +template +struct is_stl_container > { + static const bool value = true; +}; + +template +struct is_stl_container > { + static const bool value = true; +}; + +template +struct is_stl_container > { + static const bool value = true; +}; + +template +struct is_stl_container > { + static const bool value = true; +}; + +template +struct is_stl_container > { + static const bool value = true; +}; + +#endif + diff --git a/include/trick/checkpoint_map.hh b/include/trick/checkpoint_map.hh index 2d2691a2..29340207 100644 --- a/include/trick/checkpoint_map.hh +++ b/include/trick/checkpoint_map.hh @@ -47,11 +47,13 @@ int checkpoint_map_stl(STL & in_map , std::string object_name , std::string var_ sprintf(var_declare, "%s %s_%s_keys[%d]" , abi::__cxa_demangle(typeid(*keys).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str(), cont_size) ; keys = (typename STL::key_type *)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_keys").c_str()) ; //message_publish(1, "HERE with %s\n", var_declare) ; sprintf(var_declare, "%s %s_%s_data[%d]" , abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str(), cont_size) ; items = (typename STL::mapped_type *)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_data").c_str()) ; //message_publish(1, "HERE with %s\n", var_declare) ; /* copy the contents of the map the 2 arrays */ @@ -91,11 +93,13 @@ int checkpoint_map_stl_key_string(STL & in_map , std::string object_name , std:: if ( cont_size > 0 ) { sprintf(var_declare, "char * %s_%s_keys[%d]" , object_name.c_str(), var_name.c_str() , cont_size) ; keys = (char **)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_keys").c_str()) ; //message_publish(1, "STRING KEY HERE with %s\n", var_declare) ; sprintf(var_declare, "%s %s_%s_data[%d]" , abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str() , cont_size) ; items = (typename STL::mapped_type *)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_data").c_str()) ; //message_publish(1, "STRING KEY HERE with %s\n", var_declare) ; /* copy the contents of the map the 2 arrays */ @@ -136,10 +140,12 @@ int checkpoint_map_stl_data_string(STL & in_map , std::string object_name , std: sprintf(var_declare, "%s %s_%s_keys[%d]" , abi::__cxa_demangle(typeid(*keys).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str() , cont_size) ; keys = (typename STL::key_type *)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_keys").c_str()) ; //message_publish(1, "STRING KEY HERE with %s\n", var_declare) ; sprintf(var_declare, "char * %s_%s_data[%d]" , object_name.c_str(), var_name.c_str() , cont_size) ; items = (char **)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_data").c_str()) ; //message_publish(1, "STRING KEY HERE with %s\n", var_declare) ; /* copy the contents of the map the 2 arrays */ @@ -179,10 +185,12 @@ int checkpoint_map_stl_strings(STL & in_map , std::string object_name , std::str if ( cont_size > 0 ) { sprintf(var_declare, "char * %s_%s_keys[%d]" , object_name.c_str(), var_name.c_str() , cont_size) ; keys = (char **)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_keys").c_str()) ; //message_publish(1, "STRING KEY HERE with %s\n", var_declare) ; sprintf(var_declare, "char * %s_%s_data[%d]" , object_name.c_str(), var_name.c_str() , cont_size) ; items = (char **)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_data").c_str()) ; //message_publish(1, "STRING KEY HERE with %s\n", var_declare) ; /* copy the contents of the map the 2 arrays */ @@ -239,13 +247,13 @@ int restore_map_stl(STL & in_map , std::string object_name , std::string var_nam //message_publish(1, "in regular map template restore\n") ; - in_map.clear() ; std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); keys_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_keys")).c_str()) ; items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_data")).c_str()) ; if ( keys_ref != NULL && items_ref != NULL ) { + in_map.clear() ; keys = (typename STL::key_type *)keys_ref->address ; items = (typename STL::mapped_type *)items_ref->address ; cont_size = get_size((char *)keys) ; @@ -255,7 +263,7 @@ int restore_map_stl(STL & in_map , std::string object_name , std::string var_nam } delete_stl( in_map , object_name , var_name ) ; - } + } return 0 ; } @@ -280,13 +288,13 @@ int restore_map_stl_key_string( STL & in_map , std::string object_name , std::st char ** keys ; typename STL::mapped_type * items ; - in_map.clear() ; std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); keys_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_keys")).c_str()) ; items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_data")).c_str()) ; if ( keys_ref != NULL && items_ref != NULL ) { + in_map.clear() ; keys = (char **)keys_ref->address ; items = (typename STL::mapped_type *)items_ref->address ; cont_size = get_size((char *)keys) ; @@ -296,7 +304,7 @@ int restore_map_stl_key_string( STL & in_map , std::string object_name , std::st } delete_stl( in_map , object_name , var_name ) ; - } + } return 0 ; } @@ -322,13 +330,13 @@ int restore_map_stl_data_string(STL & in_map , std::string object_name , std::st //message_publish(1, "in specialized map template restore\n") ; - in_map.clear() ; std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); keys_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_keys")).c_str()) ; items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_data")).c_str()) ; if ( keys_ref != NULL && items_ref != NULL ) { + in_map.clear() ; keys = (typename STL::key_type *)keys_ref->address ; items = (char **)items_ref->address ; cont_size = get_size((char *)keys) ; @@ -338,7 +346,7 @@ int restore_map_stl_data_string(STL & in_map , std::string object_name , std::st } delete_stl( in_map , object_name , var_name ) ; - } + } return 0 ; } @@ -369,13 +377,13 @@ int restore_map_stl_strings(STL & in_map , std::string object_name , std::string of items that were stored in the checkpoint. Knowing the size, we can restore the map from the 2 arrays. This template only works for string map keys. */ - in_map.clear() ; std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); keys_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_keys")).c_str()) ; items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_data")).c_str()) ; if ( keys_ref != NULL && items_ref != NULL ) { + in_map.clear() ; keys = (char **)keys_ref->address ; items = (char **)items_ref->address ; cont_size = get_size((char *)keys) ; diff --git a/include/trick/checkpoint_pair.hh b/include/trick/checkpoint_pair.hh index 0f7b6156..ad75230e 100644 --- a/include/trick/checkpoint_pair.hh +++ b/include/trick/checkpoint_pair.hh @@ -44,10 +44,12 @@ int checkpoint_stl(std::pair & in_stl , std::string obj sprintf(var_declare, "%s %s_%s_first[1]" , abi::__cxa_demangle(typeid(*first).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str()) ; first = (FIRST_TYPE *)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_first").c_str()) ; sprintf(var_declare, "%s %s_%s_second[1]" , abi::__cxa_demangle(typeid(*second).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str()) ; second = (SECOND_TYPE *)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_second").c_str()) ; first[0] = in_stl.first ; second[0] = in_stl.second ; @@ -68,9 +70,11 @@ int checkpoint_stl(std::pair & in_stl , std::string obj sprintf(var_declare, "%s %s_%s_first[1]" , abi::__cxa_demangle(typeid(*first).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str()) ; first = (FIRST_TYPE *)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_first").c_str()) ; sprintf(var_declare, "char * %s_%s_second[1]" , object_name.c_str(), var_name.c_str()) ; second = (char **)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_second").c_str()) ; first[0] = in_stl.first ; second[0] = (char *)(in_stl.second.c_str()) ; @@ -90,10 +94,12 @@ int checkpoint_stl(std::pair & in_stl , std::string ob sprintf(var_declare, "char * %s_%s_first[1]", object_name.c_str(), var_name.c_str()) ; first = (char **)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_first").c_str()) ; sprintf(var_declare, "%s %s_%s_second[1]" , abi::__cxa_demangle(typeid(*second).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str()) ; second = (SECOND_TYPE *)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_second").c_str()) ; first[0] = (char *)(in_stl.first.c_str()) ; second[0] = in_stl.second ; diff --git a/include/trick/checkpoint_queue.hh b/include/trick/checkpoint_queue.hh index e892bdc5..bbdb4626 100644 --- a/include/trick/checkpoint_queue.hh +++ b/include/trick/checkpoint_queue.hh @@ -52,6 +52,7 @@ int checkpoint_stl(std::queue & in_stl , std::string object_name , st sprintf(var_declare, "%s %s_%s[%d]" , abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str(), cont_size) ; items = (ITEM_TYPE *)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name).c_str()) ; //message_publish(1, "CHECKPOINT_STL_STACK with %s\n", var_declare) ; temp_queue = in_stl ; @@ -84,6 +85,7 @@ int checkpoint_stl(std::priority_queue & in_stl , std::string object_ sprintf(var_declare, "%s %s_%s[%d]" , abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str(), cont_size) ; items = (ITEM_TYPE *)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name).c_str()) ; //message_publish(1, "CHECKPOINT_STL_STACK with %s\n", var_declare) ; temp_queue = in_stl ; @@ -117,6 +119,7 @@ int checkpoint_stl(std::priority_queue, std::g sprintf(var_declare, "%s %s_%s[%d]" , abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str(), cont_size) ; items = (ITEM_TYPE *)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name).c_str()) ; //message_publish(1, "CHECKPOINT_STL_STACK with %s\n", var_declare) ; temp_queue = in_stl ; @@ -147,22 +150,22 @@ int restore_queue_stl(STL & in_stl , std::string object_name , std::string var_n //message_publish(1, "RESTORE_STL_queue %s_%s\n", object_name.c_str() , var_name.c_str()) ; - cont_size = in_stl.size() ; - for ( ii = 0 ; ii < cont_size ; ii++ ) { - in_stl.pop() ; - } - items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name).c_str()) ; if ( items_ref != NULL ) { + cont_size = in_stl.size() ; + for ( ii = 0 ; ii < cont_size ; ii++ ) { + in_stl.pop() ; + } + items = (typename STL::value_type *)items_ref->address ; cont_size = get_size((char *)items) ; for ( ii = 0 ; ii < cont_size ; ii++ ) { in_stl.push( items[ii] ) ; - } + } delete_stl( in_stl , object_name , var_name ) ; - } + } return 0 ; } @@ -179,22 +182,18 @@ int restore_queue_stl_string(STL & in_stl , std::string object_name , std::strin //message_publish(1, "RESTORE_STL_queue %s_%s\n", object_name.c_str() , var_name.c_str()) ; - cont_size = in_stl.size() ; - for ( ii = 0 ; ii < cont_size ; ii++ ) { - in_stl.pop() ; - } - items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name).c_str()) ; if ( items_ref != NULL ) { + STL().swap(in_stl) ; items = (char **)items_ref->address ; cont_size = get_size((char *)items) ; for ( ii = 0 ; ii < cont_size ; ii++ ) { in_stl.push( items[ii] ) ; - } + } delete_stl( in_stl , object_name , var_name ) ; - } + } return 0 ; } diff --git a/include/trick/checkpoint_sequence_stl.hh b/include/trick/checkpoint_sequence_stl.hh index f6baedf0..a5b61b1f 100644 --- a/include/trick/checkpoint_sequence_stl.hh +++ b/include/trick/checkpoint_sequence_stl.hh @@ -14,14 +14,249 @@ #include #include +#include +#include +#include + #ifdef __GNUC__ #include #endif +#include + #include "trick/memorymanager_c_intf.h" #include "trick/message_proto.h" +#include "checkpoint_is_stl_container.hh" -#ifndef TRICK_ICG +/* =================================================================================================*/ + +// Forward declare all of the specialized templates that can be used in checkpoint_sequence_stl_stl +template ::value>::type* = nullptr > +int checkpoint_stl(std::vector & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int checkpoint_stl(std::vector & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int checkpoint_stl(std::list & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int checkpoint_stl(std::list & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int checkpoint_stl(std::deque & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int checkpoint_stl(std::deque & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int checkpoint_stl(std::set & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int checkpoint_stl(std::set & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int checkpoint_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int checkpoint_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) ; +// End forward declarations. + +template +int checkpoint_sequence_stl_intrinsic(STL & in_stl , std::string object_name , std::string var_name ) { + + unsigned int ii ; + unsigned int cont_size ; + char var_declare[128] ; + int status ; + + typename STL::value_type * items = NULL ; + typename STL::iterator it ; + typename STL::iterator end ; + + message_publish(1, "%s\n", __PRETTY_FUNCTION__) ; + + cont_size = in_stl.size() ; + std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); + + if ( cont_size > 0 ) { + + sprintf(var_declare, "%s %s_%s[%d]" , + abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str(), cont_size) ; + items = (typename STL::value_type *)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name).c_str()) ; + //message_publish(1, "CHECKPOINT_SEQUENCE_STL with %s\n", var_declare) ; + + /* copy the contents of the stl */ + for ( ii = 0 , it = in_stl.begin() , end = in_stl.end() ; it != end ; it++ , ii++ ) { + items[ii] = *it ; + } + + } + + return 0 ; +} + +template +int checkpoint_sequence_stl_string(STL & in_stl , std::string object_name , std::string var_name ) { + + unsigned int ii ; + unsigned int cont_size ; + char var_declare[128] ; + + const char ** items ; + typename STL::iterator it ; + typename STL::iterator end ; + + + cont_size = in_stl.size() ; + std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); + + if ( cont_size > 0 ) { + + sprintf(var_declare, "char * %s_%s[%d]" , object_name.c_str(), var_name.c_str() , cont_size) ; + items = (const char **)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name).c_str()) ; + //message_publish(1, "CHECKPOINT_SEQUENCE_STL_STRING with %s\n", var_declare) ; + + /* copy the contents of the vector */ + for ( ii = 0 , it = in_stl.begin() , end = in_stl.end() ; it != end ; it++ , ii++ ) { + items[ii] = it->c_str() ; + } + } + + return 0 ; +} + +template +int checkpoint_sequence_stl_stl(STL & in_stl , std::string object_name , std::string var_name ) { + + unsigned int ii ; + unsigned int cont_size ; + char var_declare[128] ; + + const char ** items ; + typename STL::iterator it ; + typename STL::iterator end ; + + + cont_size = in_stl.size() ; + std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); + + message_publish(1, "%s\n", __PRETTY_FUNCTION__) ; + + if ( cont_size > 0 ) { + + sprintf(var_declare, "char * %s_%s[%d]" , object_name.c_str(), var_name.c_str() , cont_size) ; + items = (const char **)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name).c_str()) ; + //message_publish(1, "CHECKPOINT_SEQUENCE_STL_STL with %s\n", var_declare) ; + + /* create the names of the sub stl checkpoint names we're going to be using */ + for ( ii = 0 , it = in_stl.begin() , end = in_stl.end() ; it != end ; it++ , ii++ ) { + char sub_elements[128] ; + sprintf(sub_elements, "%s_%s_%d", object_name.c_str(), var_name.c_str() , ii) ; + items[ii] = TMM_strdup(sub_elements) ; + sprintf(sub_elements, "%s_%s_%d_name", object_name.c_str(), var_name.c_str() , ii) ; + set_alloc_name_at((void *)items[ii], sub_elements) ; + TMM_add_checkpoint_alloc_dependency(sub_elements) ; + + char index_string[16] ; + sprintf(index_string, "%d", ii) ; + message_publish(1, "recursive call to checkpoint_stl %s\n", __PRETTY_FUNCTION__) ; + checkpoint_stl( (*it) , object_name + "_" + var_name , std::string(index_string) ) ; + } + } + return 0 ; +} + +// ----------- +// std::vector + +// This template is only enabled if the items in the vector are an STL +template ::value>::type* = nullptr > +int checkpoint_stl(std::vector & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_stl_stl( in_stl , object_name , var_name ) ; +} + +// This template is only enabled if the items in the vector are NOT an STL, except for std::string +template ::value>::type* = nullptr > +int checkpoint_stl(std::vector & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; +} + +// Specialized routines for strings. found in checkpoint_sequence.cpp +int checkpoint_stl(std::vector & in_vector , std::string object_name , std::string var_name ) ; + +// ----------- +// std::list + +template ::value>::type* = nullptr > +int checkpoint_stl(std::list & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_stl_stl( in_stl , object_name , var_name ) ; +} + +// This template is only enabled if the items in the list are NOT an STL, except for std::string +template ::value>::type* = nullptr > +int checkpoint_stl(std::list & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; +} + +// Specialized routines for strings. found in checkpoint_sequence.cpp +int checkpoint_stl(std::list & in_list , std::string object_name , std::string var_name ) ; + +// ----------- +// std::deque + +template ::value>::type* = nullptr > +int checkpoint_stl(std::deque & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_stl_stl( in_stl , object_name , var_name ) ; +} + +// This template is only enabled if the items in the deque are NOT an STL, except for std::string +template ::value>::type* = nullptr > +int checkpoint_stl(std::deque & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; +} + +// Specialized routines for strings. found in checkpoint_sequence.cpp +int checkpoint_stl(std::deque & in_vector , std::string object_name , std::string var_name ) ; + +// ----------- +// std::set + +template ::value>::type* = nullptr > +int checkpoint_stl(std::set & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_stl_stl( in_stl , object_name , var_name ) ; +} + +// This template is only enabled if the items in the set are NOT an STL, except for std::string +template ::value>::type* = nullptr > +int checkpoint_stl(std::set & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; +} + +// Specialized routines for strings. found in checkpoint_sequence.cpp +int checkpoint_stl(std::set & in_vector , std::string object_name , std::string var_name ) ; + +// ----------- +// std::multiset + +template ::value>::type* = nullptr > +int checkpoint_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_stl_stl( in_stl , object_name , var_name ) ; +} + +// This template is only enabled if the items in the multiset are NOT an STL, except for std::string +template ::value>::type* = nullptr > +int checkpoint_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; +} + +// Specialized routines for strings. found in checkpoint_sequence.cpp +int checkpoint_stl(std::multiset & in_vector , std::string object_name , std::string var_name ) ; + +/* =================================================================================================*/ template int delete_sequence_stl(STL & in_stl __attribute__ ((unused)), std::string object_name , std::string var_name ) { @@ -60,75 +295,48 @@ int delete_stl(std::multiset & in_stl , std::string object_name , std return delete_sequence_stl( in_stl , object_name , var_name ) ; } -template -int checkpoint_sequence_stl(STL & in_stl , std::string object_name , std::string var_name ) { - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; - int status ; +/* =================================================================================================*/ - typename STL::value_type * items = NULL ; - typename STL::iterator it ; - typename STL::iterator end ; +// Forward declare all of the specialized templates that can be used in checkpoint_sequence_stl_stl +template ::value>::type* = nullptr > +int restore_stl(std::vector & in_stl , std::string object_name , std::string var_name ) ; - cont_size = in_stl.size() ; - std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); +template ::value>::type* = nullptr > +int restore_stl(std::vector & in_stl , std::string object_name , std::string var_name ) ; - if ( cont_size > 0 ) { +template ::value>::type* = nullptr > +int restore_stl(std::list & in_stl , std::string object_name , std::string var_name ) ; - sprintf(var_declare, "%s %s_%s[%d]" , - abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str(), cont_size) ; - items = (typename STL::value_type *)TMM_declare_var_s(var_declare) ; - //message_publish(1, "CHECKPOINT_SEQUENCE_STL with %s\n", var_declare) ; +template ::value>::type* = nullptr > +int restore_stl(std::list & in_stl , std::string object_name , std::string var_name ) ; - /* copy the contents of the stl */ - for ( ii = 0 , it = in_stl.begin() , end = in_stl.end() ; it != end ; it++ , ii++ ) { - items[ii] = *it ; - } +template ::value>::type* = nullptr > +int restore_stl(std::deque & in_stl , std::string object_name , std::string var_name ) ; - } +template ::value>::type* = nullptr > +int restore_stl(std::deque & in_stl , std::string object_name , std::string var_name ) ; - return 0 ; -} +template ::value>::type* = nullptr > +int restore_stl(std::set & in_stl , std::string object_name , std::string var_name ) ; -template -int checkpoint_sequence_stl_string(STL & in_stl , std::string object_name , std::string var_name ) { +template ::value>::type* = nullptr > +int restore_stl(std::set & in_stl , std::string object_name , std::string var_name ) ; - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; +template ::value>::type* = nullptr > +int restore_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) ; - const char ** items ; - typename STL::iterator it ; - typename STL::iterator end ; +template ::value>::type* = nullptr > +int restore_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) ; +// End forward declarations. - - cont_size = in_stl.size() ; - std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); - - if ( cont_size > 0 ) { - - sprintf(var_declare, "char * %s_%s[%d]" , object_name.c_str(), var_name.c_str() , cont_size) ; - items = (const char **)TMM_declare_var_s(var_declare) ; - //message_publish(1, "CHECKPOINT_SEQUENCE_STL_STRING with %s\n", var_declare) ; - - /* copy the contents of the vector */ - for ( ii = 0 , it = in_stl.begin() , end = in_stl.end() ; it != end ; it++ , ii++ ) { - items[ii] = it->c_str() ; - } - } - - return 0 ; -} - -/* Find the arrays the map data was stored in the checkpoint using ref_attributes +/* Find the arrays the map data was stored in the checkpoint using ref_attributes From the address of the resulting ref_attributes, we can figure out the number of items that were stored in the checkpoint. Knowing the size, we can restore - the map from the 2 arrays. + the map from the 2 arrays. */ template -int restore_sequence_stl(STL & in_stl , std::string object_name , std::string var_name ) { +int restore_sequence_stl_intrinsic(STL & in_stl , std::string object_name , std::string var_name ) { unsigned int ii ; unsigned int cont_size ; @@ -139,19 +347,19 @@ int restore_sequence_stl(STL & in_stl , std::string object_name , std::string va //message_publish(1, "RESTORE_SEQUENCE_STL %s_%s\n", object_name.c_str() , var_name.c_str()) ; - in_stl.clear() ; items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name).c_str()) ; if ( items_ref != NULL ) { + in_stl.clear() ; items = (typename STL::value_type *)items_ref->address ; cont_size = get_size((char *)items) ; for ( ii = 0 ; ii < cont_size ; ii++ ) { in_stl.insert( in_stl.end(), items[ii] ) ; - } + } delete_stl( in_stl , object_name , var_name ) ; - } + } return 0 ; } @@ -168,11 +376,11 @@ int restore_sequence_stl_string(STL & in_stl , std::string object_name , std::st //message_publish(1, "in specialized vector template restore\n") ; - in_stl.clear() ; items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name).c_str()) ; if ( items_ref != NULL ) { + in_stl.clear() ; items = (char **)items_ref->address ; cont_size = get_size((char *)items) ; @@ -185,67 +393,123 @@ int restore_sequence_stl_string(STL & in_stl , std::string object_name , std::st return 0 ; } -// General routines for all types but strings -template -int checkpoint_stl(std::vector & in_stl , std::string object_name , std::string var_name ) { - return checkpoint_sequence_stl( in_stl , object_name , var_name ) ; +template +int restore_sequence_stl_stl(STL & in_stl , std::string object_name , std::string var_name ) { + + unsigned int ii ; + unsigned int cont_size ; + + REF2 * items_ref ; + char ** items ; + std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); + + //message_publish(1, "%s\n", __PRETTY_FUNCTION__) ; + + items_ref = ref_attributes((char *)(object_name + "_" + var_name).c_str()) ; + + if ( items_ref != NULL ) { + in_stl.clear() ; + items = (char **)items_ref->address ; + cont_size = get_size((char *)items) ; + + for ( ii = 0 ; ii < cont_size ; ii++ ) { + typename STL::value_type vt ; + char index_string[16] ; + sprintf(index_string, "%d", ii) ; + restore_stl(vt, object_name + "_" + var_name , std::string(index_string)) ; + in_stl.insert( in_stl.end(), vt ) ; + } + delete_stl( in_stl , object_name , var_name ) ; + } + + return 0 ; } -template -int checkpoint_stl(std::list & in_stl , std::string object_name , std::string var_name ) { - return checkpoint_sequence_stl( in_stl , object_name , var_name ) ; -} +// ----------- +// std::vector -template -int checkpoint_stl(std::deque & in_stl , std::string object_name , std::string var_name ) { - return checkpoint_sequence_stl( in_stl , object_name , var_name ) ; -} - -template -int checkpoint_stl(std::set & in_stl , std::string object_name , std::string var_name ) { - return checkpoint_sequence_stl( in_stl , object_name , var_name ) ; -} - -template -int checkpoint_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) { - return checkpoint_sequence_stl( in_stl , object_name , var_name ) ; -} - -template +// This template is only enabled if the items in the vector are an STL +template ::value>::type* = nullptr > int restore_stl(std::vector & in_stl , std::string object_name , std::string var_name ) { - return restore_sequence_stl( in_stl , object_name , var_name ) ; + return restore_sequence_stl_stl( in_stl , object_name , var_name ) ; } -template -int restore_stl(std::list & in_stl , std::string object_name , std::string var_name ) { - return restore_sequence_stl( in_stl , object_name , var_name ) ; +// This template is only enabled if the items in the vector are NOT an STL, except for std::string +template ::value>::type* = nullptr > +int restore_stl(std::vector & in_stl , std::string object_name , std::string var_name ) { + return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; } -template -int restore_stl(std::deque & in_stl , std::string object_name , std::string var_name ) { - return restore_sequence_stl( in_stl , object_name , var_name ) ; -} - -template -int restore_stl(std::set & in_stl , std::string object_name , std::string var_name ) { - return restore_sequence_stl( in_stl , object_name , var_name ) ; -} - -template -int restore_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) { - return restore_sequence_stl( in_stl , object_name , var_name ) ; -} // Specialized routines for strings. -int checkpoint_stl(std::vector & in_vector , std::string object_name , std::string var_name ) ; -int checkpoint_stl(std::list & in_vector , std::string object_name , std::string var_name ) ; -int checkpoint_stl(std::deque & in_vector , std::string object_name , std::string var_name ) ; -int checkpoint_stl(std::set & in_vector , std::string object_name , std::string var_name ) ; -int checkpoint_stl(std::multiset & in_vector , std::string object_name , std::string var_name ) ; int restore_stl(std::vector & in_vector , std::string object_name , std::string var_name ) ; -int restore_stl(std::list & in_vector , std::string object_name , std::string var_name ) ; -int restore_stl(std::deque & in_vector , std::string object_name , std::string var_name ) ; -int restore_stl(std::set & in_vector , std::string object_name , std::string var_name ) ; -int restore_stl(std::multiset & in_vector , std::string object_name , std::string var_name ) ; -#endif + +// ----------- +// std::list + +// This template is only enabled if the items in the list are an STL +template ::value>::type* = nullptr > +int restore_stl(std::list & in_stl , std::string object_name , std::string var_name ) { + return restore_sequence_stl_stl( in_stl , object_name , var_name ) ; +} + +// This template is only enabled if the items in the list are NOT an STL, except for std::string +template ::value>::type* = nullptr > +int restore_stl(std::list & in_stl , std::string object_name , std::string var_name ) { + return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; +} + +int restore_stl(std::list & in_list , std::string object_name , std::string var_name ) ; + +// ----------- +// std::deque + +// This template is only enabled if the items in the deque are an STL +template ::value>::type* = nullptr > +int restore_stl(std::deque & in_stl , std::string object_name , std::string var_name ) { + return restore_sequence_stl_stl( in_stl , object_name , var_name ) ; +} + +// This template is only enabled if the items in the deque are NOT an STL, except for std::string +template ::value>::type* = nullptr > +int restore_stl(std::deque & in_stl , std::string object_name , std::string var_name ) { + return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; +} + +int restore_stl(std::deque & in_deque , std::string object_name , std::string var_name ) ; + +// ----------- +// std::set + +// This template is only enabled if the items in the set are an STL +template ::value>::type* = nullptr > +int restore_stl(std::set & in_stl , std::string object_name , std::string var_name ) { + return restore_sequence_stl_stl( in_stl , object_name , var_name ) ; +} + +// This template is only enabled if the items in the set are NOT an STL, except for std::string +template ::value>::type* = nullptr > +int restore_stl(std::set & in_stl , std::string object_name , std::string var_name ) { + return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; +} + +int restore_stl(std::set & in_set , std::string object_name , std::string var_name ) ; + +// ----------- +// std::multiset + +// This template is only enabled if the items in the multiset are an STL +template ::value>::type* = nullptr > +int restore_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) { + return restore_sequence_stl_stl( in_stl , object_name , var_name ) ; +} + +// This template is only enabled if the items in the multiset are NOT an STL, except for std::string +template ::value>::type* = nullptr > +int restore_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) { + return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; +} + +// Specialized routines for strings. +int restore_stl(std::multiset & in_multiset , std::string object_name , std::string var_name ) ; #endif diff --git a/include/trick/checkpoint_stack.hh b/include/trick/checkpoint_stack.hh index 5a7c28bb..1699943f 100644 --- a/include/trick/checkpoint_stack.hh +++ b/include/trick/checkpoint_stack.hh @@ -42,6 +42,7 @@ int checkpoint_stl(std::stack & in_stl , std::string object_name , st sprintf(var_declare, "%s %s_%s[%d]" , abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str(), cont_size) ; items = (ITEM_TYPE *)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name).c_str()) ; //message_publish(1, "CHECKPOINT_STL_STACK with %s\n", var_declare) ; temp_stack = in_stl ; @@ -72,22 +73,22 @@ int restore_stl(std::stack & in_stl , std::string object_name , std:: //message_publish(1, "RESTORE_STL_STACK %s_%s\n", object_name.c_str() , var_name.c_str()) ; - cont_size = in_stl.size() ; - for ( ii = 0 ; ii < cont_size ; ii++ ) { - in_stl.pop() ; - } items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name).c_str()) ; if ( items_ref != NULL ) { + cont_size = in_stl.size() ; + for ( ii = 0 ; ii < cont_size ; ii++ ) { + in_stl.pop() ; + } items = (ITEM_TYPE *)items_ref->address ; cont_size = get_size((char *)items) ; for ( ii = cont_size - 1 ; ii < cont_size ; ii-- ) { in_stl.push( items[ii] ) ; - } + } delete_stl( in_stl , object_name , var_name ) ; - } + } return 0 ; } diff --git a/include/trick/checkpoint_trick_sequence_stl.hh b/include/trick/checkpoint_trick_sequence_stl.hh index 5d4a1fde..ba13092f 100644 --- a/include/trick/checkpoint_trick_sequence_stl.hh +++ b/include/trick/checkpoint_trick_sequence_stl.hh @@ -11,9 +11,7 @@ #include #include -#ifdef __GNUC__ -#include -#endif +#ifdef __GNUC__ #include #endif #include "trick/STLInterface.hh" #include "trick/memorymanager_c_intf.h" diff --git a/include/trick/memorymanager_c_intf.h b/include/trick/memorymanager_c_intf.h index 2d5ac9c3..0e38c891 100644 --- a/include/trick/memorymanager_c_intf.h +++ b/include/trick/memorymanager_c_intf.h @@ -76,6 +76,7 @@ void ref_free( REF2 *R ) ; int get_enumerated(const char* name, V_DATA* v_data) ; +void TMM_add_checkpoint_alloc_dependency(const char * name) ; #ifdef __cplusplus } #endif diff --git a/include/trick/parameter_types.h b/include/trick/parameter_types.h index 18769e60..de96c954 100644 --- a/include/trick/parameter_types.h +++ b/include/trick/parameter_types.h @@ -34,6 +34,7 @@ extern "C" { TRICK_ENUMERATED = 21, /* User defined type (enumeration) */ TRICK_STRUCTURED = 22, /* User defined type (struct/class) */ TRICK_OPAQUE_TYPE = 23, /* User defined type (where type details are as yet unknown) */ + TRICK_STL = 24, /* Standard template library type */ TRICK_NUMBER_OF_TYPES } TRICK_TYPE ; diff --git a/libexec/trick/make_makefile_swig b/libexec/trick/make_makefile_swig index 3de1a2b6..27e1a0c9 100755 --- a/libexec/trick/make_makefile_swig +++ b/libexec/trick/make_makefile_swig @@ -87,9 +87,10 @@ sub read_files_to_process() { @defines = $ENV{"TRICK_CFLAGS"} =~ /(-D\S+)/g ; # get defines from TRICK_CFLAGS push @defines , "-DTRICK_VER=$year" ; push @defines , "-DSWIG" ; + push @defines , "-std=c++11" ; # Get the list header files from the compiler to compare to what get_headers processed. - open FILE_LIST, "$cc -MM -DSWIG @include_paths @defines S_source.hh |" ; + open FILE_LIST, "$cc -MM @include_paths @defines S_source.hh |" ; my $dir ; $dir = dirname($s_source_full_path) ; while ( ) { diff --git a/share/trick/makefiles/Makefile.tricklib b/share/trick/makefiles/Makefile.tricklib index 1a11a477..f9162d69 100644 --- a/share/trick/makefiles/Makefile.tricklib +++ b/share/trick/makefiles/Makefile.tricklib @@ -96,7 +96,8 @@ $(TRICK_LIB_DIR): $(IO_C_OBJS): $(OBJ_DIR)/%.o : $(IO_SRC_DIR)%.c | $(OBJ_DIR) $(TRICK_CC) $(TRICK_CFLAGS) $(TRICK_SYSTEM_CFLAGS) -c $< -o $@ -$(IO_CPP_OBJS): TRICK_CXXFLAGS += -Wno-invalid-offsetof +$(IO_CPP_OBJS): TRICK_SYSTEM_CXXFLAGS += -std=c++11 +$(IO_CPP_OBJS): TRICK_SYSTEM_CXXFLAGS += -Wno-invalid-offsetof ifeq ($(IS_CC_CLANG), 0) # cannot get an "expr" command to work on all platforms. Falling back to reliable perl. :) GCCVERSIONGTEQ48 := $(shell perl -e 'printf "%d\n", ($(GCC_MAJOR)>4)||(($(GCC_MAJOR)==4)&&($(GCC_MINOR)>=8)) ;' ) @@ -105,7 +106,6 @@ ifeq ($(IS_CC_CLANG), 0) endif endif - $(IO_CPP_OBJS): $(OBJ_DIR)/%.o : $(IO_SRC_DIR)%.cpp | $(OBJ_DIR) $(TRICK_CPPC) $(TRICK_CXXFLAGS) $(TRICK_SYSTEM_CXXFLAGS) -c $< -o $@ diff --git a/share/trick/sim_objects/default_trick_sys.sm b/share/trick/sim_objects/default_trick_sys.sm index 9680eda1..17bf71bd 100644 --- a/share/trick/sim_objects/default_trick_sys.sm +++ b/share/trick/sim_objects/default_trick_sys.sm @@ -93,12 +93,6 @@ a replacement SimObject will create an uncompilable sim. ##include "trick/RtiStager.hh" ##include "trick/RtiExec.hh" -// TODO: move users away from this STL checkpoint method -##include "trick/checkpoint_stl.hh" - -// TODO: move users away from this STL checkpoint method -#include "trick/stl_s_define_macro.hh" - // This is a user header block. Code here is copied without processing to S_source.hh %header{ @@ -382,7 +376,7 @@ class EventManagerSimObject : public Trick::SimObject { public: Trick::EventManager em ; Trick::EventProcessor ep ; - std::vector< ThreadProcessEventSimObject * > thread_process_event_so ; + std::vector< ThreadProcessEventSimObject * > thread_process_event_so ; // ** ignore for checkpointing void create_thread_process_event() { unsigned int ii ; @@ -748,7 +742,7 @@ class InjectorSimObject : public Trick::SimObject { public: Trick::RtiStager rtis ; - std::vector< InjectorExecSimObject * > injector_executor_so ; + std::vector< InjectorExecSimObject * > injector_executor_so ; // trick_io(**) void create_injector_executors() { unsigned int ii ; @@ -801,6 +795,5 @@ UnitTestSimObject trick_utest ; // Include optional external clocks #include "sim_objects/TPROClock.sm" #include "sim_objects/BC635Clock.sm" -#include "sim_objects/STL.sm" #endif diff --git a/test/SIM_stls/RUN_test/input.py b/test/SIM_stls/RUN_test/input.py index 0ae88b83..d49bbf77 100644 --- a/test/SIM_stls/RUN_test/input.py +++ b/test/SIM_stls/RUN_test/input.py @@ -2,21 +2,18 @@ def main(): #trick.echo_jobs_on() - simControlPanel = trick.SimControlPanel() - simControlPanel.thisown = 0 - trick.add_external_application(simControlPanel) + trick.sim_control_panel_set_enabled(True) trick.real_time_enable() - #trick.itimer_enable() + trick.itimer_enable() - trick.checkpoint_post_init(True) - trick.checkpoint_end(True) + trick.checkpoint_pre_init(True) + #trick.checkpoint_post_init(True) + #trick.checkpoint_end(True) - trick.freeze(2.0) + #trick.freeze(2.0) - the_object.stlc2.name = "Daisy" - - # Data recording HDF5 test + trick.exec_set_software_frame(0.10) trick.exec_set_freeze_frame(0.10) trick.stop(5.0) diff --git a/test/SIM_stls/S_define b/test/SIM_stls/S_define index f0a2aee1..908cbe15 100644 --- a/test/SIM_stls/S_define +++ b/test/SIM_stls/S_define @@ -1,46 +1,18 @@ #include "sim_objects/default_trick_sys.sm" -##include "stl_checkpoint/include/STLCheckpoint.hh" -##include "stl_checkpoint/include/STLCompanion.hh" - -/* This object tests having 2 of the same type of object containing STLs in the same sim_object. - The checkpoints use the name of the objects to give the STLs unique and identifiable names - in the checkpoint. */ +##include "STLCheckpoint.hh" class theSimObject : public Trick::SimObject { public: STLCheckpoint stlc ; - STLCheckpoint stlc2 ; - STLCompanion gc ; /** Constructor to add the jobs */ - theSimObject() : stlc(std::string("Petunia")) , stlc2() { - + theSimObject() : stlc("Petunia") { (1.0, "scheduled") stlc.speak() ; - - ("checkpoint") gc.checkpoint(&stlc, name + std::string("_stlc")) ; - ("checkpoint") gc.checkpoint(&stlc2, name + std::string("_stlc2")) ; - - ("post_checkpoint") gc.post_checkpoint(&stlc, name + std::string("_stlc")) ; - ("post_checkpoint") gc.post_checkpoint(&stlc2, name + std::string("_stlc2")) ; - - ("restart") gc.restart(&stlc, name + std::string("_stlc")) ; - ("restart") gc.restart(&stlc2, name + std::string("_stlc2")) ; } } ; -// Multiple simobjects theSimObject the_object ; -theSimObject the_object2 ; - -// Connect objects -void create_connections() { - - // Set the default termination time - trick_sys.sched.set_terminate_time(10.0) ; - trick_sys.sched.set_freeze_frame(0.10) ; - -} diff --git a/test/SIM_stls/S_overrides.mk b/test/SIM_stls/S_overrides.mk index 27536a3b..c4c9b818 100644 --- a/test/SIM_stls/S_overrides.mk +++ b/test/SIM_stls/S_overrides.mk @@ -2,3 +2,4 @@ TRICK_CFLAGS += -I./models TRICK_CXXFLAGS += -I./models +#TRICK_CXXFLAGS += -std=c++11 diff --git a/test/SIM_stls/models/stl_checkpoint/src/STLCheckpoint.cpp b/test/SIM_stls/models/STLCheckpoint.cpp similarity index 69% rename from test/SIM_stls/models/stl_checkpoint/src/STLCheckpoint.cpp rename to test/SIM_stls/models/STLCheckpoint.cpp index c8472d15..73a2bd35 100644 --- a/test/SIM_stls/models/stl_checkpoint/src/STLCheckpoint.cpp +++ b/test/SIM_stls/models/STLCheckpoint.cpp @@ -138,7 +138,10 @@ STLCheckpoint::STLCheckpoint() { return ; } -STLCheckpoint::STLCheckpoint(std::string in_name) { +STLCheckpoint::STLCheckpoint(std::string in_name) : + my_vector_vector_double(4, std::vector(3)) , + my_vector_vector_vector_double(5, std::vector >(4, std::vector(3))) +{ name = in_name ; @@ -271,11 +274,95 @@ STLCheckpoint::STLCheckpoint(std::string in_name) { my_string_pair.first = "pair first string" ; my_string_pair.second = "pair second string" ; + + my_vector_vector_double[0][0] = 100 ; + my_vector_vector_double[0][1] = 101 ; + my_vector_vector_double[0][2] = 102 ; + my_vector_vector_double[1][0] = 103 ; + my_vector_vector_double[1][1] = 104 ; + my_vector_vector_double[1][2] = 105 ; + my_vector_vector_double[2][0] = 106 ; + my_vector_vector_double[2][1] = 107 ; + my_vector_vector_double[2][2] = 108 ; + my_vector_vector_double[3][0] = 109 ; + my_vector_vector_double[3][1] = 110 ; + my_vector_vector_double[3][2] = 111 ; + + my_vector_vector_vector_double[0][0][0] = 0 ; + my_vector_vector_vector_double[0][0][1] = 1 ; + my_vector_vector_vector_double[0][0][2] = 2 ; + my_vector_vector_vector_double[0][1][0] = 3 ; + my_vector_vector_vector_double[0][1][1] = 4 ; + my_vector_vector_vector_double[0][1][2] = 5 ; + my_vector_vector_vector_double[0][2][0] = 6 ; + my_vector_vector_vector_double[0][2][1] = 7 ; + my_vector_vector_vector_double[0][2][2] = 8 ; + my_vector_vector_vector_double[0][3][0] = 9 ; + my_vector_vector_vector_double[0][3][1] = 10 ; + my_vector_vector_vector_double[0][3][2] = 11 ; + + my_vector_vector_vector_double[1][0][0] = 1000 ; + my_vector_vector_vector_double[1][0][1] = 1001 ; + my_vector_vector_vector_double[1][0][2] = 1002 ; + my_vector_vector_vector_double[1][1][0] = 1003 ; + my_vector_vector_vector_double[1][1][1] = 1004 ; + my_vector_vector_vector_double[1][1][2] = 1005 ; + my_vector_vector_vector_double[1][2][0] = 1006 ; + my_vector_vector_vector_double[1][2][1] = 1007 ; + my_vector_vector_vector_double[1][2][2] = 1008 ; + my_vector_vector_vector_double[1][3][0] = 1009 ; + my_vector_vector_vector_double[1][3][1] = 1010 ; + my_vector_vector_vector_double[1][3][2] = 1011 ; + + my_vector_vector_vector_double[2][0][0] = 2000 ; + my_vector_vector_vector_double[2][0][1] = 2001 ; + my_vector_vector_vector_double[2][0][2] = 2002 ; + my_vector_vector_vector_double[2][1][0] = 2003 ; + my_vector_vector_vector_double[2][1][1] = 2004 ; + my_vector_vector_vector_double[2][1][2] = 2005 ; + my_vector_vector_vector_double[2][2][0] = 2006 ; + my_vector_vector_vector_double[2][2][1] = 2007 ; + my_vector_vector_vector_double[2][2][2] = 2008 ; + my_vector_vector_vector_double[2][3][0] = 2009 ; + my_vector_vector_vector_double[2][3][1] = 2010 ; + my_vector_vector_vector_double[2][3][2] = 2011 ; + + my_vector_vector_vector_double[3][0][0] = 3000 ; + my_vector_vector_vector_double[3][0][1] = 3001 ; + my_vector_vector_vector_double[3][0][2] = 3002 ; + my_vector_vector_vector_double[3][1][0] = 3003 ; + my_vector_vector_vector_double[3][1][1] = 3004 ; + my_vector_vector_vector_double[3][1][2] = 3005 ; + my_vector_vector_vector_double[3][2][0] = 3006 ; + my_vector_vector_vector_double[3][2][1] = 3007 ; + my_vector_vector_vector_double[3][2][2] = 3008 ; + my_vector_vector_vector_double[3][3][0] = 3009 ; + my_vector_vector_vector_double[3][3][1] = 3010 ; + my_vector_vector_vector_double[3][3][2] = 3011 ; + + my_vector_vector_vector_double[4][0][0] = 4000 ; + my_vector_vector_vector_double[4][0][1] = 4001 ; + my_vector_vector_vector_double[4][0][2] = 4002 ; + my_vector_vector_vector_double[4][1][0] = 4003 ; + my_vector_vector_vector_double[4][1][1] = 4004 ; + my_vector_vector_vector_double[4][1][2] = 4005 ; + my_vector_vector_vector_double[4][2][0] = 4006 ; + my_vector_vector_vector_double[4][2][1] = 4007 ; + my_vector_vector_vector_double[4][2][2] = 4008 ; + my_vector_vector_vector_double[4][3][0] = 4009 ; + my_vector_vector_vector_double[4][3][1] = 4010 ; + my_vector_vector_vector_double[4][3][2] = 4011 ; + return ; } int STLCheckpoint::speak() { - message_publish(1,"Quack!\n") ; + //message_publish(1,"Quack!\n") ; + //message_publish(1,"my_double_vector: %f %f %f\n", my_double_vector[0], my_double_vector[1], my_double_vector[2]) ; + message_publish(1,"my_vector_vector_double[1]: %f %f %f\n", + my_vector_vector_double[1][0], my_vector_vector_double[1][1], my_vector_vector_double[1][2]) ; + message_publish(1,"my_vector_vector_vector_double[4][2]: %f %f %f\n", + my_vector_vector_vector_double[4][2][0], my_vector_vector_vector_double[4][2][1], my_vector_vector_vector_double[4][2][2]) ; return 0 ; } diff --git a/test/SIM_stls/models/stl_checkpoint/include/STLCheckpoint.hh b/test/SIM_stls/models/STLCheckpoint.hh similarity index 67% rename from test/SIM_stls/models/stl_checkpoint/include/STLCheckpoint.hh rename to test/SIM_stls/models/STLCheckpoint.hh index 8a4b4031..45c89b34 100644 --- a/test/SIM_stls/models/stl_checkpoint/include/STLCheckpoint.hh +++ b/test/SIM_stls/models/STLCheckpoint.hh @@ -18,26 +18,8 @@ #include #include -/* This shows the most difficult case in checkpointing STLs where all - STLs are private. There are no accessor routines to get individual - items out of the STLs. (In fact getting to all items in some of the - STLs forces changes in the contents, such as stacks and queues.) Anyways - in this case we need to specify a friend that carries out the checkpoint. - There are 2 methods one can use to call the Trick stl checkpoint routines: - 1) Provide a companion class that calls the Trick routines for each STL - (STLCompanion in this example). - -- OR -- - 2) Invoke Trick's CHECKPOINT_STL macro in the sim object class for each STL - (theSimObject in this example). - Whichever method is chosen, make that class a friend of the class with STLs - (STLCheckpoint in this example). - Public STLs can be checkpointed in the same way (but no need to specify friend). -*/ class STLCheckpoint { - friend class STLCompanion ; // method 1 - friend class theSimObject ; // method 2 - public: STLCheckpoint() ; @@ -46,8 +28,6 @@ class STLCheckpoint { std::string name ; - private: - std::map< double , double > my_double_map ; std::map< std::string , int > my_string_key_map ; std::map< int , std::string > my_string_data_map ; @@ -87,6 +67,9 @@ class STLCheckpoint { std::pair< int , std::string > my_string_second_pair ; std::pair< std::string , std::string > my_string_pair ; + std::vector< std::vector< double > > my_vector_vector_double ; + std::vector< std::vector< std::vector< double > > > my_vector_vector_vector_double ; + //std::vector< std::list< double > > my_vector_list_double ; } ; #endif diff --git a/test/SIM_stls/models/stl_checkpoint/include/STLCompanion.hh b/test/SIM_stls/models/stl_checkpoint/include/STLCompanion.hh deleted file mode 100644 index bc2c987b..00000000 --- a/test/SIM_stls/models/stl_checkpoint/include/STLCompanion.hh +++ /dev/null @@ -1,42 +0,0 @@ -/* - PURPOSE: (Illustrate how to checkpoint STLs) - LIBRARY_DEPENDENCIES: ( - (STLCompanion_checkpoint.o) - (STLCompanion_post_checkpoint.o) - (STLCompanion_restart.o) - ) -*/ - -#ifndef STLCOMPANION_HH -#define STLCOMPANION_HH - -#include - -#include "STLCheckpoint.hh" - -/* STLCheckpoint's friend - -This class's sole purpose in life is to keep up the STLs in the STLCheckpoint class. -Since this is a friend to the STLCheckpoint class, the methods of this class work -with the STLs in STLCheckpoint directly. -*/ - -class STLCompanion { - - public: - - STLCompanion() {} ; - - /* writes out the STL data in arrays in the memory manager */ - int checkpoint(STLCheckpoint * in_stlc, std::string var_name) ; - - /* deletes the STL data in arrays from the memory manager */ - int post_checkpoint(STLCheckpoint * in_stlc, std::string var_name) ; - - /* restores memory from a checkpoint. the data resides in memory - manager. deletes the STL data in arrays after restoration */ - int restart(STLCheckpoint * in_stlc, std::string var_name) ; -} ; - -#endif - diff --git a/test/SIM_stls/models/stl_checkpoint/src/STLCompanion_checkpoint.cpp b/test/SIM_stls/models/stl_checkpoint/src/STLCompanion_checkpoint.cpp deleted file mode 100644 index 4355dbc5..00000000 --- a/test/SIM_stls/models/stl_checkpoint/src/STLCompanion_checkpoint.cpp +++ /dev/null @@ -1,53 +0,0 @@ - -#include - -#include "STLCompanion.hh" -#include "sim_services/CheckPointRestart/include/checkpoint_stl.hh" - -/* All STLs are checkpointed through the same templated function checkpoint_stl. The - second and third arguments to the call give each set of STL data a unique name. In - this example the unique name is the concatenation of the object instance and the variable name - */ -int STLCompanion::checkpoint(STLCheckpoint * stlc, std::string object_name ) { - - checkpoint_stl(stlc->my_double_map , object_name , std::string("my_double_map")) ; - checkpoint_stl(stlc->my_string_key_map , object_name , std::string("my_string_key_map")) ; - checkpoint_stl(stlc->my_string_data_map , object_name , std::string("my_string_data_map")) ; - checkpoint_stl(stlc->my_string_map , object_name , std::string("my_string_map")) ; - - checkpoint_stl(stlc->my_int_multimap , object_name , std::string("my_int_multimap")) ; - checkpoint_stl(stlc->my_string_key_multimap , object_name , std::string("my_string_key_multimap")) ; - checkpoint_stl(stlc->my_string_data_multimap , object_name , std::string("my_string_data_multimap")) ; - checkpoint_stl(stlc->my_string_multimap , object_name , std::string("my_string_multimap")) ; - - checkpoint_stl(stlc->my_double_vector , object_name , std::string("my_double_vector")) ; - checkpoint_stl(stlc->my_string_vector , object_name , std::string("my_string_vector")) ; - - checkpoint_stl(stlc->my_short_list , object_name , std::string("my_short_list")) ; - checkpoint_stl(stlc->my_string_list , object_name , std::string("my_string_list")) ; - - checkpoint_stl(stlc->my_float_deque , object_name , std::string("my_float_deque")) ; - checkpoint_stl(stlc->my_string_deque , object_name , std::string("my_string_deque")) ; - - checkpoint_stl(stlc->my_int_set , object_name , std::string("my_int_set")) ; - checkpoint_stl(stlc->my_string_set , object_name , std::string("my_string_set")) ; - - checkpoint_stl(stlc->my_long_multiset , object_name , std::string("my_long_multiset")) ; - checkpoint_stl(stlc->my_string_multiset , object_name , std::string("my_string_multiset")) ; - - checkpoint_stl(stlc->my_uint_stack , object_name , std::string("my_uint_stack")) ; - checkpoint_stl(stlc->my_string_stack , object_name , std::string("my_string_stack")) ; - - checkpoint_stl(stlc->my_int_queue , object_name , std::string("my_int_queue")) ; - checkpoint_stl(stlc->my_string_queue , object_name , std::string("my_string_queue")) ; - - checkpoint_stl(stlc->my_int_priority_queue , object_name , std::string("my_int_priority_queue")) ; - checkpoint_stl(stlc->my_string_priority_queue , object_name , std::string("my_string_priority_queue")) ; - - checkpoint_stl(stlc->my_int_pair , object_name , std::string("my_int_pair")) ; - checkpoint_stl(stlc->my_string_first_pair , object_name , std::string("my_string_first_pair")) ; - checkpoint_stl(stlc->my_string_second_pair , object_name , std::string("my_string_second_pair")) ; - checkpoint_stl(stlc->my_string_pair , object_name , std::string("my_stringpair")) ; - - return 0 ; -} diff --git a/test/SIM_stls/models/stl_checkpoint/src/STLCompanion_post_checkpoint.cpp b/test/SIM_stls/models/stl_checkpoint/src/STLCompanion_post_checkpoint.cpp deleted file mode 100644 index c531e65e..00000000 --- a/test/SIM_stls/models/stl_checkpoint/src/STLCompanion_post_checkpoint.cpp +++ /dev/null @@ -1,55 +0,0 @@ - -#include - -#include "STLCompanion.hh" -#include "sim_services/CheckPointRestart/include/checkpoint_stl.hh" - -/* All STLs are deleted through the same templated function delete_stl. The - second and third arguments give the unique name to delete. In - this example the unique name is the concatenation of the object instance and the variable name. - Currently the first argument is unused. - */ -int STLCompanion::post_checkpoint(STLCheckpoint * stlc, std::string object_name ) { - - delete_stl(stlc->my_double_map , object_name , std::string("my_double_map")) ; - delete_stl(stlc->my_string_key_map , object_name , std::string("my_string_key_map")) ; - delete_stl(stlc->my_string_data_map , object_name , std::string("my_string_data_map")) ; - delete_stl(stlc->my_string_map , object_name , std::string("my_string_map")) ; - - delete_stl(stlc->my_int_multimap , object_name , std::string("my_int_multimap")) ; - delete_stl(stlc->my_string_key_multimap , object_name , std::string("my_string_key_multimap")) ; - delete_stl(stlc->my_string_data_multimap , object_name , std::string("my_string_data_multimap")) ; - delete_stl(stlc->my_string_multimap , object_name , std::string("my_string_multimap")) ; - - delete_stl(stlc->my_double_vector , object_name , std::string("my_double_vector")) ; - delete_stl(stlc->my_string_vector , object_name , std::string("my_string_vector")) ; - - delete_stl(stlc->my_short_list , object_name , std::string("my_short_list")) ; - delete_stl(stlc->my_string_list , object_name , std::string("my_string_list")) ; - - delete_stl(stlc->my_float_deque , object_name , std::string("my_float_deque")) ; - delete_stl(stlc->my_string_deque , object_name , std::string("my_string_deque")) ; - - delete_stl(stlc->my_int_set , object_name , std::string("my_int_set")) ; - delete_stl(stlc->my_string_set , object_name , std::string("my_string_set")) ; - - delete_stl(stlc->my_long_multiset , object_name , std::string("my_long_multiset")) ; - delete_stl(stlc->my_string_multiset , object_name , std::string("my_string_multiset")) ; - - delete_stl(stlc->my_uint_stack , object_name , std::string("my_uint_stack")) ; - delete_stl(stlc->my_string_stack , object_name , std::string("my_string_stack")) ; - - delete_stl(stlc->my_int_queue , object_name , std::string("my_int_queue")) ; - delete_stl(stlc->my_string_queue , object_name , std::string("my_string_queue")) ; - - delete_stl(stlc->my_int_priority_queue , object_name , std::string("my_int_priority_queue")) ; - delete_stl(stlc->my_string_priority_queue , object_name , std::string("my_string_priority_queue")) ; - - delete_stl(stlc->my_int_pair , object_name , std::string("my_int_pair")) ; - delete_stl(stlc->my_string_first_pair , object_name , std::string("my_string_first_pair")) ; - delete_stl(stlc->my_string_second_pair , object_name , std::string("my_string_second_pair")) ; - delete_stl(stlc->my_string_pair , object_name , std::string("my_stringpair")) ; - - return 0 ; -} - diff --git a/test/SIM_stls/models/stl_checkpoint/src/STLCompanion_restart.cpp b/test/SIM_stls/models/stl_checkpoint/src/STLCompanion_restart.cpp deleted file mode 100644 index c23166bf..00000000 --- a/test/SIM_stls/models/stl_checkpoint/src/STLCompanion_restart.cpp +++ /dev/null @@ -1,54 +0,0 @@ - -#include - -#include "STLCompanion.hh" -#include "sim_services/CheckPointRestart/include/checkpoint_stl.hh" - -/* All STLs are restored through the same templated function restore_stl. The - second and third arguments give the unique name to delete. In - this example the unique name is the concatenation of the object instance and the variable name. - retore_stl will delete the memory manager arrays. - */ -int STLCompanion::restart(STLCheckpoint * stlc, std::string object_name ) { - - restore_stl(stlc->my_double_map , object_name , std::string("my_double_map")) ; - restore_stl(stlc->my_string_key_map , object_name , std::string("my_string_key_map")) ; - restore_stl(stlc->my_string_data_map , object_name , std::string("my_string_data_map")) ; - restore_stl(stlc->my_string_map , object_name , std::string("my_string_map")) ; - - restore_stl(stlc->my_int_multimap , object_name , std::string("my_int_multimap")) ; - restore_stl(stlc->my_string_key_multimap , object_name , std::string("my_string_key_multimap")) ; - restore_stl(stlc->my_string_data_multimap , object_name , std::string("my_string_data_multimap")) ; - restore_stl(stlc->my_string_multimap , object_name , std::string("my_string_multimap")) ; - - restore_stl(stlc->my_double_vector , object_name , std::string("my_double_vector")) ; - restore_stl(stlc->my_string_vector , object_name , std::string("my_string_vector")) ; - - restore_stl(stlc->my_short_list , object_name , std::string("my_short_list")) ; - restore_stl(stlc->my_string_list , object_name , std::string("my_string_list")) ; - - restore_stl(stlc->my_float_deque , object_name , std::string("my_float_deque")) ; - restore_stl(stlc->my_string_deque , object_name , std::string("my_string_deque")) ; - - restore_stl(stlc->my_int_set , object_name , std::string("my_int_set")) ; - restore_stl(stlc->my_string_set , object_name , std::string("my_string_set")) ; - - restore_stl(stlc->my_long_multiset , object_name , std::string("my_long_multiset")) ; - restore_stl(stlc->my_string_multiset , object_name , std::string("my_string_multiset")) ; - - restore_stl(stlc->my_uint_stack , object_name , std::string("my_uint_stack")) ; - restore_stl(stlc->my_string_stack , object_name , std::string("my_string_stack")) ; - - restore_stl(stlc->my_int_queue , object_name , std::string("my_int_queue")) ; - restore_stl(stlc->my_string_queue , object_name , std::string("my_string_queue")) ; - - restore_stl(stlc->my_int_priority_queue , object_name , std::string("my_int_priority_queue")) ; - restore_stl(stlc->my_string_priority_queue , object_name , std::string("my_string_priority_queue")) ; - - restore_stl(stlc->my_int_pair , object_name , std::string("my_int_pair")) ; - restore_stl(stlc->my_string_first_pair , object_name , std::string("my_string_first_pair")) ; - restore_stl(stlc->my_string_second_pair , object_name , std::string("my_string_second_pair")) ; - restore_stl(stlc->my_string_pair , object_name , std::string("my_stringpair")) ; - - return 0 ; -} diff --git a/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp b/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp index 6ef6910d..7704b8cd 100644 --- a/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp +++ b/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp @@ -35,6 +35,8 @@ FieldDescription::FieldDescription( bitfield_word_offset(0) , is_enum(0) , is_record(0) , + is_stl(0) , + has_stl_clear(1) , is_static(0) , num_dims(0) , array_sizes() {} ; @@ -368,6 +370,22 @@ bool FieldDescription::isRecord() { return is_record ; } +void FieldDescription::setSTL(bool yes_no) { + is_stl = yes_no ; +} + +bool FieldDescription::isSTL() { + return is_stl ; +} + +void FieldDescription::setSTLClear(bool yes_no) { + has_stl_clear = yes_no ; +} + +bool FieldDescription::hasSTLClear() { + return has_stl_clear ; +} + void FieldDescription::setStatic(bool yes_no) { is_static = yes_no ; } diff --git a/trick_source/codegen/Interface_Code_Gen/FieldDescription.hh b/trick_source/codegen/Interface_Code_Gen/FieldDescription.hh index 9914697a..5335d68f 100644 --- a/trick_source/codegen/Interface_Code_Gen/FieldDescription.hh +++ b/trick_source/codegen/Interface_Code_Gen/FieldDescription.hh @@ -70,6 +70,10 @@ class FieldDescription : public ConstructValues { bool isEnum() ; void setRecord( bool yes_no ) ; bool isRecord() ; + void setSTL( bool yes_no ) ; + bool isSTL() ; + void setSTLClear( bool yes_no ) ; + bool hasSTLClear() ; void setStatic( bool yes_no ) ; bool isStatic() ; bool getAccessSpecFound() ; @@ -150,6 +154,12 @@ class FieldDescription : public ConstructValues { /** is a record class */ bool is_record ; + /** is an stl */ + bool is_stl ; + + /** does this stl have a clear */ + bool has_stl_clear ; + /** is this field declared static */ bool is_static ; diff --git a/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp b/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp index 28aa6978..719776b7 100644 --- a/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp +++ b/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp @@ -5,6 +5,7 @@ #include "clang/Basic/SourceManager.h" #include "clang/AST/RecordLayout.h" #include "clang/AST/ASTContext.h" +#include "clang/AST/Comment.h" #include "FieldVisitor.hh" #include "FieldDescription.hh" @@ -143,27 +144,28 @@ bool FieldVisitor::VisitDeclaratorDecl( clang::DeclaratorDecl *dd ) { /* Get the source location of this field. */ clang::SourceRange dd_range = dd->getSourceRange() ; - std::string file_name = ci.getSourceManager().getBufferName(dd_range.getEnd()) ; - char * resolved_path = almostRealPath( file_name.c_str() ) ; - if ( resolved_path ) { + std::string file_name = getFileName(ci, dd_range.getEnd(), hsd) ; + if ( ! file_name.empty() ) { if ( isInUserOrTrickCode( ci , dd_range.getEnd() , hsd ) ) { fdes->setLineNo(ci.getSourceManager().getSpellingLineNumber(dd_range.getEnd())) ; /* process comment if neither ICG:(No) or ICG:(NoComment) is present */ - if ( cs.hasTrickHeader(resolved_path) and - !cs.hasICGNoComment(resolved_path) and - !hsd.isPathInICGNoComment(resolved_path) ) { + if ( cs.hasTrickHeader(file_name) and + !cs.hasICGNoComment(file_name) and + !hsd.isPathInICGNoComment(file_name) ) { /* Get the possible comment on this line and parse it */ - fdes->parseComment(cs.getComment(resolved_path , fdes->getLineNo())) ; + fdes->parseComment(cs.getComment(file_name , fdes->getLineNo())) ; } } - free(resolved_path) ; } if ( debug_level >= 3 ) { if ( ! ci.getSourceManager().isInSystemHeader(dd_range.getEnd()) ) { std::cout << "FieldVisitor VisitDeclaratorDecl" << std::endl ; - //dd->dump() ; + std::cout << " file_name = " << file_name << std::endl ; + std::cout << " line num = " << fdes->getLineNo() << std::endl ; + std::cout << " comment = " << cs.getComment(file_name , fdes->getLineNo()) << std::endl ; std::cout << " public/private = " << fdes->getAccess() << std::endl ; + std::cout << " io = " << fdes->getIO() << std::endl ; } } @@ -217,19 +219,12 @@ bool FieldVisitor::VisitFieldDecl( clang::FieldDecl *field ) { if ( !qt.isCanonical() ) { clang::QualType ct = qt.getCanonicalType() ; std::string tst_string = ct.getAsString() ; - // If we have a standard template library specializations other than std::string, don't process it. - if ( (! tst_string.compare( 0 , 9 , "class std") or ! tst_string.compare( 0 , 10 , "struct std")) and - tst_string.compare( 0, 23 , "class std::basic_string") ) { - // This is a standard template library type. don't process any further. - fdes->setIO(0) ; - } else { - if ( debug_level >= 3 ) { - std::cout << "\033[33mFieldVisitor VisitFieldDecl: Processing canonical type\033[00m" << std::endl ; - ct.dump() ; - } - TraverseType(ct) ; + if ( debug_level >= 3 ) { + std::cout << "\033[33mFieldVisitor VisitFieldDecl: Processing canonical type\033[00m" << std::endl ; + ct.dump() ; } - // We have either skipped a std template or extracted the canonical type and everything else we need + TraverseType(ct) ; + // We have extracted the canonical type and everything else we need // return false so we cut off processing of this AST branch return false ; } @@ -242,6 +237,19 @@ bool FieldVisitor::VisitPointerType(clang::PointerType *p) { return true; } +static std::string mangle_string( std::string in_name ) { + // convert characters not valid in a function name to underscores + std::string mangled_name = in_name ; + // Create a mangled type name, some characters have to converted to underscores. + std::replace( mangled_name.begin(), mangled_name.end(), '<', '_') ; + std::replace( mangled_name.begin(), mangled_name.end(), '>', '_') ; + std::replace( mangled_name.begin(), mangled_name.end(), ' ', '_') ; + std::replace( mangled_name.begin(), mangled_name.end(), ',', '_') ; + std::replace( mangled_name.begin(), mangled_name.end(), ':', '_') ; + std::replace( mangled_name.begin(), mangled_name.end(), '*', '_') ; + return mangled_name ; +} + std::map < std::string , std::string > FieldVisitor::processed_templates ; bool FieldVisitor::ProcessTemplate(std::string in_name , clang::CXXRecordDecl * crd ) { @@ -251,6 +259,7 @@ bool FieldVisitor::ProcessTemplate(std::string in_name , clang::CXXRecordDecl * size_t pos ; +/* if ((pos = in_name.find("class ")) != std::string::npos ) { in_name.erase(pos , 6) ; } @@ -261,20 +270,13 @@ bool FieldVisitor::ProcessTemplate(std::string in_name , clang::CXXRecordDecl * while ((pos = in_name.find(" _Bool")) != std::string::npos ) { in_name.replace(pos , 6, " bool") ; } +*/ // NOTE: clang also changes FILE * to struct _SFILE *. We may need to change that too. // Check to see if we've processed this template before // If not we need to create attributes for this template if ( processed_templates.find(in_name) == processed_templates.end() ) { - // convert characters not valid in a function name to underscores - std::string mangled_name = in_name ; - // Create a mangled type name, some characters have to converted to underscores. - std::replace( mangled_name.begin(), mangled_name.end(), '<', '_') ; - std::replace( mangled_name.begin(), mangled_name.end(), '>', '_') ; - std::replace( mangled_name.begin(), mangled_name.end(), ' ', '_') ; - std::replace( mangled_name.begin(), mangled_name.end(), ',', '_') ; - std::replace( mangled_name.begin(), mangled_name.end(), ':', '_') ; - std::replace( mangled_name.begin(), mangled_name.end(), '*', '_') ; + std::string mangled_name = mangle_string(in_name) ; // save off the mangled name of this template to be used if another variable is the same template type processed_templates[in_name] = fdes->getContainerClass() + "_" + @@ -305,6 +307,42 @@ bool FieldVisitor::ProcessTemplate(std::string in_name , clang::CXXRecordDecl * return false ; } +static std::map init_stl_classes() { + std::map my_map ; + my_map.insert(std::pair("std::deque", 1)) ; + my_map.insert(std::pair("std::list", 1)) ; + my_map.insert(std::pair("std::map", 1)) ; + my_map.insert(std::pair("std::multiset", 1)) ; + my_map.insert(std::pair("std::multimap", 1)) ; + my_map.insert(std::pair("std::pair", 1)) ; + my_map.insert(std::pair("std::priority_queue", 0)) ; + my_map.insert(std::pair("std::queue", 0)) ; + my_map.insert(std::pair("std::set", 1)) ; + my_map.insert(std::pair("std::stack", 0)) ; + my_map.insert(std::pair("std::vector", 1)) ; + return my_map ; +} + +static std::map stl_classes = init_stl_classes() ; + +#if 0 +// C++ 11 style initialization +// list of handled STL types and if they have a clear function. +static std::map stl_classes = { + {"std::deque", 1}, + {"std::list", 1}, + {"std::map", 1}, + {"std::multiset", 1}, + {"std::multimap", 1}, + {"std::pair", 0}, + {"std::priority_queue", 0}, + {"std::queue", 0}, + {"std::set", 1}, + {"std::stack", 0}, + {"std::vector", 1} +}; +#endif + bool FieldVisitor::VisitRecordType(clang::RecordType *rt) { if ( debug_level >= 3 ) { std::cout << "FieldVisitor VisitRecordType" << std::endl ; @@ -320,12 +358,42 @@ bool FieldVisitor::VisitRecordType(clang::RecordType *rt) { return false ; } + std::string tst_string = rt->desugar().getAsString() ; + // remove class keyword if it exists + size_t pos ; + while ((pos = tst_string.find("class ")) != std::string::npos ) { + tst_string.erase(pos , 6) ; + } + // clang changes bool to _Bool. We need to change it back + if ((pos = tst_string.find("<_Bool")) != std::string::npos ) { + tst_string.replace(pos , 6, "::iterator it = stl_classes.begin() ; it != stl_classes.end() ; it++ ) { + /* Mark STL types that are not strings and exit */ + //if (!tst_string.compare( 0 , 11 , "class std::") or !tst_string.compare( 0 , 12 , "struct std::")) { + if (!tst_string.compare( 0 , (*it).first.size() , (*it).first)) { + fdes->setEnumString("TRICK_STL") ; + fdes->setSTL(true) ; + fdes->setTypeName(tst_string) ; + fdes->setSTLClear((*it).second) ; + fdes->setMangledTypeName(mangle_string(tst_string)) ; + return false ; + } + } + } + /* Template specialization types will be processed here because the canonical type will be typed as a record. We test if we have a template specialization type. If so process the template type and return */ clang::RecordDecl * rd = rt->getDecl()->getDefinition() ; if ( rd != NULL and clang::ClassTemplateSpecializationDecl::classof(rd) ) { - std::string tst_string = rt->desugar().getAsString() ; if ( debug_level >= 3 ) { rd->dump() ; std::cout << " tst_string = " << tst_string << std::endl ; diff --git a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp index 2c35973f..2c5da9c3 100644 --- a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp +++ b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp @@ -417,6 +417,7 @@ void PrintAttributes::printIOMakefile() { std::cout << "Creating/updating io_src Makefile" << std::endl ; makefile_io_src.open("build/Makefile_io_src") ; + makefile_io_src << "TRICK_SYSTEM_CXXFLAGS += -std=c++11" << std::endl ; makefile_io_src << "TRICK_SYSTEM_CXXFLAGS += \\" << std::endl ; makefile_io_src << " -Wno-invalid-offsetof \\" << std::endl ; makefile_io_src << " -Wno-old-style-cast \\" << std::endl ; diff --git a/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.cpp b/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.cpp index 3557c94e..30895f16 100644 --- a/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.cpp +++ b/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.cpp @@ -45,6 +45,7 @@ void PrintFileContents10::printIOHeader(std::ofstream & outfile , std::string he "#include \"trick/attributes.h\"\n" "#include \"trick/parameter_types.h\"\n" "#include \"trick/UnitsMap.hh\"\n\n" +"#include \"trick/checkpoint_stl.hh\"\n\n" "#include \"" << header_file_name << "\"\n\n" ; @@ -103,7 +104,9 @@ void PrintFileContents10::print_field_attr(std::ofstream & outfile , FieldDescr if ( array_dim < 0 ) array_dim = 0 ; outfile << ",{" << array_dim << ",0}" ; // indexes 1 through 7 } - outfile << "} }" ; + outfile << "}," << std::endl ; + outfile << " NULL, NULL, NULL, NULL" ; + outfile << "}" ; } /** Prints class attributes */ @@ -186,7 +189,7 @@ void PrintFileContents10::print_field_init_attr_stmts( std::ofstream & outfile , outfile << cv->getMangledTypeName() << "," << fdes->getName() << ") ;\n" ; } - if ( !fdes->isRecord() and !fdes->isEnum() and !fdes->isBitField() ) { + if ( !fdes->isRecord() and !fdes->isEnum() and !fdes->isBitField() and !fdes->isSTL()) { outfile << " attr" ; printNamespaces( outfile, cv , "__" ) ; printContainerClasses( outfile, cv , "__" ) ; @@ -196,6 +199,46 @@ void PrintFileContents10::print_field_init_attr_stmts( std::ofstream & outfile , outfile << fdes->getTypeName() << ") ;\n" ; } + if ( fdes->isSTL()) { + outfile << " attr" ; + printNamespaces( outfile, cv , "__" ) ; + printContainerClasses( outfile, cv , "__" ) ; + outfile << cv->getMangledTypeName() << "[i].checkpoint_stl = checkpoint_stl_" ; + outfile << cv->getMangledTypeName() ; + outfile << "_" ; + outfile << fdes->getName() ; + outfile << " ;\n" ; + + outfile << " attr" ; + printNamespaces( outfile, cv , "__" ) ; + printContainerClasses( outfile, cv , "__" ) ; + outfile << cv->getMangledTypeName() << "[i].post_checkpoint_stl = post_checkpoint_stl_" ; + outfile << cv->getMangledTypeName() ; + outfile << "_" ; + outfile << fdes->getName() ; + outfile << " ;\n" ; + + outfile << " attr" ; + printNamespaces( outfile, cv , "__" ) ; + printContainerClasses( outfile, cv , "__" ) ; + outfile << cv->getMangledTypeName() << "[i].restore_stl = restore_stl_" ; + outfile << cv->getMangledTypeName() ; + outfile << "_" ; + outfile << fdes->getName() ; + outfile << " ;\n" ; + + if (fdes->hasSTLClear()) { + outfile << " attr" ; + printNamespaces( outfile, cv , "__" ) ; + printContainerClasses( outfile, cv , "__" ) ; + outfile << cv->getMangledTypeName() << "[i].clear_stl = clear_stl_" ; + outfile << cv->getMangledTypeName() ; + outfile << "_" ; + outfile << fdes->getName() ; + outfile << " ;\n" ; + } + } + if ( fdes->isRecord() or fdes->isEnum()) { outfile << " next_attr = std::string(attr" ; printNamespaces( outfile, cv , "__" ) ; @@ -425,8 +468,121 @@ void PrintFileContents10::print_io_src_delete( std::ofstream & outfile , ClassVa } } +void PrintFileContents10::print_stl_helper_proto(std::ofstream & outfile , ClassValues * cv ) { + + unsigned int ii ; + ClassValues::FieldIterator fit ; + + print_open_extern_c(outfile) ; + + for ( fit = cv->field_begin() ; fit != cv->field_end() ; fit++ ) { + if ( (*fit)->isSTL() and determinePrintAttr(cv , *fit) ) { + outfile << "void checkpoint_stl_" ; + outfile << cv->getMangledTypeName() ; + outfile << "_" ; + outfile << (*fit)->getName() ; + outfile << "(void * start_address, const char * obj_name , const char * var_name) ;" << std::endl ; + + outfile << "void post_checkpoint_stl_" ; + outfile << cv->getMangledTypeName() ; + outfile << "_" ; + outfile << (*fit)->getName() ; + outfile << "(void * start_address, const char * obj_name , const char * var_name) ;" << std::endl ; + + outfile << "void restore_stl_" ; + outfile << cv->getMangledTypeName() ; + outfile << "_" ; + outfile << (*fit)->getName() ; + outfile << "(void * start_address, const char * obj_name , const char * var_name) ;" << std::endl ; + + if ((*fit)->hasSTLClear()) { + outfile << "void clear_stl_" ; + outfile << cv->getMangledTypeName() ; + outfile << "_" ; + outfile << (*fit)->getName() ; + outfile << "(void * start_address) ;" << std::endl ; + } + } + } + print_close_extern_c(outfile) ; +} + +void PrintFileContents10::print_checkpoint_stl(std::ofstream & outfile , FieldDescription * fdes , ClassValues * cv ) { + outfile << "void checkpoint_stl_" ; + outfile << cv->getMangledTypeName() ; + outfile << "_" ; + outfile << fdes->getName() ; + outfile << "(void * start_address, const char * obj_name , const char * var_name) {" << std::endl ; + + outfile << " " << fdes->getTypeName() << " * stl = reinterpret_cast<" << fdes->getTypeName() << " * >(start_address) ;" << std::endl ; + outfile << " " << "checkpoint_stl(*stl , obj_name , var_name) ;" << std::endl ; + + outfile << "}" << std::endl ; +} + +void PrintFileContents10::print_post_checkpoint_stl(std::ofstream & outfile , FieldDescription * fdes , ClassValues * cv ) { + outfile << "void post_checkpoint_stl_" ; + outfile << cv->getMangledTypeName() ; + outfile << "_" ; + outfile << fdes->getName() ; + outfile << "(void * start_address, const char * obj_name , const char * var_name) {" << std::endl ; + + outfile << " " << fdes->getTypeName() << " * stl = reinterpret_cast<" << fdes->getTypeName() << " * >(start_address) ;" << std::endl ; + outfile << " " << "delete_stl(*stl , obj_name , var_name) ;" << std::endl ; + + outfile << "}" << std::endl ; +} + +void PrintFileContents10::print_restore_stl(std::ofstream & outfile , FieldDescription * fdes , ClassValues * cv ) { + outfile << "void restore_stl_" ; + outfile << cv->getMangledTypeName() ; + outfile << "_" ; + outfile << fdes->getName() ; + outfile << "(void * start_address, const char * obj_name , const char * var_name) {" << std::endl ; + + outfile << " " << fdes->getTypeName() << " * stl = reinterpret_cast<" << fdes->getTypeName() << " * >(start_address) ;" << std::endl ; + outfile << " " << "restore_stl(*stl , obj_name , var_name) ;" << std::endl ; + + outfile << "}" << std::endl ; +} + +void PrintFileContents10::print_clear_stl(std::ofstream & outfile , FieldDescription * fdes , ClassValues * cv ) { + outfile << "void clear_stl_" ; + outfile << cv->getMangledTypeName() ; + outfile << "_" ; + outfile << fdes->getName() ; + outfile << "(void * start_address) {" << std::endl ; + + outfile << " " << fdes->getTypeName() << " * stl = reinterpret_cast<" << fdes->getTypeName() << " * >(start_address) ;" << std::endl ; + outfile << " " << "stl->clear() ;" << std::endl ; + + outfile << "}" << std::endl ; +} + +void PrintFileContents10::print_stl_helper(std::ofstream & outfile , ClassValues * cv ) { + + unsigned int ii ; + ClassValues::FieldIterator fit ; + + print_open_extern_c(outfile) ; + + for ( fit = cv->field_begin() ; fit != cv->field_end() ; fit++ ) { + if ( (*fit)->isSTL() and determinePrintAttr(cv , *fit) ) { + print_checkpoint_stl(outfile , *fit, cv) ; + print_post_checkpoint_stl(outfile , *fit, cv) ; + print_restore_stl(outfile , *fit, cv) ; + if ((*fit)->hasSTLClear()) { + print_clear_stl(outfile , *fit, cv) ; + } + } + } + print_close_extern_c(outfile) ; +} + void PrintFileContents10::printClass( std::ofstream & outfile , ClassValues * cv ) { + print_stl_helper_proto(outfile, cv) ; print_class_attr(outfile, cv) ; + print_stl_helper(outfile, cv) ; print_init_attr_func(outfile, cv) ; print_open_extern_c(outfile) ; print_init_attr_c_intf(outfile, cv) ; diff --git a/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.hh b/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.hh index 09ca274c..53f91047 100644 --- a/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.hh +++ b/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.hh @@ -83,6 +83,24 @@ class PrintFileContents10 : public PrintFileContentsBase { /** Prints the io_src_delete function */ void print_io_src_delete(std::ofstream & outfile , ClassValues * cv ) ; + + /** Prints stl helper function prototypes */ + void print_stl_helper_proto(std::ofstream & outfile , ClassValues * in_class) ; + + /** Prints stl helper function */ + void print_stl_helper(std::ofstream & outfile , ClassValues * in_class) ; + + /** Prints stl checkpoint function */ + void print_checkpoint_stl(std::ofstream & outfile , FieldDescription * fdes , ClassValues * in_class) ; + + /** Prints stl post_checkpoint function */ + void print_post_checkpoint_stl(std::ofstream & outfile , FieldDescription * fdes , ClassValues * in_class) ; + + /** Prints stl restart function */ + void print_restore_stl(std::ofstream & outfile , FieldDescription * fdes , ClassValues * in_class) ; + + /** Prints stl clear function */ + void print_clear_stl(std::ofstream & outfile , FieldDescription * fdes , ClassValues * in_class) ; } ; #endif diff --git a/trick_source/sim_services/CheckPointAgent/ClassicCheckPointerAgent.cpp b/trick_source/sim_services/CheckPointAgent/ClassicCheckPointerAgent.cpp index cdb9e718..8ea6a738 100644 --- a/trick_source/sim_services/CheckPointAgent/ClassicCheckPointerAgent.cpp +++ b/trick_source/sim_services/CheckPointAgent/ClassicCheckPointerAgent.cpp @@ -40,7 +40,8 @@ const int Trick::ClassicCheckPointAgent::array_elements_per_line[TRICK_NUMBER_OF 5, /** TRICK_VOID_PTR */ 10, /** TRICK_ENUMERATED */ 5, /** TRICK_STRUCTURED (for pointers) */ - 5 /** TRICK_OPAQUE_TYPE */ + 5, /** TRICK_OPAQUE_TYPE */ + 1 /** TRICK_STL */ }; // MEMBER FUNCTION @@ -489,6 +490,10 @@ int Trick::ClassicCheckPointAgent::is_nil_valued( void* address, test_addr = (char*)address + offset * sizeof(void*); if (*(std::string*)test_addr == "") return(1); break; + case TRICK_STL : + // Can't test properly, always return 0 to indicate the STL is not empty. + return(0); + break; default : message_publish(MSG_ERROR, "Checkpoint Agent file %s: Unhandled Type (%d).\n", __FILE__, attr->type) ; return(-1); @@ -1059,9 +1064,13 @@ void Trick::ClassicCheckPointAgent::assign_rvalue(std::ostream& chkpnt_os, void* if (!input_perm_check(attr)) { chkpnt_os << "/* OUTPUT-ONLY: "; } - chkpnt_os << lname << " = "; - write_rvalue( chkpnt_os, (void*)address, attr, curr_dim, offset); - chkpnt_os << ";"; + if ( attr->type == TRICK_STL ) { + chkpnt_os << "// STL: " << lname ; + } else { + chkpnt_os << lname << " = "; + write_rvalue( chkpnt_os, (void*)address, attr, curr_dim, offset); + chkpnt_os << ";"; + } if (!input_perm_check(attr)) { chkpnt_os << "*/"; } diff --git a/trick_source/sim_services/CheckPointRestart/Makefile b/trick_source/sim_services/CheckPointRestart/Makefile index 7261c8c1..2d680508 100644 --- a/trick_source/sim_services/CheckPointRestart/Makefile +++ b/trick_source/sim_services/CheckPointRestart/Makefile @@ -7,3 +7,5 @@ ifneq ($(DMTCP),) TRICK_CXXFLAGS += -D_DMTCP -I$(DMTCP)/dmtcpaware endif +TRICK_CXXFLAGS += -std=c++11 + diff --git a/trick_source/sim_services/CheckPointRestart/checkpoint_pair.cpp b/trick_source/sim_services/CheckPointRestart/checkpoint_pair.cpp index 31ba0c1b..f9512944 100644 --- a/trick_source/sim_services/CheckPointRestart/checkpoint_pair.cpp +++ b/trick_source/sim_services/CheckPointRestart/checkpoint_pair.cpp @@ -13,9 +13,11 @@ int checkpoint_stl(std::pair & in_stl , std::string ob sprintf(var_declare, "char * %s_%s_first[1]", object_name.c_str(), var_name.c_str()) ; first = (char **)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_first").c_str()) ; sprintf(var_declare, "char * %s_%s_second[1]" , object_name.c_str(), var_name.c_str()) ; second = (char **)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_second").c_str()) ; first[0] = (char *)(in_stl.first.c_str()) ; second[0] = (char *)(in_stl.second.c_str()) ; diff --git a/trick_source/sim_services/CheckPointRestart/checkpoint_queue.cpp b/trick_source/sim_services/CheckPointRestart/checkpoint_queue.cpp index 9b528b47..ee97277c 100644 --- a/trick_source/sim_services/CheckPointRestart/checkpoint_queue.cpp +++ b/trick_source/sim_services/CheckPointRestart/checkpoint_queue.cpp @@ -19,6 +19,7 @@ int checkpoint_stl(std::queue & in_stl , std::string object_name , sprintf(var_declare, "%s %s_%s[%d]" , abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str(), cont_size) ; items = (char **)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name).c_str()) ; //message_publish(1, "CHECKPOINT_STL_STACK with %s\n", var_declare) ; temp_queue = in_stl ; @@ -50,6 +51,7 @@ int checkpoint_stl(std::priority_queue & in_stl , std::string objec sprintf(var_declare, "%s %s_%s[%d]" , abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str(), cont_size) ; items = (char **)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name).c_str()) ; //message_publish(1, "CHECKPOINT_STL_STACK with %s\n", var_declare) ; temp_queue = in_stl ; diff --git a/trick_source/sim_services/CheckPointRestart/checkpoint_stack.cpp b/trick_source/sim_services/CheckPointRestart/checkpoint_stack.cpp index 42d0ff8b..b47492b9 100644 --- a/trick_source/sim_services/CheckPointRestart/checkpoint_stack.cpp +++ b/trick_source/sim_services/CheckPointRestart/checkpoint_stack.cpp @@ -19,6 +19,7 @@ int checkpoint_stl(std::stack & in_stl , std::string object_name , sprintf(var_declare, "%s %s_%s[%d]" , abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str(), cont_size) ; items = (char **)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name).c_str()) ; //message_publish(1, "CHECKPOINT_STL_STACK with %s\n", var_declare) ; temp_stack = in_stl ; @@ -43,14 +44,13 @@ int restore_stl(std::stack & in_stl , std::string object_name , std //message_publish(1, "RESTORE_STL_STACK %s_%s\n", object_name.c_str() , var_name.c_str()) ; - cont_size = in_stl.size() ; - for ( ii = 0 ; ii < cont_size ; ii++ ) { - in_stl.pop() ; - } - items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name).c_str()) ; if ( items_ref != NULL ) { + cont_size = in_stl.size() ; + for ( ii = 0 ; ii < cont_size ; ii++ ) { + in_stl.pop() ; + } items = (char **)items_ref->address ; cont_size = get_size((char *)items) ; diff --git a/trick_source/sim_services/Executive/Executive.cpp b/trick_source/sim_services/Executive/Executive.cpp index e858898e..d46d9dae 100644 --- a/trick_source/sim_services/Executive/Executive.cpp +++ b/trick_source/sim_services/Executive/Executive.cpp @@ -64,8 +64,6 @@ Trick::Executive::Executive() { num_all_jobs = 0 ; all_jobs_for_checkpoint = NULL ; - num_sim_objects_in_checkpoint = 0 ; - sim_objects_for_checkpoint = NULL ; software_frame_tics = (long long)(software_frame * time_tic_value) ; next_frame_check_tics = software_frame_tics ; diff --git a/trick_source/sim_services/Executive/Executive_checkpoint.cpp b/trick_source/sim_services/Executive/Executive_checkpoint.cpp index 7a335f55..a7e9669c 100644 --- a/trick_source/sim_services/Executive/Executive_checkpoint.cpp +++ b/trick_source/sim_services/Executive/Executive_checkpoint.cpp @@ -4,19 +4,20 @@ #include "trick/Executive.hh" #include "trick/exec_proto.h" #include "trick/memorymanager_c_intf.h" -#include "trick/checkpoint_stl.hh" /** @details -# Save the number of jobs in the scheduler -# Copy all of the job information in a checkpointable array --# Save the number of sim_objects in the scheduler --# Copy all of the sim_objects in a checkpointable array */ int Trick::Executive::checkpoint() { unsigned int ii ; + /* + The all_jobs_vector contains memory that is not known to the memory manager. We need to + copy the information into memory that is declared to the memory manager. + */ /* save the number of jobs in the scheduler */ num_all_jobs = all_jobs_vector.size() ; @@ -29,9 +30,6 @@ int Trick::Executive::checkpoint() { } } - checkpoint_stl(sim_objects , std::string("trick_sys") , std::string("sim_objects")) ; - checkpoint_stl(freeze_times , std::string("trick_sys") , std::string("freeze_times")) ; - return(0) ; } diff --git a/trick_source/sim_services/Executive/Executive_init.cpp b/trick_source/sim_services/Executive/Executive_init.cpp index ee71c8f5..6b959c6c 100644 --- a/trick_source/sim_services/Executive/Executive_init.cpp +++ b/trick_source/sim_services/Executive/Executive_init.cpp @@ -68,7 +68,7 @@ int Trick::Executive::init() { } else { except_file = "somewhere in Executive::init" ; } - fprintf(stderr, "\nExecutive::loop terminated with std::exception\n ROUTINE: %s\n DIAGNOSTIC: %s\n", + fprintf(stderr, "\nExecutive::init terminated with std::exception\n ROUTINE: %s\n DIAGNOSTIC: %s\n", except_file.c_str(), ex.what()) ; exit(-1) ; } catch (...) { @@ -78,7 +78,7 @@ int Trick::Executive::init() { except_file = "somewhere in Executive::init" ; } except_message = "unknown error" ; - fprintf(stderr, "\nExecutive::loop terminated with unknown exception\n ROUTINE: %s\n DIAGNOSTIC: %s\n", + fprintf(stderr, "\nExecutive::init terminated with unknown exception\n ROUTINE: %s\n DIAGNOSTIC: %s\n", except_file.c_str() , except_message.c_str()) ; exit(-1) ; } diff --git a/trick_source/sim_services/Executive/Executive_post_checkpoint.cpp b/trick_source/sim_services/Executive/Executive_post_checkpoint.cpp index 4b6e6054..91fcb1ba 100644 --- a/trick_source/sim_services/Executive/Executive_post_checkpoint.cpp +++ b/trick_source/sim_services/Executive/Executive_post_checkpoint.cpp @@ -4,19 +4,11 @@ #include "trick/Executive.hh" #include "trick/exec_proto.h" #include "trick/memorymanager_c_intf.h" -#include "trick/checkpoint_stl.hh" int Trick::Executive::post_checkpoint() { TMM_delete_var_a(all_jobs_for_checkpoint) ; - all_jobs_for_checkpoint = NULL ; - delete_stl(sim_objects , std::string("trick_sys") , std::string("sim_objects")) ; - - if ( ! freeze_times.empty() ) { - delete_stl(freeze_times , std::string("trick_sys") , std::string("freeze_times")) ; - } - return(0) ; } diff --git a/trick_source/sim_services/Executive/Executive_restart.cpp b/trick_source/sim_services/Executive/Executive_restart.cpp index 1572f436..7cd6fec3 100644 --- a/trick_source/sim_services/Executive/Executive_restart.cpp +++ b/trick_source/sim_services/Executive/Executive_restart.cpp @@ -7,7 +7,6 @@ #include "trick/message_proto.h" #include "trick/message_type.h" #include "trick/memorymanager_c_intf.h" -#include "trick/checkpoint_stl.hh" #include "trick/ScheduledJobQueue.hh" #include "trick/Threads.hh" @@ -44,13 +43,6 @@ int Trick::Executive::restart() { all_jobs_vector.clear() ; all_tagged_jobs.clear() ; - /* clear all sim_object information in scheduler */ - num_sim_objects = 0 ; - sim_objects.clear() ; - - /* restore the list of sim_objects from the checkpoint. */ - restore_stl(sim_objects , std::string("trick_sys") , std::string("sim_objects")) ; - /* Create a temporary all_jobs map to use to restore job data from all_jobs_for_checkpoint */ for ( sit = sim_objects.begin() ; sit != sim_objects.end() ; sit++ ) { for ( jit = (*sit)->jobs.begin() ; jit != (*sit)->jobs.end() ; jit++ ) { @@ -107,9 +99,6 @@ int Trick::Executive::restart() { TMM_delete_var_a(all_jobs_for_checkpoint) ; all_jobs_for_checkpoint = NULL ; - // restore the vector of freeze times - restore_stl(freeze_times , std::string("trick_sys") , std::string("freeze_times")) ; - /* Set the main thread current time to the simulation time tics value, used with Executive::get_sim_time() */ threads[0]->curr_time_tics = time_tics ; diff --git a/trick_source/sim_services/Integrator/src/IntegLoopSimObject.cpp b/trick_source/sim_services/Integrator/src/IntegLoopSimObject.cpp index 36473cf4..f450b4ae 100644 --- a/trick_source/sim_services/Integrator/src/IntegLoopSimObject.cpp +++ b/trick_source/sim_services/Integrator/src/IntegLoopSimObject.cpp @@ -1,7 +1,6 @@ #include "trick/IntegLoopSimObject.hh" #include "trick/exec_proto.hh" -#include "trick/checkpoint_stl.hh" void IntegLoopSimObject::add_jobs(double in_cycle, unsigned int child) { Trick::JobData * job ; @@ -15,14 +14,11 @@ void IntegLoopSimObject::add_jobs(double in_cycle, unsigned int child) { job->add_tag("TRK") ; job = add_job(child, 3, "integ_loop", NULL, in_cycle, "integ_sched.integrate", "", 60000) ; job->add_tag("TRK") ; - job = add_job(0, 4, "checkpoint", NULL, 1, "checkpoint_stl", "", 60000) ; - job = add_job(0, 5, "post_checkpoint", NULL, 1, "delete_stl", "", 60000) ; - job = add_job(0, 6, "restart", NULL, 1, "restore_stl", "", 60000) ; - job = add_job(0, 7, "preload_checkpoint", NULL, 1, "integ_sched.restart_checkpoint", "", 0) ; + job = add_job(0, 4, "preload_checkpoint", NULL, 1, "integ_sched.restart_checkpoint", "", 0) ; job->add_tag("TRK") ; - job = add_job(0, 8, "restart", NULL, 1, "integ_sched.rebuild_jobs", "", 60000) ; + job = add_job(0, 5, "restart", NULL, 1, "integ_sched.rebuild_jobs", "", 60000) ; job->add_tag("TRK") ; - job = add_job(0, 9, "restart", NULL, 1, "integ_sched.get_first_step_deriv_from_integrator", "", 65535) ; + job = add_job(0, 6, "restart", NULL, 1, "integ_sched.get_first_step_deriv_from_integrator", "", 65535) ; job->add_tag("TRK") ; } @@ -45,21 +41,12 @@ int IntegLoopSimObject::call_function ( Trick::JobData * curr_job ) { integ_sched.integrate() ; break ; case 4: - checkpoint_stl(integ_sched.sim_objects, name + std::string("_") + std::string("integ_sched.sim_objects"), std::string("")) ; - break ; - case 5: - delete_stl (integ_sched.sim_objects, name + std::string("_") + std::string("integ_sched.sim_objects"), std::string("")) ; - break ; - case 6: - restore_stl (integ_sched.sim_objects, name + std::string("_") + std::string("integ_sched.sim_objects"), std::string("")) ; - break ; - case 7: integ_sched.restart_checkpoint() ; break ; - case 8: + case 5: integ_sched.rebuild_jobs() ; break ; - case 9: + case 6: integ_sched.get_first_step_deriv_from_integrator() ; break ; default: diff --git a/trick_source/sim_services/MemoryManager/MemoryManager_C_Intf.cpp b/trick_source/sim_services/MemoryManager/MemoryManager_C_Intf.cpp index cba47da7..7a76921d 100644 --- a/trick_source/sim_services/MemoryManager/MemoryManager_C_Intf.cpp +++ b/trick_source/sim_services/MemoryManager/MemoryManager_C_Intf.cpp @@ -17,7 +17,7 @@ extern "C" void* TMM_declare_var( TRICK_TYPE type, const char*class_name, int n_ std::string svar_name = var_name; return ( trick_MM->declare_var( type, sclass_name, n_stars, svar_name, n_cdims, cdims)); } else { - Trick::MemoryManager::emitError("TMM_declare_var() called before MemoryManager instantiation. Returning NULL.") ; + Trick::MemoryManager::emitError("TMM_declare_var() called before MemoryManager instantiation. Returning NULL.") ; return ( (void*)NULL); } } @@ -31,7 +31,7 @@ extern "C" void* TMM_declare_var_1d( const char* enh_type_spec, int e_elems) { if (trick_MM != NULL) { return ( trick_MM->declare_var( enh_type_spec, e_elems)); } else { - Trick::MemoryManager::emitError("TMM_declare_var_1d() called before MemoryManager instantiation. Returning NULL.\n") ; + Trick::MemoryManager::emitError("TMM_declare_var_1d() called before MemoryManager instantiation. Returning NULL.\n") ; return ( (void*)NULL); } } @@ -45,7 +45,7 @@ extern "C" void* TMM_declare_var_s( const char* declaration) { if (trick_MM != NULL) { return ( trick_MM->declare_var( declaration)); } else { - Trick::MemoryManager::emitError("TMM_declare_var_s() called before MemoryManager instantiation. Returning NULL.\n") ; + Trick::MemoryManager::emitError("TMM_declare_var_s() called before MemoryManager instantiation. Returning NULL.\n") ; return ( (void*)NULL); } } @@ -61,7 +61,7 @@ extern "C" void* alloc_type( int e_elems, const char* enh_type_spec) { if (trick_MM != NULL) { return ( trick_MM->declare_var( enh_type_spec, e_elems)); } else { - Trick::MemoryManager::emitError("alloc_type() called before MemoryManager instantiation. Returning NULL.\n") ; + Trick::MemoryManager::emitError("alloc_type() called before MemoryManager instantiation. Returning NULL.\n") ; return ( (void*)NULL); } } @@ -75,7 +75,7 @@ extern "C" void* TMM_declare_operatornew_var( const char * class_name, unsigned if (trick_MM != NULL) { return trick_MM->declare_operatornew_var( std::string(class_name), alloc_size, element_size ) ; } else { - Trick::MemoryManager::emitError("TMM_declare_var() called before MemoryManager instantiation. Returning NULL.\n") ; + Trick::MemoryManager::emitError("TMM_declare_var() called before MemoryManager instantiation. Returning NULL.\n") ; return (void*)NULL ; } } @@ -91,7 +91,7 @@ extern "C" void* TMM_declare_ext_var( void* addr, TRICK_TYPE type, const char*cl std::string svar_name = var_name; return ( trick_MM->declare_extern_var( addr, type, sclass_name, n_stars, svar_name, n_cdims, cdims)); } else { - Trick::MemoryManager::emitError("TMM_declare_ext_var() called before MemoryManager instantiation. Returning NULL.\n") ; + Trick::MemoryManager::emitError("TMM_declare_ext_var() called before MemoryManager instantiation. Returning NULL.\n") ; return ( (void*)NULL); } } @@ -105,7 +105,7 @@ extern "C" void* TMM_declare_ext_var_1d( void* addr, const char* elem_decl, int if (trick_MM != NULL) { return ( trick_MM->declare_extern_var( addr, elem_decl, n_elems)); } else { - Trick::MemoryManager::emitError("TMM_declare_ext_var_1d() called before MemoryManager instantiation. Returning NULL.\n") ; + Trick::MemoryManager::emitError("TMM_declare_ext_var_1d() called before MemoryManager instantiation. Returning NULL.\n") ; return ( (void*)NULL); } } @@ -119,7 +119,7 @@ extern "C" void* TMM_declare_ext_var_s( void* addr, const char* declaration) { if (trick_MM != NULL) { return ( trick_MM->declare_extern_var(addr, declaration)); } else { - Trick::MemoryManager::emitError("TMM_declare_ext_var_s() called before MemoryManager instantiation. Returning NULL.\n") ; + Trick::MemoryManager::emitError("TMM_declare_ext_var_s() called before MemoryManager instantiation. Returning NULL.\n") ; return ( (void*)NULL); } } @@ -135,7 +135,7 @@ void* TMM_resize_array_a(void *address, int n_cdims, int *cdims){ if (trick_MM != NULL) { return ( trick_MM->resize_array(address, n_cdims, cdims)); } else { - Trick::MemoryManager::emitError("TMM_resize_array_a() called before MemoryManager instantiation. Returning NULL.\n") ; + Trick::MemoryManager::emitError("TMM_resize_array_a() called before MemoryManager instantiation. Returning NULL.\n") ; return ( (void*)NULL); } } @@ -151,7 +151,7 @@ void* TMM_resize_array_n(const char *name, int n_cdims, int *cdims){ if (trick_MM != NULL) { return ( trick_MM->resize_array(name, n_cdims, cdims)); } else { - Trick::MemoryManager::emitError("TMM_resize_array_n() called before MemoryManager instantiation. Returning NULL.\n") ; + Trick::MemoryManager::emitError("TMM_resize_array_n() called before MemoryManager instantiation. Returning NULL.\n") ; return ( (void*)NULL); } } @@ -165,7 +165,7 @@ void* TMM_resize_array_1d_a(void* address, int num){ if (trick_MM != NULL) { return ( trick_MM->resize_array(address, num)); } else { - Trick::MemoryManager::emitError("TMM_resize_array_1d_a() called before MemoryManager instantiation. Returning NULL.\n") ; + Trick::MemoryManager::emitError("TMM_resize_array_1d_a() called before MemoryManager instantiation. Returning NULL.\n") ; return ( (void*)NULL); } } @@ -179,7 +179,7 @@ void* TMM_resize_array_1d_n(const char *name, int num){ if (trick_MM != NULL) { return ( trick_MM->resize_array(name, num)); } else { - Trick::MemoryManager::emitError("TMM_resize_array_1d_n() called before MemoryManager instantiation. Returning NULL.\n") ; + Trick::MemoryManager::emitError("TMM_resize_array_1d_n() called before MemoryManager instantiation. Returning NULL.\n") ; return ( (void*)NULL); } } @@ -193,7 +193,7 @@ extern "C" char* TMM_strdup(char *str) { if (trick_MM != NULL) { return ( trick_MM->mm_strdup( str)); } else { - Trick::MemoryManager::emitError("TMM_strdup called before MemoryManager instantiation. Returning NULL.\n") ; + Trick::MemoryManager::emitError("TMM_strdup called before MemoryManager instantiation. Returning NULL.\n") ; return( (char*)NULL); } } @@ -208,7 +208,7 @@ extern "C" int TMM_var_exists( const char* var_name) { std::string svar_name = var_name; return ( trick_MM->var_exists( svar_name)); } else { - Trick::MemoryManager::emitError("TMM_var_exists() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_var_exists() called before MemoryManager instantiation.\n") ; return (0); } } @@ -222,7 +222,7 @@ extern "C" int TMM_is_alloced(char *addr) { if (trick_MM != NULL) { return ( trick_MM->is_alloced( addr)); } else { - Trick::MemoryManager::emitError("TMM_is_alloced() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_is_alloced() called before MemoryManager instantiation.\n") ; return (0); } } @@ -236,7 +236,7 @@ extern "C" void TMM_set_debug_level(int level) { if (trick_MM != NULL) { trick_MM->set_debug_level( level); } else { - Trick::MemoryManager::emitError("TMM_set_debug_level() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_set_debug_level() called before MemoryManager instantiation.\n") ; } } @@ -248,7 +248,7 @@ extern "C" void TMM_reduced_checkpoint(int yesno) { if (trick_MM != NULL) { trick_MM->set_reduced_checkpoint( yesno!=0 ); } else { - Trick::MemoryManager::emitError("TMM_reduced_checkpoint() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_reduced_checkpoint() called before MemoryManager instantiation.\n") ; } } @@ -260,7 +260,7 @@ extern "C" void TMM_hexfloat_checkpoint(int yesno) { if (trick_MM != NULL) { trick_MM->set_hexfloat_checkpoint( yesno!=0 ); } else { - Trick::MemoryManager::emitError("TMM_hexfloat_checkpoint() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_hexfloat_checkpoint() called before MemoryManager instantiation.\n") ; } } @@ -275,7 +275,7 @@ extern "C" void TMM_clear_var_a(void *addr) { if (trick_MM != NULL) { trick_MM->clear_var( addr); } else { - Trick::MemoryManager::emitError("TMM_clear_var_a() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_clear_var_a() called before MemoryManager instantiation.\n") ; return; } } @@ -288,7 +288,7 @@ extern "C" void TMM_clear_var_n( const char* name) { if (trick_MM != NULL) { trick_MM->clear_var( name); } else { - Trick::MemoryManager::emitError("TMM_clear_var_n() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_clear_var_n() called before MemoryManager instantiation.\n") ; return; } } @@ -301,7 +301,7 @@ extern "C" void TMM_delete_var_a(void *addr) { if (trick_MM != NULL) { trick_MM->delete_var( addr); } else { - Trick::MemoryManager::emitError("TMM_delete_var_a() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_delete_var_a() called before MemoryManager instantiation.\n") ; return; } } @@ -314,7 +314,7 @@ extern "C" void TMM_delete_var_n( const char* name) { if (trick_MM != NULL) { trick_MM->delete_var( name); } else { - Trick::MemoryManager::emitError("TMM_delete_var_n() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_delete_var_n() called before MemoryManager instantiation.\n") ; return; } } @@ -327,7 +327,7 @@ extern "C" void TMM_delete_extern_var_a(void *addr) { if (trick_MM != NULL) { trick_MM->delete_extern_var( addr); } else { - Trick::MemoryManager::emitError("TMM_delete_extern_var_a() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_delete_extern_var_a() called before MemoryManager instantiation.\n") ; return; } } @@ -340,7 +340,7 @@ extern "C" void TMM_delete_extern_var_n( const char* name) { if (trick_MM != NULL) { trick_MM->delete_extern_var( name); } else { - Trick::MemoryManager::emitError("TMM_delete_extern_var_n() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_delete_extern_var_n() called before MemoryManager instantiation.\n") ; return; } } @@ -353,7 +353,7 @@ extern "C" void TMM_write_checkpoint(const char* filename) { if (trick_MM != NULL) { return ( trick_MM->write_checkpoint( filename)); } else { - Trick::MemoryManager::emitError("TMM_write_checkpoint_fn() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_write_checkpoint_fn() called before MemoryManager instantiation.\n") ; return; } } @@ -366,7 +366,7 @@ extern "C" int TMM_read_checkpoint(const char* filename) { if (trick_MM != NULL) { return ( trick_MM->read_checkpoint( filename)); } else { - Trick::MemoryManager::emitError("TMM_read_checkpoint() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_read_checkpoint() called before MemoryManager instantiation.\n") ; return(1); } } @@ -379,7 +379,7 @@ extern "C" int TMM_read_checkpoint_from_string(const char* str) { if (trick_MM != NULL) { return ( trick_MM->read_checkpoint_from_string( str)); } else { - Trick::MemoryManager::emitError("TMM_read_checkpoint_from_string() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_read_checkpoint_from_string() called before MemoryManager instantiation.\n") ; return(1); } } @@ -392,7 +392,7 @@ extern "C" int TMM_init_from_checkpoint(const char* filename) { if (trick_MM != NULL) { return ( trick_MM->init_from_checkpoint( filename)); } else { - Trick::MemoryManager::emitError("TMM_init_from_checkpoint() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_init_from_checkpoint() called before MemoryManager instantiation.\n") ; return(1); } } @@ -405,7 +405,7 @@ extern "C" int TMM_add_shared_library_symbols(const char* filename) { if (trick_MM != NULL) { return ( trick_MM->add_shared_library_symbols( filename)); } else { - Trick::MemoryManager::emitError("TMM_add_shared_library_symbols() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_add_shared_library_symbols() called before MemoryManager instantiation.\n") ; return(1); } } @@ -418,7 +418,7 @@ extern "C" void* add_var( TRICK_TYPE type, const char* stype, VAR_DECLARE* var_d if (trick_MM != NULL) { return( trick_MM->add_var(type, stype, var_declare, units )); } else { - Trick::MemoryManager::emitError("add_var() called before MemoryManager instantiation. Returning NULL.\n") ; + Trick::MemoryManager::emitError("add_var() called before MemoryManager instantiation. Returning NULL.\n") ; return ((void*)NULL); } } @@ -431,7 +431,7 @@ extern "C" int add_vars( TRICK_TYPE type, const char* stype, VAR_LIST* var_list, if (trick_MM != NULL) { return( trick_MM->add_vars(type, stype, var_list, units )); } else { - Trick::MemoryManager::emitError("add_vars() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("add_vars() called before MemoryManager instantiation.\n") ; return (1); } } @@ -444,7 +444,7 @@ extern "C" int ref_allocate(REF2 *R, int num) { if (trick_MM != NULL) { return( trick_MM->ref_allocate( R, num)); } else { - Trick::MemoryManager::emitError("ref_allocate() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("ref_allocate() called before MemoryManager instantiation.\n") ; return (1); } } @@ -457,7 +457,7 @@ extern "C" REF2* ref_attributes( char* name) { if (trick_MM != NULL) { return( trick_MM->ref_attributes( name)); } else { - Trick::MemoryManager::emitError("ref_attributes() called before MemoryManager instantiation. Returning NULL.\n") ; + Trick::MemoryManager::emitError("ref_attributes() called before MemoryManager instantiation. Returning NULL.\n") ; return ( (REF2*)NULL); } } @@ -470,7 +470,7 @@ extern "C" int ref_assignment(REF2* R, V_TREE* V) { if (trick_MM != NULL) { return( trick_MM->ref_assignment( R, V)); } else { - Trick::MemoryManager::emitError("ref_assignment() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("ref_assignment() called before MemoryManager instantiation.\n") ; return (1); } } @@ -483,7 +483,7 @@ extern "C" int ref_var(REF2 *R, char* name) { if (trick_MM != NULL) { return( trick_MM->ref_var( R, name)); } else { - Trick::MemoryManager::emitError("ref_var() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("ref_var() called before MemoryManager instantiation.\n") ; return (1); } } @@ -496,7 +496,7 @@ extern "C" int get_size(void *addr) { if (trick_MM != NULL) { return( trick_MM->get_size( addr)); } else { - Trick::MemoryManager::emitError("get_size() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("get_size() called before MemoryManager instantiation.\n") ; return (0); } } @@ -509,7 +509,7 @@ extern "C" int get_truncated_size(void *addr) { if (trick_MM != NULL) { return( trick_MM->get_truncated_size( addr)); } else { - Trick::MemoryManager::emitError("get_truncated_size() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("get_truncated_size() called before MemoryManager instantiation.\n") ; return (0); } } @@ -523,7 +523,7 @@ extern "C" int io_get_fixed_truncated_size(char *ptr __attribute__ ((unused)), char *str __attribute__ ((unused)), int dims __attribute__ ((unused)), ATTRIBUTES * left_type __attribute__ ((unused))) { - Trick::MemoryManager::emitError("io_get_fixed_truncated_size() is not implemented yet.\n") ; + Trick::MemoryManager::emitError("io_get_fixed_truncated_size() is not implemented yet.\n") ; return(0); } @@ -535,7 +535,7 @@ extern "C" ALLOC_INFO* get_alloc_info_of(void * addr) { if (trick_MM != NULL) { return( trick_MM->get_alloc_info_of( addr)); } else { - Trick::MemoryManager::emitError("get_alloc_info_of() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("get_alloc_info_of() called before MemoryManager instantiation.\n") ; return ( (ALLOC_INFO*)NULL); } } @@ -548,7 +548,7 @@ extern "C" ALLOC_INFO* get_alloc_info_at(void * addr) { if (trick_MM != NULL) { return( trick_MM->get_alloc_info_at( addr)); } else { - Trick::MemoryManager::emitError("get_alloc_info_at() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("get_alloc_info_at() called before MemoryManager instantiation.\n") ; return ( (ALLOC_INFO*)NULL); } } @@ -557,7 +557,7 @@ extern "C" int set_alloc_name_at(void * addr, const char * name ) { if (trick_MM != NULL) { return( trick_MM->set_name_at(addr, name)); } else { - Trick::MemoryManager::emitError("get_alloc_info_at() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("get_alloc_info_at() called before MemoryManager instantiation.\n") ; return ( -1 ); } } @@ -570,7 +570,15 @@ extern "C" int get_enumerated(const char* name, V_DATA* v_data) { if (trick_MM != NULL) { return( trick_MM->get_enumerated(name, v_data )); } else { - Trick::MemoryManager::emitError("get_enumerated() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("get_enumerated() called before MemoryManager instantiation.\n") ; return 1 ; } } + +extern "C" void TMM_add_checkpoint_alloc_dependency(const char * name) { + if (trick_MM != NULL) { + trick_MM->add_checkpoint_alloc_dependency(name) ; + } + return ; +} + diff --git a/trick_source/sim_services/MemoryManager/MemoryManager_add_checkpoint_alloc_dependency.cpp b/trick_source/sim_services/MemoryManager/MemoryManager_add_checkpoint_alloc_dependency.cpp new file mode 100644 index 00000000..e461b754 --- /dev/null +++ b/trick_source/sim_services/MemoryManager/MemoryManager_add_checkpoint_alloc_dependency.cpp @@ -0,0 +1,11 @@ +#include "trick/MemoryManager.hh" + +// MEMBER FUNCTION: +void Trick::MemoryManager::add_checkpoint_alloc_dependency(const char *name) { + VARIABLE_MAP_ITER it = variable_map.find(name) ; + if ( it != variable_map.end() ) { + dependencies.push_back(it->second) ; + stl_dependencies.push_back(it->second) ; + } +} + diff --git a/trick_source/sim_services/MemoryManager/MemoryManager_alloc_depends.cpp b/trick_source/sim_services/MemoryManager/MemoryManager_alloc_depends.cpp index 7dfe9e40..5a4d9509 100644 --- a/trick_source/sim_services/MemoryManager/MemoryManager_alloc_depends.cpp +++ b/trick_source/sim_services/MemoryManager/MemoryManager_alloc_depends.cpp @@ -2,7 +2,7 @@ #include "trick/attributes.h" // MEMBER FUNCTION -void Trick::MemoryManager::get_alloc_deps_in_allocation(std::vector& dependencies, ALLOC_INFO* alloc_info ) { +void Trick::MemoryManager::get_alloc_deps_in_allocation(ALLOC_INFO* alloc_info ) { ATTRIBUTES* reference_attr; @@ -58,12 +58,12 @@ void Trick::MemoryManager::get_alloc_deps_in_allocation(std::vector // Get the dependencies of the allocation if (alloc_info->type == TRICK_STRUCTURED) { if (reference_attr->num_index > 0) { - get_alloc_deps_in_arrayed_class( dependencies, (char*)(alloc_info->start), reference_attr, 0, 0) ; + get_alloc_deps_in_arrayed_class( (char*)(alloc_info->start), reference_attr, 0, 0) ; } else { - get_alloc_deps_in_class( dependencies, (char*)(alloc_info->start), alloc_info->attr) ; + get_alloc_deps_in_class( (char*)(alloc_info->start), alloc_info->attr) ; } } else { - get_alloc_deps_in_intrinsic( dependencies, alloc_info->start, reference_attr, 0, 0 ); + get_alloc_deps_in_intrinsic( alloc_info->start, reference_attr, 0, 0 ); } if (debug_level) { @@ -76,7 +76,7 @@ void Trick::MemoryManager::get_alloc_deps_in_allocation(std::vector } // MEMBER FUNCTION -void Trick::MemoryManager::get_alloc_deps_in_allocation( std::vector& dependencies, const char* var_name ) { +void Trick::MemoryManager::get_alloc_deps_in_allocation( const char* var_name ) { VARIABLE_MAP::iterator pos; ALLOC_INFO *alloc_info; @@ -89,7 +89,7 @@ void Trick::MemoryManager::get_alloc_deps_in_allocation( std::vectorsecond; - get_alloc_deps_in_allocation( dependencies, alloc_info ); + get_alloc_deps_in_allocation( alloc_info ); } else { std::cerr << "ERROR: get_alloc_deps_in_allocation(\""<< var_name <<"\") failed because the given name is'nt known by the MemoryManager." @@ -100,7 +100,7 @@ void Trick::MemoryManager::get_alloc_deps_in_allocation( std::vector& dependencies, char* address, ATTRIBUTES* attr) { +void Trick::MemoryManager::get_alloc_deps_in_class( char* address, ATTRIBUTES* attr) { int ii; if (debug_level > 1) { @@ -123,19 +123,19 @@ void Trick::MemoryManager::get_alloc_deps_in_class( std::vector& de if (attr[ii].type == TRICK_STRUCTURED) { if (attr[ii].num_index != 0) { - get_alloc_deps_in_arrayed_class( dependencies, elem_addr, &attr[ii], 0, 0); + get_alloc_deps_in_arrayed_class( elem_addr, &attr[ii], 0, 0); } else { - get_alloc_deps_in_class( dependencies, elem_addr, (ATTRIBUTES*)(attr[ii].attr)); + get_alloc_deps_in_class( elem_addr, (ATTRIBUTES*)(attr[ii].attr)); } } else { - get_alloc_deps_in_intrinsic( dependencies, elem_addr, &(attr[ii]), 0, 0); + get_alloc_deps_in_intrinsic( elem_addr, &(attr[ii]), 0, 0); } } } } // MEMBER FUNCTION -void Trick::MemoryManager::get_alloc_deps_in_arrayed_class( std::vector& dependencies, +void Trick::MemoryManager::get_alloc_deps_in_arrayed_class( char* address, ATTRIBUTES* attr, int curr_dim, @@ -163,7 +163,7 @@ void Trick::MemoryManager::get_alloc_deps_in_arrayed_class( std::vectorname << "[" << offset << "] points to @" << (void*)pointer << std::endl; } - get_alloc_deps_in_allocation(dependencies, alloc_info); + get_alloc_deps_in_allocation(alloc_info); } else { if (debug_level) { std::cout << __FUNCTION__ << ": Pointer ("<< (void*)pointer <<") refers to memory that the MemoryManager doesn't know about." << std::endl; @@ -182,11 +182,11 @@ void Trick::MemoryManager::get_alloc_deps_in_arrayed_class( std::vectorindex[curr_dim].size; for (ii = 0; ii < curr_dim_size; ii++) { if (curr_dim < attr->num_index - 1) { - get_alloc_deps_in_arrayed_class( dependencies, address, attr, curr_dim + 1, offset * curr_dim_size + ii); + get_alloc_deps_in_arrayed_class( address, attr, curr_dim + 1, offset * curr_dim_size + ii); } else { char* elem_addr; elem_addr = address + (offset * curr_dim + ii) * attr->size ; - get_alloc_deps_in_class( dependencies, elem_addr, (ATTRIBUTES*)attr->attr ); + get_alloc_deps_in_class( elem_addr, (ATTRIBUTES*)attr->attr ); } } } @@ -194,7 +194,7 @@ void Trick::MemoryManager::get_alloc_deps_in_arrayed_class( std::vector& dependencies, void* address, ATTRIBUTES* attr, int curr_dim, int offset) { +void Trick::MemoryManager::get_alloc_deps_in_intrinsic( void* address, ATTRIBUTES* attr, int curr_dim, int offset) { if (debug_level > 1) { std::cout << "DEBUG: Entered function:" << __FUNCTION__ << std::endl; @@ -215,7 +215,7 @@ void Trick::MemoryManager::get_alloc_deps_in_intrinsic( std::vector if (debug_level) { std::cout << __FUNCTION__ << ": @" << (void*)address << "." << attr->name << "[" << offset << "] points to @" << (void*)pointer << std::endl; } - get_alloc_deps_in_allocation(dependencies, alloc_info); + get_alloc_deps_in_allocation(alloc_info); } else { if (debug_level) { std::cout << __FUNCTION__ << ": Pointer ("<< (void*)pointer <<") refers to memory that the MemoryManager doesn't know about." << std::endl; @@ -232,7 +232,7 @@ void Trick::MemoryManager::get_alloc_deps_in_intrinsic( std::vector } else { // otherwise its a constrained array. int ii; for (ii=0 ; ii< attr->index[curr_dim].size ; ii++) { - get_alloc_deps_in_intrinsic( dependencies, address, attr, curr_dim + 1, offset * attr->index[curr_dim].size + ii); + get_alloc_deps_in_intrinsic( address, attr, curr_dim + 1, offset * attr->index[curr_dim].size + ii); } } } diff --git a/trick_source/sim_services/MemoryManager/MemoryManager_clear_memory.cpp b/trick_source/sim_services/MemoryManager/MemoryManager_clear_memory.cpp index fb778b60..460d42d2 100644 --- a/trick_source/sim_services/MemoryManager/MemoryManager_clear_memory.cpp +++ b/trick_source/sim_services/MemoryManager/MemoryManager_clear_memory.cpp @@ -95,6 +95,12 @@ void Trick::MemoryManager::clear_rvalue( void* base_address, ATTRIBUTES* attr, i final_address = (char*)base_address + offset * sizeof(void*); *(std::string*)final_address = ""; break; + case TRICK_STL : + final_address = (char*)base_address + offset * attr->size ; + if ( attr->clear_stl ) { + (*attr->clear_stl)(final_address) ; + } + break; default : std::stringstream message; message << "Unhandled Type (" << (int)attr->type << ")."; diff --git a/trick_source/sim_services/MemoryManager/MemoryManager_get_stl_dependencies.cpp b/trick_source/sim_services/MemoryManager/MemoryManager_get_stl_dependencies.cpp new file mode 100644 index 00000000..3cfc3ce9 --- /dev/null +++ b/trick_source/sim_services/MemoryManager/MemoryManager_get_stl_dependencies.cpp @@ -0,0 +1,192 @@ + +#include + +#include "trick/MemoryManager.hh" +#include "trick/attributes.h" + +// MEMBER FUNCTION +void Trick::MemoryManager::get_stl_dependencies( ALLOC_INFO* alloc_info ) { + + ATTRIBUTES* reference_attr; + + if (debug_level > 1) { + std::cout << "DEBUG: Entered function:" << __FUNCTION__ << std::endl; + } + + if (alloc_info == NULL) { + std::cout << "ERROR: Trick::MemoryManager::get_stl_dependencies called with alloc_info == NULL." << std::endl; + std::cout.flush(); + return; + } + + if (debug_level) { + std::cout << __FUNCTION__ << ": Begin scan of allocation @" << (void*)alloc_info->start << " for dependencies." << std::endl; + } + + reference_attr = make_reference_attr( alloc_info ); + + // Get the dependencies of the allocation + if (alloc_info->type == TRICK_STRUCTURED) { + if (reference_attr->num_index > 0) { + get_stl_dependencies_in_arrayed_class(alloc_info->name, (char*)(alloc_info->start), reference_attr, 0, 0) ; + } else { + get_stl_dependencies_in_class(alloc_info->name, (char*)(alloc_info->start), alloc_info->attr) ; + } + } else { + get_stl_dependencies_in_intrinsic(alloc_info->name, alloc_info->start, reference_attr, 0, 0 ); + } + + if (debug_level) { + std::cout << __FUNCTION__ << ": End scan of allocation @" << (void*)alloc_info->start << "." << std::endl; + } + + free_reference_attr( reference_attr ); + +} + +// MEMBER FUNCTION +void Trick::MemoryManager::get_stl_dependencies_in_class( std::string name, char* address, ATTRIBUTES* attr) { + int ii; + + if (debug_level > 1) { + std::cout << "DEBUG: Entered function:" << __FUNCTION__ << std::endl; + } + + if (attr == NULL) { + std::cerr << "ERROR: Trick::MemoryManager::get_stl_dependencies_in_class called with attr = NULL." << std::endl; + return; + } + + for (ii = 0; attr[ii].name[0] != '\0'; ii++) { + if (currentCheckPointAgent->output_perm_check(&attr[ii])) { + char *elem_addr; + if (attr[ii].mods & 2) { + elem_addr = (char *) attr[ii].offset; + } else { + elem_addr = address + attr[ii].offset; + } + + if (attr[ii].type == TRICK_STRUCTURED) { + if (attr[ii].num_index != 0) { + get_stl_dependencies_in_arrayed_class( name + "." + attr[ii].name, elem_addr, &attr[ii], 0, 0); + } else { + get_stl_dependencies_in_class( name + "." + attr[ii].name, elem_addr, (ATTRIBUTES*)(attr[ii].attr)); + } + } else if (attr[ii].type == TRICK_STL) { + (*attr[ii].checkpoint_stl)(elem_addr, name.c_str(), attr[ii].name) ; + } else { + get_stl_dependencies_in_intrinsic( name + "." + attr[ii].name , elem_addr, &(attr[ii]), 0, 0); + } + } + } +} + +// MEMBER FUNCTION +void Trick::MemoryManager::get_stl_dependencies_in_arrayed_class( + std::string name, + char* address, + ATTRIBUTES* attr, + int curr_dim, + int offset) { + int ii; + + if (debug_level > 1) { + std::cout << "DEBUG: Entered function:" << __FUNCTION__ << std::endl; + } + + if (attr == NULL) { + std::cerr << "Trick::MemoryManager::get_stl_dependencies_in_arrayed_class: ERROR: attr = NULL." << std::endl; + return; + } + + if (attr->index[curr_dim].size == 0) { + + void* pointer = *(void**)((char*)address + offset * sizeof(void*)); + + if (pointer != NULL) { + ALLOC_INFO *alloc_info; + alloc_info = get_alloc_info_of( pointer); + if (alloc_info != NULL) { + + if (debug_level) { + std::cout << __FUNCTION__ << ": @" << (void*)address << "." << attr->name << "[" << offset << "] points to @" << (void*)pointer << std::endl; + } + //get_stl_dependencies(alloc_info); + } else { + if (debug_level) { + std::cout << __FUNCTION__ << ": Pointer ("<< (void*)pointer <<") refers to memory that the MemoryManager doesn't know about." << std::endl; + std::cout.flush(); + } + } + } else { + if (debug_level) { + std::cout << __FUNCTION__ << ": Allocation reference is NULL." << std::endl; + std::cout.flush(); + } + } + + } else { + int curr_dim_size; + curr_dim_size = attr->index[curr_dim].size; + for (ii = 0; ii < curr_dim_size; ii++) { + char index[16] ; + sprintf(index, "[%d]", ii) ; + if (curr_dim < attr->num_index - 1) { + get_stl_dependencies_in_arrayed_class( name + index, address, attr, curr_dim + 1, offset * curr_dim_size + ii); + } else { + char* elem_addr; + elem_addr = address + (offset * curr_dim + ii) * attr->size ; + get_stl_dependencies_in_class( name + index, elem_addr, (ATTRIBUTES*)attr->attr ); + } + } + } +} + + +// MEMBER FUNCTION +void Trick::MemoryManager::get_stl_dependencies_in_intrinsic( std::string name , void* address, ATTRIBUTES* attr, int curr_dim, int offset) { + + if (debug_level > 1) { + std::cout << "DEBUG: Entered function:" << __FUNCTION__ << std::endl; + } + + // If the variable that we are pointing to is an arrayed + if (curr_dim < attr->num_index) { + + // If it is an unconstrained array (a pointer) + if (attr->index[curr_dim].size == 0) { + + void* pointer = *(void**)((char*)address + offset * sizeof(void*)); + + if (pointer != NULL) { + ALLOC_INFO *alloc_info; + alloc_info = get_alloc_info_of( pointer); + if (alloc_info != NULL) { + if (debug_level) { + std::cout << __FUNCTION__ << ": @" << (void*)address << "." << attr->name << "[" << offset << "] points to @" << (void*)pointer << std::endl; + } + //get_stl_dependencies(alloc_info); + } else { + if (debug_level) { + std::cout << __FUNCTION__ << ": Pointer ("<< (void*)pointer <<") refers to memory that the MemoryManager doesn't know about." << std::endl; + std::cout.flush(); + } + } + } else { + if (debug_level) { + std::cout << __FUNCTION__ << ": Allocation reference is NULL." << std::endl; + std::cout.flush(); + } + } + + } else { // otherwise its a constrained array. + int ii; + for (ii=0 ; ii< attr->index[curr_dim].size ; ii++) { + char index[16] ; + sprintf(index, "[%d]", ii) ; + //get_stl_dependencies_in_intrinsic( name + index , address, attr, curr_dim + 1, offset * attr->index[curr_dim].size + ii); + } + } + } +} + diff --git a/trick_source/sim_services/MemoryManager/MemoryManager_restore.cpp b/trick_source/sim_services/MemoryManager/MemoryManager_restore.cpp index ea763ef5..805e360f 100644 --- a/trick_source/sim_services/MemoryManager/MemoryManager_restore.cpp +++ b/trick_source/sim_services/MemoryManager/MemoryManager_restore.cpp @@ -20,14 +20,19 @@ int Trick::MemoryManager::read_checkpoint( std::istream *is) { emitError("Checkpoint restore failed.") ; } + // Search for stls and restore them + for ( pos=alloc_info_map.begin() ; pos!=alloc_info_map.end() ; pos++ ) { + restore_stls(pos->second) ; + } + // Go through all of the allocations that have been created looking // for those whose names start with the temporary-variable prefix and: - pthread_mutex_lock(&mm_mutex); for ( pos=alloc_info_map.begin() ; pos!=alloc_info_map.end() ; pos++ ) { alloc_info = pos->second; + if ( alloc_info->stcl == TRICK_LOCAL) { // If the temporary-variable prefix occurs at the beginning of the name ... diff --git a/trick_source/sim_services/MemoryManager/MemoryManager_restore_stls.cpp b/trick_source/sim_services/MemoryManager/MemoryManager_restore_stls.cpp new file mode 100644 index 00000000..0aba1563 --- /dev/null +++ b/trick_source/sim_services/MemoryManager/MemoryManager_restore_stls.cpp @@ -0,0 +1,197 @@ + +#include + +#include "trick/MemoryManager.hh" +#include "trick/attributes.h" + +// MEMBER FUNCTION +void Trick::MemoryManager::restore_stls( ALLOC_INFO* alloc_info ) { + + ATTRIBUTES* reference_attr; + + if (debug_level > 1) { + std::cout << "DEBUG: Entered function:" << __FUNCTION__ << std::endl; + } + + if (alloc_info == NULL) { + std::cout << "ERROR: Trick::MemoryManager::restore_stls called with alloc_info == NULL." << std::endl; + std::cout.flush(); + return; + } + + // If there is no name associated with this alloc_info, we won't be able to find any stls associated with it. + if (alloc_info->name == NULL) { + return; + } + + if (debug_level) { + std::cout << __FUNCTION__ << ": Begin scan of allocation @" << (void*)alloc_info->start << " for dependencies." << std::endl; + } + + reference_attr = make_reference_attr( alloc_info ); + + // Get the dependencies of the allocation + if (alloc_info->type == TRICK_STRUCTURED) { + if (reference_attr->num_index > 0) { + restore_stls_in_arrayed_class(alloc_info->name, (char*)(alloc_info->start), reference_attr, 0, 0) ; + } else { + restore_stls_in_class(alloc_info->name, (char*)(alloc_info->start), alloc_info->attr) ; + } + } else { + restore_stls_in_intrinsic(alloc_info->name, alloc_info->start, reference_attr, 0, 0 ); + } + + if (debug_level) { + std::cout << __FUNCTION__ << ": End scan of allocation @" << (void*)alloc_info->start << "." << std::endl; + } + + free_reference_attr( reference_attr ); + +} + +// MEMBER FUNCTION +void Trick::MemoryManager::restore_stls_in_class( std::string name, char* address, ATTRIBUTES* attr) { + int ii; + + if (debug_level > 1) { + std::cout << "DEBUG: Entered function:" << __FUNCTION__ << std::endl; + } + + if (attr == NULL) { + std::cerr << "ERROR: Trick::MemoryManager::restore_stls called with attr = NULL." << std::endl; + return; + } + + for (ii = 0; attr[ii].name[0] != '\0'; ii++) { + if (currentCheckPointAgent->input_perm_check(&attr[ii])) { + char *elem_addr; + if (attr[ii].mods & 2) { + elem_addr = (char *) attr[ii].offset; + } else { + elem_addr = address + attr[ii].offset; + } + + if (attr[ii].type == TRICK_STRUCTURED) { + if (attr[ii].num_index != 0) { + restore_stls_in_arrayed_class( name + "." + attr[ii].name, elem_addr, &attr[ii], 0, 0); + } else { + restore_stls_in_class( name + "." + attr[ii].name, elem_addr, (ATTRIBUTES*)(attr[ii].attr)); + } + } else if (attr[ii].type == TRICK_STL) { + (*attr[ii].restore_stl)(elem_addr, name.c_str(), attr[ii].name) ; + } else { + restore_stls_in_intrinsic( name + "." + attr[ii].name , elem_addr, &(attr[ii]), 0, 0); + } + } + } +} + +// MEMBER FUNCTION +void Trick::MemoryManager::restore_stls_in_arrayed_class( + std::string name, + char* address, + ATTRIBUTES* attr, + int curr_dim, + int offset) { + int ii; + + if (debug_level > 1) { + std::cout << "DEBUG: Entered function:" << __FUNCTION__ << std::endl; + } + + if (attr == NULL) { + std::cerr << "Trick::MemoryManager::restore_stls_in_arrayed_class: ERROR: attr = NULL." << std::endl; + return; + } + + if (attr->index[curr_dim].size == 0) { + + void* pointer = *(void**)((char*)address + offset * sizeof(void*)); + + if (pointer != NULL) { + ALLOC_INFO *alloc_info; + alloc_info = get_alloc_info_of( pointer); + if (alloc_info != NULL) { + + if (debug_level) { + std::cout << __FUNCTION__ << ": @" << (void*)address << "." << attr->name << "[" << offset << "] points to @" << (void*)pointer << std::endl; + } + //restore_stls(alloc_info); + } else { + if (debug_level) { + std::cout << __FUNCTION__ << ": Pointer ("<< (void*)pointer <<") refers to memory that the MemoryManager doesn't know about." << std::endl; + std::cout.flush(); + } + } + } else { + if (debug_level) { + std::cout << __FUNCTION__ << ": Allocation reference is NULL." << std::endl; + std::cout.flush(); + } + } + + } else { + int curr_dim_size; + curr_dim_size = attr->index[curr_dim].size; + for (ii = 0; ii < curr_dim_size; ii++) { + char index[16] ; + sprintf(index, "[%d]", ii) ; + if (curr_dim < attr->num_index - 1) { + restore_stls_in_arrayed_class( name + index, address, attr, curr_dim + 1, offset * curr_dim_size + ii); + } else { + char* elem_addr; + elem_addr = address + (offset * curr_dim + ii) * attr->size ; + restore_stls_in_class( name + index, elem_addr, (ATTRIBUTES*)attr->attr ); + } + } + } +} + + +// MEMBER FUNCTION +void Trick::MemoryManager::restore_stls_in_intrinsic( std::string name , void* address, ATTRIBUTES* attr, int curr_dim, int offset) { + + if (debug_level > 1) { + std::cout << "DEBUG: Entered function:" << __FUNCTION__ << std::endl; + } + + // If the variable that we are pointing to is an arrayed + if (curr_dim < attr->num_index) { + + // If it is an unconstrained array (a pointer) + if (attr->index[curr_dim].size == 0) { + + void* pointer = *(void**)((char*)address + offset * sizeof(void*)); + + if (pointer != NULL) { + ALLOC_INFO *alloc_info; + alloc_info = get_alloc_info_of( pointer); + if (alloc_info != NULL) { + if (debug_level) { + std::cout << __FUNCTION__ << ": @" << (void*)address << "." << attr->name << "[" << offset << "] points to @" << (void*)pointer << std::endl; + } + //restore_stls(alloc_info); + } else { + if (debug_level) { + std::cout << __FUNCTION__ << ": Pointer ("<< (void*)pointer <<") refers to memory that the MemoryManager doesn't know about." << std::endl; + std::cout.flush(); + } + } + } else { + if (debug_level) { + std::cout << __FUNCTION__ << ": Allocation reference is NULL." << std::endl; + std::cout.flush(); + } + } + + } else { // otherwise its a constrained array. + int ii; + for (ii=0 ; ii< attr->index[curr_dim].size ; ii++) { + char index[16] ; + sprintf(index, "[%d]", ii) ; + //restore_stls_in_intrinsic( name + index , address, attr, curr_dim + 1, offset * attr->index[curr_dim].size + ii); + } + } + } +} + diff --git a/trick_source/sim_services/MemoryManager/MemoryManager_write_checkpoint.cpp b/trick_source/sim_services/MemoryManager/MemoryManager_write_checkpoint.cpp index 4464bc5a..141ba0ba 100644 --- a/trick_source/sim_services/MemoryManager/MemoryManager_write_checkpoint.cpp +++ b/trick_source/sim_services/MemoryManager/MemoryManager_write_checkpoint.cpp @@ -11,7 +11,7 @@ #endif // MEMBER FUNCTION -void Trick::MemoryManager::write_checkpoint( std::ostream& out_s, std::vector& dependencies) { +void Trick::MemoryManager::execute_checkpoint( std::ostream& out_s ) { ALLOC_INFO_MAP::iterator pos; ALLOC_INFO* alloc_info; @@ -26,16 +26,17 @@ void Trick::MemoryManager::write_checkpoint( std::ostream& out_s, std::vectorname == NULL) { if ( alloc_info->stcl == TRICK_LOCAL) { sprintf( name, "%s%d", local_anon_var_prefix, local_anon_var_number++); alloc_info->name = strdup( name); - currentCheckPointAgent->write_decl( out_s, alloc_info); } else if (alloc_info->stcl == TRICK_EXTERN) { sprintf( name, "%s%d", extern_anon_var_prefix, extern_anon_var_number++); alloc_info->name = strdup( name); @@ -44,7 +45,15 @@ void Trick::MemoryManager::write_checkpoint( std::ostream& out_s, std::vectorstcl == TRICK_LOCAL) { currentCheckPointAgent->write_decl( out_s, alloc_info); } } @@ -77,6 +86,12 @@ void Trick::MemoryManager::write_checkpoint( std::ostream& out_s, std::vectorname = NULL; } } + + // Delete the variables created by STLs. Remove memory in reverse order. + std::vector::reverse_iterator it ; + for ( it = stl_dependencies.rbegin() ; it != stl_dependencies.rend() ; it++ ) { + delete_var((*it)->start) ; + } } // Local sort function used in write_checkpoint. @@ -87,7 +102,8 @@ void Trick::MemoryManager::write_checkpoint( std::ostream& out_s) { ALLOC_INFO_MAP::iterator pos; ALLOC_INFO* alloc_info; - std::vector dependencies; + dependencies.clear(); + stl_dependencies.clear(); pthread_mutex_lock(&mm_mutex); for ( pos=alloc_info_map.begin() ; pos!=alloc_info_map.end() ; pos++ ) { @@ -98,7 +114,8 @@ void Trick::MemoryManager::write_checkpoint( std::ostream& out_s) { // Sort the dependencies by ALLOC_INFO.id. std::sort( dependencies.begin() , dependencies.end() , alloc_info_id_compare) ; pthread_mutex_unlock(&mm_mutex); - write_checkpoint( out_s, dependencies); + + execute_checkpoint( out_s ); } @@ -119,21 +136,20 @@ void Trick::MemoryManager::write_checkpoint(const char* filename) { // MEMBER FUNCTION void Trick::MemoryManager::write_checkpoint( std::ostream& out_s, const char* var_name) { - std::vector dependencies; + dependencies.clear(); + stl_dependencies.clear(); pthread_mutex_lock(&mm_mutex); - get_alloc_deps_in_allocation( dependencies, var_name); + get_alloc_deps_in_allocation( var_name); pthread_mutex_unlock(&mm_mutex); - write_checkpoint( out_s, dependencies); + execute_checkpoint( out_s ); } // MEMBER FUNCTION void Trick::MemoryManager::write_checkpoint(const char* filename, const char* var_name) { - std::vector dependencies; std::ofstream out_s( filename, std::ios::out); - if (out_s.is_open()) { write_checkpoint( out_s, var_name); } else { @@ -146,19 +162,21 @@ void Trick::MemoryManager::write_checkpoint(const char* filename, const char* va // MEMBER FUNCTION void Trick::MemoryManager::write_checkpoint( std::ostream& out_s, std::vector& var_name_list) { - std::vector dependencies; const char* var_name; int n_names; + dependencies.clear(); + stl_dependencies.clear(); + n_names = var_name_list.size(); for (int ii=0; ii< n_names; ii++) { var_name = var_name_list[ii]; pthread_mutex_lock(&mm_mutex); - get_alloc_deps_in_allocation(dependencies, var_name); + get_alloc_deps_in_allocation(var_name); pthread_mutex_unlock(&mm_mutex); } - write_checkpoint( out_s, dependencies); + execute_checkpoint( out_s ); } // MEMBER FUNCTION