/** * Instruments given module with rules from json file. * @param M module to be instrumented. * @param rw parsed rules to apply. * @return true if instrumentation was done without problems, false otherwise */ bool instrumentModule(Module &M, Rewriter rw) { // Instrument global variables if(!InstrumentGlobals(M, rw)) return false; RewriterConfig rw_config = rw.getConfig(); // Instrument instructions in functions for (Module::iterator Fiterator = M.begin(), E = M.end(); Fiterator != E; ++Fiterator) { // Do not instrument functions linked for instrumentation string functionName = (&*Fiterator)->getName().str(); if(functionName.find("__INSTR_")!=string::npos || functionName.find("__VERIFIER_")!=string::npos) { //TODO just starts with logger.write_info("Omitting function " + functionName + " from instrumentation."); continue; } for (inst_iterator Iiterator = inst_begin(&*Fiterator), End = inst_end(&*Fiterator); Iiterator != End; ++Iiterator) { // This iterator may be replaced (by an iterator to the following // instruction) in the InsertCallInstruction function // Check if the instruction is relevant if(!CheckInstruction(&*Iiterator, M, &*Fiterator, rw_config, &Iiterator)) return false; } } // Write instrumented module into the output file ofstream out_file; out_file.open(outputName, ios::out | ios::binary); raw_os_ostream rstream(out_file); WriteBitcodeToFile(&M, rstream); rstream.flush(); out_file.close(); return true; }