for (MachineFunction::iterator It = MF.begin(), E = MF.end(); It != E; ++It) { MachineBasicBlock &MBB = *It; for(MachineBasicBlock::iterator MBBI = MBB.begin(), MBBE = MBB.end(); MBBI != MBBE; ++MBBI) { DebugLoc DL = MBBI.getDebugLoc(); if (DL) { errs() << "Instruction on line " << DL.getLine() << " in file " << DL.getFilename() << ":\n"; } } }
for (MachineFunction::iterator It = MF.begin(), E = MF.end(); It != E; ++It) { MachineBasicBlock &MBB = *It; for(MachineBasicBlock::iterator MBBI = MBB.begin(), MBBE = MBB.end(); MBBI != MBBE; ++MBBI) { DebugLoc DL = MBBI.getDebugLoc(); if (DL && DL.getLine() == 42) { errs() << "Found instruction on line 42 in file " << DL.getFilename() << ":\n"; MBBI->dump(); } } }This code is similar to the first example, but it additionally checks if the instruction is on a specific line (in this case, line 42) and prints out the instruction if it is. This code uses the LLVM library.