How to get the textual representation of an LLVM IR instruction?

Viewed 2013

If I is of type llvm::Instruction, we can print out the same in human-readable form (textual representation) by errs() << I;

I want the assign the exact same representation to a std::string to C type string. How can I do that?

2 Answers

I ran into some problems using @eush77's answer. Here is my fix.

std::string str;
llvm::raw_string_ostream ss(str);
ss << I;
errs() << ss.str() << "\n";
Related