Quantcast
Channel: Common Language Runtime Internals and Architecture forum
Viewing all articles
Browse latest Browse all 1710

OpCodes.Ldlen cause an error when put more then 1 pointer into IL stack before it.

$
0
0

Hi,

I'm write a for loop array test code, it's work fine until I put a check array size code (dup; ldlen; brfalse LabelExit;).
I find OpCodes.Ldlen is a cause of error, I fixed it but I don't know why it's error when I input 2 or more native int( as pointer) into stack before ldlen.

Code here.

'JIT.ObjectPointer is Intprt(as pointer) creator.
        Dim Arraier = JIT.ObjectPointer(New String() {"A", "B", "C", "D", "E", "F"})

'Dynamic.Method is similar System.Reflection.Emit.DynamicMethod include delegate type for CreateDelegate function later.
        With Dynamic.Method(Of System.Action).Create("Runing")

'Dynamic.Method.Craft is similar with ILGenerater 
            With .Craft(Of lbLoop)(This.Module)
                .Input(Arraier) 'ldc.i Arraier
                '.Duplicate() 'OpCode.Dup but I can't put it here, even I try to put ldc.i Arraier insert it but still cause error.
                .Objective.Length() 'ldlen
                .Break.OnFalse(lbLoop.Exiter) ' brfalse.s Label(lbLoop.Exiter)

                .Input(Arraier) 'Since I can't put duplicate command on above, I have to insert command here.
                .Input(0) 'ldc.i4.0
                .Point.Element(Of String)()' ldelema String

                .Break.Mark(lbLoop.Point) 'Point:

                .Duplicate()
                .Point.LoadAsObject(Of String)() 'ldobj String
                .Duplicate()
                .Break.OnFalse(lbLoop.Exiter)

                .Invoke(GetType(System.Console).GetMethod("WriteLine", {GetType(String)})) 'call System.Console::WriteLine (String)

                .Input(System.IntPtr.Size)
                .Math(JIT.MathOperator.Add) 'add

                .Break.To(lbLoop.Point) 'br.s Label(lbLoop.Point)

                .Break.Mark(lbLoop.Exiter)
                .Pop()
                .Pop()
                .Return()() 'ret; DirectCast(DynamicMethod.CreateDelegate(GetType(DelegateType)), DelegateType)();
            End With
        End With



Viewing all articles
Browse latest Browse all 1710

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>