Пример #1
0
        static string GenIcallDecl(Icall icall)
        {
            var sb     = new StringBuilder();
            var method = icall.Method;

            sb.Append(MapType(method.ReturnType));
            sb.Append($" {icall.Func} (");
            int pindex = 0;
            int aindex = 0;

            if (method.HasThis)
            {
                sb.Append("int");
                aindex++;
            }
            foreach (var p in method.Parameters)
            {
                if (aindex > 0)
                {
                    sb.Append(",");
                }
                sb.Append(MapType(method.Parameters[pindex].ParameterType));
                pindex++;
                aindex++;
            }
            if (icall.Handles)
            {
                if (aindex > 0)
                {
                    sb.Append(",");
                }
                sb.Append("int");
                pindex++;
            }
            sb.Append(");");
            return(sb.ToString());
        }
Пример #2
0
        void ProcessType(TypeDefinition type)
        {
            foreach (var method in type.Methods)
            {
                if ((method.ImplAttributes & MethodImplAttributes.InternalCall) == 0)
                {
                    continue;
                }

                if (method.Name == ".ctor")
                {
                    continue;
                }

                var klass_name = method.DeclaringType.FullName;
                if (!runtime_icalls.ContainsKey(klass_name))
                {
                    // Registered at runtime
                    continue;
                }

                var klass = runtime_icalls[method.DeclaringType.FullName];

                Icall icall = null;

                // Try name first
                if (klass.Icalls.ContainsKey(method.Name))
                {
                    icall = klass.Icalls[method.Name];
                }
                if (icall == null)
                {
                    // Then with signature
                    var sig    = new StringBuilder(method.Name + "(");
                    int pindex = 0;
                    foreach (var par in method.Parameters)
                    {
                        if (pindex > 0)
                        {
                            sig.Append(",");
                        }
                        var t = par.ParameterType;
                        AppendType(sig, t);
                        pindex++;
                    }
                    sig.Append(")");

                    if (klass.Icalls.ContainsKey(sig.ToString()))
                    {
                        icall = klass.Icalls[sig.ToString()];
                    }
                }
                if (icall == null)
                {
                    // Registered at runtime
                    continue;
                }

                icall.Method     = method;
                icall.TokenIndex = (int)method.MetadataToken.RID;
                icall.Assembly   = method.DeclaringType.Module.Assembly.Name.Name;
                icalls.Add(icall);
            }
        }