Beispiel #1
0
        public override void Call(CallOpcode opcode, MethodBase method, Type[] parameterTypes, Type returnType)
        {
            // Sanity checks
            if (method.DeclaringType.IsGenericTypeDefinition)
            {
                throw Error("Call to a member of a generic type definition: {0}.", GetFullName(method));
            }
            if (method.IsGenericMethodDefinition)
            {
                throw Error("Call to generic method definition: {0}.", GetFullName(method));
            }
            if (opcode.Kind == CallKind.Constructor && !(method is ConstructorInfo))
            {
                throw Error("New object by calling a non-constructor: {0}.", GetFullName(method));
            }

            // Pop arguments
            int requiredStackSize = parameterTypes.Length;

            if (!method.IsStatic)
            {
                ++requiredStackSize;
            }

            if (StackSize < requiredStackSize)
            {
                throw Error("Calling {0} requires {1} stack operands, but the stack has size {2}.", GetFullName(method), requiredStackSize, stack.Size);
            }

            for (int i = parameterTypes.Length - 1; i >= 0; --i)
            {
                stack.PopAssignableTo(opcode, parameterTypes[i]);
            }

            if (!method.IsStatic)
            {
                stack.PopAssignableTo(opcode, method.DeclaringType);
            }

            // Push return value
            if (opcode.Kind == CallKind.Constructor)
            {
                stack.Push(method.DeclaringType);
            }
            else if (returnType != typeof(void))
            {
                stack.Push(returnType);
            }

            // Forward to sink
            if (sink != null)
            {
                sink.Call(opcode, method);
            }
        }
Beispiel #2
0
        protected void CallWithReflectedTypes(CallOpcode opcode, MethodBase method)
        {
            Contract.Requires(opcode != null);
            Contract.Requires(method != null && !(method is Emit.MethodBuilder) && !(method is Emit.ConstructorBuilder));

            var parameterTypes = Array.ConvertAll(method.GetParameters(), p => p.ParameterType);
            var methodInfo     = method as MethodInfo;
            var returnType     = methodInfo == null ? typeof(void) : methodInfo.ReturnType;

            Call(opcode, method, parameterTypes, returnType);
        }
Beispiel #3
0
        WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(CallOpcode opcode, WasmNodeArg arg)
        {
            var target = arg.Context.ResolveFunction(opcode.FunctionIndex);
            var node   = new CallNode(target);

            for (var i = target.Signature.Parameters.Count - 1; i >= 0; i--)
            {
                var param = arg.Pop();
                node.Arguments.Insert(0, param);
            }
            arg.Push(node);
            return(null);
        }
        public override void Call(CallOpcode opcode, MethodBase method)
        {
            OpCode emitOpCode;

            opcode.GetReflectionEmitOpCode(out emitOpCode);

            switch (opcode.Kind)
            {
            case CallKind.EarlyBound: generator.Emit(OpCodes.Call, (MethodInfo)method); break;

            case CallKind.Virtual: generator.Emit(OpCodes.Callvirt, (MethodInfo)method); break;

            case CallKind.Jump: generator.Emit(OpCodes.Call, (MethodInfo)method); break;

            case CallKind.Constructor: generator.Emit(OpCodes.Newobj, (ConstructorInfo)method); break;

            default: throw new ArgumentException("opcode");
            }
        }
 public override void VisitCall(CallOpcode opcode, VisitorParam param)
 {
     throw RequiresSymbolicOverload(opcode);
 }
Beispiel #6
0
 public override void Call(CallOpcode opcode, MethodBase method)
 {
     CallWithReflectedTypes(opcode, method);
 }
Beispiel #7
0
 public override void Call(CallOpcode opcode, MethodBase method, Type[] parameterTypes, Type returnType)
 {
     stringBuilder.AppendLine(opcode.Name + ' ' + method.DeclaringType.FullName + '.' + method.Name);
 }
Beispiel #8
0
 public XElement Visit(CallOpcode opcode, AbcMethodBodyInstruction arg)
 {
     return(new XElement("call").AddArgsCount(opcode.ArgCount));
 }
Beispiel #9
0
 public WasmOpcodeExecutor Visit(CallOpcode opcode, WasmFunctionState state) => throw new System.NotImplementedException();
Beispiel #10
0
 public BaseAvm2Opcode Visit(CallOpcode opcode, AbcDataReader arg)
 {
     opcode.ArgCount = arg.ReadU30();
     return(opcode);
 }
Beispiel #11
0
 /// <summary>
 /// Writes a method call instruction, providing type information.
 /// This is needed because <see cref="MethodBuilder"/> and <see cref="ConstructorBuilder"/>
 /// throw when querying this information.
 /// </summary>
 /// <param name="opcode">The call opcode.</param>
 /// <param name="method">The method to be called.</param>
 /// <param name="parameterTypes">The type of the method's parameters.</param>
 /// <param name="returnType">The type of the value returned by this method, or <c>typeof(void)</c>.</param>
 public abstract void Call(CallOpcode opcode, MethodBase method, Type[] parameterTypes, Type returnType);
Beispiel #12
0
 public abstract void Call(CallOpcode opcode, MethodBase method);
 WasmMSILResult IWasmOpcodeVisitor <WasmMSILArg, WasmMSILResult> .Visit(CallOpcode opcode, WasmMSILArg arg) => throw new NotImplementedException();
 public override void Call(CallOpcode opcode, MethodBase method, Type[] parameterTypes, Type returnType)
 {
     // We don't need the parameter/return types
     Call(opcode, method);
 }