Example #1
0
        public IEnumerable <CodeInstruction> TransMethod(TranspilerFactory factory)
        {
            var instructions = factory.CodeEnumerator;

            while (instructions.MoveNext())
            {
                yield return(instructions.Current);
            }
        }
Example #2
0
        public IEnumerable <CodeInstruction> TransMethod(TranspilerFactory factory)
        {
            var t            = count;
            var instructions = factory.CodeEnumerator;

            while (t > 0 && instructions.MoveNext())
            {
                t--;
            }
            return(null);
        }
Example #3
0
        public IEnumerable <CodeInstruction> TransMethod(TranspilerFactory factory)
        {
            var instructions = factory.CodeEnumerator;
            var generator    = factory.Generator;
            var locals       = factory.Locals;
            var labels       = factory.Labels;

            foreach (var code in list)
            {
                var no = code.opcode.Value;
                if (code.opcode == CodeParser.LocalvarOpcode)
                {
                    locals.Add(generator.DeclareLocal((Type)code.operand));
                }
                else if (code.opcode == CodeParser.LabelOpcode)
                {
                    var index = (int)code.operand;
                    for (int i = labels.Count - 1; i < index; i++)
                    {
                        labels.Add(generator.DefineLabel());
                    }
                    var t = new List <Label>()
                    {
                        labels[index]
                    };
                    yield return(new CodeInstruction(OpCodes.Nop)
                    {
                        labels = t
                    });
                }
                else if (no == 17 || no == 18 || no == 19 || no == -500 || no == -499 || no == -498)
                {
                    code.operand = locals[Convert.ToInt32(code.operand)];
                    yield return(code);
                }
                else if (code.opcode.OperandType == OperandType.InlineBrTarget || code.opcode.OperandType == OperandType.ShortInlineBrTarget)
                {
                    var index = (int)code.operand;
                    for (int i = labels.Count - 1; i < index; i++)
                    {
                        labels.Add(generator.DefineLabel());
                    }
                    code.operand = labels[index];
                    yield return(code);
                }
                else
                {
                    yield return(code);
                }
            }
        }
Example #4
0
        public IEnumerable <CodeInstruction> TransMethod(TranspilerFactory factory)
        {
            CodeInstruction         current;
            Queue <CodeInstruction> queue = new Queue <CodeInstruction>();
            var instructions = factory.CodeEnumerator;

            while (instructions.MoveNext())
            {
                current = instructions.Current;
                queue.Enqueue(current);
                if (queue.Count > search.Count)
                {
                    yield return(queue.Dequeue());
                }
                if (queue.Count == search.Count)
                {
                    int count = 0;
                    foreach (var item in queue)
                    {
                        if (search[count].isMatchWith(item))
                        {
                            count++;
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (count >= search.Count)
                    {
                        while (queue.Count > 0)
                        {
                            yield return(queue.Dequeue());
                        }
                        yield break;
                    }
                }
            }
            while (queue.Count > 0)
            {
                yield return(queue.Dequeue());
            }
            // can't find pattern
            throw new Exception($"SearchTranspiler '{factory.Name}' failed.");
        }