Example #1
0
        public List <Instruction> GenerateLevels(MethodDefinition curMethod, int target, int maxLevels, int maxLength = 20, bool unsigned = false, ModuleDefinition ovModule = null)
        {
            if (ovModule != null)
            {
                DynGen.Module  = ovModule;
                ExpGen.Module  = ovModule;
                MathGen.Module = ovModule;
                Module         = ovModule;

                LengthCall = Instruction.Create(OpCodes.Call, Module.Import(typeof(String).GetMethod("get_Length", Type.EmptyTypes)));

                // Avoid creating a new instance...
                // That way I can keep the previous stuff and still rename that.

                DynGen = new DynamicGenerator(rand.Next(500000), ovModule);
            }

            List <Instruction> builder = new List <Instruction>();

            builder.AddRange(Generate(curMethod, target, maxLength, unsigned));

            for (int x = 0; x < maxLevels; x++)
            {
                for (int i = 0; i < builder.Count; i++)
                {
                    Instruction inst = builder[i];

                    if (rand.Next(0, 100) % 2 == 0)
                    {
                        continue;
                    }

                    if (inst.OpCode == OpCodes.Ldc_I4)
                    {
                        int t = (int)inst.Operand;
                        if (t < 0)
                        {
                            continue;
                        }

                        var insts = Generate(curMethod, t, maxLength, unsigned);

                        builder[i] = insts[0];
                        var ee = insts.Skip(1).Reverse();
                        foreach (Instruction a in ee)
                        {
                            builder.Insert(i + 1, a);
                        }
                        i += insts.Count + 1;
                        //builder.AddRange(Generate(t, maxLength));
                    }
                }
            }

            return(builder);
        }
            public override IList <IEnumerator <KeyValuePair <long, T> > > GetOrderablePartitions(int partitionCount)
            {
                if (partitionCount < 1)
                {
                    throw new ArgumentOutOfRangeException("partitionCount");
                }
                var dynamicPartitioner = new DynamicGenerator(_source.GetEnumerator(), false);

                return((from i in Enumerable.Range(0, partitionCount) select dynamicPartitioner.GetEnumerator()).ToList());
            }
Example #3
0
            public override IList <IEnumerator <KeyValuePair <long, T> > > GetOrderablePartitions(int partitionCount)
            {
                partitionCount.ShouldBePositive("partitionCount");

                var dynamicPartitioner = new DynamicGenerator(_source.GetEnumerator(), false);

                return
                    (Enumerable.Range(0, partitionCount)
                     .Select(i => dynamicPartitioner.GetEnumerator())
                     .ToList());
            }
Example #4
0
        public StringGenerator(int seed, ModuleDefinition mod)
        {
            rand = new Random(seed);

            Module = mod;

            LengthCall  = Instruction.Create(OpCodes.Call, Module.Import(typeof(String).GetMethod("get_Length", Type.EmptyTypes)));
            StringEmpty = Instruction.Create(OpCodes.Ldsfld, Module.Import(typeof(String).GetField("Empty")));

            ExpGen  = new ExpressionGenerator(rand.Next(500000), Module);
            MathGen = new MathGenerator(rand.Next(500000), Module);
            DynGen  = new DynamicGenerator(rand.Next(500000), Module);
        }
        GetOrderablePartitions(int partitionCount)
        {
            if (partitionCount < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(partitionCount));
            }

            var dynamicPartitioner = new DynamicGenerator(source.GetEnumerator(), batchSize, false);

            var partitions = new IEnumerator <KeyValuePair <long, IReadOnlyList <T> > > [partitionCount];

            for (int i = 0; i < partitionCount; ++i)
            {
                partitions[i] = dynamicPartitioner.GetEnumerator();
            }
            return(partitions);
        }