Пример #1
0
 public static object ToObject(StackObject *esp, ILEnvironment env, FastList <object> mObjects)
 {
     switch (esp->ObjectType)
     {
     case StackObjectType.Object:
         return(mObjects[esp->Int32]);
     }
     throw new NotSupportedException();
 }
Пример #2
0
        private static void Test()
        {
            var env = new ILEnvironment();

            env.LoadAssemblyFromFile(Constant.TestCaseDll);
            var type   = env.GetType("TestCase.Test01");
            var method = type.GetDeclaredMethod("Run3", null, new ILType[] { env.Int }, env.Int);

            Console.WriteLine(method.Invoke(null, 10));
            //Console.WriteLine(typeof(object).GetConstructors()[0].Invoke(null));
        }
Пример #3
0
 public RuntimeArrayType(ILType elementType, ArrayType reference, ILEnvironment env) : base(elementType, reference, env)
 {
     rank = reference.Rank;
     if (rank == 1)
     {
         typeForCLR = elementType.TypeForCLR.MakeArrayType();
     }
     else
     {
         typeForCLR = elementType.TypeForCLR.MakeArrayType(rank);
     }
 }
Пример #4
0
 internal static RuntimeType Create(TypeDefinition definition, ILEnvironment env)
 {
     if (definition.IsGenericParameter)
     {
         return(new RuntimeGenericParameterType(definition, env));
     }
     if (definition.HasGenericParameters)
     {
         return(new RuntimeGenericDefinitionType(definition, env));
     }
     return(new RuntimeDirectType(definition, env));
 }
Пример #5
0
        internal static CLRType Create(Type type, ILEnvironment env)
        {
            if (type.IsPointer)
            {
                var elementType = env.GetType(type.GetElementType());
                return(new CLRPointerType(elementType, type, env));
            }

            if (type.IsByRef)
            {
                var elementType = env.GetType(type.GetElementType());
                return(new CLRByRefType(elementType, type, env));
            }

            if (type.IsArray)
            {
                var elementType = env.GetType(type.GetElementType());
                return(new CLRArrayType(elementType, type, env));
            }

            if (type.IsGenericParameter)
            {
                if (type.DeclaringType != null)
                {
                    return(new CLRTypeGenericParameterType(type, env));
                }
            }

            if (type.IsGenericType)
            {
                if (type.IsGenericTypeDefinition)
                {
                    return(new CLRGenericDefinitionType(type, env));
                }

                var clrGenericArguments = type.GetGenericArguments();
                var genericArguments    = new FastList <ILType>(clrGenericArguments.Length);
                foreach (var generic in clrGenericArguments)
                {
                    genericArguments.Add(env.GetType(generic));
                }
                var genericTypeDefinition = env.GetType(type.GetGenericTypeDefinition());
                return(new CLRGenericSpecificationType(genericTypeDefinition, genericArguments, type, env));
            }

            return(new CLRDirectType(type, env));
        }
 public CLRGenericDefinitionType(Type type, ILEnvironment env) : base(type, env)
 {
 }
Пример #7
0
 public static void Before()
 {
     env = new ILEnvironment();
 }
Пример #8
0
 public static void After()
 {
     env = null;
 }
Пример #9
0
 public CLRDirectType(Type type, ILEnvironment env) : base(type, env)
 {
 }
 public CLRGenericSpecificationType(ILType genericTypeDefinition, FastList <ILType> genericArguments, Type type, ILEnvironment env) : base(type, env)
 {
     this.genericTypeDefinition = genericTypeDefinition;
     this.genericArguments      = genericArguments;
 }
Пример #11
0
 public CLRPointerType(ILType elementType, Type type, ILEnvironment env) : base(type, env)
 {
     this.elementType = elementType;
 }
Пример #12
0
 public RuntimeByRefType(ILType elementType, ByReferenceType reference, ILEnvironment env) : base(elementType, reference, env)
 {
     typeForCLR = elementType.TypeForCLR.MakeByRefType();
 }
Пример #13
0
 public RuntimeInterpreter(ILEnvironment environment)
 {
     this.environment = environment;
     stack            = new RuntimeStack();
     clrArguments.Add(0, null);
 }
 public RuntimeGenericDefinitionType(TypeDefinition definition, ILEnvironment env) : base(definition, env)
 {
 }
Пример #15
0
 public static void Before()
 {
     env = new ILEnvironment();
     env.LoadAssembly(new MemoryStream(bs));
 }
Пример #16
0
 internal CLRType(Type type, ILEnvironment env) : base(env)
 {
     typeForCLR   = type;
     assemblyName = new AssemblyName(type.Assembly.GetName());
 }
Пример #17
0
 internal ILType(ILEnvironment env)
 {
     Id          = IdConstant.NextTypeId();
     Environment = env;
 }
Пример #18
0
        public static Instruction Create(Code code, object operand, ILEnvironment env, Dictionary <Mono.Cecil.Cil.Instruction, int> address)
        {
            var instruction = new Instruction
            {
                Code = code,
            };

            switch (code)
            {
                #region jump
            case Code.Leave:
            case Code.Leave_S:
            case Code.Br:
            case Code.Br_S:
            case Code.Brtrue:
            case Code.Brtrue_S:
            case Code.Brfalse:
            case Code.Brfalse_S:
            case Code.Beq:
            case Code.Beq_S:
            case Code.Bne_Un:
            case Code.Bne_Un_S:
            case Code.Bge:
            case Code.Bge_S:
            case Code.Bge_Un:
            case Code.Bge_Un_S:
            case Code.Bgt:
            case Code.Bgt_S:
            case Code.Bgt_Un:
            case Code.Bgt_Un_S:
            case Code.Ble:
            case Code.Ble_S:
            case Code.Ble_Un:
            case Code.Ble_Un_S:
            case Code.Blt:
            case Code.Blt_S:
            case Code.Blt_Un:
            case Code.Blt_Un_S:
                instruction.Int32 = address[(Mono.Cecil.Cil.Instruction)operand];
                break;
                #endregion

                #region ldc
            case Code.Ldc_I4:
                instruction.Int32 = (int)operand;
                break;

            case Code.Ldc_I4_S:
                instruction.Int32 = (sbyte)operand;
                break;

            case Code.Ldc_I8:
                instruction.Int64 = (long)operand;
                break;

            case Code.Ldstr:
                StringPool.Put((string)operand, out instruction.High32, out instruction.Low32);
                break;
                #endregion

                #region call
            case Code.Newobj:
            case Code.Call:
                var methodReference = (MethodReference)operand;
                var type            = env.GetType(methodReference.DeclaringType);
                var method          = type.GetDeclaredMethod(methodReference);
                instruction.High32 = type.GetHashCode();
                instruction.Low32  = method.GetHashCode();
                break;
                #endregion
            }
            return(instruction);
        }
Пример #19
0
 protected RuntimeDefinitonType(TypeDefinition definition, ILEnvironment env) : base(definition, env)
 {
     this.definition = definition;
 }
Пример #20
0
 internal RuntimeType(TypeReference reference, ILEnvironment env) : base(env)
 {
     this.reference = reference;
     assemblyName   = new AssemblyName(reference.Module.Assembly.FullName);
 }
Пример #21
0
 public CLRArrayType(ILType elementType, Type type, ILEnvironment env) : base(type, env)
 {
     this.elementType = elementType;
     rank = type.GetArrayRank();
 }
 public CLRTypeGenericParameterType(Type type, ILEnvironment env) : base(type, env)
 {
 }
Пример #23
0
 public RuntimePointerType(ILType elementType, PointerType reference, ILEnvironment env) : base(elementType, reference, env)
 {
     typeForCLR = elementType.TypeForCLR.MakePointerType();
 }
 protected RuntimeSpecificationType(ILType elementType, TypeReference reference, ILEnvironment env) : base(reference, env)
 {
     this.elementType = elementType;
 }
Пример #25
0
 public RuntimeDirectType(TypeDefinition definition, ILEnvironment env) : base(definition, env)
 {
 }