如何在LLVM中打印指令? [英] How do I print out an Instruction in LLVM?

查看:515
本文介绍了如何在LLVM中打印指令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

for (BasicBlock::iterator i = bb->begin(), e = bb->end(); i != e; ++i) {
    i.print(errs()); ???

我正在编写一个 LLVM PASS ,我想获得基本块中的指令列表,但是如何在控制台上将它们打印出来以便看到它们呢?上面的代码显示了我尝试过的代码,它遍历了基本块中的每条指令,但在打印功能下出现了以下错误.

I am writing an LLVM PASS and I want to get the list of instructions inside the basic block, but how do print them out on the console so I can see them? The code above shows the code i have tried, it iterates through every instruction in the basic block but I get the error below for the print function.

错误:"llvm :: BasicBlock :: iterator"没有名为"print"的成员 i.print(errs());

error: ‘llvm::BasicBlock::iterator’ has no member named ‘print’ i.print(errs());

是否有更好的方法来打印说明?

Is there a better approach to printing out instructions?

推荐答案

问题是您正在尝试打印迭代器而不是指令.您可以尝试以下方法之一.您可以通过打印基本块或打印每条指令来在基本块中打印指令:

The problem is that you are trying to print the iterator and not an instruction. You can try one of the following approaches. You can print the instructions in a basic block by either printing the basic block or printing each instruction:

BasicBlock* bb = ...; // 
errs() << *bb;
for (BasicBlock::iterator i = bb->begin(), e = bb->end(); i != e; ++i) {
  Instruction* ii = &*i;
  errs() << *ii << "\n";

两张照片都将输出相同的结果.

Both prints will output the same results.

这篇关于如何在LLVM中打印指令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆