예제 #1
0
        public static string DocId(this IPlatformInvokeInformation platformInvoke)
        {
            // return string.Format("I:{0}.{1}", platformInvoke.ImportModule.Name.Value, platformInvoke.ImportName.Value);

            // For now so we can use this to match up with the modern sdk names only include the pinvoke name in the identifier.
            return(string.Format(CultureInfo.InvariantCulture, "{0}", platformInvoke.ImportName.Value));
        }
 public override void Visit(IPlatformInvokeInformation platformInvokeInformation)
 {
     if (Process(platformInvokeInformation))
     {
         visitor.Visit(platformInvokeInformation);
     }
     base.Visit(platformInvokeInformation);
 }
예제 #3
0
 //^ ensures this.path.Count == old(this.path.Count);
 /// <summary>
 /// Visits the specified platform invoke information.
 /// </summary>
 /// <param name="platformInvokeInformation">The platform invoke information.</param>
 public virtual void Visit(IPlatformInvokeInformation platformInvokeInformation)
 {
     if (this.stopTraversal) return;
       //^ int oldCount = this.path.Count;
       this.path.Push(platformInvokeInformation);
       this.Visit(platformInvokeInformation.ImportModule);
       //^ assume this.path.Count == oldCount+1; //True because all of the virtual methods of this class promise not decrease this.path.Count.
       this.path.Pop();
 }
 public override void Visit(IPlatformInvokeInformation platformInvokeInformation)
 {
     if(Process(platformInvokeInformation)){visitor.Visit(platformInvokeInformation);}
     base.Visit(platformInvokeInformation);
 }
예제 #5
0
 public virtual void onMetadataElement(IPlatformInvokeInformation platformInvokeInformation) { }
 public override void TraverseChildren(IPlatformInvokeInformation platformInvokeInformation) {
   base.TraverseChildren(platformInvokeInformation);
 }
예제 #7
0
 /// <summary>
 /// Performs some compuation with the given platoform invoke information.
 /// </summary>
 public void Visit(IPlatformInvokeInformation platformInvokeInformation)
 {
 }
        private void EmitNonBlittableArrayMarshalling(List <ILocalDefinition> locals, ILGenerator ilGenerator, IArrayType arrayType, IParameterDefinition parameter, Dictionary <IParameterDefinition, ILocalDefinition> paramToLocalMap, IPlatformInvokeInformation pinvokeInfo)
        {
            if (TypeHelper.TypesAreEquivalent(arrayType.ElementType, this.host.PlatformType.SystemString))
            {
                var prologMethod = this.stringArrayAnsiMarshallingProlog;

                if (parameter.MarshallingInformation.ElementType == UnmanagedType.LPWStr)
                {
                    prologMethod = this.stringArrayUnicodeMarshallingProlog;
                }
                else if (pinvokeInfo.StringFormat == StringFormatKind.Unicode)
                {
                    if (parameter.MarshallingInformation.ElementType != UnmanagedType.LPStr && parameter.MarshallingInformation.ElementType != UnmanagedType.LPTStr)
                    {
                        prologMethod = this.stringArrayUnicodeMarshallingProlog;
                    }
                }

                var intPtrLocal = paramToLocalMap[parameter];
                ilGenerator.Emit(OperationCode.Ldloc, intPtrLocal);
                ilGenerator.Emit(OperationCode.Call, prologMethod);
                ilGenerator.Emit(OperationCode.Ldloc, intPtrLocal);
                EmitBlittableTypeArrayMarshalling(locals, ilGenerator, new VectorTypeReference {
                    ElementType = this.host.PlatformType.SystemIntPtr, Rank = 1
                }.ResolvedArrayType);
            }
            else
            {
                throw new Exception("NYI");
            }
        }
예제 #9
0
 public void Visit(IPlatformInvokeInformation platformInvokeInformation)
 {
     Contract.Assume(false);
 }
예제 #10
0
        public override void TraverseChildren(IPlatformInvokeInformation platformInvokeInformation)
{ MethodEnter(platformInvokeInformation);
            base.TraverseChildren(platformInvokeInformation);
     MethodExit();   }
예제 #11
0
 public virtual void onMetadataElement(IPlatformInvokeInformation platformInvokeInformation)
 {
 }
 public void PlatformInvokeInformation(IPlatformInvokeInformation pInvokeInfo) {
   this.ILDasmPaper.Keyword("pinvokeimpl");
   this.ILDasmPaper.Symbol("(");
   this.ILDasmPaper.Identifier(pInvokeInfo.ImportModule.Name.Value);
   this.ILDasmPaper.Keyword("as");
   this.ILDasmPaper.Identifier(pInvokeInfo.ImportName.Value);
   if (pInvokeInfo.NoMangle)
     this.ILDasmPaper.Keyword("nomangle");
   switch (pInvokeInfo.StringFormat) {
     case StringFormatKind.Unspecified:
       break;
     case StringFormatKind.Ansi:
       this.ILDasmPaper.Keyword("ansi");
       break;
     case StringFormatKind.Unicode:
       this.ILDasmPaper.Keyword("unicode");
       break;
     case StringFormatKind.AutoChar:
       this.ILDasmPaper.Keyword("autochar");
       break;
   }
   switch (pInvokeInfo.PInvokeCallingConvention) {
     case PInvokeCallingConvention.WinApi:
       this.ILDasmPaper.Keyword("winapi");
       break;
     case PInvokeCallingConvention.CDecl:
       this.ILDasmPaper.Keyword("cdecl");
       break;
     case PInvokeCallingConvention.StdCall:
       this.ILDasmPaper.Keyword("stdcall");
       break;
     case PInvokeCallingConvention.ThisCall:
       this.ILDasmPaper.Keyword("thiscall");
       break;
     case PInvokeCallingConvention.FastCall:
       this.ILDasmPaper.Keyword("fastcall");
       break;
     default:
       break;
   }
   if (pInvokeInfo.SupportsLastError)
     this.ILDasmPaper.Keyword("lasterr");
   this.ILDasmPaper.Symbol(")");
 }
 /// <summary>
 /// Rewrites the specified platform invoke information.
 /// </summary>
 public virtual IPlatformInvokeInformation Rewrite(IPlatformInvokeInformation platformInvokeInformation)
 {
     return platformInvokeInformation;
 }
예제 #14
0
 public override void Visit(IPlatformInvokeInformation platformInvokeInformation)
 {
     allElements.Add(new InvokInfo(Traverser, "IPlatformInvokeInformation", platformInvokeInformation));
 }
예제 #15
0
 /// <summary>
 /// Traverses the specified platform invoke information.
 /// </summary>
 public void Traverse(IPlatformInvokeInformation platformInvokeInformation)
 {
     Contract.Requires(platformInvokeInformation != null);
       if (this.preorderVisitor != null) this.preorderVisitor.Visit(platformInvokeInformation);
       if (this.stopTraversal) return;
       this.TraverseChildren(platformInvokeInformation);
       if (this.stopTraversal) return;
       if (this.postorderVisitor != null) this.postorderVisitor.Visit(platformInvokeInformation);
 }
예제 #16
0
 public void Visit(IPlatformInvokeInformation platformInvokeInformation)
 {
     throw new NotImplementedException();
 }
예제 #17
0
 /// <summary>
 /// Traverses the specified platform invoke information.
 /// </summary>
 public virtual void TraverseChildren(IPlatformInvokeInformation platformInvokeInformation)
 {
     Contract.Requires(platformInvokeInformation != null);
       this.Traverse(platformInvokeInformation.ImportModule);
 }
예제 #18
0
 public override abstract void Visit(IPlatformInvokeInformation platformInvokeInformation);
예제 #19
0
 public override void Visit(IPlatformInvokeInformation platformInvokeInformation)
 {
     this.metadataWriter.GetModuleRefIndex(platformInvokeInformation.ModuleName);
 }
예제 #20
0
 public override void Visit(IPlatformInvokeInformation platformInvokeInformation)
 {
     this.metadataWriter.GetModuleRefIndex(platformInvokeInformation.ModuleName);
 }
        private void LoadArguments(List <ILocalDefinition> locals, Dictionary <IParameterDefinition, ILocalDefinition> paramToLocalMap, ILGenerator ilGenerator, int argumentCount, Func <int, IParameterDefinition> parameterProvider, IPlatformInvokeInformation pinvokeInfo)
        {
            this.PreprocessNonBlittableArrayArguments(locals, paramToLocalMap, ilGenerator, argumentCount, parameterProvider);
            for (int i = 0; i < argumentCount; ++i)
            {
                var parameter = parameterProvider(i);
                Ldarg(ilGenerator, parameter, i);

                if (parameter.Type.ResolvedType is IArrayType)
                {
                    var arrayType = (IArrayType)parameter.Type.ResolvedType;

                    if (arrayType.IsBlittable())
                    {
                        EmitBlittableTypeArrayMarshalling(locals, ilGenerator, arrayType);
                    }
                    else
                    {
                        this.EmitNonBlittableArrayMarshalling(locals, ilGenerator, arrayType, parameter, paramToLocalMap, pinvokeInfo);
                    }
                }
                else if (parameter.IsByReference)
                {
                    EmitByRefMarshalling(locals, ilGenerator, parameter.Type);
                }
                else if (parameter.Type.TypeCode == PrimitiveTypeCode.Boolean)
                {
                    EmitBoolMarshalling(ilGenerator);
                }
                else if (parameter.Type.ResolvedType.IsDelegate)
                {
                    ilGenerator.Emit(OperationCode.Call, this.getFunctionPointerForDelegate);
                }
                else if (TypeHelper.TypesAreEquivalent(parameter.Type, this.host.PlatformType.SystemString))
                {
                    bool doUnicodeMarshalling = false;
                    if (parameter.MarshallingInformation.UnmanagedType == UnmanagedType.LPWStr)
                    {
                        doUnicodeMarshalling = true;
                    }
                    else if (pinvokeInfo.StringFormat == StringFormatKind.Unicode)
                    {
                        if (parameter.MarshallingInformation.UnmanagedType != UnmanagedType.LPStr &&
                            parameter.MarshallingInformation.UnmanagedType != UnmanagedType.LPTStr)
                        {
                            doUnicodeMarshalling = true;
                        }
                    }

                    if (doUnicodeMarshalling)
                    {
                        EmitUnicodeStringMarshalling(locals, ilGenerator, this.getOffSetToStringData, this.host.PlatformType.SystemString);
                    }
                    else
                    {
                        EmitAnsiStringMarshalling(locals, ilGenerator, this.stringToAnsiArray, this.host.PlatformType);
                    }
                }
            }
        }
예제 #22
0
 public override void Visit(IPlatformInvokeInformation platformInvokeInformation)
 {
 }
예제 #23
0
 public virtual void Visit(IPlatformInvokeInformation platformInvokeInformation)
 {
 }
예제 #24
0
 public override abstract void Visit(IPlatformInvokeInformation platformInvokeInformation);
예제 #25
0
        private IMethodDefinition CreateInitMethod(IMethodDefinition incomingMethodDefinition, IFieldReference loadLibraryModule, IFieldReference methodField, IMethodReference isLibraryInitMethod, IPlatformInvokeInformation platformInvokeInformation)
        {
            var methodDefinition = new MethodDefinition
            {
                IsStatic = true,
                Type     = this.platformType.SystemVoid,
                ContainingTypeDefinition = incomingMethodDefinition.ContainingTypeDefinition,
                Name           = this.nameTable.GetNameFor("init_" + incomingMethodDefinition.Name.Value),
                IsNeverInlined = true,
                Visibility     = TypeMemberVisibility.Private
            };

            var ilGenerator = new ILGenerator(this.host, methodDefinition);

            ilGenerator.Emit(OperationCode.Ldsfld, loadLibraryModule);
            ilGenerator.Emit(OperationCode.Dup);
            ilGenerator.Emit(OperationCode.Ldstr, platformInvokeInformation.ImportModule.Name.Value);
            ilGenerator.Emit(OperationCode.Call, isLibraryInitMethod);
            ilGenerator.Emit(OperationCode.Ldstr, platformInvokeInformation.ImportName.Value);
            ilGenerator.Emit(OperationCode.Call, this.getProcAddress);
            ilGenerator.Emit(OperationCode.Stsfld, methodField);
            ilGenerator.Emit(OperationCode.Ret);

            var ilMethodBody = new ILGeneratorMethodBody(ilGenerator, false, 2, methodDefinition, Enumerable.Empty <ILocalDefinition>(), Enumerable.Empty <ITypeDefinition>());

            methodDefinition.Body = ilMethodBody;

            return(methodDefinition);
        }
예제 #26
0
 public override void Visit(IPlatformInvokeInformation platformInvokeInformation)
 {
 }
예제 #27
0
 public override void TraverseChildren(IPlatformInvokeInformation platformInvokeInformation)
 {
     MethodEnter(platformInvokeInformation);
     base.TraverseChildren(platformInvokeInformation);
     MethodExit();
 }
예제 #28
0
 /// <summary>
 /// Traverses the specified platform invoke information.
 /// </summary>
 public virtual void TraverseChildren(IPlatformInvokeInformation platformInvokeInformation)
 {
     this.Traverse(platformInvokeInformation.ImportModule);
 }