Esempio n. 1
0
        /// <summary>
        /// Given an offset of 3 and a value of 2, generates:
        /// buffer[index + 3] = 2;
        /// </summary>
        /// <param name="ilg"></param>
        /// <param name="array"></param>
        /// <param name="ptr"></param>
        public void Emit(ILGenerator ilg, LocalBuilder array, LocalBuilder ptr)
        {
            ilg.Emit(OpCodes.Ldloc, array);
            if (Constant != null)
            {
                ILGeneratorHelpers.Load32BitIntegerConstant(ilg, Constant.Value);
            }
            else
            {
                ilg.Emit(OpCodes.Ldloc, ptr);
                if (Offset != 0)
                {
                    ILGeneratorHelpers.Load32BitIntegerConstant(ilg, Math.Abs(Offset));
                    if (Offset > 0)
                    {
                        ilg.Emit(OpCodes.Add);
                    }
                    else
                    {
                        ilg.Emit(OpCodes.Sub);
                    }
                }
            }

            ILGeneratorHelpers.Load32BitIntegerConstant(ilg, Value);
            ilg.Emit(OpCodes.Stelem_I1);
        }
Esempio n. 2
0
        private void IncDec(ILGenerator ilg, LocalBuilder array, LocalBuilder ptr, ConstantValue constantValue, int offset, int step, OpCode addSub)
        {
            ilg.Emit(OpCodes.Ldloc, array);
            if (constantValue != null)
            {
                ILGeneratorHelpers.Load32BitIntegerConstant(ilg, constantValue.Value);
            }
            else
            {
                ilg.Emit(OpCodes.Ldloc, ptr);
                if (offset != 0)
                {
                    ILGeneratorHelpers.Load32BitIntegerConstant(ilg, Math.Abs(offset));
                    if (offset > 0)
                    {
                        ilg.Emit(OpCodes.Add);
                    }
                    else
                    {
                        ilg.Emit(OpCodes.Sub);
                    }
                }
            }

            ilg.Emit(OpCodes.Ldloc, array);
            if (constantValue != null)
            {
                ILGeneratorHelpers.Load32BitIntegerConstant(ilg, constantValue.Value);
            }
            else
            {
                ilg.Emit(OpCodes.Ldloc, ptr);
                if (offset != 0)
                {
                    ILGeneratorHelpers.Load32BitIntegerConstant(ilg, Math.Abs(offset));
                    if (offset > 0)
                    {
                        ilg.Emit(OpCodes.Add);
                    }
                    else
                    {
                        ilg.Emit(OpCodes.Sub);
                    }
                }
            }

            ilg.Emit(OpCodes.Ldelem_U1);
            ILGeneratorHelpers.Load32BitIntegerConstant(ilg, step);
            ilg.Emit(addSub);
            ilg.Emit(OpCodes.Conv_U1);
            ilg.Emit(OpCodes.Stelem_I1);
        }
Esempio n. 3
0
        /// <summary>
        /// Given an offset of 2, generates:
        /// Console.Write((char) buffer[index + 2]);
        ///
        /// TODO: This method is missing the Offset usage
        /// </summary>
        /// <param name="ilg"></param>
        /// <param name="array"></param>
        /// <param name="ptr"></param>
        public void Emit(ILGenerator ilg, LocalBuilder array, LocalBuilder ptr)
        {
            for (int i = 0; i < Repeated; i++)
            {
                ilg.Emit(OpCodes.Ldloc, array);
                if (Constant != null)
                {
                    ILGeneratorHelpers.Load32BitIntegerConstant(ilg, Constant.Value);
                }
                else
                {
                    ilg.Emit(OpCodes.Ldloc, ptr);
                }

                ilg.Emit(OpCodes.Ldelem_U1);
                ilg.EmitCall(OpCodes.Call, consoleWriteMethodInfo, null);
            }
        }
        /// <summary>
        /// Given an offset of 2 and scalar of 3, generates:
        /// buffer[index + 2] = (byte) (buffer[index + 2] + (buffer[index] * 3));
        ///
        /// If the scalar is 1, no multiplication is done:
        /// buffer[index + 2] = (byte) (buffer[index + 2] + buffer[index]);
        /// </summary>
        public void Emit(ILGenerator ilg, LocalBuilder array, LocalBuilder ptr)
        {
            ilg.Emit(OpCodes.Ldloc, array);
            if (Constant != null)
            {
                ILGeneratorHelpers.Load32BitIntegerConstant(ilg, Constant.Value);
            }
            else
            {
                ilg.Emit(OpCodes.Ldloc, ptr);
                if (Offset != 0)
                {
                    ILGeneratorHelpers.Load32BitIntegerConstant(ilg, Math.Abs(Offset));
                    if (Offset > 0)
                    {
                        ilg.Emit(OpCodes.Add);
                    }
                    else
                    {
                        ilg.Emit(OpCodes.Sub);
                    }
                }
            }

            ilg.Emit(OpCodes.Ldloc, array);
            if (Constant != null)
            {
                ILGeneratorHelpers.Load32BitIntegerConstant(ilg, Constant.Value);
            }
            else
            {
                ilg.Emit(OpCodes.Ldloc, ptr);
                if (Offset != 0)
                {
                    ILGeneratorHelpers.Load32BitIntegerConstant(ilg, Math.Abs(Offset));
                    if (Offset > 0)
                    {
                        ilg.Emit(OpCodes.Add);
                    }
                    else
                    {
                        ilg.Emit(OpCodes.Sub);
                    }
                }
            }

            ilg.Emit(OpCodes.Ldelem_U1);
            ilg.Emit(OpCodes.Ldloc, array);
            if (MultiplicationConstant != null)
            {
                ILGeneratorHelpers.Load32BitIntegerConstant(ilg, MultiplicationConstant.Value);
            }
            else
            {
                ilg.Emit(OpCodes.Ldloc, ptr);
            }

            ilg.Emit(OpCodes.Ldelem_U1);
            if (Scalar != 1) // multiply only if the scalar is != 1
            {
                ILGeneratorHelpers.Load32BitIntegerConstant(ilg, Scalar);
                ilg.Emit(OpCodes.Mul);
            }

            ilg.Emit(OpCodes.Add);
            ilg.Emit(OpCodes.Conv_U1); // Cast the whole expression to byte
            ilg.Emit(OpCodes.Stelem_I1);
        }