Beispiel #1
0
        private static void EmitBranch(AILEmitterCtx Context, OpCode ILOp)
        {
            AOpCodeBImm Op = (AOpCodeBImm)Context.CurrOp;

            if (Context.CurrBlock.Next != null &&
                Context.CurrBlock.Branch != null)
            {
                Context.Emit(ILOp, Context.GetLabel(Op.Imm));
            }
            else
            {
                Context.EmitStoreState();

                AILLabel LblTaken = new AILLabel();

                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);
            }
        }
Beispiel #2
0
        private static void EmitCb(AILEmitterCtx Context, OpCode ILOp)
        {
            AOpCodeBImmCmp Op = (AOpCodeBImmCmp)Context.CurrOp;

            Context.EmitLdintzr(Op.Rt);
            Context.EmitLdc_I(0);

            Context.Emit(ILOp, Context.GetLabel(Op.Imm));
        }
Beispiel #3
0
        private static void EmitTb(AILEmitterCtx Context, OpCode ILOp)
        {
            AOpCodeBImmTest Op = (AOpCodeBImmTest)Context.CurrOp;

            Context.EmitLdintzr(Op.Rt);
            Context.EmitLdc_I(1L << Op.Pos);

            Context.Emit(OpCodes.And);

            Context.EmitLdc_I(0);

            Context.Emit(ILOp, Context.GetLabel(Op.Imm));
        }
Beispiel #4
0
        public static void B(AILEmitterCtx Context)
        {
            AOpCodeBImmAl Op = (AOpCodeBImmAl)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);
            }
        }
Beispiel #5
0
        private ATranslatedSub TranslateSubroutine(AMemory Memory, long Position)
        {
            (ABlock[] Graph, ABlock Root)Cfg = ADecoder.DecodeSubroutine(this, Memory, Position);

            string SubName = SymbolTable.GetOrAdd(Position, $"Sub{Position:x16}");

            PropagateName(Cfg.Graph, SubName);

            AILEmitterCtx Context = new AILEmitterCtx(
                this,
                Cfg.Graph,
                Cfg.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.
            foreach (ATranslatedSub TS in CachedSubs.Values)
            {
                if (TS.SubCalls.Contains(Position))
                {
                    TS.MarkForReJit();
                }
            }

            ATranslatedSub Subroutine = Context.GetSubroutine();

            CachedSubs.AddOrUpdate(Position, Subroutine, (Key, OldVal) => Subroutine);

            return(Subroutine);
        }
Beispiel #6
0
        private void TranslateTier1(AThreadState State, AMemory Memory, long Position)
        {
            (ABlock[] Graph, ABlock Root)Cfg = ADecoder.DecodeSubroutine(State, this, Memory, Position);

            string SubName = GetSubName(Position);

            PropagateName(Cfg.Graph, SubName);

            AILEmitterCtx Context = new AILEmitterCtx(this, Cfg.Graph, Cfg.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 (CachedSubs.TryGetValue(Position, out ATranslatedSub OldSub))
            {
                foreach (long CallerPos in OldSub.GetCallerPositions())
                {
                    if (CachedSubs.TryGetValue(Position, out ATranslatedSub CallerSub))
                    {
                        CallerSub.MarkForReJit();
                    }
                }
            }

            ATranslatedSub Subroutine = Context.GetSubroutine();

            Subroutine.SetType(ATranslatedSubType.SubTier1);

            CachedSubs.AddOrUpdate(Position, Subroutine, (Key, OldVal) => Subroutine);
        }
Beispiel #7
0
        private ATranslatedSub TranslateSubroutine(long Position)
        {
            (ABlock[] Graph, ABlock Root)Cfg = ADecoder.DecodeSubroutine(this, Position);

            AILEmitterCtx Context = new AILEmitterCtx(
                this,
                Cfg.Graph,
                Cfg.Root);

            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.
            foreach (ATranslatedSub TS in CachedSubs.Values)
            {
                if (TS.SubCalls.Contains(Position))
                {
                    TS.MarkForReJit();
                }
            }

            ATranslatedSub Subroutine = Context.GetSubroutine();

            if (!CachedSubs.TryAdd(Position, Subroutine))
            {
                CachedSubs[Position] = Subroutine;
            }

            return(Subroutine);
        }
Beispiel #8
0
        public static void B(AILEmitterCtx Context)
        {
            AOpCodeBImmAl Op = (AOpCodeBImmAl)Context.CurrOp;

            Context.Emit(OpCodes.Br, Context.GetLabel(Op.Imm));
        }
Beispiel #9
0
        public static void B_Cond(AILEmitterCtx Context)
        {
            AOpCodeBImmCond Op = (AOpCodeBImmCond)Context.CurrOp;

            Context.EmitCondBranch(Context.GetLabel(Op.Imm), Op.Cond);
        }