public override void Transform(IRType type)
		{
			if (!type.IsAbstract && (type.IsGeneric || type.NestedInsideOfType != null || type.IsArrayType || type.IsManagedPointerType || type.IsUnmanagedPointerType))
			{
				if (type.VirtualMethodTree[3].ParentType != type)
				{
					// It doesn't already implement ToString() itself.
					IRMethod ts = new IRMethod(type.Assembly);
					ts.ParentType = type;
					ts.ReturnType = type.Assembly.AppDomain.System_String;
					ts.Parameters.Add(new IRParameter(type.Assembly) { ParentMethod = ts, Type = type });
					ts.VirtualMethodIndex = 3;
					var r = new IRReturnInstruction();
					r.ParentMethod = ts;
					r.Linearized = true;
					var loc = new IRLinearizedLocation(r, IRLinearizedLocationType.String);
					loc.String.Value = type.ToString();
					r.Sources.Add(loc);
					ts.Instructions.Add(r);

					ts.ParentTypeMethodIndex = type.Methods.Count;
					type.Methods.Add(ts);
					type.VirtualMethodTree[3] = ts;

					if (!ts.Resolved) // This adds it to the Domain's Methods list.
						throw new Exception();
				}
			}
		}
Exemplo n.º 2
0
        public IRCallExpression(IRType returnType, string targetName, params IRExpression[] arguments)
            : base(returnType)

        {
            TargetName = targetName;
            Arguments.AddRange(arguments);
        }
 public IRLoadRuntimeHandleInstruction(IRType pTargetType, IRMethod pTargetMethod, IRField pTargetField)
     : base(IROpcode.LoadRuntimeHandle)
 {
     TargetType = pTargetType;
     TargetMethod = pTargetMethod;
     TargetField = pTargetField;
 }
Exemplo n.º 4
0
        public override void Linearize(Stack <IRStackObject> pStack)
        {
            for (int count = 0; count < Target.Parameters.Count; ++count)
            {
                Sources.Add(new IRLinearizedLocation(pStack.Pop().LinearizedTarget));
            }

            if (Target.ReturnType != null)
            {
                IRStackObject returned = new IRStackObject();
                IRType        retType  = Target.ReturnType;

                if (retType.IsTemporaryVar)
                {
                    retType = Target.ParentType.GenericParameters[retType.TemporaryVarOrMVarIndex];
                }
                else if (retType.IsTemporaryMVar)
                {
                    retType = Target.GenericParameters[retType.TemporaryVarOrMVarIndex];
                }

                returned.Type             = retType;
                returned.LinearizedTarget = new IRLinearizedLocation(IRLinearizedLocationType.Local);
                returned.LinearizedTarget.Local.LocalIndex = AddLinearizedLocal(pStack, retType);
                Destination = new IRLinearizedLocation(returned.LinearizedTarget);
                pStack.Push(returned);
            }
        }
Exemplo n.º 5
0
 public IRExpression Cast(IRType type)
 {
     if (type == Type)
     {
         return(this);
     }
     return(new IRConversionExpression(type, this));
 }
Exemplo n.º 6
0
 public IRVariable(IRType type, string name)
     : base(type)
 {
     if (type == IRPrimitive.Void)
     {
         throw new IRTypeException();
     }
     Name = name;
 }
Exemplo n.º 7
0
		private static IRType ResolveSimpleReturn(IRType tp, IRMethod target)
		{
			if (tp.IsTemporaryVar)
				return target.ParentType.GenericParameters[tp.TemporaryVarOrMVarIndex];
			else if (tp.IsTemporaryMVar)
				return target.GenericParameters[tp.TemporaryVarOrMVarIndex];
			else if (tp.IsArrayType)
				return target.Assembly.AppDomain.GetArrayType(ResolveSimpleReturn(tp.ArrayElementType, target));
			else
				return tp;
		}
Exemplo n.º 8
0
 internal override void SemanticValidation(Semantic.SemanticContext semanticContext)
 {
     Expression.SemanticValidation(semanticContext);
     if (!(Expression.GetIRType() is NumericType))
     {
         throw new Semantic.SemanticValidationException("No se puede PreDecrement");
     }
     else
     {
         returnType = new IntType();
     }
 }
Exemplo n.º 9
0
 internal override void SemanticValidation(Semantic.SemanticContext semanticContext)
 {
     Expression.SemanticValidation(semanticContext);
     if (!(Expression.GetIRType() is BoolType))
     {
         throw new Semantic.SemanticValidationException("No se puede negar");
     }
     else
     {
         returnType = new BoolType(); //a exp tiene que poder negarse
     }
 }
Exemplo n.º 10
0
        public override void Linearize(Stack <IRStackObject> pStack)
        {
            Sources.Add(new IRLinearizedLocation(pStack.Pop().LinearizedTarget));

            IRType        arrayType = ParentMethod.Assembly.AppDomain.GetArrayType(Type);
            IRStackObject result    = new IRStackObject();

            result.Type             = arrayType;
            result.LinearizedTarget = new IRLinearizedLocation(IRLinearizedLocationType.Local);
            result.LinearizedTarget.Local.LocalIndex = AddLinearizedLocal(pStack, arrayType);
            Destination = new IRLinearizedLocation(result.LinearizedTarget);
            pStack.Push(result);
        }
Exemplo n.º 11
0
 private int GetTypeSizeInWords(IRType type)
 {
     if (type is IntType)
     {
         return(1);
     }
     else if (type is StructType)
     {
         var strucType = type as StructType;
         return(strucType.DeclarationStatement.OfType <IdDeclarationStatement>().Sum(dec => GetTypeSizeInWords(dec.Type)));
     }
     return(0);
 }
Exemplo n.º 12
0
 public IRStore(IRBasicBlock parentBlock, IRType type, IRExpression address, IRExpression operand)
     : base(parentBlock)
 {
     if (type == IRPrimitive.Void || type == IRPrimitive.Bool)
     {
         throw new IRTypeException();
     }
     Type    = type;
     Address = address;
     Operand = operand;
     Uses.UnionWith(Address.GetAllVariables());
     Uses.UnionWith(Operand.GetAllVariables());
 }
        public override void Linearize(Stack<IRStackObject> pStack)
        {
            Sources.Add(new IRLinearizedLocation(pStack.Pop().LinearizedTarget));

            Destination = new IRLinearizedLocation(IRLinearizedLocationType.ArrayElement);
            Destination.ArrayElement.IndexLocation = new IRLinearizedLocation(pStack.Pop().LinearizedTarget);
            var arraySource = pStack.Pop();
            Destination.ArrayElement.ArrayLocation = new IRLinearizedLocation(arraySource.LinearizedTarget);
            if (Type == null)
            {
                Type = arraySource.Type.ArrayType;
            }
            Destination.ArrayElement.ElementType = Type;
        }
Exemplo n.º 14
0
        internal override void SemanticValidation(Semantic.SemanticContext semanticContext)
        {
            Left.SemanticValidation(semanticContext);
            Right.SemanticValidation(semanticContext);

            if (!(Left.GetIRType() is NumericType && Right.GetIRType() is NumericType))
            {
                throw new Semantic.SemanticValidationException("No se puede asignar");
            }
            else
            {
                returnType = Left.GetIRType(); //evaluar cual tipo de podría asignar dependiendo de su tamanio
            }
        }
Exemplo n.º 15
0
        internal override void SemanticValidation(Semantic.SemanticContext semanticContext)
        {
            Left.SemanticValidation(semanticContext);
            Right.SemanticValidation(semanticContext);

            if (!(Left.GetIRType() is NumericType && Right.GetIRType() is NumericType))
            {
                throw new Semantic.SemanticValidationException("No se puede operar");
            }
            else
            {
                returnType = Left.GetIRType();
            }
        }
Exemplo n.º 16
0
        public override void Linearize(Stack <IRStackObject> pStack)
        {
            Sources.Add(new IRLinearizedLocation(pStack.Pop().LinearizedTarget));

            Destination = new IRLinearizedLocation(IRLinearizedLocationType.ArrayElement);
            Destination.ArrayElement.IndexLocation = new IRLinearizedLocation(pStack.Pop().LinearizedTarget);
            var arraySource = pStack.Pop();

            Destination.ArrayElement.ArrayLocation = new IRLinearizedLocation(arraySource.LinearizedTarget);
            if (Type == null)
            {
                Type = arraySource.Type.ArrayType;
            }
            Destination.ArrayElement.ElementType = Type;
        }
		public override void Linearize(Stack<IRStackObject> pStack)
		{
			Sources.Add(new IRLinearizedLocation(this, pStack.Pop().LinearizedTarget));

			Destination = new IRLinearizedLocation(this, IRLinearizedLocationType.Indirect);
			var addressLocation = pStack.Pop();
			Destination.Indirect.AddressLocation = new IRLinearizedLocation(this, addressLocation.LinearizedTarget);
			if (Type == null)
			{
				if (addressLocation.Type.IsManagedPointerType)
					Type = addressLocation.Type.ManagedPointerType;
				else
					Type = addressLocation.Type.UnmanagedPointerType;
			}
			if (Type == null) throw new Exception();
			Destination.Indirect.Type = Type;
		}
Exemplo n.º 18
0
        public override void Linearize(Stack <IRStackObject> pStack)
        {
            IRStackObject value2 = pStack.Pop();
            IRStackObject value1 = pStack.Pop();

            Sources.Add(new IRLinearizedLocation(value1.LinearizedTarget));
            Sources.Add(new IRLinearizedLocation(value2.LinearizedTarget));

            IRType        resultType = ParentMethod.Assembly.AppDomain.BinaryNumericResult(value1.Type, value2.Type);
            IRStackObject result     = new IRStackObject();

            result.Type             = resultType;
            result.LinearizedTarget = new IRLinearizedLocation(IRLinearizedLocationType.Local);
            result.LinearizedTarget.Local.LocalIndex = AddLinearizedLocal(pStack, resultType);
            Destination = new IRLinearizedLocation(result.LinearizedTarget);
            pStack.Push(result);
        }
        public override void Linearize(Stack<IRStackObject> pStack)
        {
            IRLinearizedLocation source = new IRLinearizedLocation(IRLinearizedLocationType.ArrayElement);
            source.ArrayElement.IndexLocation = new IRLinearizedLocation(pStack.Pop().LinearizedTarget);
            var arraySource = pStack.Pop();
            source.ArrayElement.ArrayLocation = new IRLinearizedLocation(arraySource.LinearizedTarget);
            if (Type == null)
            {
                Type = arraySource.Type.ArrayType;
            }
            source.ArrayElement.ElementType = Type;
            Sources.Add(source);

            IRStackObject result = new IRStackObject();
            result.Type = Type;
            result.LinearizedTarget = new IRLinearizedLocation(IRLinearizedLocationType.Local);
            result.LinearizedTarget.Local.LocalIndex = AddLinearizedLocal(pStack, Type);
            Destination = new IRLinearizedLocation(result.LinearizedTarget);
            pStack.Push(result);
        }
		public override void Linearize(Stack<IRStackObject> pStack)
		{
			IRLinearizedLocation source = new IRLinearizedLocation(this, IRLinearizedLocationType.ArrayElementAddress);
			source.ArrayElementAddress.IndexLocation = new IRLinearizedLocation(this, pStack.Pop().LinearizedTarget);
			var arraySource = pStack.Pop();
			source.ArrayElementAddress.ArrayLocation = new IRLinearizedLocation(this, arraySource.LinearizedTarget);
			if (Type == null)
			{
				Type = arraySource.Type.ArrayElementType;
			}
			if (Type == null) throw new Exception();
			source.ArrayElementAddress.ElementType = Type;
			Sources.Add(source);

			IRStackObject result = new IRStackObject();
			result.Type = ParentMethod.Assembly.AppDomain.System_IntPtr;
			result.LinearizedTarget = new IRLinearizedLocation(this, IRLinearizedLocationType.Local);
			result.LinearizedTarget.Local.LocalIndex = AddLinearizedLocal(pStack, ParentMethod.Assembly.AppDomain.System_IntPtr);
			Destination = new IRLinearizedLocation(this, result.LinearizedTarget);
			pStack.Push(result);
		}
		public override void Linearize(Stack<IRStackObject> pStack)
		{
			IRLinearizedLocation source = new IRLinearizedLocation(this, IRLinearizedLocationType.Indirect);
			var addressLocation = pStack.Pop();
			source.Indirect.AddressLocation = new IRLinearizedLocation(this, addressLocation.LinearizedTarget);
			if (Type == null)
			{
				if (addressLocation.Type.IsManagedPointerType)
					Type = addressLocation.Type.ManagedPointerType;
				else
					Type = addressLocation.Type.UnmanagedPointerType;
			}
			if (Type == null) throw new Exception();
			source.Indirect.Type = Type;
			Sources.Add(source);

			IRStackObject result = new IRStackObject();
			result.Type = Type;
			result.LinearizedTarget = new IRLinearizedLocation(this, IRLinearizedLocationType.Local);
			result.LinearizedTarget.Local.LocalIndex = AddLinearizedLocal(pStack, Type);
			Destination = new IRLinearizedLocation(this, result.LinearizedTarget);
			pStack.Push(result);
		}
        public override void Linearize(Stack <IRStackObject> pStack)
        {
            IRLinearizedLocation source = new IRLinearizedLocation(IRLinearizedLocationType.ArrayElement);

            source.ArrayElement.IndexLocation = new IRLinearizedLocation(pStack.Pop().LinearizedTarget);
            var arraySource = pStack.Pop();

            source.ArrayElement.ArrayLocation = new IRLinearizedLocation(arraySource.LinearizedTarget);
            if (Type == null)
            {
                Type = arraySource.Type.ArrayType;
            }
            source.ArrayElement.ElementType = Type;
            Sources.Add(source);

            IRStackObject result = new IRStackObject();

            result.Type             = Type;
            result.LinearizedTarget = new IRLinearizedLocation(IRLinearizedLocationType.Local);
            result.LinearizedTarget.Local.LocalIndex = AddLinearizedLocal(pStack, Type);
            Destination = new IRLinearizedLocation(result.LinearizedTarget);
            pStack.Push(result);
        }
Exemplo n.º 23
0
        public override void Linearize(Stack <IRStackObject> pStack)
        {
            IRType handleType = null;

            if (TargetType != null)
            {
                handleType = ParentMethod.Assembly.AppDomain.System_RuntimeTypeHandle;
            }
            else if (TargetMethod != null)
            {
                handleType = ParentMethod.Assembly.AppDomain.System_RuntimeMethodHandle;
            }
            else if (TargetField != null)
            {
                handleType = ParentMethod.Assembly.AppDomain.System_RuntimeFieldHandle;
            }
            else
            {
                throw new NullReferenceException();
            }

            IRLinearizedLocation value = new IRLinearizedLocation(IRLinearizedLocationType.RuntimeHandle);

            value.RuntimeHandle.HandleType   = handleType;
            value.RuntimeHandle.TargetType   = TargetType;
            value.RuntimeHandle.TargetMethod = TargetMethod;
            value.RuntimeHandle.TargetField  = TargetField;
            Sources.Add(value);

            IRStackObject result = new IRStackObject();

            result.Type             = handleType;
            result.LinearizedTarget = new IRLinearizedLocation(IRLinearizedLocationType.Local);
            result.LinearizedTarget.Local.LocalIndex = AddLinearizedLocal(pStack, handleType);
            Destination = new IRLinearizedLocation(result.LinearizedTarget);
            pStack.Push(result);
        }
 public IRInitializeObjectInstruction(IRType pType)
     : base(IROpcode.InitializeObject)
 {
     Type = pType;
 }
		public IRConvertCheckedInstruction(IRType pType, IROverflowType pOverflowType) : base(IROpcode.ConvertChecked)
		{
			Type = pType;
			OverflowType = pOverflowType;
		}
 public IRLoadTypedReferenceInstruction(IRType pType)
     : base(IROpcode.LoadTypedReference)
 {
     Type = pType;
 }
		public IRStoreArrayElementInstruction(IRType pType) : base(IROpcode.StoreArrayElement) { Type = pType; }
Exemplo n.º 28
0
		public IRCopyObjectInstruction(IRType pType) : base(IROpcode.CopyObject) { Type = pType; }
Exemplo n.º 29
0
		/// <summary>
		/// This creates a shallow clone of this method, but
		/// does a deep clone of it's instructions, parameters, and locals.
		/// </summary>
		/// <param name="newParent">The parent for the new method.</param>
		/// <returns>The clone of this method.</returns>
		public IRMethod Clone(IRType newParent)
		{
			if (newParent == null) throw new Exception();
			IRMethod m = new IRMethod(this.Assembly);

			if (this.PresolvedMethod)
				m.mParentMethod = this.GenericMethod;
			else
				m.mParentMethod = this;
			m.ParentType = newParent;
			m.GenericMethod = this.GenericMethod;
			m.GenericParameters.AddRange(this.GenericParameters);
			if (this.mInstructions.Count != 0 && Assembly.AppDomain.CurrentCompileStage >= 3)
			{
				m.mBoundInstructions = true;
				this.Instructions.ForEach(i => m.mInstructions.Add(i.Clone(m)));
				m.Instructions.FixClonedTargetInstructions();
			}
			if (this.mLocals.Count != 0 && Assembly.AppDomain.CurrentCompileStage >= 3)
			{
				m.mBoundLocals = true;
				this.mLocals.ForEach(l => m.mLocals.Add(l.Clone(m)));
			}
			this.mParameters.ForEach(p => m.mParameters.Add(p.Clone(m)));
			m.MaximumStackDepth = this.MaximumStackDepth;
			m.Name = this.Name;
			m.Flags = this.Flags;
			m.ImplFlags = this.ImplFlags;
			m.ReturnType = this.ReturnType;
			return m;
		}
Exemplo n.º 30
0
 public VarDeclaration(string id, Expression initializationExpression, IRType type)
 {
     this.Id = id;
     this.InitializationExpression = initializationExpression;
     this.Type = type;
 }
Exemplo n.º 31
0
 public IRCastInstruction(IRType pType, bool pThrowExceptionOnFailure) : base(IROpcode.Cast)
 {
     Type = pType;
     ThrowExceptionOnFailure = pThrowExceptionOnFailure;
 }
Exemplo n.º 32
0
		public static void EmitStaticConstructorCheck(LIRMethod m, IRType targetType, IRType curType, bool forceEmit = false)
		{
			if (targetType.HasStaticConstructor && (forceEmit || targetType != curType))
			{
				var con = targetType.StaticConstructor;
				if (
					(
						con.Instructions.Count == 1 &&
						con.Instructions[0].Opcode == IROpcode.Return
					) ||
					(
						con.Instructions.Count == 2 &&
						con.Instructions[0].Opcode == IROpcode.Nop &&
						con.Instructions[1].Opcode == IROpcode.Return
					)
				)
				{
					// We don't need a static constructor call
				}
				else
				{
					StaticConstructorCalledEmittableDataItem d = null;
					if (!KnownStaticConstructors.TryGetValue(targetType, out d))
					{
						d = new StaticConstructorCalledEmittableDataItem(targetType);
						m.CompileUnit.AddData(d);
						KnownStaticConstructors.Add(targetType, d);
					}
					new LIRInstructions.Comment(m, "Static Constructor Check");
					var c = m.RequestLocal(targetType.Assembly.AppDomain.System_Boolean);
					new LIRInstructions.Move(m, new Indirect(d.Label), c, targetType.Assembly.AppDomain.System_Boolean);
					Label called = new Label();
					new LIRInstructions.BranchTrue(m, c, called);
					m.ReleaseLocal(c);
					new LIRInstructions.Move(m, (LIRImm)1, new Indirect(d.Label), targetType.Assembly.AppDomain.System_Boolean);
					new LIRInstructions.Call(m, con);
					m.MarkLabel(called);
				}
			}
		}
Exemplo n.º 33
0
			public StaticConstructorCalledEmittableDataItem(IRType tp)
			{
				this.TypeName = tp.ToString();
			}
Exemplo n.º 34
0
 public IRSizeOfInstruction(IRType pType) : base(IROpcode.SizeOf)
 {
     Type = pType;
 }
Exemplo n.º 35
0
 internal override void SemanticValidation(Semantic.SemanticContext semanticContext)
 {
     returnType = new FloatType();
 }
Exemplo n.º 36
0
 public IRExpression(IRType type)
 {
     Type = type;
 }
Exemplo n.º 37
0
 public IRStoreArrayElementInstruction(IRType pType) : base(IROpcode.StoreArrayElement)
 {
     Type = pType;
 }
Exemplo n.º 38
0
		public IRUnboxInstruction(IRType pType, bool pValue) : base(IROpcode.Unbox)
		{
			Type = pType;
			GetValue = pValue;
		}
Exemplo n.º 39
0
		public int AddLinearizedLocal(Stack<IRStackObject> pStack, IRType pType)
		{
			IRLocal local = null;
			if (!LinearizedStackLocalLookup.TryGetValue(new Tuple<int, IRType>(pStack.Count, pType), out local))
			{
				local = new IRLocal(Assembly);
				local.ParentMethod = this;
				local.Type = pType;
				local.Index = Locals.Count;
				Locals.Add(local);
				LinearizedStackLocalLookup[new Tuple<int, IRType>(pStack.Count, pType)] = local;
			}
			return local.Index;
		}
Exemplo n.º 40
0
 public IdDeclarationStatement(string id, Expression initializationExpression, IRType type)
 {
     this.Id = id;
     this.InitializationExpression = initializationExpression;
     this.Type = type;
 }
Exemplo n.º 41
0
 public IRStoreObjectInstruction(IRType pType)
     : base(IROpcode.StoreObject)
 {
     Type = pType;
 }
Exemplo n.º 42
0
		public IRSizeOfInstruction(IRType pType) : base(IROpcode.SizeOf) { Type = pType; }
		public IRConvertUncheckedInstruction(IRType pType) : base(IROpcode.ConvertUnchecked) { TargetType = pType; }
Exemplo n.º 44
0
		public int AddLinearizedLocal(Stack<IRStackObject> pStack, IRType pType) { return ParentMethod.AddLinearizedLocal(pStack, pType); }
Exemplo n.º 45
0
		/// <summary>
		/// Creates a shallow copy of this field.
		/// </summary>
		/// <returns>The shallow copy.</returns>
		public IRField Clone(IRType newParent)
		{
			IRField f = new IRField(this.Assembly);

			f.Name = this.Name;
			f.Flags = this.Flags;
			f.ParentType = newParent;
			f.Type = this.Type;
			f.mParentField = this.Type == null ? this : null;

			return f;
		}
 public IRLoadArrayElementInstruction(IRType pType)
     : base(IROpcode.LoadArrayElement)
 {
     Type = pType;
 }
 public IRLoadArrayElementInstruction(IRType pType) : base(IROpcode.LoadArrayElement)
 {
     Type = pType;
 }
        public override IEnumerable <IRInstruction> GetIRInstructions(IRContext context, IRBasicBlock parentBlock)
        {
            switch (Instruction.Id)
            {
            case ArmInstructionId.ARM_INS_ADD:
                if (Instruction.Details.Operands[0].Register.Id == ArmRegisterId.ARM_REG_PC)
                {
                    yield break;
                }
                if (Instruction.DisassembleMode == ArmDisassembleMode.Thumb &&
                    Instruction.Details.Operands.Length == 2)
                {
                    yield return(new IRAssignment(parentBlock, GetIROperand(context, 0),
                                                  GetIROperand(context, 0) + GetIRSecondOperand(context, 1)));
                }
                else if (Instruction.DisassembleMode == ArmDisassembleMode.Thumb &&
                         Instruction.Details.Operands.Length == 3 &&
                         Instruction.Details.Operands[2].Type == ArmOperandType.Immediate &&
                         Instruction.Details.Operands[2].Immediate == 0)
                {
                    yield return(new IRAssignment(parentBlock, GetIROperand(context, 0),
                                                  GetIROperand(context, 1)));
                }
                else
                {
                    yield return(new IRAssignment(parentBlock, GetIROperand(context, 0),
                                                  GetIROperand(context, 1) + GetIRSecondOperand(context, 2)));
                }
                break;

            case ArmInstructionId.ARM_INS_SUB:
                if (Instruction.DisassembleMode == ArmDisassembleMode.Thumb &&
                    Instruction.Details.Operands.Length == 2)
                {
                    yield return(new IRAssignment(parentBlock, GetIROperand(context, 0),
                                                  GetIROperand(context, 0) - GetIRSecondOperand(context, 1)));
                }
                else
                {
                    yield return(new IRAssignment(parentBlock, GetIROperand(context, 0),
                                                  GetIROperand(context, 1) - GetIRSecondOperand(context, 2)));
                }
                break;

            case ArmInstructionId.ARM_INS_RSB:
                yield return(new IRAssignment(parentBlock, GetIROperand(context, 0),
                                              GetIRSecondOperand(context, 2) - GetIROperand(context, 1)));

                break;

            case ArmInstructionId.ARM_INS_AND:
                yield return(new IRAssignment(parentBlock, GetIROperand(context, 0),
                                              GetIROperand(context, 1) & GetIRSecondOperand(context, 2)));

                break;

            case ArmInstructionId.ARM_INS_ORR:
                yield return(new IRAssignment(parentBlock, GetIROperand(context, 0),
                                              GetIROperand(context, 1) | GetIRSecondOperand(context, 2)));

                break;

            case ArmInstructionId.ARM_INS_EOR:
                yield return(new IRAssignment(parentBlock, GetIROperand(context, 0),
                                              GetIROperand(context, 1) ^ GetIRSecondOperand(context, 2)));

                break;

            case ArmInstructionId.ARM_INS_BIC:
                yield return(new IRAssignment(parentBlock, GetIROperand(context, 0),
                                              GetIROperand(context, 1) & ~GetIRSecondOperand(context, 2)));

                break;

            case ArmInstructionId.ARM_INS_LSL:
                if (Instruction.DisassembleMode == ArmDisassembleMode.Arm)
                {
                    goto case ArmInstructionId.ARM_INS_MOV;
                }
                yield return(new IRAssignment(parentBlock, GetIROperand(context, 0),
                                              GetIROperand(context, 1).ShiftLeft(GetIRSecondOperand(context, 2))));

                break;

            case ArmInstructionId.ARM_INS_LSR:
                if (Instruction.DisassembleMode == ArmDisassembleMode.Arm)
                {
                    goto case ArmInstructionId.ARM_INS_MOV;
                }
                yield return(new IRAssignment(parentBlock, GetIROperand(context, 0),
                                              GetIROperand(context, 1).ShiftRightLogical(GetIRSecondOperand(context, 2))));

                break;

            case ArmInstructionId.ARM_INS_ASR:
                if (Instruction.DisassembleMode == ArmDisassembleMode.Arm)
                {
                    goto case ArmInstructionId.ARM_INS_MOV;
                }
                yield return(new IRAssignment(parentBlock, GetIROperand(context, 0),
                                              GetIROperand(context, 1).ShiftRightArithmetic(GetIRSecondOperand(context, 2))));

                break;

            case ArmInstructionId.ARM_INS_ROR:
                if (Instruction.DisassembleMode == ArmDisassembleMode.Arm)
                {
                    goto case ArmInstructionId.ARM_INS_MOV;
                }
                throw new NotImplementedException();
                break;

            case ArmInstructionId.ARM_INS_RRX:
                if (Instruction.DisassembleMode == ArmDisassembleMode.Arm)
                {
                    goto case ArmInstructionId.ARM_INS_MOV;
                }
                throw new NotImplementedException();
                break;

            case ArmInstructionId.ARM_INS_MOV:
                yield return(new IRAssignment(parentBlock, GetIROperand(context, 0),
                                              GetIRSecondOperand(context, 1)));

                break;

            case ArmInstructionId.ARM_INS_MVN:
                yield return(new IRAssignment(parentBlock, GetIROperand(context, 0),
                                              ~GetIRSecondOperand(context, 1)));

                break;

            case ArmInstructionId.ARM_INS_MUL:
                yield return(new IRAssignment(parentBlock, GetIROperand(context, 0),
                                              GetIROperand(context, 1) * GetIROperand(context, 2)));

                break;

            case ArmInstructionId.ARM_INS_MLA:
                yield return(new IRAssignment(parentBlock, GetIROperand(context, 0),
                                              GetIROperand(context, 1) * GetIROperand(context, 2) + GetIROperand(context, 3)));

                break;

            case ArmInstructionId.ARM_INS_SMULL:
                yield return(new IRAssignment(parentBlock,
                                              GetIROperand(context, 0),
                                              (GetIROperand(context, 2).Cast(IRPrimitive.S32).Cast(IRPrimitive.S64) *
                                               GetIROperand(context, 3).Cast(IRPrimitive.S32).Cast(IRPrimitive.S64)).Cast(IRPrimitive.U32)));

                yield return(new IRAssignment(parentBlock,
                                              GetIROperand(context, 1),
                                              (GetIROperand(context, 2).Cast(IRPrimitive.S32).Cast(IRPrimitive.S64) *
                                               GetIROperand(context, 3).Cast(IRPrimitive.S32).Cast(IRPrimitive.S64)).ShiftRightLogical(32)
                                              .Cast(IRPrimitive.U32)));

                break;

            case ArmInstructionId.ARM_INS_LDR:
            case ArmInstructionId.ARM_INS_LDRH:
            case ArmInstructionId.ARM_INS_LDRSH:
            case ArmInstructionId.ARM_INS_LDRB:
            case ArmInstructionId.ARM_INS_LDRSB:
            {
                IRType type = IRPrimitive.Void;
                switch (Instruction.Id)
                {
                case ArmInstructionId.ARM_INS_LDR:
                    type = IRPrimitive.U32;
                    break;

                case ArmInstructionId.ARM_INS_LDRH:
                    type = IRPrimitive.U16;
                    break;

                case ArmInstructionId.ARM_INS_LDRSH:
                    type = IRPrimitive.S16;
                    break;

                case ArmInstructionId.ARM_INS_LDRB:
                    type = IRPrimitive.U8;
                    break;

                case ArmInstructionId.ARM_INS_LDRSB:
                    type = IRPrimitive.S8;
                    break;
                }

                if (Instruction.Details.WriteBack)
                {
                    throw new NotImplementedException("Unimplemented instruction!");
                }


                if (Instruction.Details.Operands[1].Memory.Base.Id == ArmRegisterId.ARM_REG_SP)
                {
                    yield return(new IRAssignment(parentBlock, GetIROperand(context, 0),
                                                  context.VariableMapping[VariableUses.First(v => v.Location == VariableLocation.Stack)]));

                    break;
                }

                if (Instruction.Details.Operands[1].Memory.Index == null &&
                    Instruction.Details.Operands[1].Memory.Displacement == 0)
                {
                    yield return(new IRAssignment(parentBlock, GetIROperand(context, 0),
                                                  new IRDerefExpression(type, GetIROperand(context, 1)).Cast(IRPrimitive.U32)));

                    break;
                }
                else if (Instruction.Details.Operands[1].Memory.Index == null)
                {
                    var deref = new IRDerefExpression(type,
                                                      GetIROperand(context, 1) + (uint)Instruction.Details.Operands[1].Memory.Displacement);
                    yield return(new IRAssignment(parentBlock, GetIROperand(context, 0),
                                                  deref.Cast(IRPrimitive.U32)));

                    break;
                }
                else
                {
                    if (Instruction.Details.Operands[1].ShiftOperation == ArmShiftOperation.Invalid ||
                        (Instruction.Details.Operands[1].ShiftOperation == ArmShiftOperation.ARM_SFT_LSL &&
                         Instruction.Details.Operands[1].ShiftValue == 0))
                    {
                        var deref = new IRDerefExpression(type,
                                                          GetIROperand(context, 1) + GetIROperand(context, 2));
                        yield return(new IRAssignment(parentBlock, GetIROperand(context, 0),
                                                      deref.Cast(IRPrimitive.U32)));

                        break;
                    }
                    else
                    {
                        throw new NotImplementedException("Unimplemented instruction!");
                    }
                }
            }

            case ArmInstructionId.ARM_INS_STR:
            case ArmInstructionId.ARM_INS_STRH:
            case ArmInstructionId.ARM_INS_STRB:
            {
                var type = IRPrimitive.Void;
                switch (Instruction.Id)
                {
                case ArmInstructionId.ARM_INS_STR:
                    type = IRPrimitive.U32;
                    break;

                case ArmInstructionId.ARM_INS_STRH:
                    type = IRPrimitive.U16;
                    break;

                case ArmInstructionId.ARM_INS_STRB:
                    type = IRPrimitive.U8;
                    break;
                }

                if (Instruction.Details.WriteBack)
                {
                    throw new NotImplementedException("Unimplemented instruction!");
                }


                if (Instruction.Details.Operands[1].Memory.Base.Id == ArmRegisterId.ARM_REG_SP)
                {
                    yield return(new IRAssignment(parentBlock,
                                                  context.VariableMapping[VariableDefs.First(v => v.Location == VariableLocation.Stack)],
                                                  GetIROperand(context, 0)));

                    break;
                }

                if (Instruction.Details.Operands[1].Memory.Index == null &&
                    Instruction.Details.Operands[1].Memory.Displacement == 0)
                {
                    yield return(new IRStore(parentBlock, type, GetIROperand(context, 1),
                                             GetIROperand(context, 0)));

                    break;
                }
                else if (Instruction.Details.Operands[1].Memory.Index == null)
                {
                    yield return(new IRStore(parentBlock, type,
                                             GetIROperand(context, 1) + (uint)Instruction.Details.Operands[1].Memory.Displacement,
                                             GetIROperand(context, 0)));

                    break;
                }
                else
                {
                    if (Instruction.Details.Operands[1].ShiftOperation == ArmShiftOperation.Invalid ||
                        (Instruction.Details.Operands[1].ShiftOperation == ArmShiftOperation.ARM_SFT_LSL &&
                         Instruction.Details.Operands[1].ShiftValue == 0))
                    {
                        yield return(new IRStore(parentBlock, type,
                                                 GetIROperand(context, 1) + GetIROperand(context, 2),
                                                 GetIROperand(context, 0)));

                        break;
                    }
                    else
                    {
                        throw new NotImplementedException("Unimplemented instruction!");
                    }
                }
            }

            case ArmInstructionId.ARM_INS_BL:
                yield return(new IRAssignment(parentBlock,
                                              context.VariableMapping[VariableDefs
                                                                      .First(v => v.Location == VariableLocation.Register && v.Address == 0)],
                                              new IRCallExpression(IRPrimitive.U32, $"sub_{Instruction.Details.Operands[0].Immediate:X08}",
                                                                   context.VariableMapping[VariableUses
                                                                                           .First(v => v.Location == VariableLocation.Register && v.Address == 0)],
                                                                   context.VariableMapping[VariableUses
                                                                                           .First(v => v.Location == VariableLocation.Register && v.Address == 1)],
                                                                   context.VariableMapping[VariableUses
                                                                                           .First(v => v.Location == VariableLocation.Register && v.Address == 2)],
                                                                   context.VariableMapping[VariableUses
                                                                                           .First(v => v.Location == VariableLocation.Register && v.Address == 3)]
                                                                   )));

                break;

            case ArmInstructionId.ARM_INS_BLX:
                if (Instruction.Details.Operands[0].Type == ArmOperandType.Immediate)
                {
                    goto case ArmInstructionId.ARM_INS_BL;
                }
                yield return(new IRAssignment(parentBlock,
                                              context.VariableMapping[VariableDefs
                                                                      .First(v => v.Location == VariableLocation.Register && v.Address == 0)],
                                              new IRCallExpression(IRPrimitive.U32, ((Variable)Operands[0].op).Name,
                                                                   context.VariableMapping[VariableUses
                                                                                           .First(v => v.Location == VariableLocation.Register && v.Address == 0)],
                                                                   context.VariableMapping[VariableUses
                                                                                           .First(v => v.Location == VariableLocation.Register && v.Address == 1)],
                                                                   context.VariableMapping[VariableUses
                                                                                           .First(v => v.Location == VariableLocation.Register && v.Address == 2)],
                                                                   context.VariableMapping[VariableUses
                                                                                           .First(v => v.Location == VariableLocation.Register && v.Address == 3)]
                                                                   )));

                break;

            case ArmInstructionId.ARM_INS_LDM:
                if (Instruction.Details.Operands[0].Register.Id == ArmRegisterId.ARM_REG_SP &&
                    Instruction.Details.WriteBack)
                {
                    break;
                }
                goto default;

            case ArmInstructionId.ARM_INS_STMDB:
                if (Instruction.Details.Operands[0].Register.Id == ArmRegisterId.ARM_REG_SP &&
                    Instruction.Details.WriteBack)
                {
                    break;
                }
                goto default;

            case ArmInstructionId.ARM_INS_PUSH:
            case ArmInstructionId.ARM_INS_POP:
            case ArmInstructionId.ARM_INS_CMP:
            case ArmInstructionId.ARM_INS_B:
            case ArmInstructionId.ARM_INS_BX:
                break;

            default:
                throw new NotImplementedException("Unimplemented instruction!");
            }
        }
Exemplo n.º 49
0
 public IRLoadTypedReferenceInstruction(IRType pType) : base(IROpcode.LoadTypedReference)
 {
     Type = pType;
 }
Exemplo n.º 50
0
 private int GetTypeSizeInBytes(IRType type)
 {
     return(GetTypeSizeInWords(type) * 4);
 }
Exemplo n.º 51
0
 public Parameter(IRType type, string id)
 {
     // TODO: Complete member initialization
     this.type = type;
     this.id   = id;
 }
Exemplo n.º 52
0
 public IRCastInstruction(IRType pType, bool pThrowExceptionOnFailure)
     : base(IROpcode.Cast)
 {
     Type = pType;
     ThrowExceptionOnFailure = pThrowExceptionOnFailure;
 }
Exemplo n.º 53
0
		public IRNewArrayInstruction(IRType pElementType) : base(IROpcode.NewArray) { ElementType = pElementType; }
Exemplo n.º 54
0
		public virtual void Transform(IRType type)
		{
			throw new NotImplementedException("This pass doesn't implement a transform for types!");
		}
Exemplo n.º 55
0
 public IRConvertCheckedInstruction(IRType pType, IROverflowType pOverflowType) : base(IROpcode.ConvertChecked)
 {
     Type         = pType;
     OverflowType = pOverflowType;
 }
Exemplo n.º 56
0
 public IRBoxInstruction(IRType pType) : base(IROpcode.Box)
 {
     Type = pType;
 }
Exemplo n.º 57
0
		public IRBoxInstruction(IRType pType) : base(IROpcode.Box) { Type = pType; }
Exemplo n.º 58
0
 public IRNewArrayInstruction(IRType pType) : base(IROpcode.NewArray)
 {
     Type = pType;
 }
Exemplo n.º 59
0
 public IRLoadObjectInstruction(IRType pType)
     : base(IROpcode.LoadObject)
 {
     Type = pType;
 }
Exemplo n.º 60
0
 public IRNewArrayInstruction(IRType pType)
     : base(IROpcode.NewArray)
 {
     Type = pType;
 }