llvm::Type结构的字符串表示形式

string representation of llvm::Type structure

本文关键字:表示 字符串 Type 结构 llvm      更新时间:2023-10-16

llvm::Type 2.9及更早版本曾经使用getDescription方法来检索该类型的字符串表示。此方法在llvm 3.0中已不存在。

我不确定这是否被弃用以支持Type::print(raw_ostream&),但无论如何,我对这个API很好奇。关于如何使用它,有哪些例子?如何转储到stringconst char*

特别是,我想将字符串传递给Boost::Format,它是一个现代的c++sprintf

我想,您需要创建一个llvm::raw_string_ostream的实例,并将std::string传递到它的构造器中。现在您可以将其用作llvm::raw_ostream,完成后只需调用.str()即可获得字符串。

类似的东西:

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

LLVM已经更改了它的接口,所以现在以下内容将起作用:

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