Esempio n. 1
0
        protected override void Compile(CodeContext c)
        {
            var fn = c.IntPtr("fn");
            var rv = c.Int32("rv");

            var fp = Memory.Fn(new Func <IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, int>(CalledFunction));

            c.Mov(fn, fp);

            var call = c.Call(fn, fp);

            call.SetArgument(0, 1);
            call.SetArgument(1, 2);
            call.SetArgument(2, 3);
            call.SetArgument(3, 4);
            call.SetArgument(4, 5);
            call.SetArgument(5, 6);
            call.SetArgument(6, 7);
            call.SetArgument(7, 8);
            call.SetArgument(8, 9);
            call.SetArgument(9, 10);
            call.SetReturn(0, rv);

            c.Ret(rv);
        }
Esempio n. 2
0
        protected override void Compile(CodeContext c)
        {
            var v0 = c.Int32("v0");
            var v1 = c.Int32("v1");
            var v2 = c.Int32("v2");

            c.SetArgument(0, v0);
            c.SetArgument(1, v1);
            c.SetArgument(2, v2);

            var fp = Memory.Fn(new Func <int, int, int, int>(CalledFunction));

            // Just do something.
            c.Shl(v0, 1);
            c.Shl(v1, 1);
            c.Shl(v2, 1);

            var fn = c.IntPtr("fn");

            c.Mov(fn, fp);

            var call = c.Call(fn, fp);

            call.SetArgument(0, v2);
            call.SetArgument(1, v1);
            call.SetArgument(2, v0);
            call.SetReturn(0, v0);

            c.Ret(v0);
        }
Esempio n. 3
0
        protected override void Compile(CodeContext c)
        {
            var fn = c.IntPtr("fn");
            var a  = c.Int32("a");

            var fp = Memory.Fn(new Func <int, int, int, int, int, int, int, int, int, int, int>(CalledFunction));

            c.Mov(fn, fp);
            c.Mov(a, 3);

            var call = c.Call(fn, fp);

            call.SetArgument(0, a);
            call.SetArgument(1, a);
            call.SetArgument(2, a);
            call.SetArgument(3, a);
            call.SetArgument(4, a);
            call.SetArgument(5, a);
            call.SetArgument(6, a);
            call.SetArgument(7, a);
            call.SetArgument(8, a);
            call.SetArgument(9, a);
            call.SetReturn(0, a);

            c.Ret(a);
        }
Esempio n. 4
0
        protected override void Compile(CodeContext c)
        {
            var fn = c.IntPtr("fn");
            var rv = c.Int32("rv");

            var fp = Memory.Fn(new Func <int, int, int, int, int, int, int, int, int, int, int>(CalledFunction));

            c.Mov(fn, fp);

            var call = c.Call(fn, fp);

            call.SetArgument(0, 0x03);
            call.SetArgument(1, 0x12);
            call.SetArgument(2, 0xA0);
            call.SetArgument(3, 0x0B);
            call.SetArgument(4, 0x2F);
            call.SetArgument(5, 0x02);
            call.SetArgument(6, 0x0C);
            call.SetArgument(7, 0x12);
            call.SetArgument(8, 0x18);
            call.SetArgument(9, 0x1E);
            call.SetReturn(0, rv);

            c.Ret(rv);
        }
Esempio n. 5
0
//		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
//		delegate int CalledFunctionDel(int x, int y);

        protected override void Compile(CodeContext c)
        {
            var x  = c.Int32("x");
            var y  = c.Int32("y");
            var op = c.Int32("op");

            c.SetArgument(0, x);
            c.SetArgument(1, y);
            c.SetArgument(2, op);

            var opAdd = c.Label();
            var opMul = c.Label();

            c.Cmp(op, 0);
            c.Jz(opAdd);
            c.Cmp(op, 1);
            c.Jz(opMul);

            var result = c.Int32("result_0");

            c.Mov(result, 0);
            c.Ret(result);

            c.Bind(opAdd);
            result = c.Int32("result_1");

//			CalledFunctionDel f = CalledFunctionAdd;
//			var call = c.Call(Memory.Fn(f));
            var call = c.Call(Memory.Fn(new Func <int, int, int>(CalledFunctionAdd)));

            call.SetArgument(0, x);
            call.SetArgument(1, y);
            call.SetReturn(0, result);
            c.Ret(result);

            c.Bind(opMul);
            result = c.Int32("result_2");

//			f = CalledFunctionMul;
//			call = c.Call(Memory.Fn(f));
            call = c.Call(Memory.Fn(new Func <int, int, int>(CalledFunctionMul)));
            call.SetArgument(0, x);
            call.SetArgument(1, y);
            call.SetReturn(0, result);

            c.Ret(result);
        }
Esempio n. 6
0
        protected override void Compile(CodeContext c)
        {
            int i;

            var buf  = c.IntPtr("buf");
            var acc0 = c.Int32("acc0");
            var acc1 = c.Int32("acc1");

            c.SetArgument(0, buf);

            c.Mov(acc0, 0);
            c.Mov(acc1, 0);

            for (i = 0; i < 4; i++)
            {
                var ret = c.Int32("ret");
                var ptr = c.IntPtr("ptr");
                var idx = c.Int32("idx");

                c.Mov(ptr, buf);
                c.Mov(idx, i);

                var call = c.Call(Memory.Fn(new Func <IntPtr, int, int>(CalledFunction) /*, CallingConvention.HostDefaultFast*/));
                call.SetArgument(0, ptr);
                call.SetArgument(1, idx);
                call.SetReturn(0, ret);

                c.Add(acc0, ret);

                c.Mov(ptr, buf);
                c.Mov(idx, i);

                call = c.Call(Memory.Fn(new Func <IntPtr, int, int>(CalledFunction) /*, CallingConvention.HostDefaultFast*/));
                call.SetArgument(0, ptr);
                call.SetArgument(1, idx);
                call.SetReturn(0, ret);

                c.Sub(acc1, ret);
            }

            c.Add(acc0, acc1);
            c.Ret(acc0);
        }
Esempio n. 7
0
        protected override void Compile(CodeContext c)
        {
            var var = c.Int32("var");
            var fn  = c.IntPtr("fn");

            c.SetArgument(0, var);

            var fp = Memory.Fn(new Func <int, int>(CalledFunction) /*, CallingConvention.HostDefaultFast*/);

            c.Mov(fn, fp);

            var call = c.Call(fn, fp);

            call.SetArgument(0, var);
            call.SetReturn(0, var);

            call = c.Call(fn, fp);
            call.SetArgument(0, var);
            call.SetReturn(0, var);

            c.Ret(var);
        }
Esempio n. 8
0
        protected override void Compile(CodeContext c)
        {
            var fn = c.IntPtr("fn");
            var va = c.Int32("va");
            var vb = c.Int32("vb");
            var vc = c.Int32("vc");
            var vd = c.Int32("vd");
            var ve = c.Int32("ve");
            var vf = c.Int32("vf");
            var vg = c.Int32("vg");
            var vh = c.Int32("vh");
            var vi = c.Int32("vi");
            var vj = c.Int32("vj");

            var fp = Memory.Fn(new Func <int, int, int, int, int, int, int, int, int, int, int>(CalledFunction));

            c.Mov(fn, fp);
            c.Mov(va, 0x03);
            c.Mov(vb, 0x12);
            c.Mov(vc, 0xA0);
            c.Mov(vd, 0x0B);
            c.Mov(ve, 0x2F);
            c.Mov(vf, 0x02);
            c.Mov(vg, 0x0C);
            c.Mov(vh, 0x12);
            c.Mov(vi, 0x18);
            c.Mov(vj, 0x1E);

            var call = c.Call(fn, fp);

            call.SetArgument(0, va);
            call.SetArgument(1, vb);
            call.SetArgument(2, vc);
            call.SetArgument(3, vd);
            call.SetArgument(4, ve);
            call.SetArgument(5, vf);
            call.SetArgument(6, vg);
            call.SetArgument(7, vh);
            call.SetArgument(8, vi);
            call.SetArgument(9, vj);
            call.SetReturn(0, va);

            c.Ret(va);
        }
Esempio n. 9
0
        protected override void Compile(CodeContext c)
        {
            var h     = LoadLibrary(IntPtr.Size > 4 ? "c:\\SampleDLL64.dll" : "c:\\SampleDLL.dll");
            var fnPtr = GetProcAddress(h, "addNumbers");

            var v0 = c.Int32("v0");
            var v1 = c.Int32("v1");
            var v2 = c.Int32("v2");

            c.SetArgument(0, v0);
            c.SetArgument(1, v1);

            var call = c.Call(Memory.Fn <Func <int, int, int> >(fnPtr));

            call.SetArgument(0, v0);
            call.SetArgument(1, v1);
            call.SetReturn(0, v2);

            c.Ret(v2);
        }
Esempio n. 10
0
        protected override void Compile(CodeContext c)
        {
            var p  = c.IntPtr("p");
            var fn = c.IntPtr("fn");

            var arg = c.XmmSd("arg");
            var ret = c.XmmSd("ret");

            var fp = Memory.Fn(new Func <double, double>(CalledFunction));

            c.SetArgument(0, p);
            c.Movsd(arg, Memory.Ptr(p));
            c.Mov(fn, fp);

            var call = c.Call(fn, fp);

            call.SetArgument(0, arg);
            call.SetReturn(0, ret);

            c.Ret(ret);
        }
Esempio n. 11
0
        protected override void Compile(CodeContext c)
        {
            var fn  = c.IntPtr("fn");
            var a   = c.XmmSd("a");
            var b   = c.XmmSd("b");
            var ret = c.XmmSd("ret");

            c.SetArgument(0, a);
            c.SetArgument(1, b);

            var fp = Memory.Fn(new Func <double, double, double>(CalledFunction));

            c.Mov(fn, fp);

            var call = c.Call(fn, fp);

            call.SetArgument(0, a);
            call.SetArgument(1, b);
            call.SetReturn(0, ret);

            c.Ret(ret);
        }