From 375c31ff1f6b5ba7f2e62c142c3c00945c782c43 Mon Sep 17 00:00:00 2001 From: jbevain Date: Wed, 9 Dec 2009 19:27:58 +0000 Subject: [PATCH] 2009-12-09 Jb Evain * ILGenerator.cs (Emit(OpCode,LocalBuilder)): deal with opcodes not related to locals. git-svn-id: svn+ssh://mono-cvs.ximian.com/source/trunk/mcs@147940 e3ebcda4-bce8-0310-ba0a-eca2169e7518 --- class/corlib/System.Reflection.Emit/ChangeLog | 5 +++++ class/corlib/System.Reflection.Emit/ILGenerator.cs | 13 ++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/class/corlib/System.Reflection.Emit/ChangeLog b/class/corlib/System.Reflection.Emit/ChangeLog index 41ed1cfd7e..7c9d91f947 100644 --- a/class/corlib/System.Reflection.Emit/ChangeLog +++ b/class/corlib/System.Reflection.Emit/ChangeLog @@ -1,3 +1,8 @@ +2009-12-09 Jb Evain + + * ILGenerator.cs (Emit(OpCode,LocalBuilder)): deal with + opcodes not related to locals. + 2009-12-08 Rodrigo Kumpera * MethodOnTypeBuilderInst.cs: Add new constructor that takes a MethodInfo diff --git a/class/corlib/System.Reflection.Emit/ILGenerator.cs b/class/corlib/System.Reflection.Emit/ILGenerator.cs index 8e180b3c25..849e290a4b 100644 --- a/class/corlib/System.Reflection.Emit/ILGenerator.cs +++ b/class/corlib/System.Reflection.Emit/ILGenerator.cs @@ -659,21 +659,22 @@ namespace System.Reflection.Emit { { if (local == null) throw new ArgumentNullException ("local"); + if (local.ilgen != this) + throw new ArgumentException ("Trying to emit a local from a different ILGenerator."); uint pos = local.position; bool load_addr = false; bool is_store = false; + bool is_load = false; make_room (6); - if (local.ilgen != this) - throw new ArgumentException ("Trying to emit a local from a different ILGenerator."); - /* inline the code from ll_emit () to optimize il code size */ if (opcode.StackBehaviourPop == StackBehaviour.Pop1) { cur_stack --; is_store = true; - } else { + } else if (opcode.StackBehaviourPush == StackBehaviour.Push1 || opcode.StackBehaviourPush == StackBehaviour.Pushi) { cur_stack++; + is_load = true; if (cur_stack > max_stack) max_stack = cur_stack; load_addr = opcode.StackBehaviourPush == StackBehaviour.Pushi; @@ -701,7 +702,7 @@ namespace System.Reflection.Emit { code [code_len++] = (byte)(pos & 0xff); code [code_len++] = (byte)((pos >> 8) & 0xff); } - } else { + } else if (is_load) { if (pos < 4) { code [code_len++] = (byte)(0x06 + pos); } else if (pos < 256) { @@ -713,6 +714,8 @@ namespace System.Reflection.Emit { code [code_len++] = (byte)(pos & 0xff); code [code_len++] = (byte)((pos >> 8) & 0xff); } + } else { + ll_emit (opcode); } } } -- 2.11.4.GIT