Thanks for your reply. I'm a bit confused. Wouldn't the last line in the
block:
jump.Operand <- e //this sets the jump instruction's operand
to the instruction for OpCodes.Ret
do the same thing?
On Sat, Jan 9, 2010 at 3:03 AM, Jb Evain <[email protected]> wrote:
> When you Create an Instruction that is either InlineBrTarget or
> ShortInlineBrTarget, you must give it another Instruction to branch
> to.
>
> So you have to call: Create (OpCodes.Brtrue, target)
>
> Where target is the instruction to branch to if you have true on the stack.
>
> On Sat, Jan 9, 2010 at 7:01 AM, Michael Kohout <[email protected]> wrote:
> > here's a little test function I'm trying to do. It should operate like
> > this:
> > public void Methodname()
> > {
> > if{this.fieldName<0) {System.Console.WriteLine("hello zero")}
> > }
> > here's where I try and generate this:
> > (fun (worker:CilWorker)->
> >
> > worker.Append (worker.Create( OpCodes.Ldc_I4_0 ))
> > worker.Append (worker.Create( OpCodes.Ldarg_0 ))
> > worker.Append (worker.Create( OpCodes.Ldfld, field))
> > worker.Append (worker.Create( OpCodes.Clt ))
> > let jump = worker.Create( OpCodes.Brtrue )
> > worker.Append(jump)
> > worker.Append(worker.Create(OpCodes.Ldstr, "hello zero"))
> >
> > let mi = (typeof<System.Console>).GetMethod("WriteLine",
> > [|typeof<string>|]) in let methodRef:MethodReference =
> > builder.GetMethodReference(mi)
> > worker.Append(worker.Create(OpCodes.Call, methodRef) )
> > let e = worker.Create( OpCodes.Ret)
> > worker.Append(e)
> > jump.Operand <- e
> > )
> > You might notice that set the jump instruction operand at the end, after
> > I've generated my return opcode. However this isn't working. The stack
> > trace starts with "System.ArgumentException: opcode". What am I doing
> > wrong?
> > thanks
> > Mike
> > --
> > --
> > mono-cecil
> >
>
>
>
> --
> Jb Evain <[email protected]>
>
> --
> --
> mono-cecil
>
--
--
mono-cecil