Ejemplo n.º 1
0
        /// <summary>
        /// Calls the method being constructed by the given emit.  Emits so used must have been constructed with BuildMethod or related methods.
        ///
        /// Pops its arguments in reverse order (left-most deepest in the stack), and pushes the return value if it is non-void.
        ///
        /// If the given method is an instance method, the `this` reference should appear before any parameters.
        ///
        /// Call does not respect overrides, the implementation defined by the given MethodInfo is what will be called at runtime.
        ///
        /// To call overrides of instance methods, use CallVirtual.
        /// Recursive calls can only be performed with DynamicMethods, other passed in Emits must already have their methods created.
        /// When calling VarArgs methods, arglist should be set to the types of the extra parameters to be passed.
        /// </summary>
        public Emit Call(Emit emit, Type[] arglist = null)
        {
            if (emit == null)
            {
                throw new ArgumentNullException("emit");
            }

            InnerEmit.Call(emit.InnerEmit, arglist);
            return(this);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Calls the method being constructed by the given emit.  Emits so used must have been constructed with BuildMethod or related methods.
        ///
        /// Pops its arguments in reverse order (left-most deepest in the stack), and pushes the return value if it is non-void.
        ///
        /// If the given method is an instance method, the `this` reference should appear before any parameters.
        ///
        /// Call does not respect overrides, the implementation defined by the given MethodInfo is what will be called at runtime.
        ///
        /// To call overrides of instance methods, use CallVirtual.
        /// Recursive calls can only be performed with DynamicMethods, other passed in Emits must already have their methods created.
        /// When calling VarArgs methods, arglist should be set to the types of the extra parameters to be passed.
        /// </summary>
        public Emit Call(Emit emit, Type[] arglist = null)
        {
            if (emit == null)
            {
                throw new ArgumentNullException("emit");
            }

            MethodInfo methodInfo = emit.InnerEmit.MtdBuilder ?? (MethodInfo)emit.InnerEmit.DynMethod;

            if (methodInfo == null)
            {
                var dynMethod = new System.Reflection.Emit.DynamicMethod(emit.Name, emit.ReturnType, emit.ParameterTypes, emit.Module, skipVisibility: true);

                emit.InnerEmit.DynMethod = dynMethod;
                methodInfo = dynMethod;
            }

            InnerEmit.Call(emit.InnerEmit, arglist);
            return(this);
        }
Ejemplo n.º 3
0
 public Emit NewObject <ReferenceType, ParameterType1>()
 {
     InnerEmit.NewObject <ReferenceType, ParameterType1>();
     return(this);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Pops # of parameters to the given constructor arguments from the stack, invokes the constructor, and pushes a reference to the new object onto the stack.
 /// </summary>
 public Emit NewObject(ConstructorInfo constructor)
 {
     InnerEmit.NewObject(constructor);
     return(this);
 }
Ejemplo n.º 5
0
 public Emit NewObject <ReferenceType, ParameterType1, ParameterType2, ParameterType3, ParameterType4, ParameterType5, ParameterType6, ParameterType7, ParameterType8, ParameterType9, ParameterType10, ParameterType11, ParameterType12, ParameterType13, ParameterType14, ParameterType15, ParameterType16>()
 {
     InnerEmit.NewObject <ReferenceType, ParameterType1, ParameterType2, ParameterType3, ParameterType4, ParameterType5, ParameterType6, ParameterType7, ParameterType8, ParameterType9, ParameterType10, ParameterType11, ParameterType12, ParameterType13, ParameterType14, ParameterType15, ParameterType16>();
     return(this);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Converts a pointer or reference to a value on the stack into a TypedReference of the given type.
 ///
 /// TypedReferences can be used with ReferenceAnyType and ReferenceAnyValue to pass arbitrary types as parameters.
 /// </summary>
 public Emit MakeReferenceAny(Type type)
 {
     InnerEmit.MakeReferenceAny(type);
     return(this);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// <para>Expects a destination pointer, a source pointer, and a length on the stack.  Pops all three values.</para>
 /// <para>Copies length bytes from destination to the source.</para>
 /// </summary>
 public Emit CopyBlock(bool isVolatile = false, int?unaligned = null)
 {
     InnerEmit.CopyBlock(isVolatile, unaligned);
     return(this);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Pops a value off the stack and throws it as an exception.
 ///
 /// Throw expects the value to be or extend from a System.Exception.
 /// </summary>
 public Emit Throw()
 {
     InnerEmit.Throw();
     return(this);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// <para>Pops two arguments off the stack, multiplies them as if they were unsigned, and pushes the result.</para>
 /// <para>Throws an OverflowException if the result overflows the destination type.</para>
 /// </summary>
 public Emit UnsignedMultiplyOverflow()
 {
     InnerEmit.UnsignedMultiplyOverflow();
     return(this);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Pops two arguments off the stack, adds them, and pushes the result.
 /// </summary>
 public Emit Add()
 {
     InnerEmit.Add();
     return(this);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// <para>Pops two arguments off the stack, multiplies them, and pushes the result.</para>
 /// <para>Throws an OverflowException if the result overflows the destination type.</para>
 /// </summary>
 public Emit MultiplyOverflow()
 {
     InnerEmit.MultiplyOverflow();
     return(this);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Pops two arguments off the stack, multiplies them, and pushes the result.
 /// </summary>
 public Emit Multiply()
 {
     InnerEmit.Multiply();
     return(this);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Pops two arguments off the stack, divides the second by the first as if they were unsigned, and pushes the result.
 /// </summary>
 public Emit UnsignedDivide()
 {
     InnerEmit.UnsignedDivide();
     return(this);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Pops two arguments off the stack, divides the second by the first, and pushes the result.
 /// </summary>
 public Emit Divide()
 {
     InnerEmit.Divide();
     return(this);
 }
Ejemplo n.º 15
0
 /// <summary>
 /// <para>Pops two arguments off the stack, adds them as if they were unsigned, and pushes the result.</para>
 /// <para>Throws an OverflowException if the result overflows the destination type.</para>
 /// </summary>
 public Emit UnsignedAddOverflow()
 {
     InnerEmit.UnsignedAddOverflow();
     return(this);
 }
Ejemplo n.º 16
0
 /// <summary>
 /// <para>Declare a new local of the given type in the current method.</para>
 /// <para>
 /// Name is optional, and only provided for debugging purposes.  It has no
 /// effect on emitted IL.
 /// </para>
 /// <para>
 /// Be aware that each local takes some space on the stack, inefficient use of locals
 /// could lead to StackOverflowExceptions at runtime.
 /// </para>
 /// </summary>
 public Local DeclareLocal(Type type, string name = null)
 {
     return(InnerEmit.DeclareLocal(type, name));
 }
Ejemplo n.º 17
0
 /// <summary>
 /// <para>Declare a new local of the given type in the current method.</para>
 /// <para>
 /// Name is optional, and only provided for debugging purposes.  It has no
 /// effect on emitted IL.
 /// </para>
 /// <para>
 /// Be aware that each local takes some space on the stack, inefficient use of locals
 /// could lead to StackOverflowExceptions at runtime.
 /// </para>
 /// </summary>
 public Emit DeclareLocal(Type type, out Local local, string name = null)
 {
     InnerEmit.DeclareLocal(type, out local, name);
     return(this);
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Pops two arguments off the stack, calculates the remainder of the second divided by the first, and pushes the result.
 /// </summary>
 public Emit Remainder()
 {
     InnerEmit.Remainder();
     return(this);
 }
Ejemplo n.º 19
0
 /// <summary>
 /// <para>Pushes a pointer to the current argument list onto the stack.</para>
 /// <para>This instruction can only be used in VarArgs methods.</para>
 /// </summary>
 public Emit ArgumentList()
 {
     InnerEmit.ArgumentList();
     return(this);
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Pops two arguments off the stack, calculates the remainder of the second divided by the first as if both were unsigned, and pushes the result.
 /// </summary>
 public Emit UnsignedRemainder()
 {
     InnerEmit.UnsignedRemainder();
     return(this);
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Converts a pointer or reference to a value on the stack into a TypedReference of the given type.
 ///
 /// TypedReferences can be used with ReferenceAnyType and ReferenceAnyValue to pass arbitrary types as parameters.
 /// </summary>
 public Emit MakeReferenceAny <Type>()
 {
     InnerEmit.MakeReferenceAny <Type>();
     return(this);
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Pushes the size of the given value type onto the stack.
 /// </summary>
 public Emit SizeOf(Type valueType)
 {
     InnerEmit.SizeOf(valueType);
     return(this);
 }
Ejemplo n.º 23
0
 public Emit NewObject <ReferenceType>()
 {
     InnerEmit.NewObject <ReferenceType>();
     return(this);
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Pushes the size of the given value type onto the stack.
 /// </summary>
 public Emit SizeOf <ValueType>()
     where ValueType : struct
 {
     InnerEmit.SizeOf <ValueType>();
     return(this);
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Pops parameterTypes.Length arguments from the stack, invokes the constructor on the given type that matches parameterTypes, and pushes a reference to the new object onto the stack.
 /// </summary>
 public Emit NewObject(Type type, params Type[] parameterTypes)
 {
     InnerEmit.NewObject(type, parameterTypes);
     return(this);
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Throws an ArithmeticException on runtime if the value on the stack is not a finite number.
 ///
 /// This leaves the value checked on the stack, rather than popping it as might be expected.
 /// </summary>
 public Emit CheckFinite()
 {
     InnerEmit.CheckFinite();
     return(this);
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Pops # of parameters from the stack, invokes the constructor, and pushes a reference to the new object onto the stack.
 ///
 /// This method is provided as ConstructorBuilder cannot be inspected for parameter information at runtime.  If the passed parameterTypes
 /// do not match the given constructor, the produced code will be invalid.
 /// </summary>
 public Emit NewObject(ConstructorBuilder constructor, Type[] parameterTypes)
 {
     InnerEmit.NewObject(constructor, parameterTypes);
     return(this);
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Removes the top value on the stack.
 /// </summary>
 public Emit Pop()
 {
     InnerEmit.Pop();
     return(this);
 }
Ejemplo n.º 29
0
 public Emit NewObject <ReferenceType, ParameterType1, ParameterType2, ParameterType3, ParameterType4, ParameterType5, ParameterType6>()
 {
     InnerEmit.NewObject <ReferenceType, ParameterType1, ParameterType2, ParameterType3, ParameterType4, ParameterType5, ParameterType6>();
     return(this);
 }
Ejemplo n.º 30
0
 /// <summary>
 /// <para>Declare a new local of the given type in the current method.</para>
 /// <para>
 /// Name is optional, and only provided for debugging purposes.  It has no
 /// effect on emitted IL.
 /// </para>
 /// <para>
 /// Be aware that each local takes some space on the stack, inefficient use of locals
 /// could lead to StackOverflowExceptions at runtime.
 /// </para>
 /// </summary>
 public Local DeclareLocal <Type>(string name = null)
 {
     return(InnerEmit.DeclareLocal <Type>(name));
 }