2009-12-09 Jb Evain <jbevain@novell.com>
authorJb Evain <jbevain@gmail.com>
Wed, 9 Dec 2009 19:27:58 +0000 (19:27 -0000)
committerJb Evain <jbevain@gmail.com>
Wed, 9 Dec 2009 19:27:58 +0000 (19:27 -0000)
* ILGenerator.cs (Emit(OpCode,LocalBuilder)): deal with
opcodes not related to locals.

svn path=/trunk/mcs/; revision=147940

mcs/class/corlib/System.Reflection.Emit/ChangeLog
mcs/class/corlib/System.Reflection.Emit/ILGenerator.cs

index 41ed1cfd7e6b2684b9db6272238198f269ba11b5..7c9d91f9475c4f86e1064025ffa2d7dc6538ab35 100644 (file)
@@ -1,3 +1,8 @@
+2009-12-09  Jb Evain  <jbevain@novell.com>
+
+       * ILGenerator.cs (Emit(OpCode,LocalBuilder)): deal with
+       opcodes not related to locals.
+
 2009-12-08 Rodrigo Kumpera  <rkumpera@novell.com>
 
        * MethodOnTypeBuilderInst.cs: Add new constructor that takes a MethodInfo
index 8e180b3c25ed63cf95078a5a81a14f3ea37adafb..849e290a4bf1d1842c3897a2d42b7695f6400386 100644 (file)
@@ -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);
                                }
                        }
                }