예제 #1
0
파일: NEWOBJ.cs 프로젝트: NielsDev/IL2VM
        public override void Process(Compiler compiler, MethodData methodData, Instruction instruction)
        {
            // Get .ctor method from operand and get the class associated with it
            MethodReference ctor = instruction.Operand as MethodReference;
            TypeReference type = ctor.DeclaringType;

            // If the object type is native, we ignore the IL object and don't emit a NEWOBJ
            // After that, we call the .CTOR which will be in runtime
            // The .CTOR in runtime will also initialize this object
            if(Util.IsNativeType(type))
            {
                // Create call to .CTOR
                Instruction call = Instruction.Create(OpCodes.Call, ctor);
                compiler.HandleInstruction(call, methodData);
                return;
            }

            // Write opcode and class ID
            int classID = compiler.GetTypeDataFromType(type.Resolve()).Id;
            methodData.AddInstruction(instruction.OpCode.Value);
            methodData.AddInstruction(classID);

            // Write CALL to .ctor
            // Count one extra parameter for the "this" object
            MethodDefinition methodDef = ctor.Resolve();
            int ctorID = compiler.GetMethodID(methodDef);
            if (ctorID == -1)
                ctorID = compiler.ProcessMethod(methodDef);

            methodData.AddInstruction(ctorID);
            methodData.AddInstruction(ctor.Parameters.Count);
        }
예제 #2
0
파일: LDSTFLD.cs 프로젝트: NielsDev/IL2VM
        public override void Process(Compiler compiler, MethodData methodData, Instruction instruction)
        {
            // Get field and class data
            FieldDefinition field = instruction.Operand as FieldDefinition;
            TypeData classData = compiler.GetTypeDataFromType(field.DeclaringType);

            // Output opcode followed by field ID
            methodData.AddInstruction(instruction.OpCode.Value);
            methodData.AddInstruction(classData.GetMemberFieldId(field));
        }
예제 #3
0
파일: InitOBJ.cs 프로젝트: NielsDev/IL2VM
        public override void Process(Compiler compiler, MethodData methodData, Instruction instruction)
        {
            // Get type ID
            TypeReference type = instruction.Operand as TypeReference;
            int id = compiler.GetTypeDataFromType(type.Resolve()).Id;

            // Write opcode and type ID
            methodData.AddInstruction(instruction.OpCode.Value);
            methodData.AddInstruction(id);
        }
예제 #4
0
파일: LDSFLD.cs 프로젝트: NielsDev/IL2VM
        public override void Process(Compiler compiler, MethodData methodData, Instruction instruction)
        {
            // Get field and class data
            FieldDefinition field = (instruction.Operand as FieldReference).Resolve();
            TypeData classData = compiler.GetTypeDataFromType(field.DeclaringType);

            // Output opcode followed by class ID followed by field ID
            methodData.AddInstruction(instruction.OpCode.Value);
            methodData.AddInstruction(classData.Id);
            methodData.AddInstruction(classData.GetStaticFieldId(field));
        }