【问题标题】:How to get the textual representation of an LLVM IR instruction?如何获取 LLVM IR 指令的文本表示?
【发布时间】:2017-10-15 07:12:00
【问题描述】:

如果Illvm::Instruction 类型,我们可以通过errs() << I; 以人类可读的形式(文本表示)打印出同样的内容

我希望将完全相同的表示分配给 std::string 到 C 类型的字符串。我该怎么做?

【问题讨论】:

    标签: llvm llvm-clang llvm-ir


    【解决方案1】:

    嗯,LLVM 也提供了一个字符串流:

    #include <llvm/Support/raw_ostream.h>
    

    像这样使用它:

    std::string str;
    llvm::raw_string_ostream(str) << I;
    
    // use str
    

    【讨论】:

      【解决方案2】:

      我在使用@eush77 的回答时遇到了一些问题。这是我的解决方法。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-01-12
        • 2014-12-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-31
        • 1970-01-01
        相关资源
        最近更新 更多