Reputation: 45
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?
Upvotes: 3
Views: 7836
Reputation: 2813
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.
Upvotes: 4