Ejemplo n.º 1
0
        private static void EmitBranch(ILEmitterCtx context, Condition cond)
        {
            OpCodeBImm64 op = (OpCodeBImm64)context.CurrOp;

            if (context.CurrBlock.Branch != null)
            {
                context.EmitCondBranch(context.GetLabel(op.Imm), cond);

                if (context.CurrBlock.Next == null)
                {
                    context.EmitStoreContext();
                    context.EmitLdc_I8(op.Position + 4);

                    context.Emit(OpCodes.Ret);
                }
            }
            else
            {
                context.EmitStoreContext();

                ILLabel lblTaken = new ILLabel();

                context.EmitCondBranch(lblTaken, cond);

                context.EmitLdc_I8(op.Position + 4);

                context.Emit(OpCodes.Ret);

                context.MarkLabel(lblTaken);

                context.EmitLdc_I8(op.Imm);

                context.Emit(OpCodes.Ret);
            }
        }
Ejemplo n.º 2
0
        private static void EmitBranch(ILEmitterCtx context, OpCode ilOp)
        {
            OpCodeBImm64 op = (OpCodeBImm64)context.CurrOp;

            if (context.CurrBlock.Next != null &&
                context.CurrBlock.Branch != null)
            {
                context.Emit(ilOp, context.GetLabel(op.Imm));
            }
            else
            {
                context.EmitStoreState();

                ILLabel lblTaken = new ILLabel();

                context.Emit(ilOp, lblTaken);

                context.EmitLdc_I8(op.Position + 4);

                context.Emit(OpCodes.Ret);

                context.MarkLabel(lblTaken);

                context.EmitLdc_I8(op.Imm);

                context.Emit(OpCodes.Ret);
            }
        }
Ejemplo n.º 3
0
        public static void B(ILEmitterCtx context)
        {
            IOpCode32BImm op = (IOpCode32BImm)context.CurrOp;

            if (context.CurrBlock.Branch != null)
            {
                context.Emit(OpCodes.Br, context.GetLabel(op.Imm));
            }
            else
            {
                context.EmitStoreContext();
                context.EmitLdc_I8(op.Imm);

                context.Emit(OpCodes.Ret);
            }
        }
Ejemplo n.º 4
0
        public static void B(ILEmitterCtx context)
        {
            OpCodeBImmAl64 op = (OpCodeBImmAl64)context.CurrOp;

            if (context.CurrBlock.Branch != null)
            {
                context.Emit(OpCodes.Br, context.GetLabel(op.Imm));
            }
            else
            {
                context.EmitStoreState();
                context.EmitLdc_I8(op.Imm);

                context.Emit(OpCodes.Ret);
            }
        }
Ejemplo n.º 5
0
        private void TranslateTier1(CpuThreadState state, MemoryManager memory, long position)
        {
            (Block[] graph, Block root) = Decoder.DecodeSubroutine(_cache, state, memory, position);

            string subName = GetSubroutineName(position);

            ILEmitterCtx context = new ILEmitterCtx(_cache, graph, root, subName);

            if (context.CurrBlock.Position != position)
            {
                context.Emit(OpCodes.Br, context.GetLabel(position));
            }

            do
            {
                context.EmitOpCode();
            }while (context.AdvanceOpCode());

            //Mark all methods that calls this method for ReJiting,
            //since we can now call it directly which is faster.
            if (_cache.TryGetSubroutine(position, out TranslatedSub oldSub))
            {
                foreach (long callerPos in oldSub.GetCallerPositions())
                {
                    if (_cache.TryGetSubroutine(position, out TranslatedSub callerSub))
                    {
                        callerSub.MarkForReJit();
                    }
                }
            }

            TranslatedSub subroutine = context.GetSubroutine();

            subroutine.SetType(TranslatedSubType.SubTier1);

            _cache.AddOrUpdate(position, subroutine, GetGraphInstCount(graph));
        }