Ejemplo n.º 1
0
        private void PostProcessMethod(MethodDef method, bool isExport)
        {
            CFG.ScopeBlock scope = this.Runtime.LookupMethod(method);

            var ilTransformer = new ILPostTransformer(method, scope, this.Runtime);

            ilTransformer.Transform();
        }
Ejemplo n.º 2
0
        private void PostProcessMethod(MethodDef method, bool isExport)
        {
            var scope = Runtime.LookupMethod(method);

            var ilTransformer = new ILPostTransformer(method, scope, Runtime);

            ilTransformer.Transform();
        }
Ejemplo n.º 3
0
        public void Transform(ILPostTransformer tr)
        {
            var key = Keys[tr.Block];

            methodInfo.BlockKeys[tr.Block] = new VMBlockKey {
                EntryKey = (byte)key.Entry,
                ExitKey  = (byte)key.Exit
            };
        }
Ejemplo n.º 4
0
        void VisitInstr(ILInstrList instrs, ILInstruction instr, ref int index, ILPostTransformer tr)
        {
            if (instr.OpCode != ILOpCode.__BEGINCALL && instr.OpCode != ILOpCode.__ENDCALL)
            {
                return;
            }

            var callInfo = (InstrCallInfo)instr.Annotation;

            if (callInfo.IsECall)
            {
                instrs.RemoveAt(index);
                index--;
                return;
            }

            var saving = new HashSet <VMRegisters>(saveRegs);
            var retVar = (IRVariable)callInfo.ReturnValue;

            // R0 = return register, need to save if retVar register is not R0
            Debug.Assert(!(retVar == null ^ (callInfo.ReturnRegister == null ^ callInfo.ReturnSlot == null)));
            if (retVar != null)
            {
                if (callInfo.ReturnSlot == null)
                {
                    var retReg = callInfo.ReturnRegister.Register;
                    saving.Remove(retReg);
                    if (retReg != VMRegisters.R0)
                    {
                        saving.Add(VMRegisters.R0);
                    }
                }
                else
                {
                    saving.Add(VMRegisters.R0);
                }
            }
            else
            {
                saving.Add(VMRegisters.R0);
            }

            if (instr.OpCode == ILOpCode.__BEGINCALL)
            {
                instrs.Replace(index, saving
                               .Select(reg => new ILInstruction(ILOpCode.PUSHR_OBJECT, ILRegister.LookupRegister(reg), instr)));
            }
            else
            {
                instrs.Replace(index, saving
                               .Select(reg => new ILInstruction(ILOpCode.POP, ILRegister.LookupRegister(reg), instr))
                               .Reverse());
            }
            index--;
        }
Ejemplo n.º 5
0
        void VisitInstr(ILInstrList instrs, ILInstruction instr, ref int index, ILPostTransformer tr)
        {
            var rel = instr.Operand as ILRelReference;

            if (rel == null)
            {
                return;
            }

            var methodRef = rel.Target as ILMethodTarget;

            if (methodRef == null)
            {
                return;
            }

            methodRef.Resolve(tr.Runtime);
        }
Ejemplo n.º 6
0
        private void CompileHelpers(MethodDef method, ScopeBlock scope)
        {
            var methodCtx = new IRContext(method, method.Body);

            methodCtx.IsRuntime = true;
            var irTransformer = new IRTransformer(scope, methodCtx, rt);

            irTransformer.Transform();

            var ilTranslator  = new ILTranslator(rt);
            var ilTransformer = new ILTransformer(method, scope, rt);

            ilTranslator.Translate(scope);
            ilTransformer.Transform();

            var postTransformer = new ILPostTransformer(method, scope, rt);

            postTransformer.Transform();
        }
 public void Transform(ILPostTransformer tr)
 {
     tr.Instructions.VisitInstrs(VisitInstr, tr);
 }
 public void Initialize(ILPostTransformer tr)
 {
     saveRegs = tr.Runtime.Descriptor.Data.LookupInfo(tr.Method).UsedRegister;
 }
 public void Transform(ILPostTransformer tr) => tr.Instructions.VisitInstrs(this.VisitInstr, tr);
Ejemplo n.º 10
0
 public void Initialize(ILPostTransformer tr)
 {
     runtime    = tr.Runtime;
     methodInfo = tr.Runtime.Descriptor.Data.LookupInfo(tr.Method);
     ComputeBlockKeys(tr.RootScope);
 }
Ejemplo n.º 11
0
        void VisitInstr(ILInstrList instrs, ILInstruction instr, ref int index, ILPostTransformer tr)
        {
            if (instr.OpCode != ILOpCode.__BEGINCALL && instr.OpCode != ILOpCode.__ENDCALL)
            {
                return;
            }

            var callInfo = (InstrCallInfo)instr.Annotation;

            if (callInfo.IsECall)
            {
                instrs.RemoveAt(index);
                index--;
                return;
            }

            var saving = new HashSet <VMRegisters>(saveRegs);
            var retVar = (IRVariable)callInfo.ReturnValue;

            // R0 = return register, need to save if retVar register is not R07
            if (retVar == null ^ (callInfo.ReturnRegister == null ^ callInfo.ReturnSlot == null))
            {
                ConsoleColor c = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Debug.Assert [SaveRegistersTransform.cs] L36");
                Console.WriteLine($"Method target->{callInfo.Method.FullName}");
                Console.ForegroundColor = c;
            }
            if (retVar != null)
            {
                if (callInfo.ReturnSlot == null)
                {
                    var retReg = callInfo.ReturnRegister.Register;
                    saving.Remove(retReg);
                    if (retReg != VMRegisters.R0)
                    {
                        saving.Add(VMRegisters.R0);
                    }
                }
                else
                {
                    saving.Add(VMRegisters.R0);
                }
            }
            else
            {
                saving.Add(VMRegisters.R0);
            }

            if (instr.OpCode == ILOpCode.__BEGINCALL)
            {
                instrs.Replace(index, saving
                               .Select(reg => new ILInstruction(ILOpCode.PUSHR_OBJECT, ILRegister.LookupRegister(reg), instr)));
            }
            else
            {
                instrs.Replace(index, saving
                               .Select(reg => new ILInstruction(ILOpCode.POP, ILRegister.LookupRegister(reg), instr))
                               .Reverse());
            }
            index--;
        }
        private void VisitInstr(ILInstrList instrs, ILInstruction instr, ref int index, ILPostTransformer tr)
        {
            if (!(instr.Operand is ILRelReference rel))
            {
                return;
            }

            if (!(rel.Target is ILMethodTarget methodRef))
            {
                return;
            }

            methodRef.Resolve(tr.Runtime);
        }