private void SplitJsrExceptionRanges(HashSet <BasicBlock> common_blocks, IDictionary <int, BasicBlock> mapNewNodes) { for (int i = exceptions.Count - 1; i >= 0; i--) { ExceptionRangeCFG range = exceptions[i]; List <BasicBlock> lstRange = range.GetProtectedRange(); HashSet <BasicBlock> setBoth = new HashSet <BasicBlock>(common_blocks); setBoth.IntersectWith(lstRange); if (setBoth.Count > 0) { List <BasicBlock> lstNewRange; if (setBoth.Count == lstRange.Count) { lstNewRange = new List <BasicBlock>(); ExceptionRangeCFG newRange = new ExceptionRangeCFG(lstNewRange, mapNewNodes.GetOrNull (range.GetHandler().id), range.GetExceptionTypes()); exceptions.Add(newRange); } else { lstNewRange = lstRange; } foreach (BasicBlock block in setBoth) { lstNewRange.Add(mapNewNodes.GetOrNull(block.id)); } } } }
private void SetExceptionEdges(InstructionSequence instrseq, Dictionary <int, BasicBlock > instrBlocks) { exceptions = new List <ExceptionRangeCFG>(); Dictionary <string, ExceptionRangeCFG> mapRanges = new Dictionary <string, ExceptionRangeCFG >(); foreach (ExceptionHandler handler in instrseq.GetExceptionTable().GetHandlers()) { BasicBlock from = instrBlocks.GetOrNull(handler.from_instr); BasicBlock to = instrBlocks.GetOrNull(handler.to_instr); BasicBlock handle = instrBlocks.GetOrNull(handler.handler_instr); string key = from.id + ":" + to.id + ":" + handle.id; if (mapRanges.ContainsKey(key)) { ExceptionRangeCFG range = mapRanges.GetOrNull(key); range.AddExceptionType(handler.exceptionClass); } else { List <BasicBlock> protectedRange = new List <BasicBlock>(); for (int j = from.id; j < to.id; j++) { BasicBlock block = blocks.GetWithKey(j); protectedRange.Add(block); block.AddSuccessorException(handle); } ExceptionRangeCFG range = new ExceptionRangeCFG(protectedRange, handle, handler.exceptionClass == null ? null : System.Linq.Enumerable.ToList(new [] { handler.exceptionClass }) ); Sharpen.Collections.Put(mapRanges, key, range); exceptions.Add(range); } } }
public override string ToString() { if (blocks == null) { return("Empty"); } string new_line_separator = DecompilerContext.GetNewLineSeparator(); StringBuilder buf = new StringBuilder(); foreach (BasicBlock block in blocks) { buf.Append("----- Block ").Append(block.id).Append(" -----").Append(new_line_separator ); buf.Append(block.ToString()); buf.Append("----- Edges -----").Append(new_line_separator); List <BasicBlock> suc = block.GetSuccs(); foreach (BasicBlock aSuc in suc) { buf.Append(">>>>>>>>(regular) Block ").Append(aSuc.id).Append(new_line_separator); } suc = block.GetSuccExceptions(); foreach (BasicBlock handler in suc) { ExceptionRangeCFG range = GetExceptionRange(handler, block); if (range == null) { buf.Append(">>>>>>>>(exception) Block ").Append(handler.id).Append("\t").Append("ERROR: range not found!" ).Append(new_line_separator); } else { List <string> exceptionTypes = range.GetExceptionTypes(); if (exceptionTypes == null) { buf.Append(">>>>>>>>(exception) Block ").Append(handler.id).Append("\t").Append("NULL" ).Append(new_line_separator); } else { foreach (string exceptionType in exceptionTypes) { buf.Append(">>>>>>>>(exception) Block ").Append(handler.id).Append("\t").Append(exceptionType ).Append(new_line_separator); } } } } buf.Append("----- ----- -----").Append(new_line_separator); } return(buf.ToString()); }
public virtual ExceptionRangeCFG GetExceptionRange(BasicBlock handler, BasicBlock block) { //List<ExceptionRangeCFG> ranges = new ArrayList<ExceptionRangeCFG>(); for (int i = exceptions.Count - 1; i >= 0; i--) { ExceptionRangeCFG range = exceptions[i]; if (range.GetHandler() == handler && range.GetProtectedRange().Contains(block)) { return(range); } } //ranges.add(range); return(null); }
public virtual void RemoveBlock(BasicBlock block) { while (block.GetSuccs().Count > 0) { block.RemoveSuccessor(block.GetSuccs()[0]); } while (block.GetSuccExceptions().Count > 0) { block.RemoveSuccessorException(block.GetSuccExceptions()[0]); } while (block.GetPreds().Count > 0) { block.GetPreds()[0].RemoveSuccessor(block); } while (block.GetPredExceptions().Count > 0) { block.GetPredExceptions()[0].RemoveSuccessorException(block); } last.RemovePredecessor(block); blocks.RemoveWithKey(block.id); for (int i = exceptions.Count - 1; i >= 0; i--) { ExceptionRangeCFG range = exceptions[i]; if (range.GetHandler() == block) { exceptions.RemoveAtReturningValue(i); } else { List <BasicBlock> lstRange = range.GetProtectedRange(); lstRange.Remove(block); if ((lstRange.Count == 0)) { exceptions.RemoveAtReturningValue(i); } } } subroutines.RemoveIf(ent => ent.Key == block || ent.Value == block); }