Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

string representation of llvm::Type structure

llvm::Type 2.9 and earlier used to have getDescription method to retrieve a string representation of the type. This method does not exist anymore in llvm 3.0.

I'm not sure if this is deprecated in favor of Type::print(raw_ostream&), but in any case I'm curious of this API. What examples are there about how to use it? How can I dump to a string or const char*?

In particular, I want to pass the string to Boost::Format which is a modern c++ sprintf.

like image 690
lurscher Avatar asked Jan 04 '12 01:01

lurscher


1 Answers

I suppose, you need to create an instance of llvm::raw_string_ostream and pass your std::string into it's construtor. Now you can use it as llvm::raw_ostream and when you are done just call .str() to get your string.

Something like that:

std::string type_str;
llvm::raw_string_ostream rso(&type_str);
your_type->print(rso);
std::cout<<rso.str();

LLVM has changed its interface, so now the following will work:

std::string type_str;
llvm::raw_string_ostream rso(type_str);
your_type->print(rso);
std::cout<<rso.str();
like image 84
arrowd Avatar answered Oct 02 '22 06:10

arrowd