Ejemplo n.º 1
0
    public void basicBlockTest()
    {
        basicBlockPass();

        bool caught = false;

        try
        {
            basicBlockFail1();
        }
        catch (VerificationException verexcept)
        {
            verexcept = null;
            caught    = true;
        }
        finally
        {
            ReadonlyTests.Test(caught, "basicBlockFail1");
        }
        caught = false;
        try
        {
            basicBlockFail2();
        }
        catch (VerificationException verexcept)
        {
            verexcept = null;
            caught    = true;
        }
        finally
        {
            ReadonlyTests.Test(caught, "basicBlockFail2");
        }
    }
Ejemplo n.º 2
0
    private void cpobjVerifyPass(T obj)
    {
        ILASM.Inline(".maxstack 8");
        T temp = obj;

        //
        // readonly source is OK
        //
        ILASM.Inline("ldarg.1");
        ILASM.Inline("stloc.0 ");
        temp.setx(1);
        temp.sety(1);
        temp.setz(1);
        //
        // cpobj from m_data[3] to temp
        //
        ILASM.Inline("ldloca 0 ");
        ILASM.Inline("ldarg.0");
        ILASM.Inline("ldfld      !0[] class FixedStack<!0>::m_data ");
        ILASM.Inline("ldc.i4.3");
        ILASM.Inline("readonly.");
        ILASM.Inline("ldelema !0    ");
        ILASM.Inline("cpobj !0");
        ReadonlyTests.Test(temp.getx() == 103, "cpobj1 x");
        ReadonlyTests.Test(temp.gety() == 104, "cpobj1 y");
        ReadonlyTests.Test(temp.getz() == 105, "cpobj1 z");
        temp.setx(1);
        temp.sety(1);
        temp.setz(1);
        // this fails with reference types, but succeeds with value types
        // with reference semantics m_data[3].x,y and z become 1
        ReadonlyTests.Test(m_data[3].getx() == 103, "cpobj2 x");
        ReadonlyTests.Test(m_data[3].gety() == 104, "cpobj2 y");
        ReadonlyTests.Test(m_data[3].getz() == 105, "cpobj2 z");
        //
        // no readonly is OK
        //
        // cpobj from m_data[3] to temp
        //
        ILASM.Inline("ldarg.0");
        ILASM.Inline("ldfld      !0[] class FixedStack<!0>::m_data ");
        ILASM.Inline("ldc.i4.3");
        ILASM.Inline("ldelema !0");
        ILASM.Inline("ldloca 0 ");
        ILASM.Inline("cpobj !0");
        //for(int i = 0; i < 10 ; ++i)
        //{
        //    Console.WriteLine("i: " + i.ToString() + " data: " + m_data[i].getx().ToString());
        //}
        ReadonlyTests.Test(temp.getx() == 103, "cpobj3 x");
        ReadonlyTests.Test(temp.gety() == 104, "cpobj3 y");
        ReadonlyTests.Test(temp.getz() == 105, "cpobj3 z");
    }
Ejemplo n.º 3
0
    public static void stind_i8Pass()
    {
        Int64 [] arrayInt64 = new Int64[1];
        Int64    tempInt64  = 101;

        arrayInt64[0] = 1;
        ILASM.Inline("ldloc.0");
        ILASM.Inline("ldc.i4.0");
        ILASM.Inline("ldelema [mscorlib]System.Int64");
        ILASM.Inline("ldloc.1");
        ILASM.Inline("stind.i8");
        ReadonlyTests.Test(arrayInt64[0] == 101, "stind_i8Pass");
    }
Ejemplo n.º 4
0
    public static void stind_iPass()
    {
        IntPtr [] arrayIntPtr = new IntPtr[1];
        IntPtr    tempIntPtr  = (IntPtr)101;

        arrayIntPtr[0] = (IntPtr)1;
        ILASM.Inline("ldloc.0");
        ILASM.Inline("ldc.i4.0");
        ILASM.Inline("ldelema [mscorlib]System.IntPtr");
        ILASM.Inline("ldloc.1");
        ILASM.Inline("stind.i");
        ReadonlyTests.Test(arrayIntPtr[0] == tempIntPtr, "stind_iPass");
    }
Ejemplo n.º 5
0
    public static void stind_i1Pass()
    {
        Byte [] arrayByte = new Byte[1];
        Byte    tempByte  = 101;

        arrayByte[0] = 1;
        ILASM.Inline("ldloc.0");
        ILASM.Inline("ldc.i4.0");
        ILASM.Inline("ldelema [mscorlib]System.Byte");
        ILASM.Inline("ldloc.1");
        ILASM.Inline("stind.i1");
        ReadonlyTests.Test(arrayByte[0] == 101, "stind_i1Pass");
    }
Ejemplo n.º 6
0
    public static void stind_i2Pass()
    {
        Int16 [] arrayInt16 = new Int16[1];
        Int16    tempInt16  = 101;

        arrayInt16[0] = 1;
        ILASM.Inline("ldloc.0");
        ILASM.Inline("ldc.i4.0");
        ILASM.Inline("ldelema [mscorlib]System.Int16");
        ILASM.Inline("ldloc.1");
        ILASM.Inline("stind.i2");
        ReadonlyTests.Test(arrayInt16[0] == 101, "stind_i2Pass");
    }
Ejemplo n.º 7
0
    public static void stind_r4Pass()
    {
        Single [] arraySingle = new Single[1];
        Single    tempSingle  = 101;

        arraySingle[0] = 1;
        ILASM.Inline("ldloc.0");
        ILASM.Inline("ldc.i4.0");
        ILASM.Inline("ldelema [mscorlib]System.Single");
        ILASM.Inline("ldloc.1");
        ILASM.Inline("stind.r4");
        ReadonlyTests.Test(arraySingle[0] == tempSingle, "stind_r4Pass");
    }
Ejemplo n.º 8
0
    public static void stind_r8Pass()
    {
        Double [] arrayDouble = new Double[1];
        Double    tempDouble  = 101;

        arrayDouble[0] = 1;
        ILASM.Inline("ldloc.0");
        ILASM.Inline("ldc.i4.0");
        ILASM.Inline("ldelema [mscorlib]System.Double");
        ILASM.Inline("ldloc.1");
        ILASM.Inline("stind.r8");
        ReadonlyTests.Test(arrayDouble[0] == tempDouble, "stind_r8Pass");
    }
Ejemplo n.º 9
0
    public static void stind_refPass()
    {
        Object [] arrayObject = new Object[1];
        Object    tempObject  = 101 as Object;

        arrayObject[0] = 1 as Object;
        ILASM.Inline("ldloc.0");
        ILASM.Inline("ldc.i4.0");
        ILASM.Inline("ldelema [mscorlib]System.Object");
        ILASM.Inline("ldloc.1");
        ILASM.Inline("stind.ref");
        ReadonlyTests.Test(arrayObject[0] == tempObject, "stind_refPass");
        ReadonlyTests.Test(Object.ReferenceEquals(arrayObject[0], tempObject), "stind_refPass ReferenceEquals");
    }
Ejemplo n.º 10
0
    private static void callVerifyPass()
    {
        ILASM.Inline(".maxstack 8");
        ValType [] varr = new ValType[1];
        varr[0] = new ValType(1, 2, 3);
        int result = 0;

        ILASM.Inline("ldloc.0");
        ILASM.Inline("ldc.i4.0");
        ILASM.Inline("readonly.");
        ILASM.Inline("ldelema ValType");
        ILASM.Inline("call instance int32 ValType::getx()");
        ILASM.Inline("stloc.1");
        ReadonlyTests.Test(result == 1, "callVerifyPass");
    }
Ejemplo n.º 11
0
    private void basicBlockPass()
    {
        ILASM.Inline(".maxstack 8");
        bool takeme = true;
        int  result = 0;

        if (takeme)
        {
            ILASM.Inline("ldarg.0");
            ILASM.Inline("ldfld      !0[] class FixedStack<!0>::m_data");
            ILASM.Inline("ldc.i4.5");
            ILASM.Inline("readonly.");
            ILASM.Inline("ldelema !0");
        }
        else
        {
            ILASM.Inline("ldarg.0");
            ILASM.Inline("ldfld      !0[] class FixedStack<!0>::m_data");
            ILASM.Inline("ldc.i4.6");
            ILASM.Inline("readonly.");
            ILASM.Inline("ldelema !0");
        }
        ILASM.Inline("constrained. !0");
        ILASM.Inline("callvirt instance int32 IPoint::getx()");
        ILASM.Inline("stloc.1");
        ReadonlyTests.Test(result == 105, "basicBlockPass");

        if (!takeme)
        {
            ILASM.Inline("ldarg.0");
            ILASM.Inline("ldfld      !0[] class FixedStack<!0>::m_data");
            ILASM.Inline("ldc.i4.5");
            ILASM.Inline("readonly.");
            ILASM.Inline("ldelema !0");
        }
        else
        {
            // note no readonly here
            ILASM.Inline("ldarg.0");
            ILASM.Inline("ldfld      !0[] class FixedStack<!0>::m_data");
            ILASM.Inline("ldc.i4.6");
            ILASM.Inline("ldelema !0");
        }
        ILASM.Inline("constrained. !0");
        ILASM.Inline("callvirt instance int32 IPoint::getx()");
        ILASM.Inline("stloc.1");
        ReadonlyTests.Test(result == 106, "basicBlockPass");
    }
Ejemplo n.º 12
0
 private void stobjVerifyPass(T obj)
 {
     ILASM.Inline(".maxstack 10");
     ReadonlyTests.Test(m_data[0].getx() == 100, "stobj1 x");
     ReadonlyTests.Test(m_data[0].gety() == 101, "stobj1 y");
     ReadonlyTests.Test(m_data[0].getz() == 102, "stobj1 z");
     ILASM.Inline("ldarg.0");
     ILASM.Inline("ldfld      !0[] class FixedStack<!0>::m_data");
     ILASM.Inline("ldc.i4.0");
     ILASM.Inline("ldelema !0");
     ILASM.Inline("ldarg.1");
     ILASM.Inline("stobj !0");
     ReadonlyTests.Test(m_data[0].getx() == 345, "stobj2 x");
     ReadonlyTests.Test(m_data[0].gety() == 346, "stobj2 y");
     ReadonlyTests.Test(m_data[0].getz() == 347, "stobj2 z");
 }
Ejemplo n.º 13
0
    public void constrainedTest()
    {
        bool caught = false;

        try
        {
            constrainedVerifyPass();
        }
        catch (VerificationException verexcept)
        {
            verexcept = null;
            caught    = true;
        }
        finally
        {
            ReadonlyTests.Test(!caught, "constrainedTest");
        }
    }
Ejemplo n.º 14
0
    public static void callvirtTest()
    {
        bool caught = false;

        try
        {
            callvirtVerifyPass();
        }
        catch (VerificationException verexcept)
        {
            verexcept = null;
            caught    = true;
        }
        finally
        {
            ReadonlyTests.Test(!caught, "callvirtTest");
        }
    }
Ejemplo n.º 15
0
    public void stobjTest(T obj)
    {
        bool caught = false;

        stobjVerifyPass(obj);

        try
        {
            stobjVerifyFail(obj);
        }
        catch (VerificationException verexcept)
        {
            caught = true;
        }
        finally
        {
            ReadonlyTests.Test(caught, "stobjTest");
        }
    }
Ejemplo n.º 16
0
    public void cpobjTest(T obj)
    {
        bool caught = false;

        cpobjVerifyPass(obj);
        try
        {
            cpobjVerifyFail(obj);
        }
        catch (VerificationException verexcept)
        {
            verexcept = null;
            caught    = true;
        }
        finally
        {
            ReadonlyTests.Test(caught, "cpobjTest");
        }
    }
Ejemplo n.º 17
0
    public void mkrefanyTest()
    {
        bool caught = false;

        mkrefanyVerifyPass();
        try
        {
            mkrefanyVerifyFail();
        }
        catch (VerificationException verexcept)
        {
            verexcept = null;
            caught    = true;
        }
        finally
        {
            ReadonlyTests.Test(caught, "mkrefanyTest");
        }
    }
Ejemplo n.º 18
0
    public void initobjTest()
    {
        bool caught = false;

        initobjVerifyPass();
        try
        {
            initobjVerifyFail();
        }
        catch (VerificationException verexcept)
        {
            verexcept = null;
            caught    = true;
        }
        finally
        {
            ReadonlyTests.Test(caught, "initobjTest");
        }
    }
Ejemplo n.º 19
0
    public static void stind_iTest()
    {
        bool caught = false;

        stind_iPass();
        try
        {
            stind_iFail();
        }
        catch (VerificationException verexcept)
        {
            verexcept = null;
            caught    = true;
        }
        finally
        {
            ReadonlyTests.Test(caught, "stind_iTest");
        }
    }
Ejemplo n.º 20
0
    private void constrainedVerifyPass()
    {
        ILASM.Inline(".maxstack 8");
        int result = 0;

        ILASM.Inline("ldarg.0");
        ILASM.Inline("ldfld      !0[] class FixedStack<!0>::m_data");
        ILASM.Inline("ldc.i4.4");
        ILASM.Inline("readonly.");
        ILASM.Inline("ldelema !0");
        ILASM.Inline("constrained. !0");
        ILASM.Inline("callvirt instance int32 IPoint::getx()");
        ILASM.Inline("stloc.0");
        ReadonlyTests.Test(result == 104, "constrainedVerifyPass");
        //Console.WriteLine("result: " + result.ToString());
        //for(int i = 0; i < 10; ++i)
        //{
        //Console.WriteLine("i: " + i.ToString() + " data: " + m_data[i].getx().ToString());
        //}
    }
Ejemplo n.º 21
0
 private void initobjVerifyPass()
 {
     ILASM.Inline(".maxstack 10");
     //Console.WriteLine("m_data x " + m_data[0].getx().ToString());
     ReadonlyTests.Test(m_data[1].getx() == 101, "initobj1 x");
     ReadonlyTests.Test(m_data[1].gety() == 102, "initobj1 y");
     ReadonlyTests.Test(m_data[1].getz() == 103, "initobj1 z");
     ILASM.Inline("ldarg.0");
     ILASM.Inline("ldfld      !0[] class FixedStack<!0>::m_data");
     ILASM.Inline("ldc.i4.1");
     ILASM.Inline("ldelema !0");
     ILASM.Inline("initobj !0");
     //
     // this only succeeds with value types)
     // with reftype m_data[0] itself becomes null and it errors out
     //
     ReadonlyTests.Test(m_data[1].getx() == 0, "initobj2 x");
     ReadonlyTests.Test(m_data[1].gety() == 0, "initobj2 y");
     ReadonlyTests.Test(m_data[1].getz() == 0, "initobj2 z");
 }