Example #1
0
 private void RewriteAlu(Operator op)
 {
     var dst = RewriteOp(instrCur.Op3);
     var src1 = RewriteOp(instrCur.Op1);
     var src2 = RewriteOp(instrCur.Op2);
     emitter.Assign(dst, new BinaryExpression(op, PrimitiveType.Word32, src1, src2));
 }
Example #2
0
 private void RewriteRevBinOp(Operator op, bool setflags)
 {
     var opDst = this.Operand(instr.Dst);
     var opSrc1 = this.Operand(instr.Src2);
     var opSrc2 = this.Operand(instr.Src1);
     ConditionalAssign(opDst, new BinaryExpression(op, PrimitiveType.Word32, opSrc1, opSrc2));
     if (setflags)
     {
         ConditionalAssign(frame.EnsureFlagGroup(0x1111, "SZCO", PrimitiveType.Byte), emitter.Cond(opDst));
     }
 }
Example #3
0
		public bool Match(BinaryExpression binExp)
		{
			cLeft = binExp.Left as Constant; 
			cRight = binExp.Right as Constant;
			if (cLeft != null && cRight != null && binExp.Operator != Operator.Eq)
			{
				if (!cLeft.IsReal && !cRight.IsReal)
				{
					op = binExp.Operator;
					return true;
				}
			}
			return false;
		}
Example #4
0
		public bool Match(BinaryExpression b)
		{
			op = b.Operator;
			if (op != Operator.Shl && op != Operator.Shr && op != Operator.Sar)
				return false;
			c1 = b.Right as Constant;
			if (c1 == null)
				return false;
			BinaryExpression b2 = b.Left as BinaryExpression;
			if (b2 == null)
				return false;
			if (op != b2.Operator)
				return false;
			c2 = b2.Right as Constant;
			if (c2 == null)
				return false;
			e = b2.Left;
			return true;
		}
Example #5
0
		public bool Match(BinaryExpression b)
		{
			if (b.Operator != Operator.Shl)
				return false;
			cShift = b.Right as Constant;
			if (cShift == null)
				return false;

			b = b.Left as BinaryExpression;
			if (b == null)
				return false;

			if (b.Operator != Operator.SMul && b.Operator != Operator.UMul && b.Operator != Operator.IMul)
				return false;
			op = b.Operator;
			cMul = b.Right as Constant;
			if (cMul == null)
				return false;

			e = b.Left;
			return true;
		}
		public void VisitBinaryExpression(Operator op, DataType dataType, Expression left, Expression right)
		{
			if (op == Operator.IAdd || op == Operator.ISub)
			{
				// Handle mem[x+const] case. Array accesses of the form
				// mem[x + (i * const) + const] will have been converted
				// to ArrayAccesses by a previous stage.

				Constant offset = right as Constant;
				if (offset != null)
				{
                    if (op == Operator.ISub)
                        offset = offset.Negate();
					var iv = GetInductionVariable(left);
                    if (iv != null)
                    {
                        VisitInductionVariable((Identifier) left, iv, offset);
                        return;
                    }
                    else if (left is BinaryExpression)
                    {
                        var bl = (BinaryExpression) left;
                        //$HACK: we've already done the analysis of the mul operator!
                        // We should be using the returned value of trait collection.
                        if (bl.Operator is IMulOperator)
                        {
                            arrayContext = true;
                            EmitAccessTrait(basePointer, left, dataType.Size, offset.ToInt32());
                            return;
                        }
                    }
                    EmitAccessTrait(basePointer, left, dataType.Size, offset.ToInt32());
					return;
				}

				// Handle odd mem[x + y] case; perhaps a later stage can detect that x (or y)
				// is a pointer and therefore y isn't.

				EmitAccessTrait(basePointer, left, dataType.Size, 0);
				return;
			}
            throw new TypeInferenceException("Couldn't generate address traits for binary operator {0}.", op);
		}
Example #7
0
 private void RewriteAluCc(Operator op)
 {
     RewriteAlu(op);
     var dst = RewriteOp(instrCur.Op3);
     EmitCc(dst);
 }
 private bool IsSignedOperator(Operator op)
 {
     return
         op == Operator.Lt || op == Operator.Le ||
         op == Operator.Gt || op == Operator.Ge;
 }
		private static bool IsAddOrSub(Operator op)
		{
			return op == Operator.IAdd || op == Operator.ISub;
		}
Example #10
0
 private static bool IsIAddOrISub(Operator op)
 {
     return (op == Operator.IAdd || op == Operator.ISub);
 }
Example #11
0
 public int FindUsingInstruction2(StatementList stms, int i, Operator next)
 {
     for (++i; i < stms.Count; ++i)
     {
         var ass = stms[i].Instruction as Assignment;
         if (ass == null)
             continue;
         var bin = ass.Src as BinaryExpression;
         if (bin == null)
             continue;
         if (bin.Operator == next)
             return i;
         if (IsCarryFlag(ass.Dst))
             return -1;
     }
     return -1;
 }
        private void RewriteCtrBranch(bool updateLinkRegister, bool toLinkRegister, Operator decOp, bool ifSet)
        {
            var ctr = frame.EnsureRegister(arch.ctr);
            var ccOp = instr.op1 as ConditionOperand;
            Expression dest;

            Expression cond = new BinaryExpression(
                decOp, 
                PrimitiveType.Bool,
                ctr,
                Constant.Zero(ctr.DataType));

            if (ccOp != null)
            {
                Expression test = emitter.Test(
                    CcFromOperand(ccOp),
                    frame.EnsureRegister(CrFromOperand(ccOp)));
                if (!ifSet)
                    test = test.Invert();
                cond = emitter.Cand(cond, test);
                dest = RewriteOperand(instr.op2);
            }
            else
            {
                dest = RewriteOperand(instr.op1);
            }
            
            emitter.Assign(ctr, emitter.ISub(ctr, 1));
            if (updateLinkRegister)
            {
                emitter.If(
                    cond,
                    new RtlCall(dest, 0, RtlClass.ConditionalTransfer));
            }
            else
            {
                emitter.Branch(
                    cond,
                    (Address)dest,
                    RtlClass.ConditionalTransfer);
            }
        }