[cfe-dev] how to get c++ name for llvm::Type
theraven at sucs.org
Wed Jul 7 09:04:56 PDT 2010
On 7 Jul 2010, at 16:44, Jochen Wilhelmy wrote:
> How can this be done?
The first question is 'can this be done?' and the answer is 'no'. LLVM types encode the structure of a type, but nothing else. Two structs in C with the same layout will be mapped to the same LLVM type, therefore you can not go from an LLVM type back to a C type, because there is no unambiguous mapping.
That said, there are a few things that you can do that might be 'good enough.'
You might iterate through the types declared in a given compilation unit, generate the corresponding LLVM types, and produce a reverse mapping. This would work for unambiguous types, but not for ambiguous ones. For example, the Cocoa standard types NSPoint and NSSize would both map to the same LLVM type.
Alternatively, you could use the LLVM debugging info, which does include the source type name. This is not completely trivial to parse, but is relatively easy. This will tell you the source-language type of a specific value, but not of an LLVM type (some things, such as source-language unions, map to multiple LLVM types).
More information about the cfe-dev