예제 #1
0
        /// <summary>
        /// Pops a value off the stack and stores it into the given local.
        ///
        /// To create a local, use DeclareLocal().
        /// </summary>
        public Emit <DelegateType> StoreLocal(Local local)
        {
            if (local == null)
            {
                throw new ArgumentNullException("local");
            }

            if (((IOwned)local).Owner != this)
            {
                if (((IOwned)local).Owner is DisassembledOperations <DelegateType> )
                {
                    return(StoreLocal(local.Name));
                }

                FailOwnership(local);
            }

            UnusedLocals.Remove(local);

            switch (local.Index)
            {
            case 0: UpdateState(OpCodes.Stloc_0, Wrap(StackTransition.Pop(local.StackType), "StoreLocal")); return(this);

            case 1: UpdateState(OpCodes.Stloc_1, Wrap(StackTransition.Pop(local.StackType), "StoreLocal")); return(this);

            case 2: UpdateState(OpCodes.Stloc_2, Wrap(StackTransition.Pop(local.StackType), "StoreLocal")); return(this);

            case 3: UpdateState(OpCodes.Stloc_3, Wrap(StackTransition.Pop(local.StackType), "StoreLocal")); return(this);
            }

            if (local.Index >= byte.MinValue && local.Index <= byte.MaxValue)
            {
                byte asByte;
                unchecked
                {
                    asByte = (byte)local.Index;
                }

                UpdateState(OpCodes.Stloc_S, asByte, Wrap(StackTransition.Pop(local.StackType), "StoreLocal"));
                return(this);
            }

            UpdateState(OpCodes.Stloc, local, Wrap(StackTransition.Pop(local.StackType), "StoreLocal"));

            return(this);
        }
예제 #2
0
        /// <summary>
        /// Pushes a pointer to the given local onto the stack.
        ///
        /// To create a local, use DeclareLocal.
        /// </summary>
        public Emit <DelegateType> LoadLocalAddress(Local local)
        {
            if (local == null)
            {
                throw new ArgumentNullException("local");
            }

            if (((IOwned)local).Owner != this)
            {
                if (((IOwned)local).Owner is DisassembledOperations <DelegateType> )
                {
                    return(LoadLocalAddress(local.Name));
                }

                FailOwnership(local);
            }

            UnusedLocals.Remove(local);

            var type = local.StackType.Type;

            var ptrType = type.MakePointerType();

            if (local.Index >= byte.MinValue && local.Index <= byte.MaxValue)
            {
                byte asByte;
                unchecked
                {
                    asByte = (byte)local.Index;
                }

                UpdateState(OpCodes.Ldloca_S, asByte, Wrap(StackTransition.Push(ptrType), "LoadLocalAddress"));
                return(this);
            }

            short asShort;

            unchecked
            {
                asShort = (short)local.Index;
            }

            UpdateState(OpCodes.Ldloca, asShort, Wrap(StackTransition.Push(ptrType), "LoadLocalAddress"));

            return(this);
        }