示例#1
0
文件: ILLog.cs 项目: xiaopan1991/ILR
        public static void Log(ILIntepreter __intp, Enviorment.AppDomain __domain, UnityEngine.LogType level, string format, params object[] objs)
        {
            var text = (objs == null || objs.Length == 0) ? format : string.Format(format, objs);

            UnityEngine.Debug.unityLogger.Log(level,
                                              string.Format("{0}\nStackTrance:{1}", text, __domain.DebugService.GetStackTrance(__intp)));
        }
        static bool CheckAssignableToCrossBindingAdapters(Enviorment.AppDomain domain, Type type)
        {
            bool res = domain.CrossBindingAdaptors.ContainsKey(type);

            if (!res)
            {
                var baseType = type.BaseType;
                if (baseType != null && baseType != typeof(object))
                {
                    res = CheckAssignableToCrossBindingAdapters(domain, baseType);
                }
            }
            if (!res)
            {
                var interfaces = type.GetInterfaces();
                foreach (var i in interfaces)
                {
                    res = CheckAssignableToCrossBindingAdapters(domain, i);
                    if (res)
                    {
                        break;
                    }
                }
            }
            return(res);
        }
示例#3
0
 protected DelegateAdapter(Enviorment.AppDomain appdomain, ILTypeInstance instance, ILMethod method)
 {
     this.appdomain = appdomain;
     this.instance  = instance;
     this.method    = method;
     CLRInstance    = this;
 }
示例#4
0
        bool CheckCompilerGeneratedStateMachine(ILMethod ilm, Enviorment.AppDomain domain, int startLine, out ILMethod found)
        {
            var mDef = ilm.Definition;

            Mono.Cecil.CustomAttribute ca = null;
            found = null;
            foreach (var attr in mDef.CustomAttributes)
            {
                switch (attr.AttributeType.FullName)
                {
                case "System.Runtime.CompilerServices.AsyncStateMachineAttribute":
                case "System.Runtime.CompilerServices.IteratorStateMachineAttribute":
                    ca = attr;
                    break;
                }
            }
            if (ca != null)
            {
                if (ca.ConstructorArguments.Count > 0)
                {
                    var smType = domain.GetType(ca.ConstructorArguments[0].Value, null, null);
                    if (smType != null)
                    {
                        ilm = smType.GetMethod("MoveNext", 0, true) as ILMethod;
                        if (ilm != null && ilm.StartLine <= (startLine + 1) && ilm.EndLine >= (startLine + 1))
                        {
                            found = ilm;
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
示例#5
0
 public JITCompiler(Enviorment.AppDomain appDomain, ILType declaringType, ILMethod method)
 {
     this.appdomain     = appDomain;
     this.declaringType = declaringType;
     this.method        = method;
     def          = method.Definition;
     hasReturn    = method.ReturnType != appdomain.VoidType;
     entryMapping = null;
     jumptables   = null;
 }
示例#6
0
        internal unsafe void AssignFromStack(StackObject *esp, Enviorment.AppDomain appdomain, IList <object> managedStack)
        {
            StackObject *val = ILIntepreter.ResolveReference(esp);
            int          cnt = val->ValueLow;

            for (int i = 0; i < cnt; i++)
            {
                var addr = ILIntepreter.Minus(val, i + 1);
                AssignFromStack(i, addr, type.AppDomain, managedStack);
            }
        }
示例#7
0
 internal unsafe void PushToStack(int fieldIdx, StackObject *esp, Enviorment.AppDomain appdomain, IList <object> managedStack)
 {
     if (fieldIdx < fields.Length && fieldIdx >= 0)
     {
         PushToStackSub(ref fields[fieldIdx], fieldIdx, esp, managedStack);
     }
     else
     {
         if (Type.FirstCLRBaseType != null && Type.FirstCLRBaseType is Enviorment.CrossBindingAdaptor)
         {
             CLRType clrType = appdomain.GetType(((Enviorment.CrossBindingAdaptor)Type.FirstCLRBaseType).BaseCLRType) as CLRType;
             ILIntepreter.PushObject(esp, managedStack, clrType.GetFieldValue(fieldIdx, clrInstance));
         }
         else
         {
             throw new TypeLoadException();
         }
     }
 }
示例#8
0
 internal unsafe void AssignFromStack(int fieldIdx, StackObject *esp, Enviorment.AppDomain appdomain, List <object> managedStack)
 {
     if (fieldIdx < fields.Length && fieldIdx >= 0)
     {
         AssignFromStackSub(ref fields[fieldIdx], fieldIdx, esp, managedStack);
     }
     else
     {
         if (Type.BaseType != null && Type.BaseType is Enviorment.CrossBindingAdaptor)
         {
             CLRType clrType = appdomain.GetType(((Enviorment.CrossBindingAdaptor)Type.BaseType).BaseCLRType) as CLRType;
             var     field   = clrType.Fields[fieldIdx];
             field.SetValue(clrInstance, field.FieldType.CheckCLRTypes(appdomain, esp->ToObject(appdomain, managedStack)));
         }
         else
         {
             throw new TypeLoadException();
         }
     }
 }
示例#9
0
 internal unsafe void AssignFromStack(int fieldIdx, StackObject *esp, Enviorment.AppDomain appdomain, IList <object> managedStack)
 {
     if (fieldIdx < fields.Length && fieldIdx >= 0)
     {
         AssignFromStackSub(ref fields[fieldIdx], fieldIdx, esp, managedStack);
     }
     else
     {
         if (Type.FirstCLRBaseType != null && Type.FirstCLRBaseType is Enviorment.CrossBindingAdaptor)
         {
             CLRType clrType = appdomain.GetType(((Enviorment.CrossBindingAdaptor)Type.FirstCLRBaseType).BaseCLRType) as CLRType;
             var     field   = clrType.GetField(fieldIdx);
             clrType.SetFieldValue(fieldIdx, ref clrInstance, field.FieldType.CheckCLRTypes(ILIntepreter.CheckAndCloneValueType(StackObject.ToObject(esp, appdomain, managedStack), appdomain)));
         }
         else
         {
             throw new TypeLoadException();
         }
     }
 }
 internal static void GetReturnValueCode(this Type type, StringBuilder sb, Enviorment.AppDomain domain)
 {
     if (type.IsPrimitive)
     {
         if (type == typeof(int))
         {
             sb.AppendLine("            __ret->ObjectType = ObjectTypes.Integer;");
             sb.AppendLine("            __ret->Value = result_of_this_method;");
         }
         else if (type == typeof(long))
         {
             sb.AppendLine("            __ret->ObjectType = ObjectTypes.Long;");
             sb.AppendLine("            *(long*)&__ret->Value = result_of_this_method;");
         }
         else if (type == typeof(short))
         {
             sb.AppendLine("            __ret->ObjectType = ObjectTypes.Integer;");
             sb.AppendLine("            __ret->Value = result_of_this_method;");
         }
         else if (type == typeof(bool))
         {
             sb.AppendLine("            __ret->ObjectType = ObjectTypes.Integer;");
             sb.AppendLine("            __ret->Value = result_of_this_method ? 1 : 0;");
         }
         else if (type == typeof(ushort))
         {
             sb.AppendLine("            __ret->ObjectType = ObjectTypes.Integer;");
             sb.AppendLine("            __ret->Value = result_of_this_method;");
         }
         else if (type == typeof(float))
         {
             sb.AppendLine("            __ret->ObjectType = ObjectTypes.Float;");
             sb.AppendLine("            *(float*)&__ret->Value = result_of_this_method;");
         }
         else if (type == typeof(double))
         {
             sb.AppendLine("            __ret->ObjectType = ObjectTypes.Double;");
             sb.AppendLine("            *(double*)&__ret->Value = result_of_this_method;");
         }
         else if (type == typeof(byte))
         {
             sb.AppendLine("            __ret->ObjectType = ObjectTypes.Integer;");
             sb.AppendLine("            __ret->Value = result_of_this_method;");
         }
         else if (type == typeof(sbyte))
         {
             sb.AppendLine("            __ret->ObjectType = ObjectTypes.Integer;");
             sb.AppendLine("            __ret->Value = result_of_this_method;");
         }
         else if (type == typeof(uint))
         {
             sb.AppendLine("            __ret->ObjectType = ObjectTypes.Integer;");
             sb.AppendLine("            __ret->Value = (int)result_of_this_method;");
         }
         else if (type == typeof(char))
         {
             sb.AppendLine("            __ret->ObjectType = ObjectTypes.Integer;");
             sb.AppendLine("            __ret->Value = (int)result_of_this_method;");
         }
         else if (type == typeof(ulong))
         {
             sb.AppendLine("            __ret->ObjectType = ObjectTypes.Long;");
             sb.AppendLine("            *(ulong*)&__ret->Value = result_of_this_method;");
         }
         else
         {
             throw new NotImplementedException();
         }
         sb.AppendLine("            return __ret + 1;");
     }
     else
     {
         string isBox;
         if (type == typeof(object))
         {
             isBox = ", true";
         }
         else
         {
             isBox = "";
         }
         if (!type.IsSealed && type != typeof(ILRuntime.Runtime.Intepreter.ILTypeInstance))
         {
             if (domain == null || CheckAssignableToCrossBindingAdapters(domain, type))
             {
                 sb.Append(@"            object obj_result_of_this_method = result_of_this_method;
     if(obj_result_of_this_method is CrossBindingAdaptorType)
     {    
         return ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType)obj_result_of_this_method).ILInstance");
                 sb.Append(isBox);
                 sb.AppendLine(@");
     }");
             }
             else if (typeof(CrossBindingAdaptorType).IsAssignableFrom(type))
             {
                 sb.AppendLine(string.Format("            return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method.ILInstance{0});", isBox));
                 return;
             }
         }
         sb.AppendLine(string.Format("            return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method{0});", isBox));
     }
 }
示例#11
0
        internal static string GenerateMethodWraperCode(this Type type, MethodInfo[] methods, string typeClsName, HashSet <MethodBase> excludes, List <Type> valueTypeBinders, Enviorment.AppDomain domain)
        {
            StringBuilder sb         = new StringBuilder();
            bool          isMultiArr = type.IsArray && type.GetArrayRank() > 1;
            int           idx        = 0;

            foreach (var i in methods)
            {
                if (excludes != null && excludes.Contains(i))
                {
                    continue;
                }
                if (type.ShouldSkipMethod(i))
                {
                    continue;
                }
                bool isProperty = i.IsSpecialName;
                var  param      = i.GetParameters();
                int  paramCnt   = param.Length;
                if (!i.IsStatic)
                {
                    paramCnt++;
                }
                sb.AppendLine(string.Format("        static StackObject* {0}_{1}(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)", i.Name, idx));
                sb.AppendLine("        {");
                sb.AppendLine("            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;");
                if (param.Length != 0 || !i.IsStatic)
                {
                    sb.AppendLine("            StackObject* ptr_of_this_method;");
                }
                sb.AppendLine(string.Format("            StackObject* __ret = ILIntepreter.Minus(__esp, {0});", paramCnt));
                sb.AppendLine();
                bool   hasByRef        = param.HasByRefParam();
                string shouldFreeParam = hasByRef ? "false" : "true";
                for (int j = param.Length; j > 0; j--)
                {
                    var p = param[j - 1];
                    sb.AppendLine(string.Format("            ptr_of_this_method = ILIntepreter.Minus(__esp, {0});", param.Length - j + 1));
                    p.ParameterType.AppendArgumentCode(sb, j, p.Name, valueTypeBinders, isMultiArr, hasByRef, true);
                    sb.AppendLine();
                }
                bool noUnbox = (type.Name.Contains("AsyncTaskMethodBuilder") || type.FullName.StartsWith("System.Runtime.CompilerServices.AsyncVoidMethodBuilder")) && i.Name == "Start";

                if (!i.IsStatic)
                {
                    sb.AppendLine(string.Format("            ptr_of_this_method = ILIntepreter.Minus(__esp, {0});", paramCnt));
                    if (type.IsPrimitive)
                    {
                        sb.AppendLine(string.Format("            {0} instance_of_this_method = GetInstance(__domain, ptr_of_this_method, __mStack);", typeClsName));
                    }
                    else if (type.IsValueType && !type.IsPrimitive && valueTypeBinders != null && valueTypeBinders.Contains(type))
                    {
                        string clsName, realClsName;
                        bool   isByRef;
                        type.GetClassName(out clsName, out realClsName, out isByRef);

                        sb.AppendLine(string.Format("            {0} instance_of_this_method = new {0}();", realClsName));

                        sb.AppendLine(string.Format("            if (ILRuntime.Runtime.Generated.CLRBindings.s_{0}_Binder != null) {{", clsName));

                        sb.AppendLine(string.Format("                ILRuntime.Runtime.Generated.CLRBindings.s_{0}_Binder.ParseValue(ref instance_of_this_method, __intp, ptr_of_this_method, __mStack, false);", clsName));

                        sb.AppendLine("            } else {");

                        if (type.IsValueType)
                        {
                            sb.AppendLine("                ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method);");
                        }
                        sb.AppendLine(string.Format("                instance_of_this_method = {0};", type.GetRetrieveValueCode(typeClsName)));
                        if (!type.IsValueType && !hasByRef)
                        {
                            sb.AppendLine("                __intp.Free(ptr_of_this_method);");
                        }

                        sb.AppendLine("            }");
                    }
                    else
                    {
                        if (type.IsValueType && !type.IsPrimitive)
                        {
                            sb.AppendLine("            ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method);");
                        }
                        if (noUnbox)
                        {
                            sb.AppendLine(string.Format("            object instance_of_this_method = {0};", type.GetRetrieveValueCode(typeClsName)));
                        }
                        else
                        {
                            sb.AppendLine(string.Format("            {0} instance_of_this_method = {1};", typeClsName, type.GetRetrieveValueCode(typeClsName)));
                        }
                        if (!type.IsValueType && !hasByRef)
                        {
                            sb.AppendLine("            __intp.Free(ptr_of_this_method);");
                        }
                    }
                }
                sb.AppendLine();
                if (i.ReturnType != typeof(void))
                {
                    sb.Append("            var result_of_this_method = ");
                }
                else
                {
                    sb.Append("            ");
                }
                string genericArguments = "";
                if (i.IsGenericMethod)
                {
                    var           p     = i.GetGenericArguments();
                    StringBuilder sb2   = new StringBuilder();
                    bool          first = true;
                    sb2.Append('<');
                    foreach (var j in p)
                    {
                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            sb2.Append(", ");
                        }
                        string clsName, realClsName;
                        bool   isByRef;
                        j.GetClassName(out clsName, out realClsName, out isByRef);
                        sb2.Append(realClsName);
                    }
                    sb2.Append('>');
                    genericArguments = sb2.ToString();
                }

                if (i.IsStatic)
                {
                    if (isProperty)
                    {
                        string[] t = new string[2];
                        int      firstUnderlineIndex = i.Name.IndexOf("_");
                        t[0] = i.Name.Substring(0, firstUnderlineIndex);
                        t[1] = i.Name.Substring(firstUnderlineIndex + 1);
                        string propType = t[0];

                        if (propType == "get")
                        {
                            bool isIndexer = param.Length > 0;
                            if (isIndexer)
                            {
                                sb.AppendLine(string.Format("{1}[{0}];", param[0].Name, typeClsName));
                            }
                            else
                            {
                                sb.AppendLine(string.Format("{1}.{0};", t[1], typeClsName));
                            }
                        }
                        else if (propType == "set")
                        {
                            bool isIndexer = param.Length > 1;
                            if (isIndexer)
                            {
                                sb.AppendLine(string.Format("{2}[{0}] = {1};", param[0].Name, param[1].Name, typeClsName));
                            }
                            else
                            {
                                sb.AppendLine(string.Format("{2}.{0} = {1};", t[1], param[0].Name, typeClsName));
                            }
                        }
                        else if (propType == "op")
                        {
                            switch (t[1])
                            {
                            case "Equality":
                                sb.AppendLine(string.Format("{0} == {1};", param[0].Name, param[1].Name));
                                break;

                            case "Inequality":
                                sb.AppendLine(string.Format("{0} != {1};", param[0].Name, param[1].Name));
                                break;

                            case "Addition":
                                sb.AppendLine(string.Format("{0} + {1};", param[0].Name, param[1].Name));
                                break;

                            case "Subtraction":
                                sb.AppendLine(string.Format("{0} - {1};", param[0].Name, param[1].Name));
                                break;

                            case "Multiply":
                                sb.AppendLine(string.Format("{0} * {1};", param[0].Name, param[1].Name));
                                break;

                            case "Division":
                                sb.AppendLine(string.Format("{0} / {1};", param[0].Name, param[1].Name));
                                break;

                            case "GreaterThan":
                                sb.AppendLine(string.Format("{0} > {1};", param[0].Name, param[1].Name));
                                break;

                            case "GreaterThanOrEqual":
                                sb.AppendLine(string.Format("{0} >= {1};", param[0].Name, param[1].Name));
                                break;

                            case "LessThan":
                                sb.AppendLine(string.Format("{0} < {1};", param[0].Name, param[1].Name));
                                break;

                            case "LessThanOrEqual":
                                sb.AppendLine(string.Format("{0} <= {1};", param[0].Name, param[1].Name));
                                break;

                            case "UnaryNegation":
                                sb.AppendLine(string.Format("-{0};", param[0].Name));
                                break;

                            case "Modulus":
                                sb.AppendLine(string.Format("{0} % {1};", param[0].Name, param[1].Name));
                                break;

                            case "Implicit":
                            case "Explicit":
                            {
                                string clsName, realClsName;
                                bool   isByRef;
                                i.ReturnType.GetClassName(out clsName, out realClsName, out isByRef);
                                sb.AppendLine(string.Format("({1}){0};", param[0].Name, realClsName));
                            }
                            break;

                            default:
                                throw new NotImplementedException(i.Name);
                            }
                        }
                        else if (propType == "add")
                        {
                            string clsName, realClsName;
                            bool   isByRef;
                            i.DeclaringType.GetClassName(out clsName, out realClsName, out isByRef);
                            sb.AppendLine(string.Format("{0}.{1} += {2};", realClsName, i.Name.Substring(4), param[0].Name));
                        }
                        else if (propType == "remove")
                        {
                            string clsName, realClsName;
                            bool   isByRef;
                            i.DeclaringType.GetClassName(out clsName, out realClsName, out isByRef);
                            sb.AppendLine(string.Format("{0}.{1} -= {2};", realClsName, i.Name.Substring(7), param[0].Name));
                        }
                        else
                        {
                            throw new NotImplementedException();
                        }
                    }
                    else
                    {
                        sb.Append(string.Format("{0}.{1}{2}(", typeClsName, i.Name, genericArguments));
                        param.AppendParameters(sb);
                        sb.AppendLine(");");
                    }
                }
                else
                {
                    if (isProperty)
                    {
                        string[] t = new string[2];
                        int      firstUnderlineIndex = i.Name.IndexOf("_");
                        t[0] = i.Name.Substring(0, firstUnderlineIndex);
                        t[1] = i.Name.Substring(firstUnderlineIndex + 1);
                        string propType = t[0];

                        if (noUnbox)
                        {
                            if (propType == "get")
                            {
                                bool isIndexer = param.Length > 0;
                                if (isIndexer)
                                {
                                    sb.AppendLine(string.Format("(({1})instance_of_this_method)[{0}];", param[0].Name, typeClsName));
                                }
                                else
                                {
                                    sb.AppendLine(string.Format("(({1})instance_of_this_method).{0};", t[1], typeClsName));
                                }
                            }
                            else if (propType == "set")
                            {
                                bool isIndexer = param.Length > 1;
                                if (isIndexer)
                                {
                                    sb.AppendLine(string.Format("(({2})instance_of_this_method)[{0}] = {1};", param[0].Name, param[1].Name, typeClsName));
                                }
                                else
                                {
                                    sb.AppendLine(string.Format("(({2})instance_of_this_method).{0} = {1};", t[1], param[0].Name, typeClsName, typeClsName));
                                }
                            }
                            else if (propType == "add")
                            {
                                sb.AppendLine(string.Format("(({2})instance_of_this_method).{0} += {1};", i.Name.Substring(4), param[0].Name, typeClsName));
                            }
                            else if (propType == "remove")
                            {
                                sb.AppendLine(string.Format("(({2})instance_of_this_method).{0} -= {1};", i.Name.Substring(7), param[0].Name, typeClsName));
                            }
                            else
                            {
                                throw new NotImplementedException();
                            }
                        }
                        else
                        {
                            if (propType == "get")
                            {
                                bool isIndexer = param.Length > 0;
                                if (isIndexer)
                                {
                                    sb.AppendLine(string.Format("instance_of_this_method[{0}];", param[0].Name));
                                }
                                else
                                {
                                    sb.AppendLine(string.Format("instance_of_this_method.{0};", t[1]));
                                }
                            }
                            else if (propType == "set")
                            {
                                bool isIndexer = param.Length > 1;
                                if (isIndexer)
                                {
                                    sb.AppendLine(string.Format("instance_of_this_method[{0}] = {1};", param[0].Name, param[1].Name));
                                }
                                else
                                {
                                    sb.AppendLine(string.Format("instance_of_this_method.{0} = {1};", t[1], param[0].Name));
                                }
                            }
                            else if (propType == "add")
                            {
                                sb.AppendLine(string.Format("instance_of_this_method.{0} += {1};", i.Name.Substring(4), param[0].Name));
                            }
                            else if (propType == "remove")
                            {
                                sb.AppendLine(string.Format("instance_of_this_method.{0} -= {1};", i.Name.Substring(7), param[0].Name));
                            }
                            else
                            {
                                throw new NotImplementedException();
                            }
                        }
                    }
                    else if (isMultiArr)
                    {
                        if (i.Name == "Get")
                        {
                            sb.Append("instance_of_this_method[");
                            param.AppendParameters(sb, true);
                            sb.AppendLine("];");
                        }
                        else
                        {
                            sb.Append("instance_of_this_method[");
                            param.AppendParameters(sb, true, 1);
                            sb.Append("]");
                            sb.Append(" = a");
                            sb.Append(param.Length);
                            sb.AppendLine(";");
                        }
                    }
                    else
                    {
                        if (noUnbox)
                        {
                            sb.Append(string.Format("(({2})instance_of_this_method).{0}{1}(", i.Name, genericArguments, typeClsName));
                        }
                        else
                        {
                            sb.Append(string.Format("instance_of_this_method.{0}{1}(", i.Name, genericArguments));
                        }
                        param.AppendParameters(sb);
                        sb.AppendLine(");");
                    }
                }
                sb.AppendLine();

                //Ref/Out
                for (int j = param.Length; j > 0; j--)
                {
                    var p = param[j - 1];
                    if (!p.ParameterType.IsByRef && !hasByRef)
                    {
                        continue;
                    }
                    string clsName, realClsName;
                    bool   isByRef;
                    var    pt = p.ParameterType.IsByRef ? p.ParameterType.GetElementType() : p.ParameterType;
                    pt.GetClassName(out clsName, out realClsName, out isByRef);
                    sb.AppendLine(string.Format("            ptr_of_this_method = ILIntepreter.Minus(__esp, {0});", param.Length - j + 1));
                    if (p.ParameterType.IsByRef)
                    {
                        sb.AppendLine(@"            switch(ptr_of_this_method->ObjectType)
            {
                case ObjectTypes.StackObjectReference:
                    {
                        var ___dst = ILIntepreter.ResolveReference(ptr_of_this_method);");

                        if (pt.IsValueType && !pt.IsPrimitive && valueTypeBinders != null && valueTypeBinders.Contains(pt))
                        {
                            sb.AppendLine(string.Format("                if (ILRuntime.Runtime.Generated.CLRBindings.s_{0}_Binder != null) {{", clsName));

                            sb.AppendLine(string.Format("                        ILRuntime.Runtime.Generated.CLRBindings.s_{0}_Binder.WriteBackValue(__domain, ptr_of_this_method, __mStack, ref {1});", clsName, p.Name));

                            sb.AppendLine("                } else {");

                            pt.GetRefWriteBackValueCode(sb, p.Name);

                            sb.AppendLine("                }");
                        }
                        else
                        {
                            pt.GetRefWriteBackValueCode(sb, p.Name);
                        }

                        sb.Append(@"                    }
                    break;
                case ObjectTypes.FieldReference:
                    {
                        var ___obj = __mStack[ptr_of_this_method->Value];
                        if(___obj is ILTypeInstance)
                        {
                            ((ILTypeInstance)___obj)[ptr_of_this_method->ValueLow] = @");
                        sb.Append(p.Name);
                        sb.Append(@";
                        }
                        else
                        {
                            var ___type = __domain.GetType(___obj.GetType()) as CLRType;
                            ___type.SetFieldValue(ptr_of_this_method->ValueLow, ref ___obj, @");
                        sb.Append(p.Name);
                        sb.Append(@");
                        }
                    }
                    break;
                case ObjectTypes.StaticFieldReference:
                    {
                        var ___type = __domain.GetType(ptr_of_this_method->Value);
                        if(___type is ILType)
                        {
                            ((ILType)___type).StaticInstance[ptr_of_this_method->ValueLow] = @");
                        sb.Append(p.Name);
                        sb.Append(@";
                        }
                        else
                        {
                            ((CLRType)___type).SetStaticFieldValue(ptr_of_this_method->ValueLow, @");
                        sb.Append(p.Name);
                        sb.Append(@");
                        }
                    }
                    break;
                 case ObjectTypes.ArrayReference:
                    {
                        var instance_of_arrayReference = __mStack[ptr_of_this_method->Value] as ");
                        sb.Append(realClsName);
                        sb.Append(@"[];
                        instance_of_arrayReference[ptr_of_this_method->ValueLow] = @");
                        sb.Append(p.Name);
                        sb.AppendLine(@";
                    }
                    break;
            }");
                        sb.AppendLine();
                    }
                    else if (pt.IsValueType && !pt.IsPrimitive)
                    {
                        sb.AppendLine("            __intp.FreeStackValueType(ptr_of_this_method);");
                    }

                    sb.AppendLine("            __intp.Free(ptr_of_this_method);");
                }

                if (!i.IsStatic && ((type.IsValueType && !type.IsPrimitive) || hasByRef))//need to write back value type instance
                {
                    sb.AppendLine(string.Format("            ptr_of_this_method = ILIntepreter.Minus(__esp, {0});", paramCnt));
                    bool noWriteback = noUnbox;
                    if (type.IsValueType && !type.IsPrimitive && !noWriteback)
                    {
                        if (valueTypeBinders != null && valueTypeBinders.Contains(type))
                        {
                            string clsName, realClsName;
                            bool   isByRef;
                            type.GetClassName(out clsName, out realClsName, out isByRef);

                            sb.AppendLine(string.Format("            if (ILRuntime.Runtime.Generated.CLRBindings.s_{0}_Binder != null) {{", clsName));

                            sb.AppendLine(string.Format("                ILRuntime.Runtime.Generated.CLRBindings.s_{0}_Binder.WriteBackValue(__domain, ptr_of_this_method, __mStack, ref instance_of_this_method);", clsName));

                            sb.AppendLine("            } else {");

                            sb.AppendLine("                WriteBackInstance(__domain, ptr_of_this_method, __mStack, ref instance_of_this_method);");

                            sb.AppendLine("            }");
                        }
                        else
                        {
                            sb.AppendLine("            WriteBackInstance(__domain, ptr_of_this_method, __mStack, ref instance_of_this_method);");
                        }
                        sb.AppendLine();
                    }
                    sb.AppendLine("            __intp.Free(ptr_of_this_method);");
                }

                if (i.ReturnType != typeof(void))
                {
                    if (i.ReturnType.IsValueType && !i.ReturnType.IsPrimitive && valueTypeBinders != null && valueTypeBinders.Contains(i.ReturnType))
                    {
                        string clsName, realClsName;
                        bool   isByRef;
                        i.ReturnType.GetClassName(out clsName, out realClsName, out isByRef);

                        sb.AppendLine(string.Format("            if (ILRuntime.Runtime.Generated.CLRBindings.s_{0}_Binder != null) {{", clsName));

                        sb.AppendLine(string.Format("                ILRuntime.Runtime.Generated.CLRBindings.s_{0}_Binder.PushValue(ref result_of_this_method, __intp, __ret, __mStack);", clsName));
                        sb.AppendLine("                return __ret + 1;");

                        sb.AppendLine("            } else {");

                        i.ReturnType.GetReturnValueCode(sb, domain);

                        sb.AppendLine("            }");
                    }
                    else
                    {
                        i.ReturnType.GetReturnValueCode(sb, domain);
                    }
                }
                else
                {
                    sb.AppendLine("            return __ret;");
                }
                sb.AppendLine("        }");
                sb.AppendLine();
                idx++;
            }

            return(sb.ToString());
        }
示例#12
0
        internal static string GenerateFieldWraperCode(this Type type, FieldInfo[] fields, string typeClsName, HashSet <FieldInfo> excludes, List <Type> valueTypeBinders, Enviorment.AppDomain domain)
        {
            StringBuilder sb = new StringBuilder();

            int idx = 0;

            foreach (var i in fields)
            {
                if (excludes != null && excludes.Contains(i))
                {
                    continue;
                }
                if (type.ShouldSkipField(i))
                {
                    continue;
                }
                sb.AppendLine(string.Format("        static object get_{0}_{1}(ref object o)", i.Name, idx));
                sb.AppendLine("        {");
                if (i.IsStatic)
                {
                    sb.AppendLine(string.Format("            return {0}.{1};", typeClsName, i.Name));
                }
                else
                {
                    sb.AppendLine(string.Format("            return (({0})o).{1};", typeClsName, i.Name));
                }
                sb.AppendLine("        }");
                sb.AppendLine();
                sb.AppendLine(string.Format("        static StackObject* CopyToStack_{0}_{1}(ref object o, ILIntepreter __intp, StackObject* __ret, IList<object> __mStack)", i.Name, idx));
                sb.AppendLine("        {");
                if (i.IsStatic)
                {
                    sb.AppendLine(string.Format("            var result_of_this_method = {0}.{1};", typeClsName, i.Name));
                }
                else
                {
                    sb.AppendLine(string.Format("            var result_of_this_method = (({0})o).{1};", typeClsName, i.Name));
                }
                string clsName, realClsName;
                bool   isByRef;
                i.FieldType.GetClassName(out clsName, out realClsName, out isByRef);

                if (i.FieldType.IsValueType && !i.FieldType.IsPrimitive && valueTypeBinders != null && valueTypeBinders.Contains(i.FieldType))
                {
                    sb.AppendLine(string.Format("            if (ILRuntime.Runtime.Generated.CLRBindings.s_{0}_Binder != null) {{", clsName));

                    sb.AppendLine(string.Format("                ILRuntime.Runtime.Generated.CLRBindings.s_{0}_Binder.PushValue(ref result_of_this_method, __intp, __ret, __mStack);", clsName));
                    sb.AppendLine("                return __ret + 1;");

                    sb.AppendLine("            } else {");

                    i.FieldType.GetReturnValueCode(sb, domain);

                    sb.AppendLine("            }");
                }
                else
                {
                    i.FieldType.GetReturnValueCode(sb, domain);
                }
                sb.AppendLine("        }");
                sb.AppendLine();

                if (!i.IsInitOnly && !i.IsLiteral)
                {
                    sb.AppendLine(string.Format("        static void set_{0}_{1}(ref object o, object v)", i.Name, idx));
                    sb.AppendLine("        {");
                    if (i.IsStatic)
                    {
                        sb.AppendLine(string.Format("            {0}.{1} = ({2})v;", typeClsName, i.Name, realClsName));
                    }
                    else
                    {
                        if (type.IsValueType)
                        {
                            sb.AppendLine(string.Format("            {0} ins =({0})o;", typeClsName));
                            sb.AppendLine(string.Format("            ins.{0} = ({1})v;", i.Name, realClsName));
                            sb.AppendLine("            o = ins;");
                        }
                        else
                        {
                            sb.AppendLine(string.Format("            (({0})o).{1} = ({2})v;", typeClsName, i.Name, realClsName));
                        }
                    }
                    sb.AppendLine("        }");
                    sb.AppendLine();
                    sb.AppendLine(string.Format("        static StackObject* AssignFromStack_{0}_{1}(ref object o, ILIntepreter __intp, StackObject* ptr_of_this_method, IList<object> __mStack)", i.Name, idx));
                    sb.AppendLine("        {");
                    sb.AppendLine("            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;");
                    i.FieldType.AppendArgumentCode(sb, 0, i.Name, valueTypeBinders, false, false, false);
                    if (i.IsStatic)
                    {
                        sb.AppendLine(string.Format("            {0}.{1} = @{1};", typeClsName, i.Name));
                    }
                    else
                    {
                        if (type.IsValueType)
                        {
                            sb.AppendLine(string.Format("            {0} ins =({0})o;", typeClsName));
                            sb.AppendLine(string.Format("            ins.{0} = @{0};", i.Name));
                            sb.AppendLine("            o = ins;");
                        }
                        else
                        {
                            sb.AppendLine(string.Format("            (({0})o).{1} = @{1};", typeClsName, i.Name));
                        }
                    }
                    sb.AppendLine("            return ptr_of_this_method;");
                    sb.AppendLine("        }");
                    sb.AppendLine();
                }
                idx++;
            }

            return(sb.ToString());
        }
示例#13
0
文件: ILLog.cs 项目: kimch2/Unity-1
 public static void Log(ILIntepreter __intp, Enviorment.AppDomain __domain, UnityEngine.LogType level, string text)
 {
     UnityEngine.Debug.unityLogger.Log(level,
                                       string.Format("{0}\nStackTrance:{1}", text, __domain.DebugService.GetStackTrace(__intp)));
 }
示例#14
0
 protected DummyDelegateAdapter(Enviorment.AppDomain appdomain, ILTypeInstance instance, ILMethod method)
     : base(appdomain, instance, method)
 {
 }
示例#15
0
 public override IDelegateAdapter Instantiate(Enviorment.AppDomain appdomain, ILTypeInstance instance, ILMethod method)
 {
     return(new DummyDelegateAdapter(appdomain, instance, method));
 }
示例#16
0
 private MethodDelegateAdapter(Enviorment.AppDomain appdomain, ILTypeInstance instance, ILMethod method)
     : base(appdomain, instance, method)
 {
     action = InvokeILMethod;
 }
示例#17
0
 public override IDelegateAdapter Instantiate(Enviorment.AppDomain appdomain, ILTypeInstance instance, ILMethod method)
 {
     return(new FunctionDelegateAdapter <TResult>(appdomain, instance, method));
 }
示例#18
0
 public DelegateManager(Enviorment.AppDomain appdomain)
 {
     this.appdomain = appdomain;
 }
示例#19
0
 public override object CreateCLRInstance(Enviorment.AppDomain appdomain, ILTypeInstance instance)
 {
     return(new Adaptor(appdomain, instance));
 }
示例#20
0
        public string ToString(Enviorment.AppDomain domain)
        {
            string param = null;

            switch (Code)
            {
            case OpCodeREnum.Move:
            case OpCodeREnum.Ldind_I:
            case OpCodeREnum.Ldind_I1:
            case OpCodeREnum.Ldind_I2:
            case OpCodeREnum.Ldind_I4:
            case OpCodeREnum.Ldind_I8:
            case OpCodeREnum.Ldind_R4:
            case OpCodeREnum.Ldind_R8:
            case OpCodeREnum.Ldind_U1:
            case OpCodeREnum.Ldind_U2:
            case OpCodeREnum.Ldind_U4:
            case OpCodeREnum.Ldind_Ref:
            case OpCodeREnum.Ldobj:
            case OpCodeREnum.Stind_I:
            case OpCodeREnum.Stind_I1:
            case OpCodeREnum.Stind_I2:
            case OpCodeREnum.Stind_I4:
            case OpCodeREnum.Stind_I8:
            case OpCodeREnum.Stind_R4:
            case OpCodeREnum.Stind_R8:
            case OpCodeREnum.Stind_Ref:
            case OpCodeREnum.Stobj:
            case OpCodeREnum.Ldloca:
            case OpCodeREnum.Ldloca_S:
            case OpCodeREnum.Ldarga:
            case OpCodeREnum.Ldarga_S:
            case OpCodeREnum.Conv_I:
            case OpCodeREnum.Conv_I1:
            case OpCodeREnum.Conv_I2:
            case OpCodeREnum.Conv_I4:
            case OpCodeREnum.Conv_I8:
            case OpCodeREnum.Conv_Ovf_I:
            case OpCodeREnum.Conv_Ovf_I1:
            case OpCodeREnum.Conv_Ovf_I1_Un:
            case OpCodeREnum.Conv_Ovf_I2:
            case OpCodeREnum.Conv_Ovf_I2_Un:
            case OpCodeREnum.Conv_Ovf_I4:
            case OpCodeREnum.Conv_Ovf_I4_Un:
            case OpCodeREnum.Conv_Ovf_I8:
            case OpCodeREnum.Conv_Ovf_I8_Un:
            case OpCodeREnum.Conv_Ovf_I_Un:
            case OpCodeREnum.Conv_Ovf_U:
            case OpCodeREnum.Conv_Ovf_U1:
            case OpCodeREnum.Conv_Ovf_U1_Un:
            case OpCodeREnum.Conv_Ovf_U2:
            case OpCodeREnum.Conv_Ovf_U2_Un:
            case OpCodeREnum.Conv_Ovf_U4:
            case OpCodeREnum.Conv_Ovf_U4_Un:
            case OpCodeREnum.Conv_Ovf_U8:
            case OpCodeREnum.Conv_Ovf_U8_Un:
            case OpCodeREnum.Conv_Ovf_U_Un:
            case OpCodeREnum.Conv_R4:
            case OpCodeREnum.Conv_R8:
            case OpCodeREnum.Conv_R_Un:
            case OpCodeREnum.Conv_U:
            case OpCodeREnum.Conv_U1:
            case OpCodeREnum.Conv_U2:
            case OpCodeREnum.Conv_U4:
            case OpCodeREnum.Conv_U8:
            case OpCodeREnum.Not:
            case OpCodeREnum.Neg:
                param = string.Format("r{0}, r{1}", Register1, Register2);
                break;

            case OpCodeREnum.Box:
            case OpCodeREnum.Unbox:
            case OpCodeREnum.Unbox_Any:
            case OpCodeREnum.Isinst:
                if (domain == null)
                {
                    param = string.Format("r{0}, r{1}, {2}", Register1, Register2, Operand);
                }
                else
                {
                    var type = domain.GetType(Operand);
                    param = string.Format("r{0}, r{1}, {2}", Register1, Register2, type);
                }
                break;

            case OpCodeREnum.Stfld:
            case OpCodeREnum.Ldfld:
                param = string.Format("r{0}, r{1}, 0x{2:X8}", Register1, Register2, OperandLong);
                break;

            case OpCodeREnum.Stsfld:
            case OpCodeREnum.Ldsfld:
                param = string.Format("r{0}, 0x{1:X8}", Register1, OperandLong);
                break;

            case OpCodeREnum.Beqi:
            case OpCodeREnum.Bgei:
            case OpCodeREnum.Bgei_Un:
            case OpCodeREnum.Bgti:
            case OpCodeREnum.Bgti_Un:
            case OpCodeREnum.Bnei_Un:
            case OpCodeREnum.Blei:
            case OpCodeREnum.Blei_Un:
            case OpCodeREnum.Blti:
            case OpCodeREnum.Blti_Un:
                if (Operand != 0)
                {
                    param = string.Format("r{0},{1},{2}", Register1, Operand, Operand4);
                }
                else if (OperandLong != 0)
                {
                    param = string.Format("r{0},{1},{2}", Register1, OperandLong, Operand4);
                }
                else if (OperandFloat != 0)
                {
                    param = string.Format("r{0},{1},{2}", Register1, OperandFloat, Operand4);
                }
                else if (OperandDouble != 0)
                {
                    param = string.Format("r{0},{1},{2}", Register1, OperandDouble, Operand4);
                }
                else
                {
                    param = string.Format("r{0},0,{1}", Register1, Operand4);
                }
                break;

            case OpCodeREnum.Ceqi:
            case OpCodeREnum.Cgti:
            case OpCodeREnum.Cgti_Un:
            case OpCodeREnum.Clti:
            case OpCodeREnum.Clti_Un:
            case OpCodeREnum.Addi:
            case OpCodeREnum.Subi:
            case OpCodeREnum.Muli:
            case OpCodeREnum.Divi:
            case OpCodeREnum.Remi:
            case OpCodeREnum.Remi_Un:
            case OpCodeREnum.Andi:
            case OpCodeREnum.Ori:
            case OpCodeREnum.Xori:
            case OpCodeREnum.Shli:
            case OpCodeREnum.Shri:
            case OpCodeREnum.Shri_Un:
                if (Operand != 0)
                {
                    param = string.Format("r{0},r{1},{2}", Register1, Register2, Operand);
                }
                else if (OperandLong != 0)
                {
                    param = string.Format("r{0},r{1},{2}", Register1, Register2, OperandLong);
                }
                else if (OperandFloat != 0)
                {
                    param = string.Format("r{0},r{1},{2}", Register1, Register2, OperandFloat);
                }
                else if (OperandDouble != 0)
                {
                    param = string.Format("r{0},r{1},{2}", Register1, Register2, OperandDouble);
                }
                else
                {
                    param = string.Format("r{0},r{1},0", Register1, Register2);
                }
                break;

            case OpCodeREnum.Add:
            case OpCodeREnum.Add_Ovf:
            case OpCodeREnum.Add_Ovf_Un:
            case OpCodeREnum.Sub:
            case OpCodeREnum.Sub_Ovf:
            case OpCodeREnum.Sub_Ovf_Un:
            case OpCodeREnum.Mul:
            case OpCodeREnum.Mul_Ovf:
            case OpCodeREnum.Mul_Ovf_Un:
            case OpCodeREnum.Div:
            case OpCodeREnum.Div_Un:
            case OpCodeREnum.Rem:
            case OpCodeREnum.Rem_Un:
            case OpCodeREnum.Xor:
            case OpCodeREnum.And:
            case OpCodeREnum.Or:
            case OpCodeREnum.Shl:
            case OpCodeREnum.Shr:
            case OpCodeREnum.Shr_Un:
            case OpCodeREnum.Clt:
            case OpCodeREnum.Clt_Un:
            case OpCodeREnum.Cgt:
            case OpCodeREnum.Cgt_Un:
            case OpCodeREnum.Ceq:
            case OpCodeREnum.Stelem_I1:
            case OpCodeREnum.Stelem_I2:
            case OpCodeREnum.Stelem_I:
            case OpCodeREnum.Stelem_I4:
            case OpCodeREnum.Stelem_R4:
            case OpCodeREnum.Stelem_R8:
            case OpCodeREnum.Stelem_Any:
            case OpCodeREnum.Stelem_Ref:
            case OpCodeREnum.Ldelem_I1:
            case OpCodeREnum.Ldelem_I2:
            case OpCodeREnum.Ldelem_I:
            case OpCodeREnum.Ldelem_I4:
            case OpCodeREnum.Ldelem_R4:
            case OpCodeREnum.Ldelem_R8:
            case OpCodeREnum.Ldelem_Ref:
            case OpCodeREnum.Ldelem_Any:
            case OpCodeREnum.Ldelema:
                param = string.Format("r{0},r{1},r{2}", Register1, Register2, Register3);
                break;

            case OpCodeREnum.Ldc_I4_0:
            case OpCodeREnum.Ldc_I4_1:
            case OpCodeREnum.Ldc_I4_2:
            case OpCodeREnum.Ldc_I4_3:
            case OpCodeREnum.Ldc_I4_4:
            case OpCodeREnum.Ldc_I4_5:
            case OpCodeREnum.Ldc_I4_6:
            case OpCodeREnum.Ldc_I4_7:
            case OpCodeREnum.Ldc_I4_8:
            case OpCodeREnum.Ldc_I4_M1:
            case OpCodeREnum.Ldnull:
            case OpCodeREnum.Ret:
            case OpCodeREnum.Push:
                param = string.Format("r{0}", Register1);
                break;

            case OpCodeREnum.Brtrue:
            case OpCodeREnum.Brtrue_S:
            case OpCodeREnum.Brfalse:
            case OpCodeREnum.Brfalse_S:
            case OpCodeREnum.Switch:
                param = string.Format("r{0}, {1}", Register1, Operand);
                break;

            case OpCodeREnum.Ldftn:
                if (domain == null)
                {
                    param = string.Format("r{0}, {1}", Register1, Operand2);
                }
                else
                {
                    IMethod m = domain.GetMethod(Operand2);
                    if (m is CLR.Method.CLRMethod)
                    {
                        param = m != null?string.Format("r{0}, {1}::{2}", Register1, m.DeclearingType.FullName, m) : string.Format("r{0}, {1}", Register1, Operand2);
                    }
                    else
                    {
                        param = m != null?string.Format("r{0}, {1}", Register1, m) : string.Format("r{0}, {1}", Register1, Operand2);
                    }
                }
                break;

            case OpCodeREnum.Ldvirtftn:
                if (domain == null)
                {
                    param = string.Format("r{0}, r{1} {2}", Register1, Register2, Operand2);
                }
                else
                {
                    IMethod m = domain.GetMethod(Operand2);
                    if (m is CLR.Method.CLRMethod)
                    {
                        param = m != null?string.Format("r{0}, r{1}, {2}::{3}", Register1, Register2, m.DeclearingType.FullName, m) : string.Format("r{0}, r{1}, {2}", Register1, Register2, Operand2);
                    }
                    else
                    {
                        param = m != null?string.Format("r{0}, r{1}, {2}", Register1, Register2, m) : string.Format("r{0}, r{1}, {2}", Register1, Register2, Operand2);
                    }
                }
                break;

            case OpCodeREnum.Constrained:
            {
                if (domain == null)
                {
                    param = Operand.ToString();
                }
                else
                {
                    var m = domain.GetType(Operand);
                    param = m != null?m.ToString() : Operand.ToString();
                }
            }
            break;

            case OpCodeREnum.Call:
            case OpCodeREnum.Callvirt:
            case OpCodeREnum.Newobj:
            {
                string retR = Register1 >= 0 ? "r" + Register1 : "-";
                if (Register2 >= 0)
                {
                    retR += ", r" + Register2;
                }
                if (Register3 >= 0)
                {
                    retR += ", r" + Register3;
                }
                if (Register4 >= 0)
                {
                    retR += ", r" + Register4;
                }

                if (domain == null)
                {
                    param = string.Format("{0}, {1}", retR, Operand2);
                }
                else
                {
                    IMethod m = domain.GetMethod(Operand2);
                    if (m is CLR.Method.CLRMethod)
                    {
                        param = m != null?string.Format("{0}, {1}::{2}", retR, m.DeclearingType.FullName, m) : string.Format("{0}, {1}", retR, Operand2);
                    }
                    else
                    {
                        param = m != null?string.Format("{0}, {1}", retR, m) : string.Format("{0}, {1}", retR, Operand2);
                    }
                }
            }
            break;

            case OpCodeREnum.Blt:
            case OpCodeREnum.Blt_S:
            case OpCodeREnum.Blt_Un:
            case OpCodeREnum.Blt_Un_S:
            case OpCodeREnum.Ble:
            case OpCodeREnum.Ble_S:
            case OpCodeREnum.Ble_Un:
            case OpCodeREnum.Ble_Un_S:
            case OpCodeREnum.Bgt:
            case OpCodeREnum.Bgt_S:
            case OpCodeREnum.Bgt_Un:
            case OpCodeREnum.Bgt_Un_S:
            case OpCodeREnum.Bge:
            case OpCodeREnum.Bge_S:
            case OpCodeREnum.Bge_Un:
            case OpCodeREnum.Bge_Un_S:
            case OpCodeREnum.Beq:
            case OpCodeREnum.Beq_S:
            case OpCodeREnum.Bne_Un:
            case OpCodeREnum.Bne_Un_S:
                param = string.Format("r{0}, r{1}, {2}", Register1, Register2, Operand);
                break;

            case OpCodeREnum.Br:
            case OpCodeREnum.Br_S:
            case OpCodeREnum.Leave:
            case OpCodeREnum.Leave_S:
                param = string.Format("{0}", Operand);
                break;

            case OpCodeREnum.Ldc_I4:
            case OpCodeREnum.Ldc_I4_S:
                param = string.Format("r{0},{1}", Register1, Operand);
                break;

            case OpCodeREnum.Ldc_I8:
                param = string.Format("r{0},{1}", Register1, OperandLong);
                break;

            case OpCodeREnum.Ldc_R4:
                param = string.Format("r{0},{1}", Register1, OperandFloat);
                break;

            case OpCodeREnum.Ldc_R8:
                param = string.Format("r{0},{1}", Register1, OperandDouble);
                break;

            case OpCodeREnum.Ldstr:
                if (domain == null)
                {
                    param = string.Format("r{0},0x{1:X}", Register1, OperandLong);
                }
                else
                {
                    param = string.Format("r{0},\"{1}\"", Register1, domain.GetString(OperandLong));
                }
                break;

            case OpCodeREnum.Ldtoken:
                if (domain == null)
                {
                    param = string.Format("r{0},0x{1:X}", Register1, OperandLong);
                }
                else
                {
                    switch (Operand)
                    {
                    case 0:
                    {
                        var type     = domain.GetType((int)(OperandLong >> 32));
                        int fieldIdx = (int)OperandLong;
                        param = string.Format("r{0},{1}.{2}", Register1, type.FullName, (type is CLR.TypeSystem.ILType) ? ((CLR.TypeSystem.ILType)type).TypeDefinition.Fields[fieldIdx].Name : ((CLR.TypeSystem.CLRType)type).Fields[fieldIdx].Name);
                    }
                    break;

                    case 1:
                    {
                        var type = domain.GetType((int)OperandLong);
                        param = string.Format("r{0},\"{1}\"", Register1, type);
                    }
                    break;

                    default:
                        throw new NotImplementedException();
                    }
                }
                break;

            case OpCodeREnum.Initobj:
                if (domain == null)
                {
                    param = string.Format("r{0}, {1}", Register1, Operand);
                }
                else
                {
                    var type = domain.GetType(Operand);
                    param = string.Format("r{0}, {1}", Register1, type);
                }
                break;

            case OpCodeREnum.Newarr:
                if (domain == null)
                {
                    param = string.Format("r{0}, r{1}", Register1, Register2);
                }
                else
                {
                    var type = domain.GetType(Operand);
                    param = string.Format("r{0}, {2}, r{1}", Register1, Register2, type);
                }
                break;
            }
            return(string.Format("{0} {1}", Code.ToString().ToLower().Replace('_', '.'), param));
        }
示例#21
0
 public virtual void RegisterCLRRedirection(Enviorment.AppDomain appdomain)
 {
 }
示例#22
0
 public DelegateManager(Enviorment.AppDomain appdomain)
 {
     this.appdomain   = appdomain;
     defaultConverter = DefaultConverterStub;
 }
示例#23
0
 public abstract object CreateCLRInstance(Enviorment.AppDomain appdomain, ILTypeInstance instance);
示例#24
0
 public abstract IDelegateAdapter Instantiate(Enviorment.AppDomain appdomain, ILTypeInstance instance, ILMethod method);