How do I print out an Instruction in LLVM?

↘锁芯ラ 提交于 2019-12-23 04:02:10

问题


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

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.

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

Is there a better approach to printing out instructions?


回答1:


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.



来源:https://stackoverflow.com/questions/41959551/how-do-i-print-out-an-instruction-in-llvm

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!