Example #1
0
        private void IncludeWriteOfVariable(MethodBody body, BitArray includedInstructions, VariableUsage readUsage)
        {
            int readIndex = body.Instructions.IndexOf(readUsage.Instruction);
            List <Instruction> precedingInstructions = body.Instructions.Take(readIndex).ToList();

            VariableUsage writeUsage = _instructionHelper
                                       .GetUsages(precedingInstructions)
                                       .LastOrDefault(usage => usage.Operation == VariableOperation.Write && usage.Index == readUsage.Index);

            if (writeUsage == null)
            {
                throw new InvalidOperationException("Could not find write of variable " + readUsage.Index);
            }

            int writeIndex = body.Instructions.IndexOf(writeUsage.Instruction);

            includedInstructions[writeIndex] = true;
            IncludeInstructionsUntilStackEmpty(body, writeUsage.Instruction, includedInstructions, 1);
        }
Example #2
0
        private void IncludeVariableInitializationInstructions(
            MethodBody body,
            BitArray includedInstructions)
        {
            while (true)
            {
                List <Instruction> instructions = body.Instructions
                                                  .Where((t, i) => includedInstructions[i])
                                                  .ToList();

                VariableUsage firstReadUsage = _instructionHelper
                                               .GetUsages(instructions)
                                               .GroupBy(usage => usage.Index)
                                               .Select(group => group.First())
                                               .FirstOrDefault(usage => usage.Operation == VariableOperation.Read);

                if (firstReadUsage == null)
                {
                    return;
                }

                IncludeWriteOfVariable(body, includedInstructions, firstReadUsage);
            }
        }
Example #3
0
        private void IncludeWriteOfVariable(MethodBody body, BitArray includedInstructions, VariableUsage readUsage)
        {
            int readIndex = body.Instructions.IndexOf(readUsage.Instruction);
            List<Instruction> precedingInstructions = body.Instructions.Take(readIndex).ToList();

            VariableUsage writeUsage = _instructionHelper
                .GetUsages(precedingInstructions)
                .LastOrDefault(usage => usage.Operation == VariableOperation.Write && usage.Index == readUsage.Index);

            if (writeUsage == null)
            {
                throw new InvalidOperationException("Could not find write of variable " + readUsage.Index);
            }

            int writeIndex = body.Instructions.IndexOf(writeUsage.Instruction);

            includedInstructions[writeIndex] = true;
            IncludeInstructionsUntilStackEmpty(body, writeUsage.Instruction, includedInstructions);
        }