Hi,
for a current project I'm required to get the types of the template
arguments key and value for std::map<K,V>. I've noticed that the STL
implementation used by Clang defines the type of the map as
%"class.std::map" = type { %"class.std::_Rb_tree" }
which then is further defined and finally ends as
%"struct.std::_Rb_tree_node_base" = type {
i32,
%"struct.std::_Rb_tree_node_base"*,
%"struct.std::_Rb_tree_node_base"*,
%"struct.std::_Rb_tree_node_base"*
}
However, indifferent what K and V are and how many different maps are
instantiated, it always ends at this definition. But, I also noticed, that
%"struct.std::pair" = type { i32, double }
is defined, which then provides the information I need.
Now the problem arises to connect %"class.std::map" to
%"struct.std::pair" correctly. To solve this I looked at the IR and
noticed, that the std::pair's are always defined in the reverse order of
the definitions of std::map. So I think about using some index to find
the correct std::pair.
From this idea two issues arise:
1. I feel that this approach is not that stable as it should be, for
instance, I think that the ordering of instantiation I'm making use of
may change.
2. I'm unable to retrieve all defined named types from the module. I
know there is LLVMContextImpl but this class is a forward declaration
and therefore I'm not able to access LLVMContextImpl::NamedStructTypes.
Thanks for any suggestions.
Best regards,
Sebastian
--
Mit freundlichen Grüßen / Kind regards
Sebastian Dreßler
Zuse Institute Berlin (ZIB)
Takustraße 7
D-14195 Berlin-Dahlem
Germany
dressler at zib.de
Phone: +49 30 84185-261
http://www.zib.de/
Sebastian Dreßler wrote> Now the problem arises to connect %"class.std::map" to > %"struct.std::pair" correctly. To solve this I looked at the IR and > noticed, that the std::pair's are always defined in the reverse order of > the definitions of std::map. So I think about using some index to find > the correct std::pair.I just thought again about this approach: this actually is the most inelegant way I could come up with. The following might be better: I will try to use the Clang library directly to convert the C++ type string, e. g. std::string, int, ..., to a LLVM type. However, any other suggestions are welcome. Maybe someone else already had this sort of problem? Best regards, Sebastian -- View this message in context: http://llvm.1065342.n5.nabble.com/Find-template-types-of-std-map-tp49951p49963.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
On Tue, Oct 16, 2012 at 4:17 AM, Sebastian Dreßler <dressler at zib.de> wrote:> Hi, > > for a current project I'm required to get the types of the template > arguments key and value for std::map<K,V>. I've noticed that the STL > implementation used by Clang defines the type of the map as > > %"class.std::map" = type { %"class.std::_Rb_tree" }Trying to dig template arguments out of LLVM IR types is a bad idea. Try a C++ demangler on a related function name, or the debug information. -Eli
Eli Friedman-2 wrote> On Tue, Oct 16, 2012 at 4:17 AM, Sebastian Dreßler <> dressler@> > wrote: >> Hi, >> >> for a current project I'm required to get the types of the template >> arguments key and value for std::map<K,V>. I've noticed that the >> STL >> implementation used by Clang defines the type of the map as >> >> %"class.std::map" = type { %"class.std::_Rb_tree" } > > Trying to dig template arguments out of LLVM IR types is a bad idea. > Try a C++ demangler on a related function name, or the debug > information.Thanks for the hint, I'll try that. However, when I successfully determined the name of the template parameters, I'll have to find the LLVM IR std::pair definition nevertheless. So, is there any function providing all names of named structs from a module? When I dump the module, I'm able to see all those structs, but I didn't find a function for e.g. iterating them. Best, Sebastian -- View this message in context: http://llvm.1065342.n5.nabble.com/Find-template-types-of-std-map-tp49951p50003.html Sent from the LLVM - Dev mailing list archive at Nabble.com.