Exemplo n.º 1
0
        public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object aMethodInfo)
        {
            // method signature: $this, object @object, IntPtr method
            var xAssembler  = aAssembler;
            var xMethodInfo = (_MethodInfo)aMethodInfo;

            XS.Comment("Save target ($this) to field");
            XS.Comment("-- ldarg 0");
            Ldarg.DoExecute(xAssembler, xMethodInfo, 0);
            XS.Comment("-- ldarg 1");
            Ldarg.DoExecute(xAssembler, xMethodInfo, 1);
            XS.Comment("-- stfld _target");
            Stfld.DoExecute(xAssembler, xMethodInfo, "System.Object System.Delegate._target", xMethodInfo.MethodBase.DeclaringType, true, false);
            XS.Comment("Save method pointer to field");
            XS.Comment("-- ldarg 0");
            Ldarg.DoExecute(xAssembler, xMethodInfo, 0);
            XS.Comment("-- ldarg 2");
            Ldarg.DoExecute(xAssembler, xMethodInfo, 2);
            XS.Comment("-- stfld _methodPtr");
            Stfld.DoExecute(xAssembler, xMethodInfo, "System.IntPtr System.Delegate._methodPtr", xMethodInfo.MethodBase.DeclaringType, true, false);
            XS.Comment("Saving ArgSize to field");
            uint xSize = 0;

            foreach (var xArg in xMethodInfo.MethodBase.DeclaringType.GetMethod("Invoke").GetParameters())
            {
                xSize += ILOp.Align(ILOp.SizeOfType(xArg.ParameterType), 4);
            }

            XS.Comment("-- ldarg 0");
            Ldarg.DoExecute(xAssembler, xMethodInfo, 0);
            XS.Comment("-- push argsize");
            XS.Push(xSize);
            XS.Comment("-- stfld ArgSize");
            Stfld.DoExecute(xAssembler, xMethodInfo, "$$ArgSize$$", xMethodInfo.MethodBase.DeclaringType, true, false);
        }
Exemplo n.º 2
0
        public void Analyse()
        {
            var toAnalyse = new List <ILGroup>(StructuredCode);

            while (toAnalyse.Count != 0)
            {
                var analysing = toAnalyse.First(g => g.StartStack != null);
                toAnalyse.Remove(analysing);
                var stack = new Stack <Type>(analysing.StartStack.Reverse());

                uint stackOffset = 0;
                foreach (var item in stack)
                {
                    stackOffset += ILOp.Align(ILOp.SizeOfType(item), 4);
                }

                foreach (var opcode in analysing.OpCodes)
                {
                    if (opcode.CurrentExceptionRegion != null && opcode.CurrentExceptionRegion.TryOffset == opcode.Position)
                    {
                        analysing.PossibleContinuations.First(c => c.StartPosition == opcode.CurrentExceptionRegion.HandlerOffset).StartStack = new Stack <Type>(analysing.StartStack.Reverse());
                    }

                    opcode.DoStackAnalysis(stack, ref stackOffset);
                }
                foreach (var c in analysing.PossibleContinuations)
                {
                    c.StartStack = new Stack <Type>(stack.Reverse());
                }
            }
        }
Exemplo n.º 3
0
        public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object aMethodInfo)
        {
            // method signature: $this, object @object, IntPtr method
            var xMethodInfo = (MethodInfo)aMethodInfo;
            var xAssembler  = (NewAssembler)aAssembler;

            new Comment("Save target ($this) to field");
            new Comment("-- ldarg 0");
            Ldarg.DoExecute(xAssembler, xMethodInfo, 0);
            //Ldarg.DoExecute(xAssembler, xMethodInfo, 0);
            new Comment("-- ldarg 1");
            Ldarg.DoExecute(xAssembler, xMethodInfo, 1);
            new Comment("-- stfld _target");
            Stfld.DoExecute(xAssembler, xMethodInfo, "System.Object System.Delegate._target", xMethodInfo.MethodBase.DeclaringType, true, false);
            new Comment("Save method pointer to field");
            //Ldarg.DoExecute(xAssembler, xMethodInfo, 0);
            new Comment("-- ldarg 0");
            Ldarg.DoExecute(xAssembler, xMethodInfo, 0);
            new Comment("-- ldarg 2");
            Ldarg.DoExecute(xAssembler, xMethodInfo, 2);
            new Comment("-- stfld _methodPtr");
            Stfld.DoExecute(xAssembler, xMethodInfo, "System.IntPtr System.Delegate._methodPtr", xMethodInfo.MethodBase.DeclaringType, true, false);
            new Comment("Saving ArgSize to field");
            uint xSize = 0;

            foreach (var xArg in xMethodInfo.MethodBase.DeclaringType.GetMethod("Invoke").GetParameters())
            {
                xSize += ILOp.Align(ILOp.SizeOfType(xArg.ParameterType), 4);
            }
            new Comment("-- ldarg 0");
            Ldarg.DoExecute(xAssembler, xMethodInfo, 0);
            if (xMethodInfo.MethodBase.DeclaringType.FullName.Contains("InterruptDelegate"))
            {
                Console.Write("");
            }
            new Comment("-- push argsize");
            new CPUx86.Push {
                DestinationValue = xSize
            };
            new Comment("-- stfld ArgSize");
            Stfld.DoExecute(xAssembler, xMethodInfo, "$$ArgSize$$", xMethodInfo.MethodBase.DeclaringType, true, false);


            //public static void Ctor(Delegate aThis, object aObject, IntPtr aMethod,
            //[FieldAccess(Name = "System.Object System.Delegate._target")] ref object aFldTarget,
            //[FieldAccess(Name = "System.IntPtr System.Delegate._methodPtr")] ref IntPtr aFldMethod) {
        }
Exemplo n.º 4
0
        public void SizeOfType_ForColorStruct_Returns24()
        {
            var size = ILOp.SizeOfType(typeof(Color));

            Assert.That(size, Is.EqualTo(24));
        }