简体   繁体   中英

How do I print out an Instruction in LLVM?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM