Ejemplo n.º 1
0
        public MADOperation(VirtualRegister target, GenericOperand mleft, GenericOperand mright, GenericOperand ad) :
            base(IROpCodes.MAD, target)
        {
            if (mleft == null)
            {
                throw new ArgumentNullException("mleft");
            }
            else
            {
                MulLeftOperand = mleft;
            }

            if (mright == null)
            {
                throw new ArgumentNullException("mright");
            }
            else
            {
                MulRightOperand = mright;
            }

            if (ad == null)
            {
                throw new ArgumentNullException("addop");
            }
            else
            {
                AddOperand = ad;
            }

            Util.CheckArgumentType(Util.NumericTypes, target.DataType, "target");
            Util.CheckArgumentType(target.DataType, mleft.DataType, "mleft");
            Util.CheckArgumentType(target.DataType, mright.DataType, "mright");
            Util.CheckArgumentType(target.DataType, ad.DataType, "ad");
        }
Ejemplo n.º 2
0
        public UnaryOperation(IROpCodes opcode, VirtualRegister target, GenericOperand operand) :
            base(opcode, target)
        {
            if (operand == null)
            {
                throw new ArgumentNullException("operand");
            }
            else
            {
                Operand = operand;
            }

            switch (opcode)
            {
            case IROpCodes.NEG:
            case IROpCodes.ABS:
                Util.CheckArgumentType(Util.SIntTypes.Concat(Util.RealTypes), target.DataType, "target");
                goto case IROpCodes.MOV;

            case IROpCodes.NOT:
                Util.CheckArgumentType(Util.IntegralTypes, target.DataType, "target");
                goto case IROpCodes.MOV;

            case IROpCodes.SQRT:
            case IROpCodes.RSQRT:
                Util.CheckArgumentType(Util.RealTypes, target.DataType, "target");
                goto case IROpCodes.MOV;

            case IROpCodes.SIN:
            case IROpCodes.COS:
            case IROpCodes.LG2:
            case IROpCodes.EX2:
                Util.CheckArgumentType(typeof(float), target.DataType, "target");
                goto case IROpCodes.MOV;

            case IROpCodes.MOV:
                Util.CheckArgumentType(target.DataType, operand.DataType, "operand");
                break;

            case IROpCodes.CVT:
                if (!(Util.NumericTypes.Contains(operand.DataType) && Util.NumericTypes.Contains(target.DataType)) ||
                    target.DataType == operand.DataType)
                {
                    throw new InvalidCastException(string.Format("There is no conversion from {0} to {1}",
                                                                 operand.DataType.Format(), target.DataType.Format()));
                }
                break;

            default:
                throw new InvalidOperationException();
            }
        }
Ejemplo n.º 3
0
		public BinaryOperation(IROpCodes opcode, VirtualRegister target, GenericOperand left, GenericOperand right) :
			base(opcode, target)
		{
			if (left == null)
				throw new ArgumentNullException("left");
			else
				LeftOperand = left;

			if (right == null)
				throw new ArgumentNullException("right");
			else
				RightOperand = right;
			
			switch (opcode)
			{
			case IROpCodes.ADD:
			case IROpCodes.SUB:
			case IROpCodes.MUL:
			case IROpCodes.DIV:
			case IROpCodes.MIN:
			case IROpCodes.MAX:
				Util.CheckArgumentType(Util.NumericTypes, target.DataType, "target");
				Util.CheckArgumentType(target.DataType, left.DataType, "left");
				Util.CheckArgumentType(target.DataType, right.DataType, "right");
				break;
			case IROpCodes.REM:
				Util.CheckArgumentType(Util.IntegralTypes, target.DataType, "target");
				Util.CheckArgumentType(target.DataType, left.DataType, "left");
				Util.CheckArgumentType(target.DataType, right.DataType, "right");
				break;
			case IROpCodes.AND:
			case IROpCodes.OR:
			case IROpCodes.XOR:
				Util.CheckArgumentType(Util.IntegralTypes, target.DataType, "target");
				Util.CheckArgumentType(target.DataType, left.DataType, "left");
				Util.CheckArgumentType(target.DataType, right.DataType, "right");
				break;
			case IROpCodes.EQ:
			case IROpCodes.NE:
			case IROpCodes.GE:
			case IROpCodes.GT:
			case IROpCodes.LE:
			case IROpCodes.LT:
				Util.CheckArgumentType(typeof(int), target.DataType, "target");
				Util.CheckArgumentType(Util.NumericTypes, left.DataType, "left");
				Util.CheckArgumentType(left.DataType, right.DataType, "right");
				break;
			default:
				throw new InvalidOperationException();
			}
		}
Ejemplo n.º 4
0
        public BinaryOperation(IROpCodes opcode, VirtualRegister target, GenericOperand left, GenericOperand right) :
            base(opcode, target)
        {
            if (left == null)
            {
                throw new ArgumentNullException("left");
            }
            else
            {
                LeftOperand = left;
            }

            if (right == null)
            {
                throw new ArgumentNullException("right");
            }
            else
            {
                RightOperand = right;
            }

            switch (opcode)
            {
            case IROpCodes.ADD:
            case IROpCodes.SUB:
            case IROpCodes.MUL:
            case IROpCodes.DIV:
            case IROpCodes.MIN:
            case IROpCodes.MAX:
                Util.CheckArgumentType(Util.NumericTypes, target.DataType, "target");
                Util.CheckArgumentType(target.DataType, left.DataType, "left");
                Util.CheckArgumentType(target.DataType, right.DataType, "right");
                break;

            case IROpCodes.REM:
                Util.CheckArgumentType(Util.IntegralTypes, target.DataType, "target");
                Util.CheckArgumentType(target.DataType, left.DataType, "left");
                Util.CheckArgumentType(target.DataType, right.DataType, "right");
                break;

            case IROpCodes.AND:
            case IROpCodes.OR:
            case IROpCodes.XOR:
                Util.CheckArgumentType(Util.IntegralTypes, target.DataType, "target");
                Util.CheckArgumentType(target.DataType, left.DataType, "left");
                Util.CheckArgumentType(target.DataType, right.DataType, "right");
                break;

            case IROpCodes.EQ:
            case IROpCodes.NE:
            case IROpCodes.GE:
            case IROpCodes.GT:
            case IROpCodes.LE:
            case IROpCodes.LT:
                Util.CheckArgumentType(typeof(int), target.DataType, "target");
                Util.CheckArgumentType(Util.NumericTypes, left.DataType, "left");
                Util.CheckArgumentType(left.DataType, right.DataType, "right");
                break;

            default:
                throw new InvalidOperationException();
            }
        }
Ejemplo n.º 5
0
 public static GenericOperand MapOperand(this GenericOperand operand,
                                         Dictionary <VirtualRegister, VirtualRegister> regmap)
 {
     return((operand is VirtualRegister) ?
            (operand as VirtualRegister).MapOperand(regmap) : operand);
 }
Ejemplo n.º 6
0
		public MADOperation(VirtualRegister target, GenericOperand mleft, GenericOperand mright, GenericOperand ad) :
			base(IROpCodes.MAD, target)
		{
			if (mleft == null)
				throw new ArgumentNullException("mleft");
			else
				MulLeftOperand = mleft;

			if (mright == null)
				throw new ArgumentNullException("mright");
			else
				MulRightOperand = mright;
			
			if (ad == null)
				throw new ArgumentNullException("addop");
			else
				AddOperand = ad;
			
			Util.CheckArgumentType(Util.NumericTypes, target.DataType, "target");
			Util.CheckArgumentType(target.DataType, mleft.DataType, "mleft");
			Util.CheckArgumentType(target.DataType, mright.DataType, "mright");
			Util.CheckArgumentType(target.DataType, ad.DataType, "ad");
		}
Ejemplo n.º 7
0
		private VirtualRegister CalculateAddress(VirtualRegister array, GenericOperand index)
		{
			VirtualRegister address = AllocateRegister(array.UnderlyingType, array.StateSpace);
			index = ConvertOperand(index, array.DataType);
			int elemsize = array.UnderlyingType.SizeOf();
			code.Add(elemsize == 1 ?
				new BinaryOperation(IROpCodes.ADD, address, index, array) as BasicBlockInstruction :
				new MADOperation(address, index, new ImmediateValue(
					(ValueType)Convert.ChangeType(elemsize, array.DataType)), array) as BasicBlockInstruction);
			ReleaseOperand(array);
			ReleaseOperand(index);
			return address;
		}
Ejemplo n.º 8
0
		public UnaryOperation(IROpCodes opcode, VirtualRegister target, GenericOperand operand) :
			base(opcode, target)
		{
			if (operand == null)
				throw new ArgumentNullException("operand");
			else
				Operand = operand;
			
			switch (opcode)
			{
			case IROpCodes.NEG:
			case IROpCodes.ABS:
				Util.CheckArgumentType(Util.SIntTypes.Concat(Util.RealTypes), target.DataType, "target");
				goto case IROpCodes.MOV;
			case IROpCodes.NOT:
				Util.CheckArgumentType(Util.IntegralTypes, target.DataType, "target");
				goto case IROpCodes.MOV;
			case IROpCodes.SQRT:
			case IROpCodes.RSQRT:
				Util.CheckArgumentType(Util.RealTypes, target.DataType, "target");
				goto case IROpCodes.MOV;
			case IROpCodes.SIN:
			case IROpCodes.COS:
			case IROpCodes.LG2:
			case IROpCodes.EX2:
				Util.CheckArgumentType(typeof(float), target.DataType, "target");
				goto case IROpCodes.MOV;
			case IROpCodes.MOV:
				Util.CheckArgumentType(target.DataType, operand.DataType, "operand");
				break;
			case IROpCodes.CVT:
				if (!(Util.NumericTypes.Contains(operand.DataType) && Util.NumericTypes.Contains(target.DataType)) ||
					target.DataType == operand.DataType)
					throw new InvalidCastException(string.Format("There is no conversion from {0} to {1}",
						operand.DataType.Format(), target.DataType.Format()));
				break;
			default:
				throw new InvalidOperationException();
			}
		}
Ejemplo n.º 9
0
		private GenericOperand ConvertOperand(GenericOperand operand, Type type)
		{
			if (operand.DataType != UpconvertMapping[type])
			{
				VirtualRegister target = AllocateRegister(UpconvertMapping[type]);
				code.Add(new UnaryOperation(IROpCodes.CVT, target, operand));
				ReleaseOperand(operand);
				return target;
			}
			return operand;
		}
Ejemplo n.º 10
0
		private VirtualRegister MapToRegister(GenericOperand operand)
		{
			if (operand is VirtualRegister)
				return operand as VirtualRegister;
			else
			{
				VirtualRegister reg = AllocateRegister(operand.DataType);
				code.Add(new UnaryOperation(IROpCodes.MOV, reg, operand));
				return reg;
			}
		}
Ejemplo n.º 11
0
		private void PushByRef(GenericOperand operand)
		{
			stack.Push(new Tuple<Tuple<GenericOperand, bool>, InstructionSelector>(
				new Tuple<GenericOperand, bool>(operand, true), this));
		}
Ejemplo n.º 12
0
		public void AddInitialization(GenericOperand actual, VirtualRegister formal)
		{
			code.Add(new UnaryOperation(IROpCodes.MOV, formal, actual));
			ReleaseOperand(actual);
		}
Ejemplo n.º 13
0
		private void ReleaseOperand(GenericOperand operand)
		{
			if (operand is DynamicRegister)
				(operand as DynamicRegister).Live = false;
		}