BaseBlocksList createBaseBlockList(List <Block> allBlocks, List <List <ExceptionHandler> > exSorted) { var bbl = new BaseBlocksList(); foreach (var block in allBlocks) { int start = instrToIndex[block.FirstInstr.Instruction]; int end = instrToIndex[block.LastInstr.Instruction]; bbl.add(block, start, end); } foreach (var exHandlers in exSorted) { var tryBlock = new TryBlock(); var tryStart = instrToIndex[exHandlers[0].TryStart]; var tryEnd = getInstrIndex(exHandlers[0].TryEnd) - 1; tryBlock.BaseBlocks = bbl.replace(tryStart, tryEnd, tryBlock); foreach (var exHandler in exHandlers) { var tryHandlerBlock = new TryHandlerBlock(exHandler); tryBlock.addTryHandler(tryHandlerBlock); int filterStart = -1, handlerStart = -1, handlerEnd = -1; if (exHandler.FilterStart != null) { filterStart = instrToIndex[exHandler.FilterStart]; var end = instrToIndex[exHandler.HandlerStart] - 1; tryHandlerBlock.FilterHandlerBlock.BaseBlocks = bbl.replace(filterStart, end, tryHandlerBlock.FilterHandlerBlock); } handlerStart = instrToIndex[exHandler.HandlerStart]; handlerEnd = getInstrIndex(exHandler.HandlerEnd) - 1; tryHandlerBlock.HandlerBlock.BaseBlocks = bbl.replace(handlerStart, handlerEnd, tryHandlerBlock.HandlerBlock); tryHandlerBlock.BaseBlocks = bbl.replace(filterStart == -1 ? handlerStart : filterStart, handlerEnd, tryHandlerBlock); } } return(bbl); }
BaseBlocksList createBaseBlockList(List<Block> allBlocks, List<List<ExceptionHandler>> exSorted) { var bbl = new BaseBlocksList(); foreach (var block in allBlocks) { int start = instrToIndex[block.FirstInstr.Instruction]; int end = instrToIndex[block.LastInstr.Instruction]; bbl.add(block, start, end); } foreach (var exHandlers in exSorted) { var tryBlock = new TryBlock(); var tryStart = instrToIndex[exHandlers[0].TryStart]; var tryEnd = getInstrIndex(exHandlers[0].TryEnd) - 1; tryBlock.BaseBlocks = bbl.replace(tryStart, tryEnd, tryBlock); foreach (var exHandler in exHandlers) { var tryHandlerBlock = new TryHandlerBlock(exHandler); tryBlock.addTryHandler(tryHandlerBlock); int filterStart = -1, handlerStart = -1, handlerEnd = -1; if (exHandler.FilterStart != null) { filterStart = instrToIndex[exHandler.FilterStart]; var end = instrToIndex[exHandler.HandlerStart] - 1; tryHandlerBlock.FilterHandlerBlock.BaseBlocks = bbl.replace(filterStart, end, tryHandlerBlock.FilterHandlerBlock); } handlerStart = instrToIndex[exHandler.HandlerStart]; handlerEnd = getInstrIndex(exHandler.HandlerEnd) - 1; tryHandlerBlock.HandlerBlock.BaseBlocks = bbl.replace(handlerStart, handlerEnd, tryHandlerBlock.HandlerBlock); tryHandlerBlock.BaseBlocks = bbl.replace(filterStart == -1 ? handlerStart : filterStart, handlerEnd, tryHandlerBlock); } } return bbl; }