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?
答案 0 :(得分:4)
嗯,LLVM也提供了一个字符串流:
#include <llvm/Support/raw_ostream.h>
像这样使用:
std::string str;
llvm::raw_string_ostream(str) << I;
// use str
答案 1 :(得分:0)
我在使用@ eush77的答案时遇到了一些问题。这是我的解决方法。
std::string str;
llvm::raw_string_ostream ss(str);
ss << I;
errs() << ss.str() << "\n";