I am following along this post however I am new to C++ and LLVM and need help breaking down what everything means in this for loop
for(auto I = inst_begin(F), E = inst_end(F); I != E; ++I) {
Instruction &Inst = *I;
if(Inst.getOpcode() == Instruction::SDiv) {
errs() << "Found Signed Division Instruction!\n";
}
}
I seem to understand what's going on inside the for loop with the if statement, however I don't understand what 'inst_begin' and 'inst_end' are doing and 'I != E' as well as 'Instruction &Int = *I' I know the *I is referencing the original value of an allocated memory address..? I guess I also need a reference for how 'for loops' are written in LLVM as well.
This is a valid C/C++ code. I'm not familiar with LLVM, so I might be not fully correct:
inst_begin(F)returns a pointer to the first instruction within some code blockF(a function?)inst_end(F)returns a pointer after the last valid instruction in a code blockFI != Eis an exit condition for theforloop - repeat some steps until this condition becomes false. If it's false - exit from the loop.I++moves your pointer to the next instruction in betweeninst_begin(F)...inst_end(F)Instruction &Int = *I.Iis a pointer to some memory location, basically, it's just a number.*Iallows you to fetch the instruction itself given some memory address. later, you inspect this instruction.There is no magic in this code, so get some decent C/C++ text book or MOOC and it will be 100% clear for you.