// ***************************************************************************** // public methods // ***************************************************************************** public virtual BasicBlock Clone() { BasicBlock block = new BasicBlock(id); block.SetSeq(seq.Clone()); Sharpen.Collections.AddAll(block.instrOldOffsets, instrOldOffsets); return(block); }
private bool CompareBasicBlocksEx(ControlFlowGraph graph, BasicBlock pattern, BasicBlock sample, int type, int finallytype, List <int[]> lstStoreVars) { InstructionSequence seqPattern = pattern.GetSeq(); InstructionSequence seqSample = sample.GetSeq(); if (type != 0) { seqPattern = seqPattern.Clone(); if ((type & 1) > 0) { // first if (finallytype > 0) { seqPattern.RemoveInstruction(0); } } if ((type & 2) > 0) { // last if (finallytype == 0 || finallytype == 2) { seqPattern.RemoveLast(); } if (finallytype == 2) { seqPattern.RemoveLast(); } } } if (seqPattern.Length() > seqSample.Length()) { return(false); } for (int i = 0; i < seqPattern.Length(); i++) { Instruction instrPattern = seqPattern.GetInstr(i); Instruction instrSample = seqSample.GetInstr(i); // compare instructions with respect to jumps if (!EqualInstructions(instrPattern, instrSample, lstStoreVars)) { return(false); } } if (seqPattern.Length() < seqSample.Length()) { // split in two blocks SimpleInstructionSequence seq = new SimpleInstructionSequence(); LinkedList <int> oldOffsets = new LinkedList <int>(); for (int i = seqSample.Length() - 1; i >= seqPattern.Length(); i--) { seq.AddInstruction(0, seqSample.GetInstr(i), -1); oldOffsets.AddFirst(sample.GetOldOffset(i)); seqSample.RemoveInstruction(i); } BasicBlock newblock = new BasicBlock(++graph.last_id); newblock.SetSeq(seq); Sharpen.Collections.AddAll(newblock.GetInstrOldOffsets(), oldOffsets); List <BasicBlock> lstTemp = new List <BasicBlock>(sample.GetSuccs()); // move successors foreach (BasicBlock suc in lstTemp) { sample.RemoveSuccessor(suc); newblock.AddSuccessor(suc); } sample.AddSuccessor(newblock); graph.GetBlocks().AddWithKey(newblock, newblock.id); HashSet <BasicBlock> setFinallyExits = graph.GetFinallyExits(); if (setFinallyExits.Contains(sample)) { setFinallyExits.Remove(sample); setFinallyExits.Add(newblock); } // copy exception edges and extend protected ranges for (int j = 0; j < sample.GetSuccExceptions().Count; j++) { BasicBlock hd = sample.GetSuccExceptions()[j]; newblock.AddSuccessorException(hd); ExceptionRangeCFG range = graph.GetExceptionRange(hd, sample); range.GetProtectedRange().Add(newblock); } } return(true); }