LLVM的Fibonacci示例使用errs() << *theModule打印出LLVM IR。
是否有任何函数能够将生成的LLVM存储到字符串的(向量)或任何其他变量,而不只是打印出来?(例如,std::string llvm_IR = theModule->getIR())
我一直在搜索llvm::模块类引用,但没有得到任何帮助。
部分Fibonacci.cpp
前面定义了//CreateFibFunction以生成fibonacci函数。
LLVMContext Context;
// Create some module to put our function into it.
std::unique_ptr<Module> Owner(new Module("test", Context));
Module *theModule = Owner.get();
// We are about to create the "fib" function:
Function *FibF = CreateFibFunction(M, Context);
errs() << "OK\n";
errs() << "We just constructed this LLVM module:\n\n---------\n";
errs() << *theModule;
errs() << "---------\nstarting fibonacci(" << n << ") with JIT...\n";发布于 2015-11-27 23:45:17
您可以使用相同的方式--而不是使用errs(),它是raw_ostream,您可以使用raw_string_ostream,如下所示:
std::string Str;
raw_string_ostream OS(Str);
OS << *theModule;
OS.flush()
// Str now contains the module text发布于 2015-11-27 15:56:23
它看起来像是将模块文本打印到模块类外部的流中。PrintModulePass或类似的版本取决于您的版本
我会找到一个打印模块的工具,看看他们是怎么做的,也许是'opt‘。
https://stackoverflow.com/questions/33960249
复制相似问题