Beispiel #1
0
        public static void ByReference__ctor(Context context, MethodCompiler methodCompiler)
        {
            var instance   = methodCompiler.Parameters[0];
            var value      = methodCompiler.Parameters[1];
            var opInstance = methodCompiler.AllocateVirtualRegisterOrStackSlot(instance.Type);
            var opValue    = methodCompiler.AllocateVirtualRegisterOrStackSlot(value.Type);

            // Load instance parameter
            var loadInstance = BaseMethodCompilerStage.GetLoadParameterInstruction(instance.Type, methodCompiler.Is32BitPlatform);

            context.AppendInstruction(loadInstance, opInstance, instance);

            // Load value parameter
            var loadValue = BaseMethodCompilerStage.GetLoadParameterInstruction(value.Type, methodCompiler.Is32BitPlatform);

            context.AppendInstruction(loadValue, opValue, value);

            // Store value inside instance
            var store = methodCompiler.Is32BitPlatform ? (BaseInstruction)IRInstruction.Store32 : IRInstruction.Store64;

            context.AppendInstruction(store, null, opInstance, methodCompiler.ConstantZero, opValue);
            context.MosaType = methodCompiler.TypeSystem.BuiltIn.I;

            context.AppendInstruction(IRInstruction.Jmp, methodCompiler.BasicBlocks.EpilogueBlock);
        }
Beispiel #2
0
        public static void Unsafe_AddByteOffset(Context context, MethodCompiler methodCompiler)
        {
            var source       = methodCompiler.Parameters[0];
            var byteOffset   = methodCompiler.Parameters[1];
            var opSource     = methodCompiler.AllocateVirtualRegisterOrStackSlot(source.Type);
            var opByteOffset = methodCompiler.AllocateVirtualRegisterOrStackSlot(byteOffset.Type);
            var opReturn     = methodCompiler.AllocateVirtualRegisterOrStackSlot(methodCompiler.Method.Signature.ReturnType);

            // Load left parameter
            var loadSource = BaseMethodCompilerStage.GetLoadParameterInstruction(source.Type, methodCompiler.Is32BitPlatform);

            context.AppendInstruction(loadSource, opSource, source);

            // Load right parameter
            var loadByteOffset = BaseMethodCompilerStage.GetLoadParameterInstruction(byteOffset.Type, methodCompiler.Is32BitPlatform);

            context.AppendInstruction(loadByteOffset, opByteOffset, byteOffset);

            // Compare and store into result operand
            var add = methodCompiler.Is32BitPlatform ? (BaseInstruction)IRInstruction.Add32 : IRInstruction.Add64;

            context.AppendInstruction(add, opReturn, opSource, opByteOffset);

            // Return comparison result
            var setReturn = BaseMethodCompilerStage.GetSetReturnInstruction(opReturn.Type, methodCompiler.Is32BitPlatform);

            context.AppendInstruction(setReturn, null, opReturn);

            context.AppendInstruction(IRInstruction.Jmp, methodCompiler.BasicBlocks.EpilogueBlock);
        }
Beispiel #3
0
        public static void Unsafe_AreSame(Context context, MethodCompiler methodCompiler)
        {
            var left     = methodCompiler.Parameters[0];
            var right    = methodCompiler.Parameters[1];
            var opLeft   = methodCompiler.AllocateVirtualRegisterOrStackSlot(left.Type);
            var opRight  = methodCompiler.AllocateVirtualRegisterOrStackSlot(right.Type);
            var opReturn = methodCompiler.AllocateVirtualRegisterOrStackSlot(methodCompiler.Method.Signature.ReturnType);

            // Load left parameter
            var loadLeft = BaseMethodCompilerStage.GetLoadParameterInstruction(left.Type, methodCompiler.Is32BitPlatform);

            context.AppendInstruction(loadLeft, opLeft, left);

            // Load right parameter
            var loadRight = BaseMethodCompilerStage.GetLoadParameterInstruction(right.Type, methodCompiler.Is32BitPlatform);

            context.AppendInstruction(loadRight, opRight, right);

            // Compare and store into result operand
            context.AppendInstruction(IRInstruction.CompareObject, ConditionCode.Equal, opReturn, opLeft, opRight);

            // Set return
            var setReturn = BaseMethodCompilerStage.GetSetReturnInstruction(opReturn.Type, methodCompiler.Is32BitPlatform);

            context.AppendInstruction(setReturn, null, opReturn);

            context.AppendInstruction(IRInstruction.Jmp, methodCompiler.BasicBlocks.EpilogueBlock);
        }
Beispiel #4
0
        public static void ByReference_get_Value(Context context, MethodCompiler methodCompiler)
        {
            var instance   = methodCompiler.Parameters[0];
            var opInstance = methodCompiler.AllocateVirtualRegisterOrStackSlot(instance.Type);
            var opReturn   = methodCompiler.AllocateVirtualRegisterOrStackSlot(methodCompiler.Method.Signature.ReturnType);

            // Load instance parameter
            var loadInstance = BaseMethodCompilerStage.GetLoadParameterInstruction(instance.Type, methodCompiler.Is32BitPlatform);

            context.AppendInstruction(loadInstance, opInstance, instance);

            // Load value from instance into return operand
            var loadValue = methodCompiler.Is32BitPlatform ? (BaseInstruction)IRInstruction.Load32 : IRInstruction.Load64;

            context.AppendInstruction(loadValue, opReturn, opInstance, methodCompiler.ConstantZero);
            context.MosaType = methodCompiler.TypeSystem.BuiltIn.I;

            // Set return
            var setReturn = BaseMethodCompilerStage.GetSetReturnInstruction(opReturn.Type, methodCompiler.Is32BitPlatform);

            context.AppendInstruction(setReturn, null, opReturn);

            context.AppendInstruction(IRInstruction.Jmp, methodCompiler.BasicBlocks.EpilogueBlock);
        }
Beispiel #5
0
        public static void Unsafe_As(Context context, MethodCompiler methodCompiler)
        {
            var source   = methodCompiler.Parameters[0];
            var opReturn = methodCompiler.AllocateVirtualRegisterOrStackSlot(methodCompiler.Method.Signature.ReturnType);

            // Load source into return operand
            var loadSource = BaseMethodCompilerStage.GetLoadParameterInstruction(source.Type, methodCompiler.Is32BitPlatform);

            context.AppendInstruction(loadSource, opReturn, source);

            // Set return
            var setReturn = BaseMethodCompilerStage.GetSetReturnInstruction(opReturn.Type, methodCompiler.Is32BitPlatform);

            context.AppendInstruction(setReturn, null, opReturn);

            context.AppendInstruction(IRInstruction.Jmp, methodCompiler.BasicBlocks.EpilogueBlock);
        }
Beispiel #6
0
        public static void Unsafe_SizeOf(Context context, MethodCompiler methodCompiler)
        {
            var type     = methodCompiler.Method.GenericArguments[0];
            var size     = methodCompiler.TypeLayout.GetTypeSize(type);
            var opReturn = methodCompiler.AllocateVirtualRegisterOrStackSlot(methodCompiler.Method.Signature.ReturnType);

            // Move constant into return operand
            var move = methodCompiler.Is32BitPlatform ? (BaseInstruction)IRInstruction.Move32 : IRInstruction.Move64;

            context.AppendInstruction(move, opReturn, methodCompiler.CreateConstant(size));

            // Set return
            var setReturn = BaseMethodCompilerStage.GetSetReturnInstruction(opReturn.Type, methodCompiler.Is32BitPlatform);

            context.AppendInstruction(setReturn, null, opReturn);

            context.AppendInstruction(IRInstruction.Jmp, methodCompiler.BasicBlocks.EpilogueBlock);
        }
Beispiel #7
0
        public static void RuntimeHelpers_IsReferenceOrContainsReferences(Context context, MethodCompiler methodCompiler)
        {
            var type     = methodCompiler.Method.GenericArguments[0];
            var opReturn = methodCompiler.AllocateVirtualRegisterOrStackSlot(methodCompiler.Method.Signature.ReturnType);

            // FIXME: we're only checking if the current type is a reference type, we aren't checking if it contains references
            var isReferenceOrContainsReferences = type.IsReferenceType;

            // Move constant into return operand
            var move = methodCompiler.Is32BitPlatform ? (BaseInstruction)IRInstruction.Move32 : IRInstruction.Move64;

            context.AppendInstruction(move, opReturn, methodCompiler.CreateConstant(isReferenceOrContainsReferences ? 1 : 0));

            // Set return
            var setReturn = BaseMethodCompilerStage.GetSetReturnInstruction(opReturn.Type, methodCompiler.Is32BitPlatform);

            context.AppendInstruction(setReturn, null, opReturn);

            context.AppendInstruction(IRInstruction.Jmp, methodCompiler.BasicBlocks.EpilogueBlock);
        }
 public static Operand AllocateVirtualRegisterOrStackSlot(MethodCompiler compiler, MosaType type)
 {
     return(compiler.AllocateVirtualRegisterOrStackSlot(type));
 }