예제 #1
0
        public static string WritePlatformInvokeMethod(this PlatformInvokeMethod platformInvoke,
                                                       ClosureEntities crRuntime)
        {
            var methodId = Import(platformInvoke.LibraryName,
                                  platformInvoke.MethodName,
                                  platformInvoke.CallingConvention,
                                  platformInvoke.EntryPoint);

            var codeOutput = new CodeOutput();

            codeOutput.AppendFormat(platformInvoke.WritePInvokeDefinition(methodId));
            codeOutput.BlankLine();
            codeOutput.Append(platformInvoke.Method.WriteHeaderMethod(crRuntime, false));

            // write PInvoke implementation
            codeOutput.BracketOpen();

            var argumentsCall = platformInvoke.Method.GetParameters()
                                .Select(CallMarshallerFactory.CreateMarshaller)
                                .Each(marshaller => { codeOutput.Append(marshaller.GetTransformationCode()); })
                                .Once(marshallers => { codeOutput.BlankLine(); })
                                .Select(p => p.GetParameterString())
                                .Join(", ");

            if (!platformInvoke.Method.GetReturnType().IsVoid())
            {
                codeOutput.Append("return ");
            }
            codeOutput.AppendFormat("{0}({1});", methodId, argumentsCall);
            codeOutput.BracketClose();

            return(codeOutput.ToString());
        }
예제 #2
0
 public override MethodInterpreter Resolve(MethodBase method)
 {
     if (!PlatformInvokeMethod.IsPlatformInvoke(method))
     {
         return(null);
     }
     return(new PlatformInvokeMethod(method));
 }
예제 #3
0
        protected static void ResolveAsPinvoke(PlatformInvokeMethod methodInterpreter, string libraryName,
                                               CallingConvention callingConvention = CallingConvention.Winapi)
        {
            var method = methodInterpreter.Method;

            methodInterpreter.LibraryName       = libraryName;
            methodInterpreter.EntryPoint        = method.Name;
            methodInterpreter.MethodName        = method.Name;
            methodInterpreter.CallingConvention = callingConvention;
        }
예제 #4
0
        public void Call(MethodBase operand)
        {
            var methodInfo = operand;

            //TODO System.Void System.Array::Resize<System.Char>(!!0[]&,System.Int32) Weird Signature

            if (methodInfo == null)
            {
                return;
            }
            MethodInterpreter interpreter;

            if (PlatformInvokeMethod.IsPlatformInvoke(methodInfo))
            {
                interpreter = new PlatformInvokeMethod(methodInfo);
                var pMethodData = new CallMethodStatic(interpreter);
                CallMethodData(methodInfo, pMethodData);
                return;
            }
            interpreter = new CilMethodInterpreter(methodInfo);
            var methodData = new CallMethodStatic(interpreter);

            CallMethodData(methodInfo, methodData);
        }
        public void Process(ClosureEntities closureEntities)
        {
            if (Kind != MethodKind.CilInstructions)
            {
                return;
            }
            if (Interpreted)
            {
                return;
            }
            Ensure.AreEqual(false, PlatformInvokeMethod.IsPlatformInvoke(Method),
                            $"Should not run it on current method: {Method}"
                            );
            if (Method.GetMethodBody() == null)
            {
                return;
            }

            MidRepresentation.Vars.SetupLocalVariables(Method);
            var midRepresentationBuilder = new MethodMidRepresentationBuilder(this, Method);

            midRepresentationBuilder.ProcessInstructions(closureEntities);
            Interpreted = true;
        }
예제 #6
0
 internal static string WritePInvokeMethodCode(PlatformInvokeMethod interpreter, ClosureEntities crRuntime)
 {
     return(interpreter.WritePlatformInvokeMethod(crRuntime));
 }