From c1eb4e6fc52b53c3be389d1c10c1d7fa073ceef3 Mon Sep 17 00:00:00 2001 From: Alex Lin Date: Thu, 31 Mar 2016 15:48:19 -0500 Subject: [PATCH] Add direct STL checkpointing The typenames on the Mac need to be converted for strings. The templates are genererating the long form of the string type name. I wrote a function to catch test the template parameter types and return std::string. refs #206 --- include/trick/checkpoint_map.hh | 13 +++++++++---- include/trick/checkpoint_pair.hh | 13 +++++++++---- include/trick/checkpoint_queue.hh | 7 +++++-- include/trick/checkpoint_sequence_stl.hh | 5 +++-- include/trick/checkpoint_stack.hh | 4 +++- include/trick/checkpoint_stl_protos.hh | 7 +++++++ .../CheckPointRestart/stl_type_name_convert.cpp | 11 +++++++++++ 7 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 include/trick/checkpoint_stl_protos.hh create mode 100644 trick_source/sim_services/CheckPointRestart/stl_type_name_convert.cpp diff --git a/include/trick/checkpoint_map.hh b/include/trick/checkpoint_map.hh index 661e66b2..cd58c6c8 100644 --- a/include/trick/checkpoint_map.hh +++ b/include/trick/checkpoint_map.hh @@ -19,6 +19,7 @@ #endif #include "checkpoint_is_stl_container.hh" +#include "checkpoint_stl_protos.hh" #include "checkpoint_fwd_declare.hh" #include "trick/memorymanager_c_intf.h" #include "trick/message_proto.h" @@ -50,7 +51,8 @@ int checkpoint_map_ik_id(STL & in_map , std::string object_name , std::string va std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); if ( cont_size > 0 ) { - var_declare << abi::__cxa_demangle(typeid(*keys).name(), 0, 0, &status ) << " " + std::string type_string = stl_type_name_convert(abi::__cxa_demangle(typeid(*keys).name(), 0, 0, &status )) ; + var_declare << type_string << " " << object_name << "_" << var_name << "_keys[" << cont_size << "]" ; keys = (typename STL::key_type *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_keys").c_str()) ; @@ -58,7 +60,8 @@ int checkpoint_map_ik_id(STL & in_map , std::string object_name , std::string va var_declare.str("") ; var_declare.clear() ; - var_declare << abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ) << " " + type_string = stl_type_name_convert(abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status )) ; + var_declare << type_string << " " << object_name << "_" << var_name << "_data[" << cont_size << "]" ; items = (typename STL::mapped_type *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_data").c_str()) ; @@ -104,7 +107,8 @@ int checkpoint_map_ik_sd(STL & in_map , std::string object_name , std::string va std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); if ( cont_size > 0 ) { - var_declare << abi::__cxa_demangle(typeid(*keys).name(), 0, 0, &status ) << " " + std::string type_string = stl_type_name_convert(abi::__cxa_demangle(typeid(*keys).name(), 0, 0, &status )) ; + var_declare << type_string << " " << object_name << "_" << var_name << "_keys[" << cont_size << "]" ; keys = (typename STL::key_type *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_keys").c_str()) ; @@ -174,7 +178,8 @@ int checkpoint_map_sk_id(STL & in_map , std::string object_name , std::string va var_declare.str("") ; var_declare.clear() ; - var_declare << abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ) << " " + std::string type_string = stl_type_name_convert(abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status )) ; + var_declare << type_string << " " << object_name << "_" << var_name << "_data[" << cont_size << "]" ; items = (typename STL::mapped_type *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_data").c_str()) ; diff --git a/include/trick/checkpoint_pair.hh b/include/trick/checkpoint_pair.hh index f4580bee..7591846e 100644 --- a/include/trick/checkpoint_pair.hh +++ b/include/trick/checkpoint_pair.hh @@ -18,6 +18,7 @@ #endif #include "checkpoint_is_stl_container.hh" +#include "checkpoint_stl_protos.hh" #include "checkpoint_fwd_declare.hh" #include "trick/memorymanager_c_intf.h" #include "trick/message_proto.h" @@ -33,7 +34,8 @@ int checkpoint_stl(std::pair & in_pair , std::string object_name SECOND * second = nullptr ; std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); - var_declare << abi::__cxa_demangle(typeid(*first).name(), 0, 0, &status ) << " " + std::string type_string = stl_type_name_convert(abi::__cxa_demangle(typeid(*first).name(), 0, 0, &status )) ; + var_declare << type_string << " " << object_name << "_" << var_name << "_first[1]" ; first = (FIRST *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_first").c_str()) ; @@ -41,7 +43,8 @@ int checkpoint_stl(std::pair & in_pair , std::string object_name var_declare.str("") ; var_declare.clear() ; - var_declare << abi::__cxa_demangle(typeid(*second).name(), 0, 0, &status ) << " " + type_string = stl_type_name_convert(abi::__cxa_demangle(typeid(*second).name(), 0, 0, &status )) ; + var_declare << type_string << " " << object_name << "_" << var_name << "_second[1]" ; second = (SECOND *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_second").c_str()) ; @@ -62,7 +65,8 @@ int checkpoint_stl(std::pair & in_pair , std::string object_name std::string * second = nullptr ; std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); - var_declare << abi::__cxa_demangle(typeid(*first).name(), 0, 0, &status ) << " " + std::string type_string = stl_type_name_convert(abi::__cxa_demangle(typeid(*first).name(), 0, 0, &status )) ; + var_declare << type_string << " " << object_name << "_" << var_name << "_first[1]" ; first = (FIRST *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_first").c_str()) ; @@ -99,7 +103,8 @@ int checkpoint_stl(std::pair & in_pair , std::string object_name var_declare.str("") ; var_declare.clear() ; - var_declare << abi::__cxa_demangle(typeid(*second).name(), 0, 0, &status ) << " " + std::string type_string = stl_type_name_convert(abi::__cxa_demangle(typeid(*second).name(), 0, 0, &status )) ; + var_declare << type_string << " " << object_name << "_" << var_name << "_second[1]" ; second = (SECOND *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_second").c_str()) ; diff --git a/include/trick/checkpoint_queue.hh b/include/trick/checkpoint_queue.hh index c784424d..f46af853 100644 --- a/include/trick/checkpoint_queue.hh +++ b/include/trick/checkpoint_queue.hh @@ -17,6 +17,7 @@ #endif #include "checkpoint_is_stl_container.hh" +#include "checkpoint_stl_protos.hh" #include "checkpoint_fwd_declare.hh" #include "checkpoint_sequence_stl.hh" #include "trick/memorymanager_c_intf.h" @@ -42,7 +43,8 @@ int checkpoint_stl(std::queue & in_stl , std::string object std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); if ( cont_size > 0 ) { - var_declare << abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ) << " " + std::string type_string = stl_type_name_convert(abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status )) ; + var_declare << type_string << " " << object_name << "_" << var_name << "[" << cont_size << "]" ; items = (ITEM_TYPE *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name).c_str()) ; @@ -110,7 +112,8 @@ int checkpoint_stl(std::priority_queue & in_stl std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); if ( cont_size > 0 ) { - var_declare << abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ) << " " + std::string type_string = stl_type_name_convert(abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status )) ; + var_declare << type_string << " " << object_name << "_" << var_name << "[" << cont_size << "]" ; items = (ITEM_TYPE *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name).c_str()) ; diff --git a/include/trick/checkpoint_sequence_stl.hh b/include/trick/checkpoint_sequence_stl.hh index cbdf9b50..aed918bc 100644 --- a/include/trick/checkpoint_sequence_stl.hh +++ b/include/trick/checkpoint_sequence_stl.hh @@ -20,6 +20,7 @@ #endif #include "checkpoint_is_stl_container.hh" +#include "checkpoint_stl_protos.hh" #include "checkpoint_fwd_declare.hh" #include "trick/memorymanager_c_intf.h" #include "trick/message_proto.h" @@ -44,8 +45,8 @@ int checkpoint_sequence_i(STL & in_stl , std::string object_name , std::string v std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); if ( cont_size > 0 ) { - - var_declare << abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ) << " " + std::string type_string = stl_type_name_convert(abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status )) ; + var_declare << type_string << " " << object_name << "_" << var_name << "[" << cont_size << "]" ; items = (typename STL::value_type *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name).c_str()) ; diff --git a/include/trick/checkpoint_stack.hh b/include/trick/checkpoint_stack.hh index 116930fc..4dca87e5 100644 --- a/include/trick/checkpoint_stack.hh +++ b/include/trick/checkpoint_stack.hh @@ -17,6 +17,7 @@ #endif #include "trick/checkpoint_sequence_stl.hh" +#include "checkpoint_stl_protos.hh" #include "trick/memorymanager_c_intf.h" #include "trick/message_proto.h" @@ -39,7 +40,8 @@ int checkpoint_stl(std::stack & in_stl , std::string object std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); if ( cont_size > 0 ) { - var_declare << abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ) << " " + std::string type_string = stl_type_name_convert(abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status )) ; + var_declare << type_string << " " << object_name << "_" << var_name << "[" << cont_size << "]" ; items = (ITEM_TYPE *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name).c_str()) ; diff --git a/include/trick/checkpoint_stl_protos.hh b/include/trick/checkpoint_stl_protos.hh new file mode 100644 index 00000000..b72c29fa --- /dev/null +++ b/include/trick/checkpoint_stl_protos.hh @@ -0,0 +1,7 @@ + +#include + +// prototype of functions used in checkpoint_stl templates + +std::string stl_type_name_convert(std::string in_type) ; + diff --git a/trick_source/sim_services/CheckPointRestart/stl_type_name_convert.cpp b/trick_source/sim_services/CheckPointRestart/stl_type_name_convert.cpp new file mode 100644 index 00000000..2299d411 --- /dev/null +++ b/trick_source/sim_services/CheckPointRestart/stl_type_name_convert.cpp @@ -0,0 +1,11 @@ + +#include + +std::string stl_type_name_convert(std::string in_type) { + std::string type_string(in_type) ; + std::string basic_string("std::__1::basic_string") ; + if ( !type_string.compare(0, basic_string.length(), basic_string)) { + type_string = "std::string" ; + } + return type_string ; +}